Add try scripts to 2005/aidan + format/typo checks
The try.sh script is for aidan.c; the try.alt.sh is for aidan.alt.c (which I added some while back based on the author's remarks). The README.md file has been format and typo fixed.
This commit is contained in:
1 parent
0917f5279e
commit
3e54799637
4 files changed
+129
-29
No files matched your search
@@ -132,6 +132,12 @@ all: data ${TARGET}
|
|||||||
${PROG}: ${PROG}.c
|
${PROG}: ${PROG}.c
|
||||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||||
|
|
||||||
|
test: test-su.perl
|
||||||
|
${PERL} $<
|
||||||
|
|
||||||
|
test-n0: test-su.perl
|
||||||
|
${PERL} $< -n 0
|
||||||
|
|
||||||
# alternative executable
|
# alternative executable
|
||||||
#
|
#
|
||||||
alt: data ${ALT_TARGET}
|
alt: data ${ALT_TARGET}
|
||||||
|
|||||||
+65
-29
@@ -4,6 +4,9 @@
|
|||||||
make
|
make
|
||||||
```
|
```
|
||||||
|
|
||||||
|
There is an alternate version based on the author's remarks. See [alternate
|
||||||
|
code](#alternate-code).
|
||||||
|
|
||||||
|
|
||||||
## To use:
|
## To use:
|
||||||
|
|
||||||
@@ -11,6 +14,7 @@ make
|
|||||||
./aidan < puzzle
|
./aidan < puzzle
|
||||||
|
|
||||||
./aidan seed
|
./aidan seed
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
where `seed` is a number.
|
where `seed` is a number.
|
||||||
@@ -19,9 +23,32 @@ where `seed` is a number.
|
|||||||
### Try:
|
### Try:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./aidan < insane1.sudoku
|
./try.sh
|
||||||
|
```
|
||||||
|
|
||||||
./aidan 42
|
|
||||||
|
## Alternate code:
|
||||||
|
|
||||||
|
This code is formatted differently and is not the approach used by the author
|
||||||
|
which is slower, inelegant and not as obscure, as the author put it.
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate build:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make alt
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate use:
|
||||||
|
|
||||||
|
Use `aidan.alt` as you would `aidan` above.
|
||||||
|
|
||||||
|
|
||||||
|
### Alternate try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./try.alt.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -30,15 +57,12 @@ where `seed` is a number.
|
|||||||
Are you puzzled about puzzles? This entry might puzzle you
|
Are you puzzled about puzzles? This entry might puzzle you
|
||||||
more while it puzzles out some puzzles: all in a puzzling way!
|
more while it puzzles out some puzzles: all in a puzzling way!
|
||||||
|
|
||||||
`Goto` the source and notice the lack of functions. Jump
|
`goto` the source and notice the lack of functions. Jump
|
||||||
to the `switch` statement. And if you think you can puzzle
|
to the `switch` statement. And if you think you can puzzle
|
||||||
it out better, try solving [insane1.sudoku](insane1.sudoku) all by yourself!
|
it out better, try solving [insane1.sudoku](insane1.sudoku) all by yourself!
|
||||||
|
|
||||||
NOTE: some of the files listed below by the author were either removed or
|
NOTE: the tarball named by the author was removed after the files were extracted
|
||||||
renamed. The removed file in question was a tarball but the files were extracted
|
into the directory instead. These files were added to the list.
|
||||||
into the directory instead. These files were added to the list. We also removed
|
|
||||||
the README.md which was at one point named `sudoku-sf.txt`. The author submitted
|
|
||||||
the program as `sudoku-sf.c` which was renamed and changed in their comments.
|
|
||||||
|
|
||||||
|
|
||||||
## Author's remarks:
|
## Author's remarks:
|
||||||
@@ -47,9 +71,9 @@ This program can solve a type of logic puzzle known as a
|
|||||||
[Sudoku](https://en.wikipedia.org/wiki/Sudoku), and also
|
[Sudoku](https://en.wikipedia.org/wiki/Sudoku), and also
|
||||||
generate new ones.
|
generate new ones.
|
||||||
|
|
||||||
|
|
||||||
### Contents
|
### Contents
|
||||||
|
|
||||||
* build file: build.txt - you don't need this
|
|
||||||
* program file: [aidan.c](aidan.c) - sudoku solver and generator
|
* program file: [aidan.c](aidan.c) - sudoku solver and generator
|
||||||
* test suite: [test-su.perl](test-su.perl) - optional test script (written for Perl5)
|
* test suite: [test-su.perl](test-su.perl) - optional test script (written for Perl5)
|
||||||
* sudoku file: [blank.sudoku](blank.sudoku)
|
* sudoku file: [blank.sudoku](blank.sudoku)
|
||||||
@@ -65,6 +89,7 @@ generate new ones.
|
|||||||
Yes, the test suite really is 5 times larger than the actual program. You
|
Yes, the test suite really is 5 times larger than the actual program. You
|
||||||
**did** say this was a parody of the software development process...
|
**did** say this was a parody of the software development process...
|
||||||
|
|
||||||
|
|
||||||
### IMPORTANT
|
### IMPORTANT
|
||||||
|
|
||||||
[test.perl](test-su.perl) expects the `sudoku-sf` executable to be
|
[test.perl](test-su.perl) expects the `sudoku-sf` executable to be
|
||||||
@@ -73,6 +98,7 @@ new name.
|
|||||||
|
|
||||||
> Judges' note: this was done.
|
> Judges' note: this was done.
|
||||||
|
|
||||||
|
|
||||||
### Legal blurb
|
### Legal blurb
|
||||||
|
|
||||||
This program comes with NO WARRANTY, not even that it'll do what I say it
|
This program comes with NO WARRANTY, not even that it'll do what I say it
|
||||||
@@ -82,13 +108,14 @@ Go find some unpopular multinational to sue instead.
|
|||||||
This program is not copyrighted and is entirely my work. Distribute or modify
|
This program is not copyrighted and is entirely my work. Distribute or modify
|
||||||
it as you wish, though please give me credit.
|
it as you wish, though please give me credit.
|
||||||
|
|
||||||
|
|
||||||
### What is a sudoku?
|
### What is a sudoku?
|
||||||
|
|
||||||
(If you know, feel free to skip this section. Get more details from [the
|
(If you know, feel free to skip this section. Get more details from [the
|
||||||
wikipedia entry](http://en.wikipedia.org/wiki/Sudoku))
|
wikipedia entry](http://en.wikipedia.org/wiki/Sudoku))
|
||||||
|
|
||||||
A sudoku is a type of logic puzzle. You are given a grid of 9x9 boxes, some
|
A sudoku is a type of logic puzzle. You are given a grid of 9x9 boxes, some
|
||||||
of which contain digits. This is divided into nine 3x3 boxes, e.g. (from the
|
of which contain digits. This is divided into a 3x3 set up, e.g. (from the
|
||||||
Wikipedia article - fairly easy):
|
Wikipedia article - fairly easy):
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -136,18 +163,18 @@ Oh, and if you think that example sudoku is too easy, try this one (which my
|
|||||||
program generated):
|
program generated):
|
||||||
|
|
||||||
```
|
```
|
||||||
--- insane1.sudoku --
|
--- insane1.sudoku --
|
||||||
. . 4 | . . . | . 5 6
|
. . 4 | . . . | . 5 6
|
||||||
5 . . | . 7 2 | . . .
|
5 . . | . 7 2 | . . .
|
||||||
. . 1 | . . . | 8 . .
|
. . 1 | . . . | 8 . .
|
||||||
------+-------+------
|
------+-------+------
|
||||||
. . . | . . . | . . .
|
. . . | . . . | . . .
|
||||||
. . . | 6 9 3 | . . 5
|
. . . | 6 9 3 | . . 5
|
||||||
. . . | . . . | 7 3 4
|
. . . | . . . | 7 3 4
|
||||||
------+-------+------
|
------+-------+------
|
||||||
. 5 . | 2 . 1 | 4 . 8
|
. 5 . | 2 . 1 | 4 . 8
|
||||||
3 . . | . . . | . . .
|
3 . . | . . . | . . .
|
||||||
. . . | . . . | . 6 1
|
. . . | . . . | . 6 1
|
||||||
```
|
```
|
||||||
|
|
||||||
Be warned - it's evil! (I certainly haven't been able to solve it by hand. The
|
Be warned - it's evil! (I certainly haven't been able to solve it by hand. The
|
||||||
@@ -155,6 +182,7 @@ brute-force program given above, `sudoku-bfi.c` ([aidan.alt.c](aidan.alt.c)),
|
|||||||
also has trouble - it took 66 seconds to solve it - but probably for different
|
also has trouble - it took 66 seconds to solve it - but probably for different
|
||||||
reasons. That's the worst performance I've had from brute-force so far!)
|
reasons. That's the worst performance I've had from brute-force so far!)
|
||||||
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
#### Building
|
#### Building
|
||||||
@@ -181,6 +209,7 @@ somewhat slow (should take under a minute on a fairly modern PC - try
|
|||||||
appending `-n 0` if you're in a hurry). I wrote it mostly for my own benefit,
|
appending `-n 0` if you're in a hurry). I wrote it mostly for my own benefit,
|
||||||
really.
|
really.
|
||||||
|
|
||||||
|
|
||||||
#### Solving
|
#### Solving
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -188,19 +217,20 @@ really.
|
|||||||
```
|
```
|
||||||
|
|
||||||
Input should be the numbers of each row in turn. Empty spaces can be
|
Input should be the numbers of each row in turn. Empty spaces can be
|
||||||
represented as a full stop (.) or zero (0). Other characters are ignored, so you
|
represented as a full stop (`.`) or zero (`0`). Other characters are ignored, so you
|
||||||
can cut-and-paste either example sudoku from above into a file and feed that
|
can cut-and-paste either example sudoku puzzle from above into a file and feed that
|
||||||
in. The program has coped with every input I've thrown at it so far, including
|
in. The program has coped with every input I've thrown at it so far, including
|
||||||
an [empty grid](blank.sudoku).
|
an [empty grid](blank.sudoku).
|
||||||
|
|
||||||
Output consists of the problem, then the solution, then a message of
|
Output consists of the problem, then the solution, then a message of
|
||||||
success/failure.
|
success/failure.
|
||||||
|
|
||||||
`./aidan` (capital `U`), may also be useful, or perhaps not. It only took
|
`./aidan U` may also be useful, or perhaps not. It only took
|
||||||
an extra 15 bytes of (very simple) code to add, so it doesn't really matter to
|
an extra 15 bytes of (very simple) code to add, so it doesn't really matter to
|
||||||
me. (It's the same as the normal mode for most input you're likely to feed it,
|
me. (It's the same as the normal mode for most input you're likely to feed it,
|
||||||
though slightly slower. See if you can figure out what it does.)
|
though slightly slower. See if you can figure out what it does.)
|
||||||
|
|
||||||
|
|
||||||
#### Generating
|
#### Generating
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -211,6 +241,7 @@ Output is a blank grid, then the solution, then the problem. There's no
|
|||||||
control over the difficulty. Sorry. However, all generated sudokus should have
|
control over the difficulty. Sorry. However, all generated sudokus should have
|
||||||
exactly one solution - if one doesn't, that's a bug.
|
exactly one solution - if one doesn't, that's a bug.
|
||||||
|
|
||||||
|
|
||||||
### Speed
|
### Speed
|
||||||
|
|
||||||
Fast enough. Solving and generating are practically instant on my 1Ghz Duron.
|
Fast enough. Solving and generating are practically instant on my 1Ghz Duron.
|
||||||
@@ -221,6 +252,7 @@ in tests on my PC (1Ghz Duron, gcc 3.4.1, `-O2` optimisation - takes about 60
|
|||||||
seconds with no optimisation). If that isn't fast enough, what on Earth are you
|
seconds with no optimisation). If that isn't fast enough, what on Earth are you
|
||||||
doing with it?
|
doing with it?
|
||||||
|
|
||||||
|
|
||||||
### Bugs
|
### Bugs
|
||||||
|
|
||||||
None known - hopefully I've worked out all the major ones. Nothing has come up
|
None known - hopefully I've worked out all the major ones. Nothing has come up
|
||||||
@@ -237,6 +269,7 @@ generate a sudoku as a bug - just a minor quirk. The fix is slightly awkward
|
|||||||
and would make the program slightly longer, so I haven't bothered - it's not
|
and would make the program slightly longer, so I haven't bothered - it's not
|
||||||
important.
|
important.
|
||||||
|
|
||||||
|
|
||||||
### Missing Features
|
### Missing Features
|
||||||
|
|
||||||
* No control over the difficulty of generated sudokus - they vary from easy to
|
* No control over the difficulty of generated sudokus - they vary from easy to
|
||||||
@@ -249,15 +282,16 @@ hurry.
|
|||||||
but I don't feel like learning curses just for this. Besides, I spent enough
|
but I don't feel like learning curses just for this. Besides, I spent enough
|
||||||
of the time swearing as it is.
|
of the time swearing as it is.
|
||||||
|
|
||||||
* If you mistype a sudoku (e.g. from a paper/magazine) - and you will - it\
|
* If you mistype a sudoku (e.g. from a paper/magazine) - and you will - it
|
||||||
can't help you figure out where the mistake is, sadly.
|
can't help you figure out where the mistake is, sadly.
|
||||||
|
|
||||||
|
|
||||||
### Portability
|
### Portability
|
||||||
|
|
||||||
Dependant on ASCII, requires that an int is at least 15 bits and a long at
|
Dependant on ASCII, requires that an `int` is at least 15 bits and a `long` at
|
||||||
least 32. (No, that isn't a typo - I did say 15, not 16).
|
least 32. (No, that isn't a typo - I did say 15, not 16).
|
||||||
|
|
||||||
Also requires that cpp can properly handle something like:
|
Also requires that `cpp` can properly handle something like:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#define foo(x,y) x y
|
#define foo(x,y) x y
|
||||||
@@ -269,17 +303,19 @@ though it usually does). Unfortunately, I didn't discover this issue until too
|
|||||||
late. (It was mentioned in the notes for people modifying GCC in the "beware
|
late. (It was mentioned in the notes for people modifying GCC in the "beware
|
||||||
of obscure compiler limitations" section, so I'm figuring it's quite unusual.)
|
of obscure compiler limitations" section, so I'm figuring it's quite unusual.)
|
||||||
|
|
||||||
|
|
||||||
### Compiler warnings
|
### Compiler warnings
|
||||||
|
|
||||||
Some when compiled with `gcc -Wall -Wextra -ansi -pedantic`:
|
Some when compiled with `gcc -Wall -Wextra -ansi -pedantic`:
|
||||||
|
|
||||||
* The left-hand operand of a comma has no effect in two places
|
* The left-hand operand of a comma has no effect in two places.
|
||||||
* Parentheses are suggested around a `+` in an operand of `&` in the `i` macro
|
* Parentheses are suggested around a `+` in an operand of `&` in the `i` macro
|
||||||
definition.
|
definition.
|
||||||
|
|
||||||
Borland C also spots some code in expressions which has no effect, and some
|
Borland C also spots some code in expressions which has no effect, and some
|
||||||
uses of `=` where you'd expect a comparison operator.
|
uses of `=` where you'd expect a comparison operator.
|
||||||
|
|
||||||
|
|
||||||
### Obfuscation
|
### Obfuscation
|
||||||
|
|
||||||
Let's see now:
|
Let's see now:
|
||||||
|
|||||||
Executable
+47
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# try.sh - demonstrate IOCCC winner 2005/aidan alt code
|
||||||
|
#
|
||||||
|
|
||||||
|
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
|
||||||
|
# this way allows us to have the user specify a different compiler in an easy
|
||||||
|
# way.
|
||||||
|
if [[ -z "$CC" ]]; then
|
||||||
|
CC="cc"
|
||||||
|
fi
|
||||||
|
|
||||||
|
make CC="$CC" everything >/dev/null || exit 1
|
||||||
|
|
||||||
|
# clear screen after compilation so that only the entry is shown
|
||||||
|
clear
|
||||||
|
|
||||||
|
AIDAN="aidan.alt"
|
||||||
|
|
||||||
|
echo "When looking at the output, notice how some of the output is different" 1>&2
|
||||||
|
echo "from the aidan.c." 1>&2
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
echo "$ ./$AIDAN < blank.sudoku" 1>&2
|
||||||
|
./"$AIDAN" < blank.sudoku
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
|
||||||
|
|
||||||
|
echo "$ echo IOCCC | ./$AIDAN" 1>&2
|
||||||
|
echo IOCCC | ./"$AIDAN"
|
||||||
|
echo "What just happened?" 1>&2
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
echo "$ echo IOCCC | ./$AIDAN 42" 1>&2
|
||||||
|
read -r -n 1 -p "Press any key to continue (q = exit pager space = go down a page): "
|
||||||
|
echo IOCCC | ./"$AIDAN" 42 1>&2
|
||||||
|
echo "Seeing that, was the 'echo IOCCC' relevant?" 1>&2
|
||||||
|
echo 1>&2
|
||||||
|
|
||||||
|
echo "$ ./$AIDAN < insane1.sudoku" 1>&2
|
||||||
|
read -r -n 1 -p "Press any key to continue: "
|
||||||
|
./"$AIDAN" < insane1.sudoku
|
||||||
|
echo "Did you notice how much slower this is than aidan? If not try try.sh!" 1>&2
|
||||||
|
echo 1>&2
|
||||||
@@ -2861,6 +2861,17 @@ Cody fixed the test script, described by the author in their remarks, to refer
|
|||||||
to the proper compiled program (it's hardcoded). This had never been done and it
|
to the proper compiled program (it's hardcoded). This had never been done and it
|
||||||
broke the script.
|
broke the script.
|
||||||
|
|
||||||
|
He also added the [alt code](2005/aidan/README.md#alternate-code) based on the
|
||||||
|
author's remarks which is a different approach than the one used and which 'is
|
||||||
|
slower (particularly in worst-case or nearly so scenarios), inelegant, and not a
|
||||||
|
good starting place for sudoku generation.'
|
||||||
|
|
||||||
|
The [try.sh](2005/aidan/try.sh) and [try.alt.sh](2005/aidan/try.alt.sh)
|
||||||
|
correspond to the entry and alt code respectively.
|
||||||
|
|
||||||
|
Cody added the `make test` and `make test-n0` rules for easier use of the test
|
||||||
|
suite.
|
||||||
|
|
||||||
|
|
||||||
## [2005/anon](2005/anon/anon.c) ([README.md](2005/anon/README.md]))
|
## [2005/anon](2005/anon/anon.c) ([README.md](2005/anon/README.md]))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user