Skip to content

Instantly share code, notes, and snippets.

@AlexVvx
Last active May 24, 2017 15:16
Show Gist options
  • Save AlexVvx/8894811db96db62d373866b8db78bb12 to your computer and use it in GitHub Desktop.
Save AlexVvx/8894811db96db62d373866b8db78bb12 to your computer and use it in GitHub Desktop.
open-day-solutions
var getChange = (cost, sum) => {
let rem = Math.round((sum - cost) * 100);
return [100, 50, 20, 10, 5, 1].map(v => {
let n = ~~(rem / v);
rem -= n * v;
return n;
}).reverse();
}
var zoom = (n, f=v=>Math.min(v,n-v-1)) =>
Array.from({ length: n }).map((_, x) =>
Array.from({ length: n }).map((_, y) =>
Math.min(f(x), f(y)) % 2 ? '□' : '■'
).join('')
).join('\n');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment