# Sodoku-Generator

**URL:** <https://www.ruby-forum.com/t/sodoku-generator/70566>\
**Category:** Ruby\
**Created:** [February 19, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566 "2006-02-19T20:10:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 19, 2006, 8:10pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/1 "2006-02-19T20:10:00Z")

</div>

Hi,

with Google I found a Quiz about a Sodoku-solver, but I didn’t find a  
Sodoku generator. Also RAA and RubyForge did not list one.

Is there any out there ? May be one, which also generated a solution  
for the generated Sodokus?

Kind regards,  
mcc

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 19, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/2 "2006-02-19T20:52:35Z")

</div>

From the R library package “sudoku”:

generateSudoku package:sudoku R Documentation

Randomly Generate a Sudoku Puzzle Grid

Description:

```
 Creates a 9x9 Sudoku grid suitable for use by 'playSudoku'.

```

Usage:

```
   generateSudoku(Nblank=50, print.it=FALSE)

```

Arguments:

Nblank: Number of cells to blank out

print.it: Logical. If true, print result to screen.

Details:

```
 The basic algorithm is to start with a 'primordial' Sudoku grid,
 swap around some rows and columns, then blank out some cells.

```

Value:

```
 A matrix, representing a 9x9 Sudoku grid.

```

Author(s):

```
 Curt S. <removed_email_address@domain.invalid>, Henrik Bengtsson
 <removed_email_address@domain.invalid>, and David Brahm <removed_email_address@domain.invalid>

```

References:

```
 <URL: http://sudoku.com/>

```

Examples:

```
 generateSudoku(print.it=TRUE)

```

Here’s the function definition for those who understand R. I might make  
pseudo-code from this if I have the time:

generateSudoku ← function(Nblank=50, print.it=FALSE) {  
z ←   
c(1:9,4:9,1:3,7:9,1:6,2:9,1,5:9,1:4,8:9,1:7,3:9,1:2,6:9,1:5,9,1:8)  
z ← matrix(sample(9)[z], 9,9)  
for (i in 1:5) z ← z[replicate(3, sample(3)) + 3_rep(sample(0:2),  
each=3),  
replicate(3, sample(3)) + 3_rep(sample(0:2),  
each=3)]  
for (bi in seq(0,6,3)) for (bj in seq(0,6,3)) {  
idx ← data.matrix(expand.grid(bi + 1:3, bj + 1:3))  
z[idx[sample(1:9, Nblank%/%9),]] ← 0  
}

## Depopulate (if we had a test for uniqueness, we’d put it here):

while (sum(!z) \< Nblank) z[matrix(sample(9,2), 1)] ← 0  
if (print.it) printSudoku(z)  
z  
}

Meino Christian C. wrote:

> 

–  
M. Edward (Ed) Borasky

> **[世界杯竞猜彩票-世界杯官网竞猜（集团）有限公司](http://www.linuxcapacityplanning.com/)**
>
> 世界杯竞猜彩票一直以来遵守商业道德，世界杯官网竞猜坚持诚信为本，保证诚实经营。世界杯竞猜彩票先后成为安徽省电子商务协会理事单位、安徽省网商协会会员单位、合肥市电子商务协会理事单位、合肥市服务外包行业协会会员单位、安徽省云计算产业促进会会员单位。世界杯官网竞猜一直保持良好的技术及服务态度，更好地为客户服务。

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 19, 2006, 9:19pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/3 "2006-02-19T21:19:57Z")

</div>

From: “M. Edward (Ed) Borasky” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Sodoku-Generator  
Date: Mon, 20 Feb 2006 04:48:30 +0900

Hi Edward,

Thank you for your fast reply ! :O)

I found nothing at RAA/Rubyforge due to a typo I did:  
S\_u\_doku is correct…I searched for “S\_o\_doku”…

Sorry for the trouble…

(rsudoku did not start, because it doesn’t find a certain preference  
file  
in my $HOME. INSTALL says: Simpy start ruby rsudoku.rb.

I will check this…

Ruby!  
mcc

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 19, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/4 "2006-02-19T23:20:50Z")

</div>

Hi!

At Mon, 20 Feb 2006 04:08:01 +0900, Meino Christian C. wrote:

> with Google I found a Quiz about a Sodoku-solver, but I didn’t find  
> a Sodoku generator. Also RAA and RubyForge did not list one.
> 
> Is there any out there ? May be one, which also generated a solution  
> for the generated Sodokus?

[http://www.puzzle.jp](http://www.puzzle.jp)

I understand that you rather seek for a program but … hand-made  
Sudoku are much more fun than those created by software. Up to now at  
least.

Josef ‘Jupp’ Schugt

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 20, 2006, 3:38am UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/5 "2006-02-20T03:38:28Z")

</div>

On Feb 19, 2006, at 2:18 PM, Josef ‘Jupp’ SCHUGT wrote:

> I understand that you rather seek for a program but … hand-made  
> Sudoku are much more fun than those created by software. Up to now at  
> least.

This is slightly OT, so I’ll only offer this one contribution…  
There is no such thing as hand-made sudoku puzzles at this point.  
Yes, some newspapers still make the claim, but it’s simply untrue.

–Steve

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 20, 2006, 3:41am UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/6 "2006-02-20T03:41:29Z")

</div>

Stephen W. wrote:

> newspapers still make the claim, but it’s simply untrue.  
> I think I’m the last person in the world to “get” this phenomenon.  
> I’ve never tried it, but it looks as exciting as solving the same  
> crossword puzzle over and over.

I guess it’s the Rubik’s Cube of the 00’s, for whatever that may  
be worth.

Hal

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 20, 2006, 4:57am UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/7 "2006-02-20T04:57:01Z")

</div>

From: Josef ‘Jupp’ SCHUGT [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: Sodoku-Generator  
Date: Mon, 20 Feb 2006 07:18:20 +0900

Hi Josef,

🙂 Thanks for the link!

One could see the implementation of a sudoku-generator in ruby as a  
meta-puzzle: The puzzle to implement a puzzle-generator :))

Have a nice day!  
mcc

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 20, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/8 "2006-02-20T14:13:29Z")

</div>

Stephen W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> On Feb 19, 2006, at 2:18 PM, Josef ‘Jupp’ SCHUGT wrote:
> 
> > I understand that you rather seek for a program but … hand-made  
> > Sudoku are much more fun than those created by software. Up to now at  
> > least.
> 
> This is slightly OT, so I’ll only offer this one contribution…  
> There is no such thing as hand-made sudoku puzzles at this point.  
> Yes, some newspapers still make the claim, but it’s simply untrue.

They could, but of course you can’t tell if they do…

[http://www.pro.or.jp/~fuji/sudoku/makesudoku/sudoku01.html.en](http://www.pro.or.jp/~fuji/sudoku/makesudoku/sudoku01.html.en)  
[http://www.pro.or.jp/~fuji/sudoku/makesudoku2/sudoku01.html.en](http://www.pro.or.jp/~fuji/sudoku/makesudoku2/sudoku01.html.en)

---

<div class="post-metadata">

**Author:** ![Meino\_Christian\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7993a0/32.png) [@Meino\_Christian\_C](https://www.ruby-forum.com/u/Meino_Christian_C)\
**Post date:** [February 21, 2006, 8:35pm UTC](https://www.ruby-forum.com/t/sodoku-generator/70566/9 "2006-02-21T20:35:33Z")

</div>

Hi!

At Mon, 20 Feb 2006 12:53:50 +0900, Meino Christian C. wrote:

> 🙂 Thanks for the link!

It was taken from “Sudoku - Das original japanische Zahlenrätsel” by  
Puzzler, published by MZV Moderner Zeitschriften Vertrieb GmbH &  
Co. KG - [http://www.mzv.de/](http://www.mzv.de/)

There is already quite a number of sudoku in print in Germany but  
according to me this one bringst the most fun (I tried several  
publications)

Josef ‘Jupp’ Schugt
