Last active
June 3, 2025 16:54
-
-
Save tilacog/ead4ab18182e6d3d04759d0bd212835a to your computer and use it in GitHub Desktop.
Mana Board
This file contains hidden or 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
(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