This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

## 2021-10-09

## Channels

- # announcements (23)
- # asami (25)
- # babashka (38)
- # beginners (53)
- # calva (17)
- # clara (5)
- # clj-commons (1)
- # clj-kondo (18)
- # clojure (11)
- # clojure-europe (17)
- # clojure-france (1)
- # clojure-germany (5)
- # clojure-nl (2)
- # clojure-sg (4)
- # conjure (3)
- # deps-new (6)
- # fulcro (16)
- # off-topic (46)
- # pedestal (11)
- # react (2)
- # reagent (5)
- # reclojure (7)
- # rewrite-clj (1)
- # sci (18)
- # shadow-cljs (75)
- # sql (3)
- # xtdb (12)

whilst solving a sudoku in the kitchen .... it crossed my mind - how would you define a sudoku dataset in clojure

just a long vector ? vector of vectors (by rows or columns) or each cell as a small vector and the whole lot as 9 vectors ?

or something completely different?

vector of vectors is the straight forward general representation. But it depends on what you do with it!

Oh, hold on - Java supports 2D arrays, doesn't it? Keep forgetting. Then those ones, instead of an array of arrays.

I haven’t looked into sudoku, but depending on how you want to operate on that data structure you may want to use a different one

well you probably want to check the current state for validity 😄

all rows all columns all cells must be made of unique numbers

yeah but with those mathematical things there are often clever algorithms that you can exploit

well sudoku doesn't have much to do with maths, you don't compute anything really from the numbers .... they are just recognizable symbols

i was thinking of generating yes

but the process of generation is pretty much (throw some numbers in there and see if it could be solved)

right now i did it as vectors of vectors .... and helper functions to check validity based on that

technically 1 function of validation is sufficient - distinct?

it's just what i cherry pick as it's input

i need to check data from a row, data from a column or data from a cell

if i start to combine the input into a set i would lose the visibility where the invalidity came from 🙂

but yeah, it's interesting to see what people come up with ... 🙂

a long time ago i had to write game engines ... and it turned out that chess may be complicated for humans but checkers was just about as annoying to code, if not more 🙂

because of the multiple hops and the enforcement of "you have to take it if you can"

If that's helpful, Peter Norvig wrote a nice lengthy article on Sudoku solver, and other people wrote implementations in other languages, including Clojure: https://norvig.com/sudoku.html

now the sabotage if dgb day is complete

my sudoku solver uses a map of cell to number for the board, i.e
`{[:a 1] 5 [:a 2] 0 ...}`

I went through a bunch of different structures and this was the one that ended up matching the algorithm the best

Since you have logical programming in Clojure, using core.logic is a very interesting approach https://nextjournal.com/helios/solving-sudokus-using-core-logic

Or Spock: https://gitlab.com/mauricioszabo/Spock :rolling_on_the_floor_laughing: