Skip to content

Instantly share code, notes, and snippets.

@optyler
Last active February 16, 2016 17:14
Show Gist options
  • Save optyler/36c9a357b9d48b1e082f to your computer and use it in GitHub Desktop.
Save optyler/36c9a357b9d48b1e082f to your computer and use it in GitHub Desktop.
Codingame - Clashes
var n = readline(); // start number
var t = [n]; // final array with all the values, the first one is the start number
while(n !== 1) {
// if n is even, divide it by 2, else, if it is odd, multiply by 3 and add 1
n = (n%2 === 0) ? (n/2) : 3*n+1;
t.push( n );
}
print(t.join(' '))
// abcd ===> aceg
// codingame ==> cpflrlgtm
Array.prototype.map.call(readline(), (c,i) => String.fromCharCode(c.charCodeAt(0)+i )).join('')
function checkPalindrom(str) {
return str == str.split('').reverse().join('');
}
// HAPPY / UNHAPPY
function c(s,t){t=(''+s).split('').map(function(o){return o*o}).reduce(function(a,b){return a+b});return (t>9)?c(t):t;}print((c(readline())!=1?'UN':'')+'HAPPY')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment