Last active
August 29, 2015 14:20
-
-
Save varmais/4b114a3ae288bf3ea9c1 to your computer and use it in GitHub Desktop.
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 fib (n, x, y) { | |
if (n < 1) return; | |
console.log(n, x); | |
n--; | |
fib(n, y, x+y); | |
} | |
fib (100, 0, 1); | |
--- | |
(function () { | |
var arr = [50, 2, 8, 3, 946, 5, 1, 9]; | |
arr = arr.join('').split(''); | |
arr = arr.sort(function (a, b) { | |
if (a > b) { | |
return -1; | |
} | |
if (a < b) { | |
return 1; | |
} | |
return 0; | |
}); | |
console.log(arr.join('')); | |
})(); | |
___ | |
(function () { | |
function cointoss () { | |
return parseInt(Math.random() * 2, 10) === 0; | |
} | |
function rnd () { | |
var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
var str = ''; | |
var sum = 0; | |
function add(nro) { | |
sum += nro; | |
str += ' + ' + nro; | |
} | |
function reduce(nro) { | |
sum -= nro; | |
str += ' - ' + nro; | |
} | |
function decide(nro) { | |
if (cointoss()) { | |
add(nro); | |
} else { | |
reduce(nro); | |
} | |
} | |
for (var i = 0; i < arr.length; i++) { | |
if (i === 0) { | |
sum += 1; | |
str += '1'; | |
} else { | |
if (cointoss()) { | |
decide(parseInt('' + arr[i] + arr[i+1], 10)); | |
i++; | |
} else { | |
decide(arr[i]); | |
} | |
} | |
} | |
if (sum === 100) { | |
console.log(str, sum); | |
} else { | |
rnd(); | |
} | |
} | |
rnd(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment