Pyth, 38 35 34 bytes
+.Rs.aM-M.:m.jF.Dx`ciUTT1b3z2 2"cm
Demonstration.
Indexing into the string of a float idea thanks to @Dennis.
Explanation, on the phony input 15.0:
First, we take the input. It is implicitly stored in z. '15.0'
We map this list as follows: m.jF.Dx`ciUTT1k3z.
UT: We g...
Consider the process of:
Taking a non-negative integer N.
e.g. 27.
Spliting it into integers N - floor(N/2) and floor(N/2) (a 'bigger' and 'smaller' half) and writing them in that order.
e.g.27 becomes 14 13.
Removing the space to join the integers into a new, much larger integer.
e.g. 14 13 be...
@trichoplax We could have a bunch of meta snippets for translating languages into JS, then Stack Snippet koths could have more allowed languages.
Anonymous
does anybody remember in perl how you could use foreach only for, for example, the third through sixth elements of an array rather than the whole thing? I don't know what keywords to use in google for this.
This is perl. There are more than one way to do it, always. Such as an array slice:
for (@arr[1 .. $#arr]) # for and foreach are exactly the same in perl
You can use shift as Andy Lester suggested, however this will of course alter your original array.