Minor fixes + alt code in 1990/baruch
Fixed formatting in README.md. Add alt code based on authors' suggestion except that the string replacement was not done because it seems like the output would be not better but worse. There's a joke in the alternate code section of the README.md file.
This commit is contained in:
1 parent
d83e53d44b
commit
9b07c646f7
3 files changed
+72
-44
No files matched your search
@@ -112,8 +112,8 @@ OBJ= ${PROG}.o
|
|||||||
DATA=
|
DATA=
|
||||||
TARGET= ${PROG}
|
TARGET= ${PROG}
|
||||||
#
|
#
|
||||||
ALT_OBJ=
|
ALT_OBJ= ${PROG}.alt.o
|
||||||
ALT_TARGET=
|
ALT_TARGET= ${PROG}.alt
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|||||||
+69
-41
@@ -1,25 +1,59 @@
|
|||||||
# Best Small Program
|
# Best Small Program
|
||||||
|
|
||||||
Doron Osovlanski
|
Baruch Nissenbaum
|
||||||
CADTECH - CAD/CAM Systems Ltd
|
Tel-Aviv University
|
||||||
24 Ben-Yosef st.
|
The Faculty of Engineering
|
||||||
Givat-Shmuel 51905
|
Tel-Aviv
|
||||||
Israel
|
Israel
|
||||||
|
|
||||||
Baruch Nissenbaum
|
Doron Osovlanski
|
||||||
Tel-Aviv University
|
CADTECH - CAD/CAM Systems Ltd
|
||||||
The Faculty of Engineering
|
24 Ben-Yosef st.
|
||||||
Tel-Aviv
|
Givat-Shmuel 51905
|
||||||
Israel
|
Israel
|
||||||
|
|
||||||
## To build:
|
## To build:
|
||||||
|
|
||||||
make all
|
```sh
|
||||||
|
make all
|
||||||
|
```
|
||||||
|
|
||||||
## To run:
|
## To run:
|
||||||
|
|
||||||
echo 4 | ./baruch
|
```sh
|
||||||
echo 7 | ./baruch
|
echo 4 | ./baruch
|
||||||
|
echo 7 | ./baruch
|
||||||
|
```
|
||||||
|
|
||||||
|
## Try:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
echo 2 | ./baruch
|
||||||
|
echo 3 | ./baruch
|
||||||
|
```
|
||||||
|
|
||||||
|
Why is there no output?
|
||||||
|
|
||||||
|
### Alternate code:
|
||||||
|
|
||||||
|
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) provided alternate code
|
||||||
|
for users using Turbo-C or MSC, based on the authors' comments below, except
|
||||||
|
that he did not change the `" #Q"` string as that showed worse looking output
|
||||||
|
instead of improved output though he has no way to test the compilers in
|
||||||
|
question. YMMV. Thank you Cody (though we all think <strike>[no
|
||||||
|
one](https://en.wiktionary.org/wiki/no_one#Pronoun)</strike> [very
|
||||||
|
few](https://en.wikipedia.org/wiki/0)
|
||||||
|
[users](https://en.wikipedia.org/wiki/Microsoft_Windows)
|
||||||
|
[here](https://www.ioccc.org) will need it :-) )!
|
||||||
|
|
||||||
|
To compile:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make alt
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `baruch.alt` as you would `baruch`.
|
||||||
|
|
||||||
|
|
||||||
## Judges' comments:
|
## Judges' comments:
|
||||||
|
|
||||||
@@ -30,44 +64,38 @@ added a final newline to the file to make unpacking easy.
|
|||||||
|
|
||||||
## Authors' comments:
|
## Authors' comments:
|
||||||
|
|
||||||
The goal of this work was to write a program that solves the
|
The goal of this work was to write a program that solves the classic [n-queens
|
||||||
classic n-queen problem, with a board size of up to 99x99, while
|
problem](https://en.wikipedia.org/wiki/Eight_queens_puzzle), with a board size
|
||||||
keeping the program as short as possible.
|
of up to 99x99, while keeping the program as short as possible.
|
||||||
|
|
||||||
The program finds all possibilities to place N chess queens on
|
The program finds all possibilities to place N chess queens on a NxN
|
||||||
a NxN chess board so that no queen is in range of any other queen
|
[chessboard](https://en.wikipedia.org/wiki/Chessboard) so that no queen is in
|
||||||
(not in the same column row or diagonal). For each solution the
|
range of any other queen (not in the same column row or diagonal). For each
|
||||||
chess board and the place of the queens is printed to stdout.
|
solution the chess board and the place of the queens is printed to stdout.
|
||||||
|
|
||||||
|
This program is about as simple and as readable as possible. To make things
|
||||||
|
even more simple we used a very limited subset of C:
|
||||||
|
|
||||||
This program is about as simple and as readable as possible.
|
- No pre-processor statements
|
||||||
To make things even more simple we used a very limited subset of C:
|
- Only one, harmless, `for` statement
|
||||||
|
- No `if`s
|
||||||
No pre-processor statements
|
- No `break`s
|
||||||
Only one, harmless, 'for' statement
|
- No `case`s
|
||||||
No ifs
|
- No functions outside the standard C library
|
||||||
No breaks
|
- No `goto`s
|
||||||
No cases
|
- No structures
|
||||||
No functions
|
|
||||||
No gotos
|
|
||||||
No structures
|
|
||||||
|
|
||||||
In short, it contains no C language that might confuse the
|
|
||||||
innocent reader. :-)
|
|
||||||
|
|
||||||
|
In short, it contains no C language that might confuse the innocent reader. :-)
|
||||||
|
|
||||||
This program demonstrates the claim that in C, any program
|
This program demonstrates the claim that in C, any program
|
||||||
can be written using a single 'for' statement, as long as it is
|
can be written using a single 'for' statement, as long as it is
|
||||||
long enough..
|
long enough..
|
||||||
|
|
||||||
The authors' further note:
|
### For PC users:
|
||||||
|
|
||||||
For PC users:
|
In order to compile the program under Turbo-C or MSC, `'int '` should be inserted
|
||||||
|
at the beginning of the program. For better looking results it is recommended
|
||||||
In order to compile the program under Turbo-C or MSC, 'int '
|
to replace the `" #Q"` string with `" \261\2"`.
|
||||||
should be inserted at the beginning of the program.
|
|
||||||
For better looking results it is recommended to replace the " #Q"
|
|
||||||
string with " \261\2".
|
|
||||||
|
|
||||||
## Copyright and CC BY-SA 4.0 License:
|
## Copyright and CC BY-SA 4.0 License:
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ int v,i,j,k,l,s,a[99];
|
|||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i])
|
for(scanf("%d",&s);*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i])
|
||||||
;
|
;puts("");
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user