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 samtsai/2031266 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 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
f=[0,1];for(i=2;i<10;i++)f[i]=f[i-1]+fb[i-2];console.log(f); | |
// 60 characters |
This file contains 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
fb=[]; | |
for(i=0;i<10;i++) | |
fb[i]=fb[i-1]+fb[i-2] || i; // assign the left value when it can (ie values are defined) otherwise set to the index | |
// takes care of first two numbers in sequence (ie f0 = 0, f1 = 1) | |
console.log(fb,"for & ||"); | |
// 70 characters | |
// Go a step further and assume first two numbers and pre-populate the array | |
fb=[0,1]; | |
for(i=2;i<10;i++) | |
fb[i]=fb[i-1]+fb[i-2]; // no more || operator | |
console.log(fb,"for & prepopulate"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment