Skip to content

Instantly share code, notes, and snippets.

@jswartwood
Forked from samtsai/Premise.md
Created March 15, 2012 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswartwood/2044436 to your computer and use it in GitHub Desktop.
Save jswartwood/2044436 to your computer and use it in GitHub Desktop.
AE Code Golf #1

Fibonacci Sequence

Classics series

Print the Fibonacci series (the first 10 values) separated by spaces. If you've ever taken a Computer Science class, you should be all over this one.

Rules

Solve the "Premise".

The smaller (bytes) the code, the better; if no one can shrink further, you win! It is good form to provide a (documented) non-minified version of your code, but it isn't required.

The programming language is dev's choice; however, languages should be compared both in isolation and overall (eg. your solution may be the best PHP solution, but Ruby may best it).

Add solutions in an appropriately suffixed solve file (eg. solve.js, solve.py).

Enjoy.

for(s=a=b=1;a<55;c=b,b+=a,a=c)s+=" "+b;console.log(s)
// 53 chars
for (
// Define s (string), a & b (fibs)
s = a = b = 1;
// While not at the 10th fib number (is this cheating?)
a < 55;
// Swap a with b and make add a + b into new b val
c = b,
b += a,
a = c
)
// Update string w/ b val
s += " " + b;
// Hooray! write results.
console.log(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment