Add preview of 1984-2019
The 2020 winners are hinted it, but the source code is not there,
nor are the hints. Someone could look into the HTML and
see what was commented out, but that is not a problem because
WHO won is known and the name of their AWARD is known already.
Moreover a number of the winners have talked about what their
entirs do, so the commented out spoiler text is not a bit problem.
One will find HTML commented out with:
<!-- XXX remove when 2020 is ready
2020 links here
XXX remove when 2020 is ready -->
The "XXX remove when 2020 is ready" string is found at the
start and end comment blocks. Again, soneone could read
what was commented out, but that is OK since most of that
information is known or can be known. The following files
have such HTML comment blocks in them.
./winners.html
./years-spoiler.html
./years.html
In addition, ./all/summary.txt was modified to not
include the 2020 entries for the momemt.
The 2020 winner code AND write-ups are NOT part of this set.
p.s. The all/all.tar.bz2 does not contain the 2020 source code (yet?).
This commit is contained in:
1 parent
28efc67f5d
commit
c0663537cb
1683 files changed
+220064
No files matched your search
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env make
|
||||
#
|
||||
# 2011 makefile
|
||||
#
|
||||
# This work by Landon Curt Noll, Simon Cooper, and Leonid A. Broukhis
|
||||
# is licensed under:
|
||||
#
|
||||
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
|
||||
#
|
||||
# See: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
|
||||
################
|
||||
# tool locations
|
||||
################
|
||||
#
|
||||
SHELL= /bin/bash
|
||||
CP= cp
|
||||
CPP= cpp
|
||||
GUNZIP= gunzip
|
||||
LD= ld
|
||||
MAKE= make
|
||||
RM= rm
|
||||
SED= sed
|
||||
TAR= tar
|
||||
TRUE= true
|
||||
|
||||
# Compiler warnings
|
||||
#
|
||||
CWARN= -Wall -W
|
||||
|
||||
# compiler standard
|
||||
#
|
||||
CSTD= -std=c99
|
||||
|
||||
# compiler bit architecture
|
||||
#
|
||||
# Some entries require 32-bitness,
|
||||
# other entries require 64-bitess.
|
||||
# By default we assume nothing.
|
||||
#
|
||||
ARCH=
|
||||
|
||||
# optimization
|
||||
#
|
||||
# Most compiles will safely use -O2. Some can use only -O1 or -O.
|
||||
# A few compilers have broken optimizers or this entry make break
|
||||
# under those buggy optimizers and thus you may not want anything.
|
||||
#
|
||||
OPT= -O2
|
||||
|
||||
# default flags for ANSI C compilation
|
||||
#
|
||||
CFLAGS= ${CWARN} ${CSTD} ${ARCH} ${OPT}
|
||||
|
||||
# ANSI compiler
|
||||
#
|
||||
# Set CC to the name of your ANSI compiler.
|
||||
#
|
||||
CC= cc
|
||||
|
||||
|
||||
##############################
|
||||
# Special flags for this entry
|
||||
##############################
|
||||
#
|
||||
ENTRY= hamaji
|
||||
DATA= dragon.nono random.nono soccer.nono
|
||||
|
||||
|
||||
#################
|
||||
# build the entry
|
||||
#################
|
||||
#
|
||||
all: ${ENTRY} ${DATA}
|
||||
@${TRUE}
|
||||
|
||||
${ENTRY}: ${ENTRY}.c
|
||||
${CC} ${CFLAGS} ${ENTRY}.c -o ${ENTRY}
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt:
|
||||
@${TRUE}
|
||||
|
||||
|
||||
###############
|
||||
# utility rules
|
||||
###############
|
||||
#
|
||||
everything: all alt
|
||||
|
||||
clean:
|
||||
${RM} -f ${ENTRY}.o
|
||||
|
||||
clobber: clean
|
||||
${RM} -f ${ENTRY}
|
||||
|
||||
nuke: clobber
|
||||
@echo gnab gib!
|
||||
|
||||
install:
|
||||
@echo "Surely you're joking Mr. Feynman!"
|
||||
|
||||
# backwards compatibility
|
||||
#
|
||||
build: all
|
||||
|
||||
|
||||
##################
|
||||
# 133t hacker rulz
|
||||
##################
|
||||
#
|
||||
love:
|
||||
@echo 'not war?'
|
||||
|
||||
haste:
|
||||
$(MAKE) waste
|
||||
|
||||
waste:
|
||||
@echo 'waste'
|
||||
|
||||
easter_egg:
|
||||
@echo you expected to mis-understand this $${RANDOM} magic
|
||||
@echo chongo '<was here>' "/\\oo/\\"
|
||||
@echo Readers shall not be disallowed from being unable to partly misunderstand this final echo.
|
||||
@${TRUE}
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/perl -n0
|
||||
s%^ *((\d+\.)+\d+)|/$%print$1||"-","
|
||||
"%emg;s%^/.+%%ms;for$i(18..75){print/^.{$i}([\d.])/gm,"
|
||||
"}
|
||||
@@ -0,0 +1,29 @@
|
||||
3.4.3.3
|
||||
1.1.1.1.1.1
|
||||
1.1.1.1.1.3
|
||||
1.1.1.1.1.1
|
||||
3.4.3.3
|
||||
0
|
||||
2.4.1.3
|
||||
1.1.1.1.1
|
||||
1.2.1.1.1.3
|
||||
1.1.1.1.1.1
|
||||
2.4.3.1
|
||||
-
|
||||
5.3
|
||||
1.1.1.1
|
||||
1.1.1.1.1
|
||||
2
|
||||
5
|
||||
1.1.5
|
||||
1.1.1.1
|
||||
5.1.1
|
||||
5
|
||||
5
|
||||
1.1.5
|
||||
1.1.1
|
||||
3.1
|
||||
0
|
||||
5.5
|
||||
1.1.1.1.1
|
||||
1.1.1.1.1
|
||||
@@ -0,0 +1,94 @@
|
||||
13.3.37
|
||||
12.2.39
|
||||
11.2.40
|
||||
10.39
|
||||
9.36
|
||||
9.31
|
||||
8.3.32
|
||||
7.3.30
|
||||
5.3.29
|
||||
3.1.3.1.28
|
||||
1.2.4.31
|
||||
7.5.31
|
||||
1.6.5.30
|
||||
5.10.12.16
|
||||
5.11.5.4.12.4
|
||||
15.2.4.4.11.5
|
||||
16.3.4.2.2.5.5
|
||||
14.8.7.3
|
||||
12.1.4.1.6.2
|
||||
11.3.4.6.1
|
||||
10.1.8.8.5.1
|
||||
9.8.11.5
|
||||
9.5.6.1.2.4.1
|
||||
9.3.5.1.5
|
||||
3.2.6.5.1
|
||||
2.6.3.5.1
|
||||
2.1.2.6.3.6.1
|
||||
2.1.2.2.1.5.2.5.1
|
||||
2.1.2.5.5.6.3
|
||||
4.1.9.7.5.1
|
||||
5.19.6.1.2
|
||||
24.6.3.3
|
||||
24.1.2.9.7.4
|
||||
25.1.2.25
|
||||
28.1.26
|
||||
-
|
||||
11.23
|
||||
10.22
|
||||
10.12.6
|
||||
9.12.9
|
||||
9.13.5
|
||||
8.2.9.4
|
||||
8.2.9.8
|
||||
7.2.11.2.5
|
||||
6.1.2.11.5
|
||||
4.2.1.8.1.6
|
||||
3.3.2.7.9
|
||||
2.2.1.6.8
|
||||
1.1.1.5.7
|
||||
1.6.7
|
||||
2.6.7
|
||||
2.4.1.6
|
||||
1.5.6
|
||||
1.6.6
|
||||
1.3.1.2.5
|
||||
3.2.2.5
|
||||
3.5.5
|
||||
4.5.6
|
||||
5.6.6
|
||||
5.3.6
|
||||
5.6.3.2
|
||||
5.7.2.1
|
||||
5.1.6.2.3
|
||||
7.2.4.2.1
|
||||
8.9.2
|
||||
9.9.2
|
||||
18.3
|
||||
18.4
|
||||
15.7.1
|
||||
14.12
|
||||
14.1.13
|
||||
17.14
|
||||
17.6.7
|
||||
16.5.5
|
||||
15.3.4
|
||||
14.3.3
|
||||
13.2.3
|
||||
13.2.2.3.3
|
||||
17.3.3.2
|
||||
17.2.2.3
|
||||
16.3.3
|
||||
16.3.4
|
||||
16.1.5
|
||||
18.4
|
||||
19.2.3
|
||||
20.4.3
|
||||
22.6.2
|
||||
29.2
|
||||
15.11.2
|
||||
14.2.9.2
|
||||
17.6.3
|
||||
18.4
|
||||
19.5
|
||||
21.1.4.6
|
||||
@@ -0,0 +1,31 @@
|
||||
5.5
|
||||
3.5.3
|
||||
2.9.2
|
||||
1.2.1.2.1
|
||||
1.11.1
|
||||
4.1.4
|
||||
4.1.4
|
||||
13
|
||||
6.6
|
||||
13
|
||||
1.2.2.1
|
||||
1.11.1
|
||||
2.9.2
|
||||
3.5.3
|
||||
5.5
|
||||
-
|
||||
5.5
|
||||
3.5.3
|
||||
2.9.2
|
||||
1.11.1
|
||||
1.1.6.2.1
|
||||
2.1.3.3
|
||||
2.1.3.3
|
||||
7.1.3
|
||||
2.1.3.3
|
||||
2.1.3.3
|
||||
1.1.6.2.1
|
||||
1.11.1
|
||||
2.9.2
|
||||
3.5.3
|
||||
5.5
|
||||
@@ -0,0 +1,47 @@
|
||||
#include<stdint.h>// 4
|
||||
#include<stdio.h>/* 76. 1
|
||||
..2321 1 57 3
|
||||
21.... . .. .11 1 2
|
||||
1 88..1321 2 33 5512 1 277 14 1
|
||||
099..12.... . .. .... 1 4 11111...111 122 5.1 .
|
||||
11...221.821112411123455676489 51.176543232666 902 .27 1
|
||||
10111...1.....................11.417...........1...21..11.
|
||||
..2239921176566156225563322299887...6533233233182469196894
|
||||
22...............................111......................
|
||||
*/// 3269548556987776665556662131223412347543332334543322223456
|
||||
/*
|
||||
13.3.37 */char C[120] [60 ];int R[120][60],W,H,J,K,B[61][61],/*
|
||||
12.2.39 */r,i,j,c,*q =& H,t=7200,x,y,k;int64_t*U,T[28800],*S=/*
|
||||
11.2.40 */T,O[120], Z[ 120],v,z;void D(){for(k=-1;7200>++k;S[/*
|
||||
10.39 */k]=v)r=! ~(v=U[k])&&*R[k/60]?2:S[k]-v?1:r;;;;}/*
|
||||
9.36 */void L( ){for(r=1;r==1;){r=3;;for(i=0;120>/*
|
||||
9.31 */i;i++){ for(k=z=1,j=0;v=R[i][j];j++)O/*
|
||||
8.3.32 */[i]|=( 1LL <<v)-1<<k,k+=v,0,Z[i]=z|=1LL<</*
|
||||
7.3.30 */k++;; v=~ (3LL<<k-2);for(j=-61;++j<60;/*
|
||||
5.3.29 */v=( v|~ z)&(j<0?v>>1:v<<1|1))v=S[60/*
|
||||
3.1.3.1.28 */* i +(j < 0?~j:j)]|=j?v:~3;}for(z=0;/*
|
||||
1.2.4.31 ; */ 7200 >z;z++)i=z/60,j=z%60,(B[i<60?/*
|
||||
7.5.31 */i:j][ i<60? j:i-60]=~S[z]&O[i]?~S[z]&Z[i]/*
|
||||
1.6.5.30 ; */?r=0 :(U=O ,1):(U=Z,2))?k=i<60?j+60:j,S/*
|
||||
5.10.12.16 */[i% 60+60*k]|= ~U[k]:0;U=S; S-=t*=-1;D();z/*
|
||||
5.11.5.4.12.4 */*9; }}int main( ){for (;K= scanf("%d",R [*/*
|
||||
15.2.4.4.11.5 */q+c*60]+j)<1? q= &W,j --,2 >++c:'\n';j =-K/*
|
||||
16.3.4.2.2.5.5 */+getchar()?j+1 :++ *q*0 ); L( );;if (!r/*
|
||||
14.8.7.3 */)for(K=0;K<W *60;K++) if(K%60 </*
|
||||
12.1.4.1.6.2 */W&!B[K/60] [ K%60 ] ){for( /*
|
||||
11.3.4.6.1 */c=64;c--; )if (!(1 &S[K/* ;
|
||||
10.1.8.8.5.1 */]>>c))U= S ,000,S+= J=14400, D()/* ;
|
||||
9.8.11.5 */,S[K]=~ (1LL<<c) ,L(),S-=J,S [K]/*
|
||||
9.5.6.1.2.4.1 */|=r==2? 1LL<< c:0;L( ) ;} q=/* ;
|
||||
9.3.5.1.5 */&K;;for (J= K=i=0 ; 120/*
|
||||
3.2.6.5.1 */> i; Z[i]=k --,/* ;
|
||||
2.6.3.5.1 */ i>59?q =&J :0,/* ;
|
||||
2.1.2.6.3.6.1 */ * q< k?*q=k :0, 0,C[/* ;
|
||||
2.1.2.2.1.5.2.5.1 */ i ++ ][ k ]=' ' ){ j=k/* ;
|
||||
2.1.2.5.5.6.3 */ = 0; for(; x=R[i ][j++] ;/*
|
||||
4.1.9.7.5.1 */0) k +=sprintf ((00,C[ i]+/* ;
|
||||
5.19.6.1.2 */k), "%d.",x);}i=~J;;r&1 ||puts ( /*
|
||||
24.6.3.3 */r?"invalid":"failed"); for(;i <H; i/*
|
||||
24.1.2.9.7.4 */++,puts(""))for(j=~K;j < W; )putchar( i<0?j<0 ||/*
|
||||
25.1.2.25 */(k=i+Z[j+60])<0?' ':C[j + 60 ][k]:j<00?(k=j+Z[i])<0?/*
|
||||
28.1.26 */' ':C[i][k]:"?X "[B[i][j]] ) ,j++;return 0;} /* 2012 */
|
||||
@@ -0,0 +1,250 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta name="GENERATOR" content="mkd2html 2.1.3 DL=DISCOUNT">
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
||||
<link rel="stylesheet"
|
||||
type="text/css"
|
||||
href="../hint.css">
|
||||
<title>Best solved puzzle</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Best solved puzzle</h1>
|
||||
|
||||
<p>Shinichiro Hamaji<br>
|
||||
<a href="mailto:shinichiro.hamaji@gmail.com">shinichiro.hamaji@gmail.com</a></p>
|
||||
|
||||
<p>bsoup</p>
|
||||
|
||||
<h2>Judges' comments:</h2>
|
||||
|
||||
<h3>To build:</h3>
|
||||
|
||||
<pre><code>make hamaji
|
||||
</code></pre>
|
||||
|
||||
<h3>To run:</h3>
|
||||
|
||||
<pre><code>./hamaji < a_nonogram_file
|
||||
</code></pre>
|
||||
|
||||
<h3>Try:</h3>
|
||||
|
||||
<pre><code>./hamaji < dragon.nono
|
||||
./hamaji < random.nono
|
||||
./hamaji < soccer.nono
|
||||
./hamaji < codegolf.nono
|
||||
./hamaji < face.nono
|
||||
./hamaji < penguin.nono
|
||||
./hamaji < samurai.nono
|
||||
</code></pre>
|
||||
|
||||
<h3>Selected Judges Remarks:</h3>
|
||||
|
||||
<p>This program solves “Nonogram”, which also known as “Paint by Numbers”:</p>
|
||||
|
||||
<p><a href="http://en.wikipedia.org/wiki/Nonogram">http://en.wikipedia.org/wiki/Nonogram</a></p>
|
||||
|
||||
<p>This entry roar as the Year of the Dragon: A year considered
|
||||
some to be good luck. Well it was certainly true that the
|
||||
IOCCC was lucky to get such a fine submission!</p>
|
||||
|
||||
<p>The source code is a solution to a Paint by Numbers puzzle when you
|
||||
paint by C. Try your hand at solving a few of the other .nono
|
||||
files and then compare your solution with this program!</p>
|
||||
|
||||
<p>NOTE: NONOGRAM ® is a registered Trademark and is used with permission.
|
||||
See http://nonogram.com/ for more information.</p>
|
||||
|
||||
<h2>Author’s comments:</h2>
|
||||
|
||||
<p>The format of the input files are as same as this site:</p>
|
||||
|
||||
<p><a href="http://codegolf.com/paint-by-numbers">http://codegolf.com/paint-by-numbers</a></p>
|
||||
|
||||
<p>For example, for a simple problem which shows a glider of <a href="http://en.wikipedia.org/wiki/Conway's_Game_of_Life">conway’s
|
||||
lifegame</a>.</p>
|
||||
|
||||
<pre><code> 1
|
||||
.
|
||||
112
|
||||
|
||||
1 X
|
||||
1 X
|
||||
3 XXX
|
||||
</code></pre>
|
||||
|
||||
<p>the input should be</p>
|
||||
|
||||
<pre><code>1
|
||||
1
|
||||
3
|
||||
-
|
||||
1
|
||||
1.1
|
||||
2
|
||||
</code></pre>
|
||||
|
||||
<p>The width and the height of an input puzzle should be less than or
|
||||
equal to 60.</p>
|
||||
|
||||
<p>When this solver finds the problem has no solution, it prints “invalid”.
|
||||
This means the problem is indeed broken. For example, this happens for
|
||||
an input like</p>
|
||||
|
||||
<pre><code>2
|
||||
-
|
||||
2
|
||||
</code></pre>
|
||||
|
||||
<p>When this solver cannot find a solution, it prints “failed”. This
|
||||
failure can happen when the problem has more than one solution or the
|
||||
solver cannot solve the input problem. Here is an example input of the
|
||||
former:</p>
|
||||
|
||||
<pre><code>1
|
||||
1
|
||||
-
|
||||
1
|
||||
1
|
||||
</code></pre>
|
||||
|
||||
<p>There are two solutions:</p>
|
||||
|
||||
<pre><code> 11
|
||||
|
||||
1 X
|
||||
1 X
|
||||
</code></pre>
|
||||
|
||||
<p>and</p>
|
||||
|
||||
<pre><code> 11
|
||||
|
||||
1 X
|
||||
1 X
|
||||
</code></pre>
|
||||
|
||||
<h3>Detail</h3>
|
||||
|
||||
<p>Solving Nonogram is known NP-complete, so we cannot make a solver
|
||||
which solves all puzzles. However, we can write a solver which solves
|
||||
most problems solvable by humans. There are a bunch of ways to write
|
||||
such programs. The two most obvious approaches are:</p>
|
||||
|
||||
<ol>
|
||||
<li>Check all possible solutions with backtracking.</li>
|
||||
<li>Implement all techniques which humans use.</li>
|
||||
</ol>
|
||||
|
||||
|
||||
<p>The former, brute-force approach is easy to implement. However, it
|
||||
works only for smaller problems (width and height should be at most 30
|
||||
or so). Similarly, using generic probabilistic metaheuristics such as
|
||||
simulated annealing doesn’t work for big problems.</p>
|
||||
|
||||
<p><a href="http://ccl.northwestern.edu/netlogo/models/community/Nonogram">http://ccl.northwestern.edu/netlogo/models/community/Nonogram</a></p>
|
||||
|
||||
<p>By its definition, the latter works for all human-solvable
|
||||
problems. The issue of the latter approach is this kind of programs
|
||||
tends to be lengthy. This approach still requires some recursions. The
|
||||
most difficult problems which are considered human-solvable may
|
||||
require some “guesses”. For this kind of problems, we need to assume a
|
||||
cell is a space or a box, go ahead some steps with simple methods,
|
||||
mark the tried cell as a box (or a space if we assumed the tried cell
|
||||
is a box) if a contradiction is found.</p>
|
||||
|
||||
<p>My program uses an approach like “Set based solver” introduced in
|
||||
<a href="http://www.haskell.org/haskellwiki/Nonogram">http://www.haskell.org/haskellwiki/Nonogram</a> .
|
||||
This should be equivalent to the combinations of simple methods (no
|
||||
advanced reasoning with guess). My solver also runs non-recursive
|
||||
guess for each undetermined cells. So, my program should be able to
|
||||
solve most human-solvable problems (assuming humans cannot execute
|
||||
deeper recursions).</p>
|
||||
|
||||
<h3>Obfuscation</h3>
|
||||
|
||||
<p>First of all, as you see, my program looks like a nonogram puzzle
|
||||
which results a dragon. This puzzle is “dragon.nono” in this
|
||||
directory. Note that whitespaces in character literals, a string
|
||||
literal, and around the last comment are considered as a boxed cell.</p>
|
||||
|
||||
<p>My program is based on bit operations for speed. Many values are
|
||||
stored using negative logic (0 means on and 1 means off) to utilize
|
||||
the initial value of global variables. Thus, it might be difficult to
|
||||
figure out how it works.</p>
|
||||
|
||||
<p>My program is decently shortened, because the size of source code is
|
||||
limited by IOCCC’s rule (2048 non-whitespace characters) and a lot of
|
||||
characters are just wasted for numbers around the picture.</p>
|
||||
|
||||
<p>The three requirements (dragon, speed, and size) naturally ended up
|
||||
with the well obfuscated code.</p>
|
||||
|
||||
<h3>Portability</h3>
|
||||
|
||||
<p>This program uses two C99 features. One line comments and “long long”.
|
||||
GCC’s “-ansi -pedantic” check should pass:</p>
|
||||
|
||||
<pre><code>$ gcc -ansi -pedantic -std=c99 hamaji.c
|
||||
</code></pre>
|
||||
|
||||
<p>I checked my program with gcc-4.6.2 on linux, llvm-gcc-4.2 on mac, and
|
||||
clang-3.0 on mac.</p>
|
||||
|
||||
<p>Note that the behavior of scanf differs on linux and mac, but this
|
||||
program supports both semantics.</p>
|
||||
|
||||
<p>This program should not depend on sizeof(int), sizeof(void*), ASCII,
|
||||
memory layout, undefined evaluation order (e.g., a[i++]=i), etc.
|
||||
This program won’t work if the size of long long literal is less than 8.
|
||||
By grepping the source code of gcc</p>
|
||||
|
||||
<pre><code>grep LONG_LONG_TYPE_SIZE gcc/config/*/*
|
||||
</code></pre>
|
||||
|
||||
<p>I found long long may be 32bit integers only on AVR.</p>
|
||||
|
||||
<h3>A few more</h3>
|
||||
|
||||
<p>This code is considered as a new year’s postcard in Japan. We chose
|
||||
the dragon because 2012 is the year of dragon.</p>
|
||||
|
||||
<p><a href="http://en.wikipedia.org/wiki/Japanese_New_Year#Postcards">http://en.wikipedia.org/wiki/Japanese_New_Year#Postcards</a></p>
|
||||
|
||||
<p>The second author wrote the picture, and the first author did
|
||||
everything else.</p>
|
||||
|
||||
<p>The dragon.nono, samurai.nono, and penguin.nono was written by the
|
||||
second author. The soccer.nono was from a wikipedia entry. This file
|
||||
is important because it requires some guesses. The random.nono file
|
||||
was randomly generated. The codegolf.nono and face.nono have borrowed
|
||||
from this site:</p>
|
||||
|
||||
<p><a href="http://codegolf.com/paint-by-numbers">http://codegolf.com/paint-by-numbers</a></p>
|
||||
|
||||
<p>You can reproduce dragon.nono from hamaji.c using c2nono.pl:</p>
|
||||
|
||||
<pre><code>perl c2nono.pl hamaji.c | ./hamaji
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
|
||||
<!--
|
||||
(c) Copyright 1984-2012, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-->
|
||||
|
||||
<TABLE><TR>
|
||||
<TD><a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a></TD>
|
||||
<TD><P>© Copyright 1984-2012,
|
||||
<A HREF="/judges.html">Leo Broukhis, Simon Cooper, Landon Curt Noll</A>
|
||||
- All rights reserved<BR>
|
||||
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>.</P></TD>
|
||||
<TD> <!--<a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>--></TD>
|
||||
</TR></TABLE>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,211 @@
|
||||
# Best solved puzzle
|
||||
|
||||
Shinichiro Hamaji
|
||||
<shinichiro.hamaji@gmail.com>
|
||||
|
||||
bsoup
|
||||
|
||||
|
||||
## Judges' comments:
|
||||
### To build:
|
||||
|
||||
make hamaji
|
||||
|
||||
### To run:
|
||||
|
||||
./hamaji < a_nonogram_file
|
||||
|
||||
### Try:
|
||||
|
||||
./hamaji < dragon.nono
|
||||
./hamaji < random.nono
|
||||
./hamaji < soccer.nono
|
||||
./hamaji < codegolf.nono
|
||||
./hamaji < face.nono
|
||||
./hamaji < penguin.nono
|
||||
./hamaji < samurai.nono
|
||||
|
||||
### Selected Judges Remarks:
|
||||
|
||||
This program solves "Nonogram", which also known as "Paint by Numbers":
|
||||
|
||||
<http://en.wikipedia.org/wiki/Nonogram>
|
||||
|
||||
This entry roar as the Year of the Dragon: A year considered
|
||||
some to be good luck. Well it was certainly true that the
|
||||
IOCCC was lucky to get such a fine submission!
|
||||
|
||||
The source code is a solution to a Paint by Numbers puzzle when you
|
||||
paint by C. Try your hand at solving a few of the other .nono
|
||||
files and then compare your solution with this program!
|
||||
|
||||
NOTE: NONOGRAM (r) is a registered Trademark and is used with permission.
|
||||
See http://nonogram.com/ for more information.
|
||||
|
||||
## Author's comments:
|
||||
The format of the input files are as same as this site:
|
||||
|
||||
<http://codegolf.com/paint-by-numbers>
|
||||
|
||||
For example, for a simple problem which shows a glider of [conway's
|
||||
lifegame](http://en.wikipedia.org/wiki/Conway's_Game_of_Life).
|
||||
|
||||
1
|
||||
.
|
||||
112
|
||||
|
||||
1 X
|
||||
1 X
|
||||
3 XXX
|
||||
|
||||
the input should be
|
||||
|
||||
1
|
||||
1
|
||||
3
|
||||
-
|
||||
1
|
||||
1.1
|
||||
2
|
||||
|
||||
The width and the height of an input puzzle should be less than or
|
||||
equal to 60.
|
||||
|
||||
When this solver finds the problem has no solution, it prints "invalid".
|
||||
This means the problem is indeed broken. For example, this happens for
|
||||
an input like
|
||||
|
||||
2
|
||||
-
|
||||
2
|
||||
|
||||
When this solver cannot find a solution, it prints "failed". This
|
||||
failure can happen when the problem has more than one solution or the
|
||||
solver cannot solve the input problem. Here is an example input of the
|
||||
former:
|
||||
|
||||
1
|
||||
1
|
||||
-
|
||||
1
|
||||
1
|
||||
|
||||
There are two solutions:
|
||||
|
||||
11
|
||||
|
||||
1 X
|
||||
1 X
|
||||
|
||||
and
|
||||
|
||||
11
|
||||
|
||||
1 X
|
||||
1 X
|
||||
|
||||
### Detail
|
||||
|
||||
Solving Nonogram is known NP-complete, so we cannot make a solver
|
||||
which solves all puzzles. However, we can write a solver which solves
|
||||
most problems solvable by humans. There are a bunch of ways to write
|
||||
such programs. The two most obvious approaches are:
|
||||
|
||||
1. Check all possible solutions with backtracking.
|
||||
2. Implement all techniques which humans use.
|
||||
|
||||
The former, brute-force approach is easy to implement. However, it
|
||||
works only for smaller problems (width and height should be at most 30
|
||||
or so). Similarly, using generic probabilistic metaheuristics such as
|
||||
simulated annealing doesn't work for big problems.
|
||||
|
||||
<http://ccl.northwestern.edu/netlogo/models/community/Nonogram>
|
||||
|
||||
By its definition, the latter works for all human-solvable
|
||||
problems. The issue of the latter approach is this kind of programs
|
||||
tends to be lengthy. This approach still requires some recursions. The
|
||||
most difficult problems which are considered human-solvable may
|
||||
require some "guesses". For this kind of problems, we need to assume a
|
||||
cell is a space or a box, go ahead some steps with simple methods,
|
||||
mark the tried cell as a box (or a space if we assumed the tried cell
|
||||
is a box) if a contradiction is found.
|
||||
|
||||
My program uses an approach like "Set based solver" introduced in
|
||||
[http://www.haskell.org/haskellwiki/Nonogram](http://www.haskell.org/haskellwiki/Nonogram) .
|
||||
This should be equivalent to the combinations of simple methods (no
|
||||
advanced reasoning with guess). My solver also runs non-recursive
|
||||
guess for each undetermined cells. So, my program should be able to
|
||||
solve most human-solvable problems (assuming humans cannot execute
|
||||
deeper recursions).
|
||||
|
||||
### Obfuscation
|
||||
|
||||
First of all, as you see, my program looks like a nonogram puzzle
|
||||
which results a dragon. This puzzle is "dragon.nono" in this
|
||||
directory. Note that whitespaces in character literals, a string
|
||||
literal, and around the last comment are considered as a boxed cell.
|
||||
|
||||
My program is based on bit operations for speed. Many values are
|
||||
stored using negative logic (0 means on and 1 means off) to utilize
|
||||
the initial value of global variables. Thus, it might be difficult to
|
||||
figure out how it works.
|
||||
|
||||
My program is decently shortened, because the size of source code is
|
||||
limited by IOCCC's rule (2048 non-whitespace characters) and a lot of
|
||||
characters are just wasted for numbers around the picture.
|
||||
|
||||
The three requirements (dragon, speed, and size) naturally ended up
|
||||
with the well obfuscated code.
|
||||
|
||||
### Portability
|
||||
|
||||
This program uses two C99 features. One line comments and "long long".
|
||||
GCC's "-ansi -pedantic" check should pass:
|
||||
|
||||
$ gcc -ansi -pedantic -std=c99 hamaji.c
|
||||
|
||||
I checked my program with gcc-4.6.2 on linux, llvm-gcc-4.2 on mac, and
|
||||
clang-3.0 on mac.
|
||||
|
||||
Note that the behavior of scanf differs on linux and mac, but this
|
||||
program supports both semantics.
|
||||
|
||||
This program should not depend on sizeof(int), sizeof(void*), ASCII,
|
||||
memory layout, undefined evaluation order (e.g., a[i++]=i), etc.
|
||||
This program won't work if the size of long long literal is less than 8.
|
||||
By grepping the source code of gcc
|
||||
|
||||
grep LONG_LONG_TYPE_SIZE gcc/config/*/*
|
||||
|
||||
I found long long may be 32bit integers only on AVR.
|
||||
|
||||
### A few more
|
||||
|
||||
This code is considered as a new year's postcard in Japan. We chose
|
||||
the dragon because 2012 is the year of dragon.
|
||||
|
||||
<http://en.wikipedia.org/wiki/Japanese_New_Year#Postcards>
|
||||
|
||||
The second author wrote the picture, and the first author did
|
||||
everything else.
|
||||
|
||||
The dragon.nono, samurai.nono, and penguin.nono was written by the
|
||||
second author. The soccer.nono was from a wikipedia entry. This file
|
||||
is important because it requires some guesses. The random.nono file
|
||||
was randomly generated. The codegolf.nono and face.nono have borrowed
|
||||
from this site:
|
||||
|
||||
<http://codegolf.com/paint-by-numbers>
|
||||
|
||||
You can reproduce dragon.nono from hamaji.c using c2nono.pl:
|
||||
|
||||
perl c2nono.pl hamaji.c | ./hamaji
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
<!--
|
||||
(c) Copyright 1984-2012, [Leo Broukhis, Simon Cooper, Landon Curt Noll][judges] - All rights reserved
|
||||
This work is licensed under a [Creative Commons Attribution-ShareAlike 3.0 Unported License][cc].
|
||||
|
||||
[judges]: http://www.ioccc.org/judges.html
|
||||
[cc]: http://creativecommons.org/licenses/by-sa/3.0/
|
||||
-->
|
||||
@@ -0,0 +1,45 @@
|
||||
6
|
||||
8
|
||||
3.5
|
||||
2.4
|
||||
3.1.4
|
||||
2.1.4
|
||||
5.5
|
||||
3.5.2
|
||||
6.2
|
||||
1.3
|
||||
2.2
|
||||
2.2.2.2
|
||||
2.1.5.1.2
|
||||
1.1.3.1
|
||||
4.5
|
||||
1.1
|
||||
1.1
|
||||
1.1
|
||||
1.1
|
||||
1.1
|
||||
1.1.1.1
|
||||
1.2.3.2
|
||||
14
|
||||
6.3
|
||||
-
|
||||
2.3
|
||||
3.2.1
|
||||
1.2.1.1.1
|
||||
3.2.1.8.2
|
||||
3.8.3
|
||||
3.1.1.2
|
||||
2.1.1.1.2
|
||||
2.2.1.4
|
||||
3.2.1.3
|
||||
4.3.1.1
|
||||
8.2.1
|
||||
7.1.2
|
||||
5.4
|
||||
4.3
|
||||
3.2.2
|
||||
2.3.2
|
||||
2.2.6
|
||||
2.1
|
||||
2.1
|
||||
3
|
||||
@@ -0,0 +1,19 @@
|
||||
1.1.1.1
|
||||
3.3
|
||||
2.2.1
|
||||
5
|
||||
3.1.1
|
||||
2
|
||||
1.1.3
|
||||
2.3.1
|
||||
5
|
||||
2.1.1
|
||||
-
|
||||
1.1.1.1
|
||||
4.2
|
||||
1.2.2
|
||||
4.4
|
||||
3.2
|
||||
2.1.5
|
||||
2.3.1
|
||||
2.2.1
|
||||
@@ -0,0 +1,73 @@
|
||||
3
|
||||
5
|
||||
6
|
||||
5.4
|
||||
7.5
|
||||
3.7
|
||||
5.7
|
||||
6
|
||||
6
|
||||
5
|
||||
8
|
||||
11
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
18
|
||||
19
|
||||
21
|
||||
4.16
|
||||
3.5.9
|
||||
3.3.9
|
||||
2.11
|
||||
2.14
|
||||
1.18
|
||||
21
|
||||
24
|
||||
25
|
||||
12.11
|
||||
9.10
|
||||
9.9
|
||||
10.4
|
||||
7.3
|
||||
4.2
|
||||
3.5
|
||||
3.5
|
||||
-
|
||||
2
|
||||
2
|
||||
2
|
||||
1
|
||||
2
|
||||
2
|
||||
2
|
||||
2.2
|
||||
2.4
|
||||
2.5
|
||||
2.2.6
|
||||
3.7.1
|
||||
1.4.7
|
||||
1.6.7
|
||||
1.1.6.7
|
||||
3.8.7
|
||||
3.9.8
|
||||
3.10.9
|
||||
2.9.9
|
||||
3.19
|
||||
3.19
|
||||
3.19
|
||||
3.2.18
|
||||
3.5.18
|
||||
29
|
||||
1.27
|
||||
28
|
||||
28
|
||||
5.6.9
|
||||
3.8
|
||||
9
|
||||
12
|
||||
12
|
||||
9.2
|
||||
6.2
|
||||
2
|
||||
@@ -0,0 +1,41 @@
|
||||
3
|
||||
5
|
||||
3.1
|
||||
2.1
|
||||
3.3.4
|
||||
2.2.7
|
||||
6.1.1
|
||||
4.2.2
|
||||
1.1
|
||||
3.1
|
||||
6
|
||||
2.7
|
||||
6.3.1
|
||||
1.2.2.1.1
|
||||
4.1.1.3
|
||||
4.2.2
|
||||
3.3.1
|
||||
3.3
|
||||
3
|
||||
2.1
|
||||
-
|
||||
2
|
||||
1.2
|
||||
2.3
|
||||
2.3
|
||||
3.1.1
|
||||
2.1.1
|
||||
1.1.1.2.2
|
||||
1.1.3.1.3
|
||||
2.6.4
|
||||
3.3.9.1
|
||||
5.3.2
|
||||
3.1.2.2
|
||||
2.1.7
|
||||
3.3.2
|
||||
2.4
|
||||
2.1.2
|
||||
2.2.1
|
||||
2.2
|
||||
1
|
||||
1
|
||||
Reference in new issue
Block a user