Created
February 15, 2012 01:37
-
-
Save pbalduino/1832376 to your computer and use it in GitHub Desktop.
Sudoku 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
#lang scheme | |
; http://www.dailysudoku.com/sudoku/archive/2012/02/2012-02-10.shtml | |
(define easy-game "020580000093600007001007000609102300180030059005908104000800500200009760000015080") | |
(define (to-number char) | |
(- (char->integer char) 48)) | |
(define (to-vector string) | |
(list->vector (map to-number (string->list string)))) | |
(define (cell-value vector line column) | |
(let ([val (vector-ref (to-vector easy-game) (+ (* line 9) column))]) | |
(if (= val 0) "." val))) | |
(define (display-board game) | |
(for ([line (in-range 9)]) | |
(when (= (modulo line 3) 0) (printf "+-----------+-----------+-----------+\n|")) | |
(for ([column (in-range 9)]) | |
(printf " ~a " (cell-value game line column)) | |
(if (= (modulo (+ column 1) 3) 0) | |
(printf "|") | |
(printf " "))) | |
(printf "\n") | |
(when (= (modulo line 3) 0) (printf "|")) | |
(when (= (modulo line 3) 1) (printf "|"))) | |
(printf "+-----------+-----------+-----------+\n")) | |
(display-board easy-game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment