Skip to content

Instantly share code, notes, and snippets.

@axelarge
Last active December 27, 2015 06:39
Show Gist options
  • Save axelarge/7283473 to your computer and use it in GitHub Desktop.
Save axelarge/7283473 to your computer and use it in GitHub Desktop.
// Shortest version
document.write("1,2,3,5,8,13,21,34,55,89,144,233")
// Shortest version without cheating
for(a=[],x=y=1;y<301;t=x,x=y,y+=t)a.push(y);document.write(a)
// If it's ok to start with 1,1, this can be shortened by another char:
for(a=[x=y=1];y<301;t=x,x=y,y+=t)a.push(y);document.write(a)
// Shortest version that doesn't introduce global variables
for(var a=[],x=1,y=1,t;y<301;t=x,x=y,y+=t)a.push(y);document.write(a)
// Shortest IIFE recursive version (also no globals; could be shortened by using them, but then one might as well use one of the above)
(function f(a,l){var x=a[l-1]+a[l-2];x<301?f(a,a.push(x)):document.write(a)})([1,2],2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment