Skip to content

Instantly share code, notes, and snippets.

View endziu's full-sized avatar

endziu endziu

View GitHub Profile
import { map, range, reduce, addIndex, identity, ompose, pipe, any, join, contains, update, equals, prop, juxt, repeat, reverse } from 'ramda';
const mapIdx = addIndex(map);
const fillGrid = arr => arr.concat(map(() => repeat(' ', arr[0].length), arr));
const shiftGrid = mapIdx((el,i,arr) => repeat(' ', arr.length - i).concat(el).concat(repeat(' ', i)));
const initBoard = size => map(() => Array(size).fill(' '), range(0,size));
const updateBoard = move => grid => update(move.x, update(move.y, move.val, grid[move.x]), grid);
const performMoves = moves => reduce(compose, identity, map(updateBoard, moves));
const xWins = compose(contains('XXX'), join(''));
const oWins = compose(contains('OOO'), join(''));
const getColumns = grid => mapIdx((el, i) => map(prop(i), grid), grid);

Keybase proof

I hereby claim:

  • I am endziu on github.
  • I am endziu ( on keybase.
  • I have a public key whose fingerprint is C14B 3B64 58BA 14DC 9036 7B0E 06BB FAE5 7D43 76F3

To claim this, I am signing this object: