Sum-It is a language I created (quite late) for the Language Design Contest in TNB, for which the theme was "Range". Naturally I interpreted this as "Mountain Range" and created a language about mountains.
Sum-It code takes the form of several ASCII art mountains, using only the /
and \
characters. The mountains are then parsed to a number representing the size of the mountain, and that number is used as either an opcode or a data value.
While developing the parser for this language, I noticed something quite interesting regarding mountain sizes:
The size of a standalone (ie: not overlapped) mountain is equivalent to double the sum of all integers lower than the mountain's height in characters.
So for example, the following mountain:
/\ <- 1
/ \ <- 2
/ \ <- 3
Has a character height of 3. Its "size" as far as Sum-It is concerned, is calculated as such:
/\
/##\
/####\
And is therefore 6.
This lines up with the above formula, because the sum of all integers lower than 3 is 1 + 2 = 3
, which doubled is 6.
The challenge
Your challenge is, given a positive integer representing a mountain's height, output the Sum-It size of the mountain, using the above formula.
Scoring
This is code-golf, so fewest bytes wins!
Test Cases
Test cases are represented as input => output => formula
1 => 0 => 2()
2 => 2 => 2(1)
3 => 6 => 2(1+2)
4 => 12 => 2(1+2+3)
5 => 20 => 2(1+2+3+4)
6 => 30 => 2(1+2+3+4+5)
7 => 42 => 2(1+2+3+4+5+6)
8 => 56 => 2(1+2+3+4+5+6+7)
9 => 72 => 2(1+2+3+4+5+6+7+8)
10 => 90 => 2(1+2+3+4+5+6+7+8+9)
15 => 210 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14)
20 => 380 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19)
25 => 600 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24)
30 => 870 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29)
40 => 1560 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39)
50 => 2450 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49)
60 => 3540 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59)
70 => 4830 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69)
80 => 6320 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79)
90 => 8010 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89)
100 => 9900 => 2(1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+36+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+94+95+96+97+98+99)