# Calculate your Icy Tower Score

Do you know Icy Tower ? Here is a gameplay example of what i'm talking about

The game concept is simple : you play as Harold the Homeboy, and your goal is to jump from floors to floors to go as high as possible without falling and getting off-screen ( the camera goes higher following you or at a speed that gets faster over time, and does not go down ).

If you get off-screen ( fell or camera was too fast for you to keep up ), it's game over, and then you get a score.

Your task is to write a program/function/whatever that calculates the score based on a input.

The formula is simple : $$\Score = 10 * LastFloor + Sum(ValidComboList.TotalFloorJumped^2)$/extract_tex] ### What is a valid combo ? You have to jump from floors to floors to go as high as possible. Sometimes, you will the to the floor $$\F+1\$$ But sometimes, if you go fast enough ( faster = higher jumps ), you will do a multi-floor jump, and skip some floors between. A combo is a sequence of multi-floors jump. To be considered as a multi-floor jump, you need to skip at least 1 floor, meaning you need to get to the floor $$\F+x\$$ where $$\x >= 2\$$ See that you always jump to $$\x >= 2\$$, jumps to lower floors with floors skipped between are not considered valid A combo ends when : • You jump to the floor $$\F+x\$$ where $$\(x < 0) | (x == 1)\$$ • You wait more than about 3 seconds on the same floor ( in the gameplay video, you can see on the left a "timing bar", and the combo ends if it gets empty ) • You get off-screen ( falling or not jumping fast enough ) In this challenge, to simplify a bit, we will consider that, when the input indicates a "jump to the same floor $$\F+0\$$" means that the 3 second timeout is passed, so the two rules will be simplified in one : "You jump to the floor $$\F+x\$$ where $$\x<2\$$ A valid combo ( a combo that will be used for the score calculation ) : • The number of multi-floor jumps $$\N >= 2\$$ • The combo MUST NOT end with going off-screen. If you go off-screen, the combo is invalid and won't included in the score. Said in another way : The combo must be followed by a jump to another floor or by waiting about 3 seconds. In this challenge, since we consider that jumping to the same floor is waiting 3 seconds, the rules to make a valid combo is "You must jump to another floor" Since you need at least 2 multi-floor jumps to make a combo, the number of total floor jumped is higher than 4 ### The input The input will be a "list" of integers ( or STDIN input ) which represents the sequence of floor jumped on. For example, the start to the video linked previously in the post will look like : [5 4 5 10 12 15 17 18 19 20 23 24 25 28 29 30 31 34 35 36 37 34 35 36 37 38 39 40 43 48 45 46 50 55 54]  for the first floors. The start floor is ommited. This input end on floor 54 meaning he went off-screen just after that, without getting to another floor, so there's the game over ( this was not the case in the video since he went to the floor 232, so the array accurately representing the sequence would end with 232 at the end ) Here, with this input, you must output $$\829\$$, because : $$\Score = 10 * 54 + 12^2 + 8^2 + 9^2\$$ Because the last floor Harold was on is the floor number 54, and he made 3 valid combos : • First combo of 4 multi-floor jumps with a total of 12 floors jumped in that combo • Second combo of 2 multi-floor jumps with a total of 8 floors jumped in that combo • The last combo of 2 multi-floor jumps with a total of 9 floors jumped in that combo ## Test cases : [] => Undefined Behavior [5] => $$\50\$$ [4 0 5 6 8 10 10] => $$\10*10 + 4^2 = 116\$$ Correction applied [4 0 5 6 6 6 6 8 10 10] => $$\10*10 + 4^2 = 116\$$ ( Here, Harold just waited 9 seconds. No combo to validate, but still a legitimate input ) Correction applied [5 7 10 10 11 9 14 17 15 16] => $$\10*16 + 10^2 + 8^2 = 324\$$ [5 4 5 10 12 15 17 18 19 20 23 24 25 28 29 30 31 34 35 36 37 34 35 36 37 38 39 40 43 48 45 46 50 55 54] => $$\10 * 54 + 12^2 + 8^2 + 9^2 = 829\$$ [5 4 5 10 12 15 17 18 19 20 23 24 25 28 29 30 31 34 35 36 37 34 35 36 37 38 39 40 43 48 45 46 50 55 56] => $$\10 * 54 + 12^2 + 8^2 + 9^2 = 849\$$ [5 4 5 10 12 15 17 18 19 20 23 24 25 28 29 30 31 34 35 36 37 34 35 36 37 38 39 40 43 48 45 46 50 55 55] => $$\10 * 55 + 12^2 + 8^2 + 9^2 = 839\$$ ( harold waited 3 seconds to validate the combo ) [5 4 5 10 12 15 17 18 19 20 23 24 25 28 29 30 31 34 35 36 37 34 35 36 37 38 39 40 43 48 45 46 50 55] => $$\10 * 55 + 12^2 + 8^2 = 758\$$ ( because harold went off-screen without confirming the combo) If you want, you can condsider that the input always starts with zero ( since the game start at floor 0 ), if this is the case, say it in your answer ## Rules : Edit : Correction applied on some test cases ## 4 Answers # Japt, 2827 24 bytes -1 byte from @kamil <3, -3 from @Shaggy :o. These guys are genius ä- ô>2n)¯J lÉ mx x²+A*Uo  # Japt, 28 bytes, prev approach Naive Way. Important Input should start with 0 to work correctly (in some cases) o *A+UóÈÄ¦Y©Y>XÃl>2 ®ä- xÃxp  # JavaScript (ES7), 72 bytes a=>a.map(v=>(v-p>1?r=c++?r:p:t+=(c>1)*(c=0,p-r)**2,p=v),t=c=p=0)&&t+p*10  Try it online! ### Commented a => // a[] = input array a.map(v => ( // for each value v in a[]: v - p > 1 ? // if the difference with the previous floor is greater than 1: r = c++ ? // increment the combo counter c; if c was not equal to 0: r // leave r unchanged : // else: p // set r (reference floor) to the previous floor p : // else: t += // update t only ... (c > 1) * ( // ... if we have a multi-floor jump combo of at least 2 jumps c = 0, // reset c to 0 p - r // compute the total number of floors jumped in the combo ) ** 2, // square it and add it to t p = v // set the previous value p to v ), // t = c = p = 0 // start with t = c = p = 0 ) && // end of map() t + p * 10 // add the final floor multiplied by 10 to t  # J, 54 bytes [:((10*{:)+1#.[:}:]((2<#)*[:*:{:-{.);.1~1,2>2-~/$)0&,


Try it online!

May add explanation later. For now here's an ungolfed and a parsed version:

### ungolfed

[: ((10 * {:) + 1 #. [: }: ] ((2 < #) * [: *: {: - {.);.1~ 1 , 2 > 2 -~/\ ]) 0&,


### parsed

┌──┬─────────────────────────────────────────────────────────────────────────────────────────────────────────┬───────┐
│[:│┌─────────┬─┬───────────────────────────────────────────────────────────────────────────────────────────┐│┌─┬─┬─┐│
│  ││┌──┬─┬──┐│+│┌─┬──┬────────────────────────────────────────────────────────────────────────────────────┐│││0│&│,││
│  │││10│*│{:││ ││1│#.│┌──┬──┬────────────────────────────────────────────────────────────────────────────┐│││└─┴─┴─┘│
│  ││└──┴─┴──┘│ ││ │  ││[:│}:│┌─┬────────────────────────────────────────┬───────────────────────────────┐││││       │
│  ││         │ ││ │  ││  │  ││]│┌────────────────────────────────────┬─┐│┌─┬─┬─────────────────────────┐│││││       │
│  ││         │ ││ │  ││  │  ││ ││┌─────────────────────────────┬──┬─┐│~│││1│,│┌─┬─┬───────────────────┐││││││       │
│  ││         │ ││ │  ││  │  ││ │││┌───────┬─┬─────────────────┐│;.│1││ │││ │ ││2│>│┌─┬─────────────┬─┐│││││││       │
│  ││         │ ││ │  ││  │  ││ ││││┌─┬─┬─┐│*│┌──┬──┬─────────┐││  │ ││ │││ │ ││ │ ││2│┌─────────┬─┐│]││││││││       │
│  ││         │ ││ │  ││  │  ││ │││││2│<│#││ ││[:│*:│┌──┬─┬──┐│││  │ ││ │││ │ ││ │ ││ ││┌─────┬─┐│\││ ││││││││       │
│  ││         │ ││ │  ││  │  ││ ││││└─┴─┴─┘│ ││  │  ││{:│-│{.││││  │ ││ │││ │ ││ │ ││ │││┌─┬─┐│/││ ││ ││││││││       │
│  ││         │ ││ │  ││  │  ││ ││││       │ ││  │  │└──┴─┴──┘│││  │ ││ │││ │ ││ │ ││ ││││-│~││ ││ ││ ││││││││       │
│  ││         │ ││ │  ││  │  ││ ││││       │ │└──┴──┴─────────┘││  │ ││ │││ │ ││ │ ││ │││└─┴─┘│ ││ ││ ││││││││       │
│  ││         │ ││ │  ││  │  ││ │││└───────┴─┴─────────────────┘│  │ ││ │││ │ ││ │ ││ ││└─────┴─┘│ ││ ││││││││       │
│  ││         │ ││ │  ││  │  ││ ││└─────────────────────────────┴──┴─┘│ │││ │ ││ │ ││ │└─────────┴─┘│ ││││││││       │
│  ││         │ ││ │  ││  │  ││ │└────────────────────────────────────┴─┘││ │ ││ │ │└─┴─────────────┴─┘│││││││       │
│  ││         │ ││ │  ││  │  ││ │                                        ││ │ │└─┴─┴───────────────────┘││││││       │
│  ││         │ ││ │  ││  │  ││ │                                        │└─┴─┴─────────────────────────┘│││││       │
│  ││         │ ││ │  ││  │  │└─┴────────────────────────────────────────┴───────────────────────────────┘││││       │
│  ││         │ ││ │  │└──┴──┴────────────────────────────────────────────────────────────────────────────┘│││       │
│  ││         │ │└─┴──┴────────────────────────────────────────────────────────────────────────────────────┘││       │
│  │└─────────┴─┴───────────────────────────────────────────────────────────────────────────────────────────┘│       │
└──┴─────────────────────────────────────────────────────────────────────────────────────────────────────────┴───────┘


# C++, 202190188187184181177170166 164 bytes

int f(int*a,int l){int r=a[l-1]*10,i=0,j,k,s;for(;i<l;i++)for(j=l;s=j-->i;s&&j-i>1&&~j+l?r+=(a[i]-a[j])*(a[i]-a[i=j]),j=l:0)for(k=j;k-i;)s*=a[k--]-a[k]>1;return r;}


Try it online!

Input must begin with 0.

-11 bytes thanks to @ceilingcat

• Updated, @ceilingcat Jan 12 '19 at 22:06