Skip to content

Instantly share code, notes, and snippets.

@tilacog
Last active June 3, 2025 16:54
Show Gist options
  • Save tilacog/ead4ab18182e6d3d04759d0bd212835a to your computer and use it in GitHub Desktop.
Save tilacog/ead4ab18182e6d3d04759d0bd212835a to your computer and use it in GitHub Desktop.
Mana Board
(define board
'((2 2 3 1 2 2)
(1 3 1 3 1 3)
(3 1 2 2 3 1)
(2 3 1 3 1 2)
(2 1 3 1 3 2)
(1 3 2 2 1 3)))
(define (invalid_range n)
(cond ((> n 5) #t)
((negative? n) #t)
(else #f)))
(define (row n b)
(cond ((invalid_range n) (error "invalid range"))
((zero? n) (car b))
(else (row (1- n) (cdr b)))))
(define (col n b)
(cond ((invalid_range n) (error "invalid range"))
((zero? n) (map car b))
(else (col (1- n) (map cdr b)))))
(define (transpose b)
(if (nil? (car b))
'()
(cons (map car b) (transpose (map cdr b)))))
(define (sum-line line) (apply + line))
;; First symmetry found: all rows sum to 12
(map sum-line board)
;; First asymmetry found: not all rows equal to 12
(map sum-line (transpose board))
(define (average list)
(/ (apply + list) (length list)))
;; Symmetry found: all rows average to 2
(map average board)
;; Asymmetry found: not all colums average to 2
(map average (transpose board))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment