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.
-
-
Save jswartwood/2044436 to your computer and use it in GitHub Desktop.
AE Code Golf #1
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(s=a=b=1;a<55;c=b,b+=a,a=c)s+=" "+b;console.log(s) | |
// 53 chars |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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