Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Created February 15, 2012 01:37
Show Gist options
  • Save pbalduino/1832376 to your computer and use it in GitHub Desktop.
Save pbalduino/1832376 to your computer and use it in GitHub Desktop.
Sudoku board
#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)
@rlorca
Copy link

rlorca commented Feb 15, 2012

Queria ver a funcao to-chair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment