#Pyth, 19 22
Pyth, 19 22
u-G*H^_!%GH/GHrhQ2Q
A fairly naive implementation of @PeterTaylor's golfscript answer.
This uses the same tricks to convert a while loop into a fold as the other Pyth program below does.
u+G**H!%GHty%/GH2rhQ2Q
A naive copy of @Sp3000's algorithm translated to Pyth.
Uses reduce (python's name for fold) to emulate the while loop. It enumerates over the range(input, 2)
which in Pyth works out to range(2, input)[::-1]
. The other Pyth-related golfs involves using not
instead of <2
and using y
's hidden mode of doubling the value of numeric arguments.