Last active
March 5, 2016 21:07
-
-
Save DanielFGray/819c62c6cfbdecd9f8e2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
'use strict'; | |
// http://www.codewars.com/kata/53db4acb1f1a7dd68700040a/train/javascript | |
function canReach(from, to, movements) { | |
//FIXME: attempt in multiple moves | |
const offset = [ Math.abs(from[0] - to[0]), Math.abs(from[1] - to[1]) ]; | |
const valid_offsets = [ [1, 2], [2, 1] ]; | |
return valid_offsets.some(o => { | |
return o[0] == offset[0] && o[1] == offset[1] | |
}); | |
} | |
(function test(cases) { | |
cases.forEach(t => console.log(t[0] == t[1])); | |
})([ | |
[ canReach([6, 2], [8, 1], 1), true ], | |
[ canReach([6, 2], [8, 2], 1), false ], | |
[ canReach([6, 2], [8, 1], 2), false ], | |
[ canReach([6, 2], [8, 2], 2), true ], | |
[ canReach([6, 2], [6, 2], 0), true ], | |
[ canReach([6, 2], [8, 1], 0), false ], | |
]); | |
function moveKnight(from) { } | |
function moveKnightRandom(from) { } | |
function compose() { } | |
function bind() { } | |
function unit() { } | |
function knightEngine(from, movements) { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment