Haskell, 157 * 0.9 = 141.3 153 * 0.9 = 137.7many previous byte counts 139 130 * 0.9 = 125.1117 bytes
f#[]=[];f#f#(a:b)=f a:f#bf#b;f#x=x
n f x (f&x)1=f x;n f x i=f$n f xx;(if&x)i=f$f&x$i-1)
i=id
r x=i%(1,x)
f (g x[]=x;f ?x)[]=x;(g ?x)(a:b)=g(f g x b?x$b)a
f%(a,b)|a>b=[]|1<2=f a:f%(a+1,b)
n&
is nest: n ((*2) & 3) 4
-> 48
f?
is fold: f ((+) ? 0) [1,2,3,4]
-> 10
As requested an ungolfed version with comments. Note, &
and ?
are ternary infix operators, which require additional parentheses when called or pattern matched.
f # [] = [] -- map on the empty list is the empty list
f # (a:b) = f a : f#b -- map on a list (a->head, b->tail) is f a in front of mapping f to b
n (f & x) 1 = f x -- nesting one time is f x
n (f & x) i = f (n$ ff&x x$ (i-1)) -- nesting i times is f (nesting one time less)
i=id -- apply is just in Haskell just the identity function
r x = i % (1,x) -- defined via the "table" of the identity function from 1 to x
f (g ? x) [] = x = x -- folding the empty list is x
f (g ? x) (a:b) = g (f g x b?x$b) a -- folding g into a list (a->head, b->tail) is g applied to (folding g into b) and a
f % (a,b)
|a>b = [] -- if iMin is greater than iMax, the table is empty
|otherwise = f a : f%(a+1,b) -- otherwise f a in front of the table with iMin increased by one
Thanks to @dfeuer and @Zgarb for some useful hints