|
|
|
@ -35,7 +35,7 @@ const touching = (v1,v2) => [v1.distanceX(v2), v1.distanceY(v2)].every(
@@ -35,7 +35,7 @@ const touching = (v1,v2) => [v1.distanceX(v2), v1.distanceY(v2)].every(
|
|
|
|
|
export function moveOnce( head, tail, d ) { |
|
|
|
|
head.add(d); |
|
|
|
|
|
|
|
|
|
if( touching(head,tail) ) return; |
|
|
|
|
if( touching(head,tail) ) return tail.toString(); |
|
|
|
|
|
|
|
|
|
const delta = head.clone().subtract(tail).normalize(); |
|
|
|
|
|
|
|
|
@ -45,26 +45,23 @@ export function moveOnce( head, tail, d ) {
@@ -45,26 +45,23 @@ export function moveOnce( head, tail, d ) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tail.add(delta); |
|
|
|
|
|
|
|
|
|
return tail.toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const moveAround = (directives) => { |
|
|
|
|
const head = new Victor(0,0); |
|
|
|
|
const tail = new Victor(0,0); |
|
|
|
|
|
|
|
|
|
const visited = [ tail.toString() ] |
|
|
|
|
|
|
|
|
|
for ( const d of directives ) { |
|
|
|
|
moveOnce(head,tail,d); |
|
|
|
|
|
|
|
|
|
visited.push( tail.toString() ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return visited; |
|
|
|
|
const move = d => moveOnce(head,tail,d); |
|
|
|
|
return [ |
|
|
|
|
tail.toString(), |
|
|
|
|
...directives.map( move ) |
|
|
|
|
] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export default R.createPipe( |
|
|
|
|
moveAround, |
|
|
|
|
passthru( x => console.log(x) ), |
|
|
|
|
R.uniq, |
|
|
|
|
R.countBy( R.identity ) |
|
|
|
|
moves => moves.length |
|
|
|
|
); |
|
|
|
|