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
| def is_fibonacci?(num, fib_array=[]) | |
| fib_array = [0, 1, 1] if fib_array.empty? | |
| if fib_array.last < num | |
| fib_array << fib_array[-1] + fib_array[-2] | |
| is_fibonacci?(num, fib_array) | |
| end | |
| fib_array.last == num | |
| end |
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
| def is_fibonacci?(num) | |
| fib_array = [0, 1, 1] | |
| while fib_array.last < num | |
| fib_array << fib_array[-1] + fib_array[-2] | |
| end | |
| fib_array.last == num | |
| end |
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
| function lookSaySequence(num) { | |
| var num = num.toString().split(""); | |
| var counters = []; | |
| for (var i=0; i < num.length; i++) { | |
| if (num[i] === num[i - 1]) { | |
| continue; | |
| } | |
| var current = num[i]; | |
| var counter = 1; | |
| var j = i + 1 |
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
| function fibonacciChecker(num) { | |
| var series = [1, 1]; | |
| while (series[series.length - 1] < num) { | |
| var item = series[series.length - 2] + series[series.length - 1]; | |
| series.push(item); | |
| } | |
| if (series[series.length - 1] === num) { | |
| return true; | |
| } else { | |
| return false |
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
| function fibonacci(num) { | |
| var sequence = [1, 1]; | |
| while (!(sequence.length === num)) { | |
| var item = sequence[sequence.length - 2] + sequence[sequence.length - 1]; | |
| sequence.push(item); | |
| } | |
| return sequence[sequence.length - 1]; | |
| } |
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
| function findMode(array) { | |
| var hashOfValues = {}; | |
| for (var i=0; i < array.length; i++) { | |
| var count = 0; | |
| var current = array[i]; | |
| for (var j=0; j < array.length; j++) { | |
| var secondCurrent = array[j]; | |
| if (secondCurrent === current) { | |
| count += 1; | |
| } |
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
| ##### Sample output: | |
| Welcome to your new castle!! | |
| This castle is quite wonderful with many awesome features and lots of potential. But | |
| unfortunately neighboring castles are suffering from various infestations of terrifying terrors | |
| like dragons, fawning ministers, and vicious library books! Oh no! | |
| Over the next 5 days, let's see if you survive life in your new castle. Every day, one new thing |
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
| assets = { | |
| 0: ["kitchen gardens", "courtyards", "stables", "libraries", "great halls", "armories"], | |
| 1: ["depressed ghosts", "sarcastic cats", "opinionated teacups"], | |
| 2: ["knights with great cooking skills", "sword-wielding ladies", "highly educated serfs"], | |
| 3: ["golden chalices of drinking", "fluffy blankets of sleeping", "shiny rubies of coding"] | |
| }; | |
| pests = { | |
| 0: ["dragons", "gorgons", "flesh-eating newts"], | |
| 1: ["children", "fleas", "overly adorable mice"], |
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
| def inconsistent_adder_with_implicit_block(num1, num2) | |
| puts "Let's play a game! Me, the program, will flip a coin." | |
| puts "If it's heads, I'll add up your numbers," | |
| puts "and if tails, I'll throw them back in your face." | |
| puts "Flipping a coin..." | |
| sleep(4) | |
| coin = ["heads", "tails"].sample | |
| if coin == "heads" |
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
| def inconsistent_adder_with_enumerable(num1, num2) | |
| puts "Let's play a game! Me, the program, will flip a coin." | |
| puts "If it's heads, I'll add up your numbers," | |
| puts "and if tails, I'll throw them back in your face." | |
| puts "Flipping a coin..." | |
| sleep(4) | |
| coin = ["heads", "tails"].sample | |
| if coin == "heads" |