Skip to content

Instantly share code, notes, and snippets.

View xojoc's full-sized avatar

Alexandru Cojocaru xojoc

View GitHub Profile
@xojoc
xojoc / 002.rkt
Created April 16, 2020 16:19
Fill a NxN grid with numbers from 1 to N. Starting from 1 the next cell can be either two places apart vertically or horizontally or one cell apart diagonally.
#lang typed/racket
(require math/array)
(: possible-moves ((Array Fixnum) Indexes -> (Listof Indexes)))
(define (possible-moves arr idx)
(let ((shape (array-shape arr)))
(cast
(filter (λ ([i : (Vector Integer Integer)]) (and (< -1 (vector-ref i 0) (vector-ref shape 0))
(< -1 (vector-ref i 1) (vector-ref shape 1))