-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepretty.pl
executable file
·204 lines (161 loc) · 3.4 KB
/
makepretty.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/perl
$name = $ARGV[0];
$name =~ s/\..*//;
@words = ();
@clues = ();
@board = ();
@solved = ();
push(@words, $1), push(@clues, $2) while <> =~ /(\w+)\s*(.*)/;
$size = (scalar @words) / 2;
@solved = split /\W*/, <> until scalar @solved == $size*$size;
@board = map {$_ eq uc $_ ? uc $_ : ""} @solved;
@solved = map {uc} @solved;
###############################
print <<HERE;
<!doctype html>
<html>
<head><title>Anasquare</title>
<style>
* {
font-family: Segoe UI,Frutiger,Frutiger Linotype,Dejavu Sans,Helvetica Neue,Arial,sans-serif;
}
div.intro {
background: #fd0064;
color: white;
padding: 0.5em;
margin: 1em 0 2em;
}
div.intro h1 {
margin: 0;
padding: 6pt
}
div.intro p {
background: white;
color: black;
margin: 0;
padding: 6pt;
}
h1 {
}
body {width: 800px; margin: 5em auto; padding: 0}
dl {
overflow:hidden;
margin: 0.25em;
margin-bottom: 1em;
}
dt {
float:left;
clear: left;
width:4em; /* adjust the width; make sure the total of both is 100% */
text-align: right;
font-weight: bold;
}
dd {
float:left;
width:70%; /* adjust the width; make sure the total of both is 100% */
margin: 0 0.5em;
}
table {
border: 2px solid black;
border-collapse: collapse
}
td {
border: 1px solid black;
width: 1.7em; height: 1.7em;
text-align: center;
font-size: 20; font-weight: bold;
position: relative;
}
td span {
position: absolute; top: 0; left: 0;
font-size: x-small;
font-weight: normal;
}
h2 {
margin: 0 0 0.25em 4.5em;
font-weight: bold;
font-size: medium;
text-transform: uppercase;
}
hr {
clear: both;
margin: 1em 0;
}
</style>
</head>
<body>
<p style="text-align: right">$name</p>
<div class="intro">
<h1 style="float:right"><small>By William Entriken</small></h1>
<h1>Anasquare</h1>
<p><em>To solve this puzzle, first answer the Across and Down clues. Then anagram each answer into the grid in the correspondingly numbered row or column, using the given letters as a guide.
</div>
<div style="width:400px; float: left">
<h2>Across</h2>
<dl>
HERE
#########################
print "<dt>1</dt><dd>$clues[0]</dd>\n";
print "<dt>".($_+$size)."</dt><dd>$clues[$_]</dd>\n" for (1..$size-1);
print <<HERE;
</dl>
<h2>Down</h2>
<dl>
HERE
#########################
print "<dt>".($_)."</dt><dd>$clues[$_+$size-1]</dd>\n" for (1..$size);
print <<HERE;
</dl>
</div>
<div style="width:400px; float: right">
<table>
HERE
#########################
print "<tr>\n";
print " <td><span>".($_+1)."</span>$board[$_]</td>\n" for (0..$size-1);
for ($size..$#board) {
print "<tr>" if $_ % $size == 0;
$insert = $_ % $size == 0 ? "<span>".(($_)/$size+$size)."</span>" : "";
print " <td>$insert$board[$_]</td>\n";
}
print <<HERE;
</table>
</div>
<div class="intro" style="clear: both; page-break-before: always">
<h1>Answers</h1>
</div>
<div style="width:400px; float: left">
<dl>
HERE
#########################
print <<HERE;
<h2>Across</h2>
<dl>
HERE
#########################
print "<dt>1</dt><dd>$words[0]</dd>\n";
print "<dt>".($_+$size)."</dt><dd>$words[$_]</dd>\n" for (1..$size-1);
print <<HERE;
</dl>
<h2>Down</h2>
<dl>
HERE
#########################
print "<dt>".($_)."</dt><dd>$words[$_+$size-1]</dd>\n" for (1..$size);
print <<HERE;
</dl>
</div>
<div style="width:400px; float: right">
<table>
HERE
#########################
for (0..$#board) {
print "<tr>" if $_ % $size == 0;
print " <td>$solved[$_]</td>\n";
}
print <<HERE;
</table>
</div>
</body>
</html>
HERE