[Haskell-cafe] In for a penny, in for a pound.
David F. Place
d at vidplace.com
Sun Jan 8 20:34:47 EST 2006
Hi All,
Regarding the Fannkuch Shootout Entry:
If we are willing to specialize flop in the way shown on the wiki,
another 8% can be gained by similarly specializing rotate:
rotate 2 (x1:x2:xs) = x2:x1:xs
rotate 3 (x1:x2:x3:xs) = x2:x3:x1:xs
rotate 4 (x1:x2:x3:x4:xs) = x2:x3:x4:x1:xs
rotate 5 (x1:x2:x3:x4:x5:xs) = x2:x3:x4:x5:x1:xs
rotate 6 (x1:x2:x3:x4:x5:x:6:xs) = x2:x3:x4:x5:x:6:x1:xs
rotate 7 (x1:x2:x3:x4:x5:x:6:x7:xs) = x2:x3:x4:x5:x:6:x7:x1:xs
rotate 8 (x1:x2:x3:x4:x5:x:6:x7:x8:xs) = x2:x3:x4:x5:x:6:x7:x8:x1:xs
rotate 9 (x1:x2:x3:x4:x5:x:6:x7:x8:x9:xs) = x2:x3:x4:x5:x:
6:x7:x8:x9:x1:xs
rotate 10 (x1:x2:x3:x4:x5:x:6:x7:x8:x9:x10:xs) = x2:x3:x4:x5:x:
6:x7:x8:x9:x10:x1:xs
rotate n (x:xs) = rot' n xs
where rot' 1 xs = x:xs
rot' n (x:xs) = x:rot' (n-1) xs
Cheers, David
--------------------------------
David F. Place
mailto:d at vidplace.com
More information about the Haskell-Cafe
mailing list