Perlgolf History

Perlgolf History

Contents 1. Intro...... 11 2. On The Game...... 13 2.1. History...... 13 2.2. For Newbies ...... 13 2.3. Notation...... 13 2.4. Generic Rules...... 14 2.4.1. Versions ...... 16 2.4.2. Some Assumptions ...... 16 2.5. Open Source Engines...... 17 2.5.1. PGAS...... 17 2.5.2. JAGGS ...... 17 3. Games – Pretournaments ...... 18 3.1. Andrew’s Santa Claus Apocalypse...... 18 3.1.1. Rules...... 18 3.1.2. Solutions Hole 1 (head) ...... 19 3.1.3. Solutions Hole 2 (tail)...... 20 3.1.4. Solutions Hole 3 (rev)...... 21 3.1.5. Solutions Hole 4 (mid)...... 22 3.1.6. Solutions Hole 5 (wc) ...... 24 3.2. Ton’s Open Ircnet Perl Golf Challenge...... 26 3.2.1. Rules...... 26 3.2.2. Solutions with explanation...... 27 3.3. Andrew’s “Get Even”...... 34 3.3.1. Rules...... 34 3.3.2. Solutions Hole 1 (Get Even)...... 36 3.3.3. Solutions Hole 2 (Golf Scorer) ...... 40 3.4. LAPM#1 "Factorial" ...... 43 3.4.1. Rules...... 43 3.4.2. Solutions...... 43 3.5. LAPM#2 "Hamming Code"...... 44 3.5.1. Rules...... 44 3.5.2. Solutions...... 45 3.6. TopMach’s "Arabic to Roman number translator" ...... 45 3.6.1. Rules...... 46 3.6.2. Solutions...... 47 3.7. TopMach’s "Odd Number Math Magic Square" ...... 47 3.7.1. Rules...... 47 3.7.2. Solutions...... 48 3.7.3. Explanation...... 48 3.8. Ton’s Minigolf 2 "Closest Number" ...... 48 3.8.1. Rules...... 48 3.8.2. Solutions...... 49 3.9. Ton’s Midigolf 1 "" ...... 49 3.9.1. Rules...... 49 3.9.2. Solutions...... 49 3.10. Ton’s Irongolf 1...... 49 3.10.1. Rules...... 49 3.10.2. Solutions...... 51 3.11. Terje’s Cryptoanalysis...... 51 3.11.1. Rules...... 51 3.11.2. Solutions...... 52 3.12. Ton’s Maxigolf 1 "Stones"...... 52 3.12.1. Rules...... 52 3.12.2. Solutions...... 53 3.13. Ton’s Maxigolf 2 "Map coloring"...... 54 3.13.1. Rules...... 54 3.13.2. Solutions...... 55 3.14. Ton’s Minigolf 3 “Boxes”...... 56 3.14.1. Rules...... 56 3.14.2. Solutions...... 57 3.15. Ton’s Minigolf 4 "Missing Numbers" ...... 58

Edition 2007-01-09 top secret / strictly confidential page 2 of 520 Perlgolf History

3.15.1. Rules...... 58 3.15.2. Solutions...... 59 4. Games - TPR...... 61 4.1. TPR(0,0) "Base 36 Converter"...... 61 4.1.1. Rules...... 61 4.1.2. Solutions...... 61 4.2. TPR(0,1) "Numerology" ...... 61 4.2.1. Rules...... 61 4.2.2. Solutions...... 62 4.3. TPR(0,2) "Anagrams" ...... 62 4.3.1. Rules...... 62 4.3.2. Solutions...... 63 4.3.3. Artistic/Unorthodox Solutions...... 73 4.3.4. Explanation by Lars Mathiesen...... 74 4.4. TPR(0,3) "Mathemathics"...... 77 4.4.1. Rules...... 78 4.4.2. Solutions “Cantor”...... 78 4.4.3. Artistic/Unorthodox Solutions “Cantor”...... 87 4.4.4. Solutions “Kolakoski” ...... 92 4.4.5. Artistic/Unorthodox Solutions “Kolakoski” ...... 100 4.4.6. Explanation by Ton Hospel ...... 104 4.4.7. Explanation by Rick Klement...... 104 4.4.8. Explanation by Mtv Europe...... 107 4.4.9. Multilingual Solution by Jérôme Quelin...... 109 4.5. TPR(0,4) "Interlinear Counts"...... 120 4.5.1. Rules...... 120 4.5.2. Solutions...... 121 4.5.3. Artistic/Unorthodox Solutions...... 130 4.6. TPR(0,4b) "Topological Sort"...... 133 4.6.1. Rules...... 133 4.6.2. Solutions...... 134 4.6.3. Artistic/Unorthodox Solutions...... 140 4.6.4. Explanation by Chris Dolan...... 140 4.6.5. Explanation by Ton Hospel ...... 143 4.7. TPR(0,4c) "Ciphers and Letters" ...... 145 4.7.1. Rules...... 145 4.7.2. Solutions Hole 1 (Factorial)...... 146 4.7.3. Artistic/Unorthodox Solutions Hole 1 (Factorial)...... 149 4.7.4. Solutions Hole 2 (Postorder)...... 150 4.7.5. Artistic/Unorthodox Solutions Hole 2 (Postorder)...... 154 4.7.6. Explanation by Stephen Turner...... 154 4.8. TPR(0,5a) "Infix to RPN" ...... 156 4.8.1. Rules...... 156 4.8.2. Solutions...... 157 4.8.3. Artistic/Unorthodox Solutions...... 162 4.8.4. Explanation by Michael Thelen ...... 163 4.8.5. Explanation by Eugene van der Pijll...... 164 4.9. TPR(0,5b) "String to Number"...... 166 4.9.1. Rules...... 166 4.9.2. Solutions...... 167 4.9.3. Artistic/Unorthodox Solutions...... 174 4.9.4. Explanation by Ton Hospel ...... 174 4.10. TPR(0,6) "The Burrows-Wheeler Transform"...... 178 4.10.1. Rules...... 179 4.10.2. Solutions...... 183 4.10.3. Artistic/Unorthodox Solutions...... 187 5. Games - Terje’s PGAS season 0...... 188 5.1. The Archeologists' Dilemma...... 188 5.1.1. Rules...... 188 5.1.2. Solutions...... 188 5.2. Godzillagolf "Laser Beam" ...... 190 5.2.1. Rules...... 190 5.2.2. Solutions...... 191 5.3. Rotating sentences...... 192 5.3.1. Rules...... 192 5.3.2. Solutions...... 192 5.4. Eggtimer...... 194

Edition 2007-01-09 top secret / strictly confidential page 3 of 520 Perlgolf History

5.4.1. Rules...... 194 5.4.2. Solutions...... 194 5.5. Forth ...... 195 5.5.1. Rules...... 195 5.5.2. Solutions...... 197 5.6. Ordered fractions...... 198 5.6.1. Rules...... 198 5.6.2. Solutions...... 198 5.7. Power Crisis...... 200 5.7.1. Rules...... 200 5.7.2. Solutions...... 200 5.8. Starmap...... 202 5.8.1. Rules...... 203 5.8.2. Solutions...... 203 5.9. Cantor's revenge...... 204 5.9.1. Rules...... 204 5.9.2. Solutions...... 205 5.10. Add 11...... 208 5.10.1. Rules...... 209 5.10.2. Solutions...... 209 5.11. Go golf...... 211 5.11.1. Rules...... 211 5.11.2. Solutions...... 212 5.12. Modular Fibonacci ...... 213 5.12.1. Rules...... 213 5.12.2. Solutions...... 213 5.13. Self numbers...... 215 5.13.1. Rules...... 215 5.13.2. Solutions...... 215 5.14. Spinning wheels...... 218 5.14.1. Rules...... 218 5.14.2. Solutions...... 219 5.15. Columns squeezer ...... 219 5.15.1. Rules...... 220 5.15.2. Solutions...... 220 5.16. DNA sorting...... 221 5.16.1. Rules...... 221 5.16.2. Solutions...... 221 5.17. Clock patience...... 223 5.17.1. Rules...... 223 5.17.2. Solutions...... 224 5.18. Ideal golf ...... 226 5.18.1. Rules...... 226 5.18.2. Solutions...... 228 5.19. Scrabble...... 230 5.19.1. Rules...... 230 5.19.2. Solutions...... 230 5.20. "LED" Display ...... 232 5.20.1. Rules...... 232 5.20.2. Solutions...... 233 5.21. Spiral ...... 238 5.21.1. Rules...... 238 5.21.2. Solutions...... 239 5.22. Card trick...... 242 5.22.1. Rules...... 242 5.22.2. Solutions...... 243 5.23. Ascii ...... 245 5.23.1. Rules...... 245 5.23.2. Solutions...... 245 5.24. Soundex...... 248 5.24.1. Rules...... 248 5.24.2. Solutions...... 249 5.25. Isometric boxes ...... 252 5.25.1. Rules...... 252

Edition 2007-01-09 top secret / strictly confidential page 4 of 520 Perlgolf History

5.25.2. Solutions...... 253 5.26. All roads leads where ? ...... 257 5.26.1. Rules...... 257 5.26.2. Solutions...... 258 5.27. Crossing (s)words...... 260 5.27.1. Rules...... 260 5.27.2. Solutions...... 261 5.28. Rough Flying...... 263 5.28.1. Rules...... 263 5.28.2. Solutions...... 263 5.29. Digit sums...... 266 5.29.1. Rules...... 266 5.29.2. Solutions...... 267 5.30. Minesweeper ...... 268 5.30.1. Rules...... 268 5.30.2. Solutions...... 269 5.31. Linear Cellular Automata...... 271 5.31.1. Rules...... 271 5.31.2. Solutions...... 272 5.32. Motley boxes...... 274 5.32.1. Rules...... 274 5.32.2. Solutions...... 275 5.33. Hamming sequence ...... 278 5.33.1. Rules...... 278 5.33.2. Solutions...... 279 5.34. Vigenere Cipher ...... 282 5.34.1. Rules...... 282 5.34.2. Solutions...... 284 5.35. Musical Notes...... 286 5.35.1. Rules...... 287 5.35.2. Solutions...... 287 5.36. Strange Numbers...... 290 5.36.1. Rules...... 290 5.36.2. Solutions...... 290 6. Games - Terje’s PGAS season 1...... 293 6.1. Candy bags ...... 293 6.1.1. Rules...... 293 6.1.2. Solutions...... 294 6.1.3. Explanation by Ton Hospel ...... 296 6.2. Boggle ...... 299 6.2.1. Rules...... 299 6.2.2. Solutions...... 300 6.2.3. Explanation...... 302 6.3. Palindrome ...... 305 6.3.1. Rules...... 305 6.3.2. Solutions...... 306 6.4. Mathematical forest...... 308 6.4.1. Rules...... 308 6.4.2. Solutions...... 309 6.5. Goldbach's Conjecture...... 311 6.5.1. Rules...... 311 6.5.2. Solutions...... 312 6.6. Automatic Editing...... 313 6.6.1. Rules...... 313 6.6.2. Solutions...... 315 6.7. Align 2...... 317 6.7.1. Rules...... 318 6.7.2. Solutions...... 318 6.8. Perl Bowling...... 320 6.8.1. Rules...... 320 6.8.2. Solutions...... 320 6.9. Huffman codes ...... 321 6.9.1. Rules...... 322 6.9.2. Solutions...... 325

Edition 2007-01-09 top secret / strictly confidential page 5 of 520 Perlgolf History

6.10. PERT/Gantt chart conversion...... 327 6.10.1. Rules...... 327 6.10.2. Solutions...... 328 6.11. LED reader ...... 330 6.11.1. Rules...... 330 6.11.2. Solutions...... 330 6.11.3. Explanation by Juho Snellman...... 332 6.12. Reversi - Yet Another 2D Perl Golf...... 333 6.12.1. Rules...... 333 6.12.2. Solutions...... 334 6.13. Entropy compress...... 336 6.13.1. Rules...... 336 6.13.2. Solutions...... 337 6.14. Matcher...... 339 6.14.1. Rules...... 339 6.14.2. Solutions...... 340 6.15. Nim...... 341 6.15.1. Rules...... 342 6.15.2. Solutions...... 343 6.16. Josephus Problem...... 344 6.16.1. Rules...... 344 6.16.2. Solutions...... 344 6.17. Unfragment...... 346 6.17.1. Rules...... 346 6.17.2. Solutions...... 346 6.18. Permutations...... 349 6.18.1. Rules...... 349 6.18.2. Solutions...... 349 6.19. A1227...... 351 6.19.1. Rules...... 351 6.19.2. Solutions...... 351 6.19.3. Explanation by Ton Hospel ...... 353 6.20. Loopy ...... 354 6.20.1. Rules...... 354 6.20.2. Solutions...... 355 6.21. Card Trick 2 ...... 356 6.21.1. Rules...... 356 6.21.2. Solutions...... 357 6.22. Subproduct ...... 358 6.22.1. Rules...... 358 6.22.2. Solutions...... 359 6.23. Regex simplification...... 360 6.23.1. Rules...... 360 6.23.2. Solutions...... 361 6.24. Matrix...... 361 6.24.1. Rules...... 362 6.24.2. Solutions...... 362 6.25. Shadow...... 363 6.25.1. Rules...... 363 6.25.2. Solutions...... 365 6.26. Mayan number converter ...... 366 6.26.1. Rules...... 366 6.26.2. Solutions...... 366 6.27. Rush Hour...... 369 6.27.1. Rules...... 369 6.27.2. Solutions...... 373 6.28. Balanced Ternary Addition ...... 374 6.28.1. Rules...... 375 6.28.2. Solutions...... 376 6.29. Mastermind...... 377 6.29.1. Rules...... 377 6.29.2. Solutions...... 378 6.30. Triangles...... 379 6.30.1. Rules...... 379

Edition 2007-01-09 top secret / strictly confidential page 6 of 520 Perlgolf History

6.30.2. Solutions...... 380 6.31. Tennis Scoresheet...... 382 6.31.1. Rules...... 382 6.31.2. Solutions...... 383 7. Games - Terje’s PGAS season 2...... 385 7.1. Beads ...... 385 7.1.1. Rules...... 385 7.1.2. Solutions...... 385 8. Games - Kernelpanic season 1 ...... 387 8.1. PCLP #4 - GRAY CMP ...... 387 8.1.1. Solutions...... 387 8.2. PCLP #5b – SAPER...... 387 8.2.1. Solutions...... 388 8.3. PCLP #6 – SPIRALA...... 388 8.3.1. Solutions...... 388 8.4. PCLP #7 – KOMIWOJAŻER...... 389 8.4.1. Solutions...... 389 8.5. PCLP #8 – SZACHY ...... 390 8.5.1. Solutions...... 390 8.6. PCLP #9 - KWADRATY...... 391 8.6.1. Solutions...... 391 8.7. PCLP #10 - OKRES...... 392 8.7.1. Solutions...... 392 8.8. PCLP #11 - SZYFRANT ...... 392 8.8.1. Solutions...... 392 8.9. PCLP #12 - KRATY ...... 393 8.9.1. Solutions...... 393 8.10. PCLP #13 - SEKWENS ...... 395 8.10.1. Solutions...... 395 8.11. PCLP #14 - LIFE...... 396 8.11.1. Solutions...... 396 8.12. PCLP #15 - ŁAMANA ...... 397 8.12.1. Solutions...... 397 8.13. PCLP #16 - DEKODER...... 397 8.13.1. Solutions...... 397 8.14. PCLP #17 - PAŃSTWA...... 398 8.14.1. Solutions...... 398 8.15. PCLP #18 ROBAK ...... 399 8.15.1. Solutions...... 400 8.16. PCLP #19 - GIF...... 400 8.16.1. Solutions...... 400 8.17. PCLP #20 - KRĘGLE ...... 401 8.17.1. Solutions...... 401 8.18. PCLP #21 - KOD PASKOWY ...... 402 8.18.1. Solutions...... 402 8.19. PCLP #22 - KANJI ...... 402 8.19.1. Solutions...... 403 8.19.2. Explanation by Ton Hospel ...... 403 8.20. PCLP #23 - Double Linear Crosswords...... 405 8.20.1. Rules...... 405 8.20.2. Solutions...... 409 8.20.3. Explanation by Ton Hospel ...... 410 8.21. PCLP #24 - WYKREŚLANKA “Remove The Letters”...... 413 8.21.1. Rules...... 413 8.21.2. Solutions...... 414 8.22. PCLP #25 - MASZYNA TURINGA “Turing Machine”...... 415 8.22.1. Rules...... 416 8.22.2. Solutions...... 417 8.22.3. Explanation by Ton Hospel ...... 418 8.23. PCLP #26 COIN SLIDING...... 420 8.23.1. Rules...... 420

Edition 2007-01-09 top secret / strictly confidential page 7 of 520 Perlgolf History

8.23.2. Solutions...... 422 8.24. PCLP #27 - NARTY “SKI” ...... 423 8.24.1. Rules...... 423 8.24.2. Solutions...... 424 9. Games – Kernelpanic season 2...... 426 9.1. PCLP #2.1 (28) - UŁAMKI ŁAŃCUCHOWE...... 426 9.1.1. Solutions...... 426 9.2. PCLP #2.2 - PERMUTATION CYCLES...... 427 9.2.1. Rules...... 427 9.2.2. Solutions...... 428 9.3. PCLP #2.3.0xF – XXX (Arabic to roman number conversion)...... 428 9.3.1. Rules...... 429 9.3.2. Solutions...... 429 9.3.3. Explanation by Ton Hospel ...... 430 9.4. PCLP #2.4 - TABLICA...... 432 9.4.1. Rules...... 432 9.4.2. Solutions...... 432 9.5. PCLP #2.5 - INTERPRETER BF ...... 434 9.5.1. Rules...... 434 9.5.2. Solutions...... 435 9.6. PCLP #2.6 MACIERZ KWADRAT “Matrix2”...... 436 9.6.1. Rules...... 436 9.6.2. Solutions...... 436 9.7. PCLP #2.7 BULGARIAN ...... 437 9.7.1. Rules...... 437 9.7.2. Solutions...... 438 9.8. PCLP #2.8 PANORAMA ...... 439 9.8.1. Rules...... 439 9.8.2. Solutions...... 440 9.9. PCLP #2.9 KOŚCI ...... 441 9.9.1. Rules...... 441 9.9.2. Solutions...... 442 9.10. PCLP #2.10 - AKORDY...... 443 9.10.1. Rules...... 443 9.10.2. Solutions...... 444 9.11. PCLP #2.11 – OPERATORY “INTERCAL OPERATORS”...... 445 9.11.1. Rules...... 445 9.11.2. Solutions...... 447 10. Games – Kernelpanic season 3...... 449 10.1. PCLP #3.1 OBRAZKI LOGICZNE “GRIDDLERS” ...... 449 10.1.1. Rules...... 449 10.1.2. Solutions...... 449 10.2. PCLP #3.2 Kwadraty II “SQUARES II” ...... 450 10.2.1. Rules...... 450 10.2.2. Solutions...... 450 10.3. PCLP #3.3 - Base64 ...... 451 10.3.1. Rules...... 451 10.3.2. Solutions...... 452 10.4. PCLP #3.4 Labirynt “The ”...... 452 10.4.1. Rules...... 453 10.4.2. Solutions...... 454 10.5. PCLP #3.5 Zegarek LED ...... 455 10.5.1. Rules...... 455 10.5.2. Solutions...... 456 10.6. PCLP #3.6 Dekompresja “DECOMPRESSION” ...... 456 10.6.1. Rules...... 456 10.6.2. Solutions...... 458 10.7. PCLP #3.7 - TABULATURA...... 459 10.7.1. Rules...... 459 10.7.2. Solutions...... 460 11. Games – Kernelpanic season 4...... 462 11.1. PCLP #4.1 - UKRYTY OBRAZEK ...... 462 11.1.1. Solutions...... 462

Edition 2007-01-09 top secret / strictly confidential page 8 of 520 Perlgolf History

11.2. PCLP #4.2...... 462 11.2.1. Solutions...... 462 11.3. PCLP #4.3 Ogrodzenie “The Fence” ...... 463 11.3.1. Rules...... 463 11.3.2. Solutions...... 464 11.4. PCLP #4.4 - Jasio Forecaster “Johnny the Jasnowidz”...... 465 11.4.1. Rules...... 465 11.4.2. Solutions...... 466 11.5. PCLP #4.5 – WISIELEC “hungman” ...... 467 11.5.1. Solutions...... 467 11.6. PCLP #4.6 deROTer ...... 468 11.6.1. Rules...... 468 11.6.2. Solutions...... 469 11.6.3. Explanation by Juho Snellman...... 470 11.7. PCLP #4.7 Circle...... 471 11.7.1. Rules...... 471 11.7.2. Solutions...... 471 11.8. PCLP #4.8 Kwadraty III (Squares III) ...... 472 11.8.1. Rules...... 472 11.8.2. Solutions...... 474 11.9. PCLP #4.9 TAC ...... 474 11.9.1. Rules...... 475 11.9.2. Solutions...... 475 12. Games – Kernelpanic season 5...... 476 12.1. PCLP #5.1 Poker...... 476 12.1.1. Rules...... 476 12.1.2. Solutions...... 476 12.2. PCLP #5.2 PIGOLF ...... 477 12.2.1. Rules...... 477 12.2.2. Solutions...... 477 13. Games – Fonality...... 479 13.1. Fonality 1 - Roman Numeral Calculator...... 479 13.1.1. Rules...... 479 13.1.2. Solutions...... 480 14. Games – Perlmonks...... 487 14.1. MD5 ...... 487 14.2. Friday Golf: All 2-digit combinations...... 487 14.3. Kaprekar Numbers ...... 487 15. Games – Assorted...... 488 15.1. Resistor Colour Codes...... 488 15.1.1. Rules...... 488 15.1.2. Solutions...... 488 15.2. Factors ...... 489 15.2.1. Rules...... 489 15.3. Sudoku Solver...... 489 16. Around The Perl Golf ...... 491 16.1. Maps...... 491 16.1.1. World map...... 491 16.1.2. USA closeup...... 491 16.1.3. Europe closeup ...... 492 16.2. Participation Intensity ...... 492 16.2.1. Terje’s Season 0...... 492 16.2.2. Terje’s Season 1...... 493 16.2.3. Conclusion...... 493 16.3. Money...... 493 16.3.1. Career Money Leaders...... 493 16.3.2. Olympic Medal Table (Dutch conspiracy)...... 502 16.4. Poetry ...... 503 16.4.1. Dueling Dingos...... 503 16.4.2. Dueling Dingos v1.1...... 505 16.4.3. BEGIN { obsession }...... 514

Edition 2007-01-09 top secret / strictly confidential page 9 of 520 Perlgolf History

16.5. ::EyeDrops ...... 515 16.5.1. Christmas Present ...... 516 16.5.2. Santa the Golfer...... 516 16.5.3. Who is this mystery lady?...... 517 16.6. Eugene's Handbook of Designing Golf Courses...... 518 17. Conclusion...... 520

Edition 2007-01-09 top secret / strictly confidential page 10 of 520 Perlgolf History

1. Intro Goals of this book: • Keep the list of all known perl golfs • Keep interesting solutions • Keep all explanations on winning solutions Restrictions of this book: • Perl 5 Thanks to: • Abigail ( http://www.abigail.nl ) • Greg Allen • Philippe ‘BooK’ Bruhat ( http://www.bruhat.net ) • J. Riley Bryant • Yanick Champoux ( http://babyl.dyndns.org ) • Chris Dolan • Alain ‘TopMach’ Dupuis • Mtv Europe ( http://www.frox25.no-ip.org/~mtve/ ) • Shlomi Fish ( http://www.shlomifish.org ) • Ask Bjørn Hansen ( http://www.askbjoernhansen.com ) • Dave Hoover ( http://www.redsquirrel.com/dave/ ) • Ton Hospel ( http://www.xs4all.nl/~thospel/ ) • Geoff Hubbard • Keith Calvert Ivey ( http://www.cpcug.org/user/kcivey/ ) • Prakash Kailasa ( http://www.kailasa.net ) • Samy Kamkar ( http://cp5.lucidx.com ) • Amir Karger ( http://home.comcast.net/~amirkarger/ ) • Ronald J. Kimball • Rick ‘tybalt89’ Klement ( http://home.pacbell.net/rklement/ ) • Terje Kristensen ( http://terje.dev.webon.net ) • Antti Lankila • David Lowe • Hubert depesz Lubaczewski • Peter Makholm ( http://peter.makholm.net ) • Kimmo Makkonen • Mateusz ‘Magus’ Matuszek • Jasper McCrea ( http://www.mccrea.demon.co.uk ) • MeowChow • Steffen Mueller ( http://steffen-mueller.net ) • Rick Myers • F. Xavier Noria ( http://www.hashref.com ) • Wladimir Palant • Jason Henry Parker • Eugène Van Der Pijll ( http://www.phys.uu.nl/~pijll/ ) • Jeff ‘japhy’ Pinyan ( http://www.pobox.com/~japhy/ ) • Lolly Pop

Edition 2007-01-09 top secret / strictly confidential page 11 of 520 Perlgolf History

• Jérôme Quelin • Julien ‘pom’ Quint ( http://pom.clacbec.net ) • Ala Qumsieh • Michael Rybakin • Tuomo 'Bass' Salo ( http://almamedia.fi/~tasalo/ ) • Andrew Savige • Andreas Schaumeier • Michael G. Schwern ( http://www.pobox.com/~schwern/ ) • Juho Snellman ( http://www.cs.helsinki.fi/u/jesnellm/ ) • Karsten ‘Spiff’ Sperling ( http://www.spiff.de ) • Adam Spiers ( http://www.adamspiers.org ) • Jukka Suomela ( http://www.sammal.pp.fi ) • ( http://www.autrijus.org ) • Mike Taylor ( http://www.miketaylor.org.uk ) • Michael W. Thelen ( http://www.cs.utah.edu/~thelenm/ ) • Jay Tilton ( http://users.erols.com/tiltonj/ ) • Tina ‘Tinita’ Müller ( http://www.tinita.de ) • Ido Trivizki • Stephen Turner ( http://homepage.ntlworld.com/adelie/stephen/ ) • Stefan ‘Sec’ Zehl ( http://www.42.org/~sec/ ) And many thanks to people from #perl/ircnet, #perlgolf/ircnet, fwp@, golf@, p5p@, c.l.p.m, p.c.l.p, perlmonks and to all perlgolfers from the universe.

Edition 2007-01-09 top secret / strictly confidential page 12 of 520 Perlgolf History

2. On The Game Definition (from http://perlgolf.sourceforge.net/ ): A competition to find the shortest (fewest keystrokes) Perl code to solve a given problem.

2.1. History History of golf is stretching deep into the past. Rick Klement has played golf in Fortran in the 60’s. Donald Knuth has played golf in machine codes1 in the 50’s. The term “Perl Golf” was coined by Greg Bacon2 in 1999/06/21. Excellent article on perlgolf, “The Lighter Side of Perl Culture (Part IV)” by Andrew is at http://perlmonks.org/index.pl?node_id=437032

2.2. For Newbies Don’t be afraid of the code you will see in this book. You’re supposed to have basic perl knowledge and what is more important – you should know how to read the documentation. If you don’t understand some of what’s going on in the perl level in some particular example, divide it to smallest pieces and read about them in perldocs. The most useful perldocs for golf are: perlvar, perlre, perlop. In some situations you may want to check the perl sources, C knowledge is required then.

2.3. Notation Code is printed with monospaced font. Sometimes notation of the code will begin from perl switches, mentioned in perlrun. It will look like for example: -p $_ x=/grep/ In this case everything before the first space you should treat like usual parameters on a shebang3 line: #!perl –p $_ x=/grep/ Code marked red means nonprintable chars provided in forms ^A (ascii code 1), \n (newline inside a string), \177 (octal) or \xFF (hexadecimal). Code that does not fit in one line spreads to next lines with deeper indent: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_that_is_actually_ one_line_sometimes_separated_by_minuses_-_or spaces_oh_stupid_word_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

1 According to 2 According to <[email protected]> 3 The first line of script that begins with #! and tells to a kernel what program will run this script

Edition 2007-01-09 top secret / strictly confidential page 13 of 520 Perlgolf History

2.4. Generic Rules Version 1.01 Note: “Generic Rules” mention current perl version which refers by $VERSION. For the time of writing $VERSION eq v5.8.0 From http://www.xs4all.nl/~thospel/golf/rules.html 1. The program must be written as one or more lines. The score for each hole is the total number of bytes you need (smaller is better). If your program is more than one line, you must count the newlines in between as one byte each. The #! line is not counted. If you use options on the #! line, the options themselves are counted, including the leading whitespace, the - and any trailing whitespace (but not the newline). Get the count program1 if you have any doubts. 2. The program is expected to finish in a reasonable time. This means that even for your program's worst case input (whether that case is in the testset or not) the average runtime of your program should be less than the contest length, even on a somewhat slow computer (for discussion purposes we'll define this to be a 100Mhz Pentium II running a well optimized perl). The program also has to be valid only during the period that the challenge runs. 3. The program is assumed to run on a perfect computer that never makes mistakes, and when the program finishes, the result should always be correct. 4. You can submit as often as you want to until the deadline, no reason to wait until the last minute. In fact, other people want to see the score to beat on the leaderboard. So don't be a spoilsport by hoarding your score. Submit early and often. 5. If teams are allowed (by default they are), you may only play in one team and not at the same time play as an individual. Teams may be extended during play, but not with people already playing. Teams should be clearly marked as such by having the word "team" in their name, e.g. "Alma Media Golf Team". 6. The program may only use the perl executable, no other executables on the system are allowed (in particular, you must not use the programs implementing any other holes. The program may use itself though). You may use any of the perl $VERSION standard core modules. Your solution must be portable in the sense that it should work on all official unpatched versions of perl $VERSION everywhere. It's perfectly fine to abuse perl $VERSION bugs. For perl golf the executable (not the documentation) defines the language. 7. Some golfs are played with the rule that you are not allowed to use any modules, even the standard core ones. However, there are some perl statements like the unicode regex /\pM/ that implicitly load a number of modules. You are still allowed to use code like that, but in a "no modules" contest you are not allowed to use the extra symbols that became available this way (like Carp::croak). Notice that perl also has builtin functions like utf8::downgrade that are available even if you don't load the utf8 module. These are always valid to use. 8. The program should be self-contained (except for any I/O mentioned in the challenge). In particular, you may not do things like fetching extra data from a remote site. 9. You may assume ASCII as character set and you may use perl's unicode semantics. 10. Any bytes may be used in the sourcecode, including things like binary 0.

1 http://www.xs4all.nl/~thospel/golf/golfcount.pl

Edition 2007-01-09 top secret / strictly confidential page 14 of 520 Perlgolf History

11. At least 55% of the sourcecode must consist of normal ASCII characters matching /[ - ~\t\n]/. 12. All input and output will have a total size that will comfortably fit in memory (without swapping) and still allow you ample memory to play with. 13. Your program should not introduce arbitrary limits not specifically mentioned in the challenge. In particular, your program should not need changes depending on the amount of free memory it runs with. E.g. doing @a = (1) x (10**8) (trying to create an array bigger than every valid inputsize) is wrong. It will fail miserably unless the machines has about 2 Gigabytes of free memory. You may however always assume enough base memory to make datastructures of a few million entries (or strings of a few million characters), so something like @a = (1) x (10**6) is just fine. Using the rule that the input fits in memory you can also see that @a = (1) x $input_size is OK (if the input is 10**8 bytes, that rule ensures that in that case you in fact have these Gigabytes of free memory).

This rule is intentionally not formulated in terms of real memory, since that is too variable. But as a (non official) rule of the thumb: if your program uses more than a few tens of megabytes of memory, start thinking whether you can justify that. 14. Since your program should work on all official versions of perl $VERSION, it should work on both the 32-bit and 64-bit versions. This has a number of implications. Among them: a. Using 2**32 bytes of memory is an absolute maximum. This does however not imply the amount of memory you may assume available is even close to this number. It could be a lot less. See the previous rule for guarantees on the minimum amount of memory you can safely use. b. Input and output sizes will be < 2**32 bytes. c. Sizes of structures will fit in plain 32-bit integers.

Still, for most things the difference between 32-bit and 64-bit won't matter. You don't directly have to try to install both. 15. The program will be called as

some_perl_$VERSION_binary -- programname {args}

The file programname will be non-executable, but readable and writable (in fact, on unix it will have permissions 644). You do not get to choose the programname, but it will match /^[a-zA- Z][\w.-]*\z/ and will be the initial value of $0. You also don't get to choose the name of the perl binary. 16. If you have no options, you may leave out the #! line. If there is one, it will start with #!, and you may decide to follow that with an optional space or tab and a /. For the rest you only know that the part before any options will match m#^[\w/.-]+\z#, but you do not get to choose the exact path. 17. STDIN, STDOUT and STDERR may or may not be files. 18. If a read on a perl handle gives EOF (End Of File), you may assume later reads on the same handle will again EOF. 19. If very late in the game an important new testcase gets added to the testsuite, the deadline should be extended so people have time change their solutions.

Edition 2007-01-09 top secret / strictly confidential page 15 of 520 Perlgolf History

20. The sort operator is stable in perl 5.8.0 (which means that elements that compare as equal among each other will appear in the output in the same order as in the input). 21. Several things are not so much determined by perl itself, but by the environment in which it runs. But in real perls some things still tend to be true. Here are a number of assumptions you may make until someone finds a real perl (not specifically built to break them) that breaks them. Some of them may be even further restricted. a. There will be a crypt operator that behaves like old-style unix crypt if the salt matches /^[.\/0-9A-Za-z]{2}/ and the password matches /^[ -~]{0,7}\z/ or /^[ - ~]{8}/. b. 10**9 < $^T < 10**10 when the program starts. c. You can use perl to get addresses of objects with constructs like this:

perl -wle 'print []+0'

You may assume that such an address will be > 100000 (At least one machine is known where the number is 156000) You may assume the address is a multiple of 4. d. The output of rand() is assumed to be uniformly distributed and completely independent of previous calls to rand() (even if you know the underlying implementation and know it can't be). You may not assume it will never return the exact same value twice. The exact sequence you get after srand with a given value is not portable. e. Shifts are done modulo some wordsize, so: 1<<64==1 and 1>>64==1 (you don't know what 1<<32 is since you don't know if your program will get tested on a 32-bit or a 64-bit perl). At least one system (powerpc mac) is known where the result is basically 2**($n % 64) & (2**32-1). f. The result of $? after an empty `` is unportable (0 on windows with activestate perl, 256 on linux). All known perls set $! to dualvar(0,""). g. -0.0 and -undef (and therefore also things like -$a on an undefined variable $a) are unportable. On some systems it gives 0, on others -0. Both of these are false for perl and are numerically equal to 0. But they stringify to "0" (false for perl) and "-0" (true for perl) respectively. -0 and -"" are 0 everywhere.

2.4.1. Perl Versions Version First game Date 5.6.1 TPR(0,0) February 1st, 2002 5.8.0 TPR(0,6) November 12th, 2002

2.4.2. Some Assumptions Sometimes game rules are given in a kind of relaxed fashion; in this case assumptions apply and should be considered as instructions unless stated otherwise. Output should be properly newline terminated. Nothing should be written to STDERR. Input can be command line (@ARGV) or from properly newline-terminated STDIN. The returncode of your program does not matter.

Edition 2007-01-09 top secret / strictly confidential page 16 of 520 Perlgolf History

2.5. Open Source Tournament Engines

2.5.1. PGAS PGAS (Perl Golf Administration System) helps Perl Golf administrators administrate Perl Golf courses on the web. It is a MySQL-driven Perl/CGI application that automates many of the tasks that make Perl Golf administration such a time-consuming endeavour. • PGAS Project Summary http://www.sourceforge.net/projects/perlgolf/ • PGAS Web Service API http://sourceforge.net/docman/display_doc.php?docid=10011&group_id=46501

2.5.2. JAGGS JAGGS (Just another Golf Game System). Wasn’t used for real games. Playing in golf including but not limited to perlgolf with automatized checking. System consists of web UI and automatic checker. Data stored in MySQL database. Web UI implemented on perl+FastCGI. Checker consists of perl script that run by cron, interacts with SQL and runs pending submission thru test script. Test script (Ton Hospel's gentest.pl is recommended for golfs http://www.xs4all.nl/~thospel/golf/gentest.pl ) check submissions, but instead of running real language interpreter (for ex. perl) it runs suid wrapper that runs real interpreter in much restricted environment - chrooted, quoted, rlimited and firewalled. http://sourceforge.net/projects/jaggs/

Edition 2007-01-09 top secret / strictly confidential page 17 of 520 Perlgolf History

3. Games – Pretournaments 3.1. Andrew’s Santa Claus Golf Apocalypse

3.1.1. Rules Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: The Santa Claus Golf Apocalypse Date: Sun, 2 Dec 2001 19:40:37 +1100 From: [email protected] (Andrew Savige) As an early Christmas present, you are invited to play Santa Claus' newly constructed 5-hole golf course. The holes are likely too easy, but that will hopefully encourage more entries (feedback welcome). In fact, this whole golf game is a little experimental and hopefully we can improve its format based on the outcome of this game. Please post solutions only to me, Santa the Arbiter. But before posting, verify your entries with the below test program, tsanta.pl. I will verify that they are indeed ok and post a daily leaderboard. I am open to ideas re the winner's prize. In most fwp golf games, we all steal ideas; the idea here is to keep the source code secret, only the current leaderboard is known. The test program, tsanta.pl, should run on both Windows and Unix (forgive me, but I don't have a Unix machine available right now). To allow for cross-platform differences, please format your code with a leading #!/usr/bin/perl line if you want to use command-line switches. For example: #!/usr/bin/perl -n print This has golf score of 8 (5 for 'print', 3 for ' -n'). All 5 holes manipulate text files. You may assume that said text files are always properly newline- terminated and that they do not contain any binary zeros. Similarly, your programs must properly newline-terminate everything they write (they always write to STDOUT). When in doubt about the specification, use the test program, tsanta.pl; if your entries pass the test program, they are ok. You must name your programs as shown below and put them in the same directory as the test program. That done, run the test program: perl tsanta.pl to verify that your entries meet the specification. • Hole 1. head.pl. Print first 10 lines of a text file. • Hole 2. tail.pl. Print last 10 lines of a text file. • Hole 3. rev.pl. Print a text file in reverse order. • Hole 4. mid.pl. Print the middle line/s of a text file (one line if an odd number of lines; two lines if an even number). • Hole 5. wc.pl. Print the number of lines in the file to STDOUT, zero-filled, right-justified, 10 chars wide.

Edition 2007-01-09 top secret / strictly confidential page 18 of 520 Perlgolf History

Merry Christmas to all participants. Santa Claus the Arbiter.

3.1.2. Solutions Hole 1 (head) Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Santa Hole 1 (head.pl) Post Mortem Date: Fri, 7 Dec 2001 10:15:43 +1100 From: [email protected] (Andrew Savige) We should call this "Piers' hole" :-). In one of the most generous gestures in the history of golf, he published his now infamous use.perl.org journal entry, effectively giving the whole field the best solution. But I will always remember this hole for his surreal: -p 11..& That said, Rick Delaney won the hole, finding Piers' solution before Piers did. Eugene did that too. 11, Eugene van der Pijll, Piers Cawley, Jonathan E Paton, ton, Dave O'Neill, Tony Payne, Scott Wessels, Ala Qumsieh, Tim Ayers, Richard Proctor, Karsten Sperling, Ian Boreham, Anthony J Breeds-Taurima, Zed Lopez -p 11..exit 11, Rick Klement, Damian James, Csaba Raduly, Japhy, Jerome Quelin, Ronald J Kimball, Rick Delaney -p 11..last 12, Aaron D Marasco -p 11..exit; 13, Yanick, anonymous -p $_ x=$.<11 14, Michael G Schwern -p $.<11||exit 14, anonymous -p $.<11||last 14, Simon Drabble, Ian Phillipps, Robin Houston, Brad Greenlee, Mark Suter, Michael Lambert -p $.>10&&exit 14, Keith C Ivey, Vladi Belperchinov-Shabanski, anonymous -p $.>10&&last 14, anonymous -p $.>9...exit 14, Evan A Zacks -p 11..1&&exit 14, BooK

Edition 2007-01-09 top secret / strictly confidential page 19 of 520 Perlgolf History

-p 11^$.||last 15, anonymous -n $.<11&&print 16, Josh Shulz -p exit if $.>10 16, anonymous -p exit if$.==11 16, anonymous print+(<>)[0..9] 16, anonymous print@_[0..9]=<> 17, anonymous -p exit if($.>10)

3.1.3. Solutions Hole 2 (tail) Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Santa Hole 2 (tail.pl) Post Mortem Date: Fri, 7 Dec 2001 10:28:46 +1100 From: [email protected] (Andrew Savige) This hole was one by Ronald J Kimball with his first post in the opening hours of the game. It proved frustrating, as evidenced by Japhy's mid-game comment: "Geez, I have three different solutions for tail.pl, ALL the same length (19 chars). Has someone gotten below 19?" Japhy was able to go below 19 by using the Unix tail command: exec tail,-10,pop though this was not allowed in this game. 18 (deep post-mortem) print+(<>)[~9..-1] 19, Simon Drabble, Eugene van der Pijll, Rick Klement, Damian James, Vladi Belperchinov- Shabanski, Ian Phillipps, Yanick, Piers Cawley, Jonathan E Paton, Robin Houston, ton, Ala Qumsieh, , Brad Greenlee, Jerome Quelin, Ronald J Kimball, Karsten Sperling, Evan A Zacks, Ian Boreham, Rick Delaney, BooK print+(<>)[-10..-1] 19, Japhy (alternative) map--$.>9||print,<> 19, Japhy (alternative) --$.>9||print for<> 20, Michael Lambert, anonymous

Edition 2007-01-09 top secret / strictly confidential page 20 of 520 Perlgolf History

print((<>)[-10..-1]) 21, Keith C Ivey, Tony Payne, Tim Ayers print@{[<>]}[-10..-1] 22, Mark Suter @A=<>;print@A[-10..-1] 22, Dave O'Neill, Csaba Raduly, Richard Proctor, Anthony J Breeds-Taurima @_=<>;print@_[-10..-1] 22, Zed Lopez @a=<>;print@a[-10..-1] 22, Scott Wessels print((<>)[-10..$.-1]) 26, Michael G Schwern -0p /(.*\n){0,10}\z/;$_=$& 35, Josh Shulz @a=<>;print splice @a,$.<10?-$.:-10 38, anonymous @a=<>;print splice @a,-(($.<10)?$.:10) 44, Aaron D Marasco -n @N[$.]=$_;10..($N[$.-10]='');END{print@N}

3.1.4. Solutions Hole 3 (rev) Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Santa Hole 3 (rev.pl) Post Mortem Date: Fri, 7 Dec 2001 10:02:54 +1100 From: [email protected] (Andrew Savige) This is the hole that won it for Eugene. In fact, he was the only golfer to find a 13-stroke solution. As you might expect, just about everybody chose the obvious FAQ solution. I almost did not include this hole; I only put it in only because I was originally designing Santa's course for beginning Perl programmers at work and thought it was instructive. Never in my wildest dreams did I expect the FAQ solution to be bettered. That this hole proved decisive underscores the unpredictable nature of golf. 13, Eugene van der Pijll -p $\=$_.$\}{ 15, Simon Drabble, Rick Klement, Keith C Ivey, Damian James, Vladi Belperchinov-Shabanski, Ian Phillipps, Yanick, Piers Cawley, Robin Houston, ton, Dave O'Neill, Tony Payne, Scott Wessels, Csaba Raduly, Japhy, Tim Ayers, Brad Greenlee, Jerome Quelin, Richard Proctor, Ronald J Kimball, Mark Suter, Evan A Zacks, Ian Boreham, Rick Delaney, Anthony J Breeds-Taurima, BooK, Michael G Schwern, Michael Lambert

Edition 2007-01-09 top secret / strictly confidential page 21 of 520 Perlgolf History

print reverse<> 15, Jonathan E Paton, Ala Qumsieh, Karsten Sperling print+reverse<> 16, Aaron D Marasco, Josh Shulz print reverse <> 16, anonymous print+reverse+<> 20, anonymous -n $l=$_.$l}{print$l 21, anonymous -n $l="$_$l"}{print$l 21, Zed Lopez @a=<>;print reverse@a 24, anonymous -n END{print$l}$l="$_$l"

3.1.5. Solutions Hole 4 (mid) Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Santa Hole 4 (mid.pl) Post Mortem Date: Fri, 7 Dec 2001 10:58:03 +1100 From: [email protected] (Andrew Savige) This hole, arguably the most interesting of the set, was won by Eugene with his first post in the opening hours of the game. He got off to a fast start because he had just analysed a similar problem from a previous fwp "middle line" thread (in fact, I blame Yanick for this golf game, and he blames Greg Bacon, and he blames...). The following elegant 26-character solution, first found by Ronald J Kimball, proved popular: @n=<>;print@n[$#n/2..@n/2] Piers and Karsten both found shorter multi-line solutions: Piers: "Grr... that one line rule is so silly:" -p0 $_=$1while/ (.+)^/ms Karsten: -p0 $_=$1while/ (.* )./s Oh well, I will leave it up to Eugene the Arbiter to decide on the scoring rules for the Easter Apocalypse, but Piers and Karsten, at least, will lobby vigorously to allow multiple lines. 25, Keith C Ivey, Piers Cawley

Edition 2007-01-09 top secret / strictly confidential page 22 of 520 Perlgolf History

-p0 $_=$1while/.(^.+)^/ms 25, Karsten Sperling -p0 $_=$1while/.(^.+^)/sm 25, Eugene van der Pijll -p0 $_=$1while/.^(.+)^/ms 25, Rick Delaney -p0 $_=$1while/.^(.+)^/sm 26, Vladi Belperchinov-Shabanski, Scott Wessels, BooK, anonymous -p0 $_=$1while/\n(.*\n)./s 26, Ala Qumsieh -p0 $_=$1while/\n(.+\n)./s 26, Mark Suter @A=<>;print@A[$#A/2..@A/2] 26, Rick Klement, Yanick, ton @F=<>;print@F[$#F/2..@F/2] 26, Richard Proctor @_=<>;print@_[$#_/2..$./2] 26, Robin Houston, Japhy @_=<>;print@_[$#_/2..@_/2] 26, Brad Greenlee, Michael G Schwern, Zed Lopez, anonymous @a=<>;print@a[$#a/2..@a/2] 26, Ronald J Kimball @n=<>;print@n[$#n/2..@n/2] 26, Ian Phillipps @x=<>;print@x[$#x/2..@x/2] 26, Damian James @z=<>;print@z[$#z/2..@z/2] 26, anonymous print@F[(@F=<>)/2.1..@F/2] 27, Simon Drabble print@a[(@a=<>)/2-.5..$./2] 28, Jerome Quelin @_=<>;print@_[$./2-.5..$./2] 28, Ian Boreham, anonymous @a=<>;print@a[$./2-.5..$./2] 28, Tim Ayers

Edition 2007-01-09 top secret / strictly confidential page 23 of 520 Perlgolf History

@a=<>;print@a[@a/2-.5..@a/2] 29, Tony Payne -0p $_=$1while/\n(.*\n).*\n/s 29, anonymous -p0 $_=$1while/\n(.+\n).*\n/s 29, Jonathan E Paton @_=<>;print@_[--$./2..++$./2] 29, Dave O'Neill @a=<>;print@a[(@a-1)/2..@a/2] 32, Anthony J Breeds-Taurima @_=<>;$_=$./2;print@_[$_-.5..$_] 33, Csaba Raduly -p0l12 chop;$_=$1while/\n(.*)\n/s 33, Michael Lambert @_=<>;print splice@_,$#_/2,2-@_%2 33, Evan A Zacks print@a[(@a=<>)%2?():@a/2-1,@a/2] 34, anonymous @_=<>;print splice@_,--$./2,1+$.%2 35, Josh Shulz @a=<>;print splice @a,$#a/2,$#a%2+1 36, anonymous @a=<>;print splice(@a,$#a/2,$#a%2+1) 37, anonymous @a=<>;@a&&print@a[@a/2-!(@a&1)..@a/2] 50, Aaron D Marasco -n $N[$.]=$_;END{print$.&1?'':$N[$./2],$N[$./2+1]}

3.1.6. Solutions Hole 5 (wc) Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Santa Hole 5 (wc.pl) Post Mortem Date: Fri, 7 Dec 2001 10:36:50 +1100 From: [email protected] (Andrew Savige) This hole was one by Japhy with his first post in the opening hours of the game. Like hole 2, this proved very frustrating with all attempts to improve on printf failing. BooK, in particular, made repeated heroic attempts: "My wc.pl is 21, but uses printf. I tried many things to get rid of printf, but all of them ended up being longer...

Edition 2007-01-09 top secret / strictly confidential page 24 of 520 Perlgolf History

Here they are (the first ' ' marks the end of the command-line switches): -n END{print$a,$/}BEGIN{$a='00'x5}++$a # 38 -n BEGIN{$a=$-x10}$a++;END{print$a,$/} # 38 -n INIT{$a=$-x10}$a++;END{print$a,$/} # 37 -lp0 $_=y/\n//;$_=$-x(- y///c%10).$_ # 36 -lp0 $_=substr$-x9 .y/\n//,-10 # 30 These are the longest I did. All my shorter ones use printf." 20 (post-mortem), Andrew -p }{$_=$.+1e9.$/^v1 21, Piers Cawley -lp $#='%010g'}{$_=$. 21, Eugene van der Pijll, Rick Klement, Yanick, Robin Houston, ton, Tony Payne, Ala Qumsieh, Scott Wessels, Japhy, Tim Ayers, Jerome Quelin, Ronald J Kimball, Karsten Sperling, Rick Delaney, BooK, Michael G Schwern printf"%010d\n",$.,<> 22, Keith C Ivey -lp }{$_=7e10+$.,s$.$$ 22, Evan A Zacks -lp }{printf"%010d",$. 22, Jonathan E Paton -pl }{printf"%.10d",$. 22, anonymous -pl }{printf"%010d",$. 23, Damian James, Csaba Raduly, Mark Suter, anonymous -n }{printf"%010d\n",$. 23, anonymous -pl }printf"%010d",$.;{ 23, Brad Greenlee [<>]&printf"%010d\n",$. 23, Ian Boreham [<>];printf"%.10d\n",$. 23, Richard Proctor, Michael Lambert, anonymous [<>];printf"%010d\n",$. 24, anonymous -n }printf"%010d\n",$.;{ 24, Dave O'Neill, anonymous @_=<>;printf"%.10d\n",$. 24, anonymous

Edition 2007-01-09 top secret / strictly confidential page 25 of 520 Perlgolf History

@_=<>;printf"%010d\n",$. 24, Simon Drabble @a=<>;printf"%010d\n",$. 24, Anthony J Breeds-Taurima [<>];printf"%0.10d\n",$. 24, Vladi Belperchinov-Shabanski printf"%010d\n",$_=@_=<> 25, Josh Shulz @a=<>;printf "%010u\n",$. 25, Ian Phillipps printf"%010d\n",(@x=<>)+0 25, anonymous printf"%010d\n",0+@{[<>]} 26, Aaron D Marasco -n END{printf"%010d\n",$.} 26, Zed Lopez -n eof..printf"%010d\n",$. 26, anonymous @a=<>;printf("%010u\n",$.) 20, Andrew (post-mortem) -p }{$_=$.+1e9.$/^v1

3.2. Ton’s Open Ircnet Perl Golf Challenge 2002/01/01 http://www.xs4all.nl/~thospel/golf/challenge.html

3.2.1. Rules “Human Sort” Sort a set of lines, but with a twist. When sorting a set of lines, humans like to see the numeric parts of a line sorted numerically and the alphabetical parts case insensitive. For the numeric parts you may ignore the possibility of negative numbers, floating point numbers and leading zeros, the numbers however are almost unconstrained in length. In other words, a sequence of one or more digits plays the same sort of role as some kind of single character, and such a sequence sorts before all normal letters, but among themselves they are ordered by numerical value. Example: 1

Edition 2007-01-09 top secret / strictly confidential page 26 of 520 Perlgolf History

• watch out, the original version of this question allowed leading zeros in the number parts, but that made programs substantially more complicated and less fun. While this change won't invalidate any existing solution, maybe you can do better now.... • The strings can also be things like: 57amstel25venn865314457646576532325988watte “Fair Shuffle” Outputs some random permutation of the input lines. Each permutation must be equally likely over many runs. “Select Two” print 2 lines each randomly chosen from the input, however the two must not come from the same line in the input. You may assume the input is 2 lines or more. each pair of outputlines must be equally likely, and their order itself also random Some more hints about randomness: • using non-consistent sort-functions will not be accepted. The results are not random on almost any sort implementation and can even coredump some implementations. • You must not ignore the fact that two calls to rand can in principle return the exact same number twice. • You may assume each value returned by rand is equally likely.

3.2.2. Solutions with explanation Newsgroups: perl.fwp Subject: Re: For those who can't stop golfing Date: Tue, 1 Jan 2002 19:54:56 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) Well, it's over, and the final results are in. About 6 beginners tried, but only one succeeded in surviving hole 1, and that person is therefore the clear winner: Dave Hoover human.pl: 276 strokes shuffle.pl: 36 strokes select.pl: 37 strokes ------total: 349 strokes Among the experienced players, the winner is spiff (Karsten Sperling), even though there were some last minute attempts to dislodge him, especially from Autrijus Tang who went from last place to third in the last few hours. Spiff needed 131 strokes to solve the challenge and was (among) the best on every hole: • Hole 1, 64 strokes, Spiff • Hole 2, 32 strokes, Eugene van der Pijll, Spiff, Andrew Savige, Marcus Holland-Moritz, Rick Klement, Autrijus Tang • Hole 3, 35 strokes, Spiff, Eugene van der Pijll, Andrew Savige Final standing:

Edition 2007-01-09 top secret / strictly confidential page 27 of 520 Perlgolf History

Spiff 131 Marcus Holland-Moritz 133 Autrijus Tang 135 Andrew Savige 137 Eugene van der Pijll 138 Suo 138 Ian Phillipps 141 Piers Cawley 146 Rick Klement 150 Llasse 154 Andrew Savige was particularly unlucky because I recognized a problem in his solution on the last day when he was already out of time to play, and he got dropped back to his last working entry. In retrospect I made two big mistakes when setting up this challenge: 1. Doing it during this period of the year. It turns out that most people have a life, and have no time for golfing. 2. Hole 1 was too vague and too complicated. This led to endless refinements of the rules, and a lack of beginner entries. Fortunately there was some very interesting golfing on this hole, and I saw several tricks for the first time here. Particularly fun was playing "BoB1". I get to see all solutions, so I can take the best elements from any of them, combine them and add my own ideas and come up with some stuff none of the players saw, having to play in isolation. In the beginning BoB did best on all holes, but in the end only kept the lead on hole 1. So, time for a hole be hole account. Hole 1, Human sort Most players decided to go for a method of encoding the length in the string in such a way that you can use "cmp" and do a normal sort with the transformed key in a sort function. There were a few exceptions however: A few people used a loop inside the sort function to split up the string in numeric and alphabetic parts and compared these piece by piece. This approach was mainly used to get on the damn scoreboard already, but leads to rather long solutions, which I'll skip here. Llasse started with a regex approach and remained true to it for the whole tournament. I however kept finding counterexamples to his attempts until finally he got one that looks fine. I thought he would be the only one to get this one working until Rick Klement came up with the same thing, "correct" at the first attempt. 82, Llasse print sort{"$a$b"=~/^(.*)(\d+).*\n\1(\d+)/i&&length$2<=>length$3||lc$a cmp lc$b}<> 81, Rick Klement print sort{($a.$b)=~/(.*)(\d+).*\n\1(\d+)/i&&length$2<=>length$3||uc$a cmp uc$b}<> Lasse missed the fact that he could use a hard newline instead of \n, Rick didn't (from here on, \n will always mean a hard newline. Almost all others did not miss this trick). Rick however used ($a.$b) to combine the strings, while Lasse did better with "$a$b". However, Rick gained back a character by

1 “Best of Breed”, solution by referees based on best ideas of players, works like mechanical hare in dog races.

Edition 2007-01-09 top secret / strictly confidential page 28 of 520 Perlgolf History leaving out the ^, which strictly speaking ought to be incorrect, but seems to work (I think that's a perl bug). Both missed some further optimizations (using @+ and @- instead of length and using - instead of <=>). However, I don't think the regex method can be made into a winner. Suo is the only one who mangled his input lines, then did the sort and next recovered the original values as follows: 69, Suo print/(.*\n)$/for sort map{($x=lc)=~s#\d+|\n#pack'xN/a*',$&#eg;$x.$_}<> (Piers Cawley had some very similar rejected entries) Again this entry could have been improved a bit, but not to a winner I think. Using inspiration from Spiff and a few small transforms, BoB can write: 65, BoB print/.*\n$/gfor sort map{$x=$_;s#\d+|\n#9x9+$+[0].$&#eg;lc().$x}<> In Suo's solution you see the pack "N/a*" which was the most common approach to set up a string on which you can do a normal sort. The tricky thing however is that you need to put something in front so it sorts roughly like a number, because what you get from a pack N can start with just any byte. Another thing many people missed (including me when judging the entries until Eugene pointed it out to me) is that applying uc/lc to the result of such a pack invalidates the solution because the pack "N" can give you letters among the four bytes it produces, and these will get converted. Here's a fairly typical working example of this approach: 71, Eugene van der Pijll sub a{$_=lc pop;s#\d+#0 .pack'N/A*',$&#ge;$_}print sort{a($a)cmp a$b}<> Another way to encode the string length is to use something like A x length$&, but you have to watch out, since comparing such a thing to a normal strings with A's makes the order depend on how many A's are in the normal string, and the challenge stated that a digit-string had to sort as "some kind of single character". So it needs either something like a 0 put in front: 71, Andrew Savige sub Z{s/\d+/0 .(A x length$&).$&/eg;uc}print sort{Z($_=$a)cmp Z$_=$b}<> or, (as Eugene pointed out to me), first do a lc() and only then set up the string of capital letters, but no one had an accepted entry based on this idea. Next people turned their attention to getting rid of that long "length", and several came up with using @+ (the end offset of the match string). There were several attempts to use things like 'A'x$+[0], which on a string like 'a0'x100000 would lead to enormous long temporary strings (it's quadratic in memory usage), which I decided to reject. The rules state that input files can be big enough to fill memory with "ample" play room left for temporally data, but this is a rather intense demand for temporary space. Still, it's one of these points where the rules were probably not precise enough. Fortunately this point did not decide the contest, so I stuck to my guns (if Andrew Savige had however written '0:'x$+[0] instead of ':0'x$+[0] in that rejected 64-stroke entry, this point would have decided if he would become shared winner or not). Ian Phillipps was the first one to realize that what he really wants is a fixed n-digit length in front of the digit string, and that you can get this with an addition if you can cap the maximum string-length. And you can, since the rules say memory usage is <2**32 (otherwise even pack"N" would fail), and

Edition 2007-01-09 top secret / strictly confidential page 29 of 520 Perlgolf History

2**32 is about 4e9. So for example 1e9+length is guaranteed to be a ten-digit string (and perl will use doubles to calculate it and not loose precision). A day later Spiff was the only other person to realize this. His first attempt was: 65, Spiff (rejected) sub f{$_=pop;s;\d+;~0/3+$+[0].$&;eg;lc}print+sort{f($a)cmp+f$b}<> The problem here is that on a 64-bit perl ~0/3 is so big that the addition will loose precision and you are unable to distinguish "short" digit strings. However, he quickly recovered with 65, Spiff sub f{$_=pop;s;\d+;9 x9+$+[0].$&;eg;lc}print+sort{f($a)cmp+f$b}<> soon followed by 64, Spiff sub f{$_=pop;s|\d+|9x9+$+[0].$&|eg;lc}print+sort{f($a)cmp+f$b}<> which basically won him the tournament. Several of the players would however directly recognize that this is not optimal. All of them had been thinking about how to get the argument to the sub into $_ and several realized that $_=pop can be improved. The first one to see that was Autrijus Tang in one of her rejected entries: 73, Autrijus Tang (rejected) sub _{s|\d+|0 x(2**07-length$&).$&|eg;lc}print+sort{_($_=$a)cmp _$_=$b}<> Here you see that assigning before the call and ignoring the sub argument gains one stroke. Andrew Savige also recognized this point later on. However, Marcus Holland-Moritz was the one who did it best: 65, Marcus Holland-Moritz print sort{s!\d+!pack'AN/A*',0,$&!egfor$"=uc$a,$;=uc$b;$"cmp$;}<> which basically netted him the second place in the tournament. If only he had hit on Spiff's addition trick, he could have been a winner: 61, BoB print sort{s!\d+!1e9+$+[0].$&!egfor$"=uc$a,$;=uc$b;$"cmp$;}<> And then one of the most interesting entries of the tournament arrived. Autrijus Tang came up with this conceptual blockbuster: 62, Autrijus Tang (rejected) -pa s!|\d+!pack'AN/Z*',0,$&!eg;$;{lc,}.="@F\n"}for(@;{sort%;}){ which is utterly brilliant in so many ways. The use of sort on a hash, indexing the hash with this result, making sure values cannot be keys with the very sneaky |, using -a to save a copy... I was so stunned, I almost missed the fact that it's wrong, because it collapses consecutive spaces and it has the "lowecase on the result of a pack N" problem. So she fell back to: 66, Autrijus Tang

Edition 2007-01-09 top secret / strictly confidential page 30 of 520 Perlgolf History

-p ($*=lc)=~s!|\d+!pack'AN/A*',0,$&!eg;$;{$*}.=$_}for(@;{sort%;}){ which puts her behind Spiff and Marcus Holland-Moritz. However, this solution is eminently fixable. First use Spiff's $+[0] to shorten the substitution body and fix the lc problem, next add -F to make sure the @F is one unit and get: 59, BoB -paF s!|\d+!1e9+$+[0].$&!eg;$;{+uc}.="@F\n"}for(@;{sort%;}){ It's in fact possible to shave off yet another character assuming epoch time is now big enough on all systems, nor too big so double arithmetic would loose precision, nor near a value that would cause a carry for some valid input lengths (it has been since September 2001 on at least Mac, windows, unix and VMS. I don't know if there are other ports of perl that would invalidate this, which is why I did not refer to a 125 stroke solution in the challenge): 58, BoB -paF s!|\d+!$^T+$+[0].$&!eg;$;{+uc}.="@F\n"}for(@;{sort%;}){ (remember, ^T and \n are one character each). It uses lots of work memory, but a purely linear amount. Interesting enough one other person tried for a somewhat similar solution having at least the great hash concept, making sure values can't be keys (in a way that is one stroke worse, but wastes a lot less memory): 65, Richard Proctor -n $a=$_;s/\d+/sprintf"%99s",$&/ge;$b{$:.uc}.=$a}{print@b{sort%b} This one however fails for digit sequences longer than 99. Still, a brilliant attempt. Another interesting set of solutions depends on the unicode semantics of perl 5.6.1, like this one: 72, Piers Cawley print map/\n(.+)/s,sort map{($a=lc)=~s/\d+/0${\chr length$&}$&/g;$a.$_}<> Strictly speaking there's nothing wrong with such a solution, but unicode in 5.6.1 is still pretty buggy, and I didn't want to get into a situation where to judge an entry, I would have to test all kinds of examples to see if it works ok at the 256 character value border. So as soon as the first unicode entry came in (Autrijus Tang on day one), I added an amendment to the rules that entries should not use this. PS: As pointed out by Ian Phillipps, some solutions would also have worked for digit-strings with leading zeros if you replace \d+ with 0*(\d+) and use $1 instead of $&. Hole 2, Shuffle The standard solution here is like this entry: 37, Suo @x=<>;print splice@x,rand@x,1 while@x Many people soon realized that the space near the end is useless, so you get: 36, Ronald J Kimball @a=<>;print splice@a,rand@a,1while@a Then Autrijus Tang came up with an utterly original method again: 35, Autrijus Tang

Edition 2007-01-09 top secret / strictly confidential page 31 of 520 Perlgolf History

@_=<>;print+delete$_[rand@_]while@_ Notice how this depends on printing nothing if you hit an entry that was already deleted and the array collapsing once the last entry is gone. But originality does not always win... The word "while" is pretty long and that @_=<>; in front is pretty yucky, so people really wanted to use something like "for". The first to succeed in this was Llasse, using 35, llasse print splice@a,rand@a,1 for@b=@a=<> the useless @b is to avoid that the splice modifies the list being walked by the for. A number of other people also discovered essentially the same code. However, if you can do "for", quite often you can also use "map", and here it turns out not to need the dummy array: 33, Suo print map{splice@x,rand@x,1}@x=<> There it stayed for a bit of time, until Eugene realized that instead of extracting the list randomly, you can build it randomly, and then use the free loop you get from -n/-p: 32, Eugene van der Pijll -p splice@a,rand$.,0,$_}for(@a){ an entry that I particularly like because of the use of the for(@a) at the end, which is a general way you can use to print a list, especially if the list cannot be put directly behind a print (where use of this trick saves one character). However, that is not the case here, so I also got solutions like: 32, Spiff -p splice@F,rand$.,0,$_}{print@F 32, Andrew Savige -n splice@x,rand$.,0,$_}{print@x A few more people almost found this solution, but failed on a small detail: 32, Piers Cawley (rejected) -p splice@a,rand@a,0,$_}for(@a){ Because @a is one too low compared to $. the array built in this way is not random (consider a two line input). There were however a number of interesting rejected entries. Very popular was using a sort where the sort function is random. I rejected these because in most sorts this does in fact not lead to a random result, and some versions of quicksort will even coredump on using a non-consistent sort function. But it would give a number of very short entries and on most perls they do in fact give permutations that tend to change from run to run: 28, Autrijus Tang (rejected) print+sort{int(rand(3))-1}<> Even more funky is this one where I'm not even sure why it varies at all: 20, Gimbo (rejected) print sort{rand 2}<> A very interesting entry came from a beginner:

Edition 2007-01-09 top secret / strictly confidential page 32 of 520 Perlgolf History

33, Jonathan E. Paton (rejected) -n $a{$..rand}=$_}{print values%a This one only fails because in fact extracting keys from a hash built with random keys is not random. Try to run the following program: #! /usr/bin/perl -w use Data::Dumper; my $n=3; for (1..100000) { my %a; $a{+rand} = $_ for 1..$n; $count{(values%a)[-1]}++; } print Dumper(\%count); which will result in something lopsided like: $VAR1 = { '1' => 39950, '3' => 27336, '2' => 32714 }; This was very bad luck for Jonathan, since it could have been a winner: 30, BoB (rejected) -n $a{$..rand}=$_}for(@a{%a}){ Or, if we ignore that rand can return the same value twice: 28, Richard Proctor (rejected) -n $_{+rand}=$_}{print@_{%_} The third person to think of the hash approach was Andrew Savige. Even though it has been known since the Santa challenge that the next character in a -n expansion is ";", nobody found this 31: -n splice@;,rand$.,0,$_}{print@ Hole 3, Select 2 For this hole most people quickly converged around this concept: 37, Suo @x=<>;print splice@x,rand@x,1 for 1,1 Of course once again it has a useless space, so we get: 36, Ronald J Kimball @a=<>;print splice@a,rand@a,1for 1,2 Suo unfortunately never realized the space was pointless in his solutions (if he had, he would have ended up before the slavering pack in fourth place). He did find a very clever trick to shave off another stroke though: 36, Suo

Edition 2007-01-09 top secret / strictly confidential page 33 of 520 Perlgolf History

print splice@x,rand@x,1 for[@x=<>],1 Spiff however didn't miss a beat, and ended up with: 35, Spiff print+splice@,,rand@,,1for[@,=<>],f For a long time this was the lone leader of the hole, until both Eugene and Andrew came up with this funky entry: 35, Eugene van der Pijll -p splice@a,rand$.,0,$_}{($_,$\)=@a The rejected entries by Jonathan E. Paton and Richard Proctor were hash based again, and lead to the same kind of things as for Shuffle: 34, Jonathan E. Paton (rejected) -n $a{$..rand}=$_}{print+(%a)[1,3] 33, BoB (rejected) -p $a{$..rand}=$_}for((%a)[1,3]){ 32, Richard Proctor (rejected) -n $_{+rand}=$_}{print+(%_)[1,3] 31, BoB (rejected) -p $a{+rand}=$_}for((%a)[1,3]){ (notice how the "for" trick gains a stroke here) And again, the following is possible: 34: -p splice@;,rand$.,0,$_}{($_,$\)=@

3.3. Andrew’s “Get Even”

3.3.1. Rules Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: FORE! Get Even Golf Game Tees Off Date: Thu, 24 Jan 2002 09:59:38 +1100 From: [email protected] (Andrew Savige) This is your chance to get even by playing a brand new two-hole golf course -- drawing its name from its signature opening hole. The game starts now and ends exactly five days from now. This game borrows heavily from its predecessors, the fwp Santa golf game and Ton's ircnet companion. A test program, teven.pl, and embedded below, is provided to help screen entries. Any program that passes the test program should be submitted. Especially if you suspect your program unsound, but it passes the test program, please submit it anyway! That is how we identify bugs in the test program.

Edition 2007-01-09 top secret / strictly confidential page 34 of 520 Perlgolf History

When you submit your entry -- to me only -- please state the golf score reported by teven.pl. I suggest you simply embed your two programs in the mail message. Please take care to not accidentally post any solutions to the fwp mailing list!! Do not publish your solutions anywhere. That will spoil the game, as your solutions are meant to be secret. All solutions will be published at the end of the game. To add a little excitement, a current leaderboard will be posted to fwp at least daily. Beginners are encouraged to enter and there will be a separate leaderboard for them. If you are a beginner, please say so when submitting your entry. The leaderboard will show total score only. However, exactly 24 hours before the game ends, the lowest available score for both holes will be published. Also, the current hole leaders (but not their score) will be continuously updated. I will also use Ton's BoB (best-of-breed) innovation in this game. If there is a tie, well, it is a tie. Due to time differences around the world and differing work and family commitments, there is no fair way to break ties. Oh, and don't forget the Supremely Unorthodox Prize awarded to the most original and artistic solution. I know there are some specialist obfuscators out there (hello BooK ;-) ) so I suppose they would be early favourites for this prize. It is recommended that you run the test program under Unix or Windows NT/2000. However, teven.pl should also run under Windows 95/98, albeit with a warning that it cannot detect what is written to STDERR. You must name your programs even.pl (hole 1) and gs.pl (hole 2), and put them in the same directory as the test program, teven.pl. That done, run the test program: perl teven.pl to verify that your entry is valid. The scoring rule is the same as that used in Ton's recent game. Multiple lines are permitted, with a newline counting as one stroke. Though the #! line is not counted, the options themselves (if any) are counted, including the leading space and -. I will try to describe the semantics of each hole below. If you are in any doubt about the semantics, please study or run the test program to see what it accepts and rejects. General Rules that apply to both holes Your program should work on Perl 5.6.1. You may use any of the standard 5.6.1 core modules. You may use only the Perl executable; other external commands are banned. Both holes read from a single input file given as the first command line argument. • The input file may be assumed to exist. • The input file may be assumed to be non-empty. • The input file may be assumed to comfortably fit into memory. • The input file may be assumed to contain no binary zeros. • Like Ton's game, you may assume ASCII as the character set but you may not use Unicode- specific semantics. • The program return code does not matter. Hole 1 -- Get Even (even.pl)

Edition 2007-01-09 top secret / strictly confidential page 35 of 520 Perlgolf History

Your program reads from a single input file and writes to STDOUT; you are not permitted to write anything to STDERR. You may assume that the input file is properly newline-terminated. Similarly, your program must properly newline-terminate everything it writes. The input file is a text file of words, one word per line. Each word consists of [a-z] only. Each input line consists of the word only, with no leading or trailing whitespace, and no empty lines. A vowel is defined as a, e, i, o, u, y. Note the 'y'. You must write to STDOUT all words that satisfy all of the following conditions: a) are on an even line number in the input file b) have an even word length c) contain an even number of each and every distinct vowel in the word You must write the matching words to STDOUT in the same order as they appear in the input file. For example, the following words (so long as they are on an even line number) should be written: doctor length=6, 2 o's (ok) kangaroo length=8, 2 a's, 2 o's (ok) while the following words should not be written: unusable length=8 (ok), 2 u's (ok), 1 a (not ok), 1 e (not ok) santa length=5 (not ok), 2 a's (ok) You may not make arbitrary assumptions about the content of a word. For example, you may not assume that every word must contain at least one vowel, or that each word contains a maximum of 9 vowels, or that all words are less than 30 characters in length, say. Hole 2 -- Golf Scorer (gs.pl) This is a primitive "golf scorer" program. You might use it to remove all newlines from a long golf program while writing its approximate golf score to STDERR. On this hole, you may not assume that the input file is properly newline terminated. That is, the last line in the input file may or may not contain a newline. This program must write to STDOUT all characters in the input file except for newlines. It must also write to STDERR the count of the total number of non-newline characters in the input file. You must properly newline terminate the number that is written to STDERR. Leading and trailing whitespace, commas, etc., are not permitted: digits only, followed by a single newline. Good luck to all the golfers, /-\ndrew

3.3.2. Solutions Hole 1 (Get Even) 40, Eugene van der Pijll -p $_ x=1&~$.&split$&while aeiouy=~/.?/g 42, Best of Breed -p for$a(/[aeiouy]?/g){$_ x=1&~$.&split$a} 44, Rick Klement

Edition 2007-01-09 top secret / strictly confidential page 36 of 520 Perlgolf History

-p $_ x=1&~$.&~s/$&/$&/gwhile'aeiouy.'=~/./g 46, Best of Breed -p $==$.&1;$=^=7 .ord for/[aeiouy]?/g;$_ x=!$= 46, Best of Breed -p $==--$|;$=^=7 .ord for/[aeiouy]?/g;$_ x=!$= 46, Best of Breed -p $_ x=1&eval"~$.@{[<&y&{a,e,i,o,u,y,}&&c>]}" 46, Best of Breed -p $_ x=eval"\$|--@{[<&y&{a,e,i,o,u,y,}&&c>]}" 48, Best of Breed -ln 1&eval"$.@{[<|y|{a,e,i,o,u,y,}||c>]}"||print 50, Ton Hospel -ln ($a=aeiouy)=~s!!--&~y-!g;eval"\$|$a--c&&print" 50, Keith C Ivey -n $==$.&1;$=^=7 .y*yuoeia***ord for/./g;$=||print 51, Best of Breed -p for$a(".aeiouy"=~/./g){$_=""if(@{[/$a/g]}|$.)&1} 52, Keith C Ivey -ln $%=($.|y|||c)&1;$%^=ord for/[yuoeia]/g;$%||print 52, Tim Gim Yee -nl 1&eval"$.@{[map<|y/$_//>,/[aeiouy]?/g]}c"||print 52, Eugene van der Pijll -p $_ x=1&~eval$..join'__|y _y',_,a,e,i,o,u,Y,' __c' 53, Jan "Yenya" Kasprzak -nl 1&eval(join qw(//|y/ $.*aeiouy//c))||print 53, Honza Pazdziora -nl s/|[aeiouy]/"y!$&!!c%2|$.%2&&next;'$&'"/gee;print 53, Eugene van der Pijll -p $_ x=1&~eval join'*//|y/y',S,e,Q,u,o,i,a,' //c|$.' 53, Wesley Darlington -p ($,="aeiouy ")=~s#.#|y|$&||#sg;$_ x=1&~eval"$.$,c" 53, Aaron Trickey

Edition 2007-01-09 top secret / strictly confidential page 37 of 520 Perlgolf History

-p ($,="aeiouy ")=~s:.:|y/$&//:gs;$_ x=~eval"$.$,c"&1 54, Matthew Byng-Maddick -n ($a=aeiouy)=~s##|||y|#g;1&eval"$.|y|a-z$a||"||print 54, Peter Makholm -nl 1&eval join qw(//|y/ $.|y/aeiouy//c)or print 54, Jason Henry Parker -p for(;aeiouy=~/./g;){$_ x=1&~eval"$.|~y///c|y/$&//"} 55, Sean McAfee -ln 1&eval join'|||y|',qw/$.|y|aeiouy||c/or print 55, Alistair McGlinchy -n $k=1&($.|y/a-z//);$k^=9*ord for/[aeiouy]/g;$k||print 55, Stephen Turner -nl $x=$.%2;map{$x^=4*2**index aeiouy,$_}/./g;$x||print 55, Yanick -p $x=$.;for$a('aei.ouy'=~/./g){$x|=@m=/$a/g}$_ x=~$x&1 56, Ronald J Kimball -ln $"='//|y/';eval"$.|y/@{[aeiouy=~/.?/g]}//c"&1||print 56, Daryl Olson -ln ($,='aeiouy1')=~s#.#|y/$&//#g;eval"($.$,c)&1||print" 56, Best of Breed -p eval sprintf'$_=""if($.|~y&%s&&c)&1;'x7,Zyoueia=~/./g 58, Qingning Huo -nl $x=$.;for$0qw|aeiouy.|{$x|=s|$0|$&|g}$x&1||print 59, Rick Myers -ln ($.|y///c|y/a//|y/e//|y/i//|y/o//|y/u//|y/y//)%2||print 59, Best of Breed, Sean McAfee -ln 1&($.|y|||c|y|a|||y|e|||y|i|||y|o|||y|u|||y|y||)||print 59, BooK -ln eval(join'//%2+y/',qw!$.%2+y/aeiouy//c%2!)||print 59, Piers Cawley -n ($.|y/a//|y/e//|y/i//|y/o//|y/u//|y/y//|y/ //c)&1||print 59, Bart Lateur -nl ($.|y|||c|y|a|||y|e|||y|i|||y|o|||y|u|||y|y||)&1||print 59, Jerome Quelin

Edition 2007-01-09 top secret / strictly confidential page 38 of 520 Perlgolf History

-p $_=""if(~y///c|$.|y/a//|y/e//|y/i//|y/o//|y/u//|y/y//)&1 59, sthoenna -p $_=''if($.|y/a//|y/e//|y/i//|y/o//|y/u//|y/y//|y/ //c)&1 60, Roberto Ruiz -nl (length|$.|y/a//|y/e//|y/i//|y/o//|y/u//|y/y//)&1||print 60, Ala Qumsieh -nl (length|$.|y/y//|y/a//|y/e//|y/i//|y/o//|y/u//)&1||print 60, Evan A Zacks -nl my%h;$h{$_}++for/[aeiouy]/g;grep$_%2,%h,y///c,$.or print 62, Dave Hoover -ln my%d;$d{$_}++for/[aeiouy]/g;(grep$_%2,length,$.,%d)||print 63, Peter Scott -ln ($x=aeiouy)=~s#.#y/$&//|#g;eval("$x$.|y///c")%2&&next;print 63, Peter Scott -ln ($x=aeiouy)=~s#.#y/$&//|#g;eval("$x$.|y///c")%2&&next;print 63, Phil Radden -lna while(s/(.)(.*)\1/$2/){}$.%2||/[aeiouy]/||y///c%2||print@F 64, David Lowe -nl eval join'&1or ',$.,y///c,(map"y/$_//",a,e,i,o,y=>u),'print' 65, Michael Assels -ln ($.|y///c|y/a/a/|y/e/e/|y/i/i/|y/o/o/|y/u/u/|y/y/y/)&1||print 65, Joerg Ziefle -nal ((grep$F[0]=~s/$_//g%2,'aeiouy'=~/./g)>0|$.|length)&1||print 65, Kwok Chern Yue -nl (y/a//|y/e//|y/i//|y/o//|y/u//|y/y//)%2|y/a-z//%2|$.%2||print 67, Jeff Helman -p for$V qw/aeiouy/{$_=''if eval"y/$V//%2"||$.%2||!(y///c%2)}; 68, Mark Suter -ln map$_%2&&next,$.,y///c,y/a//,y/e//,y/i//,y/o//,y/u//,y/y//;print 68, Byron Jones -n for$a(a,e,i,o,u,'y'){$_=''if(eval"y/$a//")%2}$.%2||y///c%2&&print 69, Anthony J Breeds-Taurima -p foreach$i(qw[aeiouy]){$_=''if !(y///c%2)+$.%2+eval"y/$i//%2"} 72, Jonathan E Paton -ln @F=/./g;$a.="+(1&grep/$_/,\@F)"for'.aeiouy'=~/./g;1&$.|eval$a||print 75, Briac Pilpre

Edition 2007-01-09 top secret / strictly confidential page 39 of 520 Perlgolf History

-ln for$=qw(aeiouy){eval"next LINE if(length)%2||$.%2||y/$=//%2"}print 75, Jasper McCrea -p split'';grep$_%2,$#_,$.,map{$i=$_;$i=grep/$i/,@_}qw(aeiouy)and$_='' 76, Lian Claudiu Sebe -n $.%2||y/a-z//%2||do{my$a;for$v(split//,aeiouy){$a+=s/$v/$v/g%2}$a}||print 76, Josh Shulz -n print if!(y/a-z//%2|y/a//%2|y/e//%2|y/i//%2|y/o//%2|y/u//%2|y/y//%2|$.%2) 76, Scott Wessels -n sub f{for$v(a,e,i,o,u,'y'){eval"y/$v//%2"&&return}print}$.%2-1&y///c%2&&f 77, Cedric Bouvier -ln $a=$_;grep{$_&&$_&1}$.,length,map{$s=()=$a=~/($_)/g}a,e,i,o,u,'y'or print 77, Jean-Pierre Vidal -n for$v($e=0,qw/aeiou y/){$e||=s/$v/$v/g%2}s/(.)/$1/g%2||$.%2||$e||print 77, rjcox -n print if(length)%2&!($.%2|y/a//%2|y/e//%2|y/i//%2|y/o//%2|y/u//%2|y/y//%2) 78, Jeff Yoak -p for$x qw(aeiouy){s/.*//s if((eval"tr/$x/$x/")%2||$.%2||!((length)%2))} 79, Patrick Gaskill -n y/a-z//%2||$.%2||y/a//%2||y/e//%2||y/i//%2||y/o//%2||y/u//%2||y/y//%2||print 80, Bill Jones -n for $y(qw/aeiouy/){!($.%2)&&(1&length)&&!eval"y/$y//%2"||next LINE}print

3.3.3. Solutions Hole 2 (Golf Scorer) 25, BooK, Wesley Darlington, Evan A Zacks, Honza Pazdziora, Keith C Ivey, Jason Henry Parker, Rick Klement, Peter Makholm, Piers Cawley, sthoenna, Stephen Turner, Tim Gim Yee, Jan "Yenya" Kasprzak -p0 y/ //d;warn y///c,' ' 25, Matthew Byng-Maddick, Eugene van der Pijll, Daryl Olson, Jerome Quelin, Ton Hospel -0p s/ //g;warn y///c." " 25, Yanick -p0 y" ""d;warn y,,,c," " 26, Alistair McGlinchy

Edition 2007-01-09 top secret / strictly confidential page 40 of 520 Perlgolf History

-0p s/ //g;warn length," " 26, Dave Hoover -n0 print@a=/./g;die@a.' ' 26, Ala Qumsieh -p0 s/ //g;warn+length," " 26, Sean McAfee -p0 warn y///c- s/ //g." " 27, Mark Suter -0p y/\n//d;warn y///c,"\n" 27, Qingning Huo -p0 s/\n//g,warn length,v10 27, David Lowe, Anthony J Breeds-Taurima -p0 s/\n//g;warn y///c,"\n" 27, Phil Radden -p0aF// warn+@F- s/ //g," " 28, Bart Lateur -n0 print@a=/./g;warn@a."\n" 28, rjcox -p0 s/ //g;warn length()." " 30, Scott Wessels -0n s/ //g;print;die y///c." " 30, Peter Scott -n0 y/ //d;print;die y///c," " 31, Ronald J Kimball -p $c+=s/./$\.=$&/ge}{warn$c,$/ 33, Byron Jones -lp $\='';END{warn$a.$/}$a+=y///c 33, Rick Myers

Edition 2007-01-09 top secret / strictly confidential page 41 of 520 Perlgolf History

-p END{warn"$c\n"}chomp;$c+=y///c 33, Joerg Ziefle -p END{warn"$s "}chomp;$s+=length 33, Aaron Trickey -p0 y/ //d;print STDERR y///c," " 34, Jeff Helman -p END{warn"$L\n"}chomp;$L+=length 34, Roberto Ruiz -p END{warn"$c\n"}chomp;$c+=length 34, Patrick Gaskill -p END{warn$a,$/}chomp;$a+=y/\n//c 34, Michael Assels s/./$x++,print$&/ge for<>;die"$x " 35, Jasper McCrea -lp END{warn"$c\n"}$\='';$c+=length 35, Josh Shulz -n s/ //;print;$c+=length}{die"$c " 35, Jean-Pierre Vidal -p chomp;$n+=length;eof&&warn"$n\n" 35, Kwok Chern Yue -pl $\="";$c+=length;END{warn"$c "} 36, Jeff Yoak -p s/\n//;$x+=length;END{warn"$x\n"} 38, Lian Claudiu Sebe -p chomp;$t+=length;eof()&&warn"$t\n"; 38, Jonathan E Paton -pl ($\.=$_)=~s/ //}{warn length$\,' ' 43, Cedric Bouvier -lp END{print STDERR"$s\n"}$\="";$s+=length 43, Briac Pilpre -p chomp;$x+=length;END{print STDERR"$x\n"} 44, Bill Jones

Edition 2007-01-09 top secret / strictly confidential page 42 of 520 Perlgolf History

-p chomp;$x+=length;END{print STDERR "$x\n"}

3.4. LAPM#1 "Factorial" http://la.pm.org/golf/gc1/ (dead link1) This course closed at Sat Apr 13 07:59:21 2002 UTC

3.4.1. Rules Write a program that prints out (to STDOUT) the factorial of the required command-line argument (a number from 0 to 171). The program must also print out a new-line after the number. The factorial of 4 is 24 because 1 * 2 * 3 * 4 = 24. The output must match /^[1-9]\d*\n\z/. Examples: $ perl gc1.pl 0 1 $ perl gc1.pl 1 1 $ perl gc1.pl 2 2 $ perl gc1.pl 3 6 $ perl gc1.pl 4 24 $ perl gc1.pl 50 30414093201713378043612608166064768844377641568960512000000000000 $ perl gc1.pl 171 1241018070217667823424840524103103992616605577501693185388951803611996075221691 7529927519781204875855764649595016703870528098898586907107673312420322184843 6431047357788996854827829075454156196485215346831804429323959817369689965723 5903947616152278558180061176365108428800000000000000000000000000000000000000 000

3.4.2. Solutions 54, spifff (would be rejected by the modern rules) -li0 $,=pop;sub p{map&p,1..$,--;++$,||++$^I}p;print$^I 60, ton -l for$n(++$_..pop){s/./'$_.=0;'.'++$_;'x$&x$n/eg;eval}print 62, Rick Myers -l $_=1;for$.(1..pop){s!.!($.*$&+$.*".$'")%($`?10:$^T)!eg}print 63, ton ($\,$q)=$q.$\!~s/./$q.=0;$q++for 1..$&*$_/eg.$/for 0..pop;print 64, ton @F=1..pop and$_=`$^X $0 $#F`;print!s/./$,.=0;$,++for(@F)x$&/eg,$/ 69, lubu

1 You may browse dead links with http://web.archive.org

Edition 2007-01-09 top secret / strictly confidential page 43 of 520 Perlgolf History

-l $_=1;for$?(1..pop){for$$(@_=/./g){substr($_,0,-@_)+=$?*chop}}print 70, tybalt89 -l for$"(++$_..pop){$,=chop($.+=$"*chop).$,while$_^$.;($_,$,)=$,}print 70, Rick Myers -l $_=pop||1;for$l(2..$_-1){s!.!($l*$&+$l*".$'")%($`?10:9999)!eg}print 70, gimbo -l for$k(++$_..pop){$,=chop($l+=$k*chop).$,while$_|$l;($_,$,)=$,}print 70, mtve @%=map chop($.+=$_*$`),@%,//gfor$.++..pop;(reverse$/,@%)=~/0*/;print$'

3.5. LAPM#2 "Hamming Code" http://la.pm.org/golf/gc2/ (dead link) ended June 15th 2002

3.5.1. Rules What Is a Hamming Code? A Hamming code is a block code capable of identifying and correcting any single bit error occurring within the block. What this means is if a hamming code is created for some data, and that code is transmitted somewhere and a bit becomes corrupt, it can be identified and fixed by the rest of the bits in the code. The program you will want to write for this challenge must take a block of bits (a binary string matching /^([01]{4}){1,8}\z/) as the command-line argument and your program must print out the hamming code for it. Calculating a Hamming Code From Calculating the Hamming Code1: The key to the Hamming Code is the use of extra parity bits to allow the identification of a single error. Create the code word as follows: 1. Mark all bit positions that are powers of two as parity bits. (positions 1, 2, 4, 8, 16, 32, etc.) 2. All other bit positions are for the data to be encoded. (positions 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, etc.) 3. Each parity bit calculates the parity for some of the bits in the code word. The position of the parity bit determines the sequence of bits that it alternately checks and skips. Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1,3,5,7,9,11,13,15,...) Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc. (2,3,6,7,10,11,14,15,...) Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc. (4,5,6,7,12,13,14,15,20,21,22,23,...) Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,24-31,40-47,...) Position 16: check 16 bits, skip 16 bits, check 16 bits, skip 16 bits, etc. (16-31,48-63,80-95,...) Position 32: check 32 bits, skip 32 bits, check 32 bits, skip 32 bits, etc. (32-63,96-127,160- 191,...) etc.

1 http://www.cs.fiu.edu/~downeyt/cop3402/hamming.html

Edition 2007-01-09 top secret / strictly confidential page 44 of 520 Perlgolf History

4. Set a parity bit to 1 if the total number of ones in the positions it checks is odd. Set a parity bit to 0 if the total number of ones in the positions it checks is even. Here is an example: A byte of data: 10011010 Create the data word, leaving spaces for the parity bits: _ _ 1 _ 0 0 1 _ 1 0 1 0 Calculate the parity for each parity bit (a ? represents the bit position being set): • Position 1 checks bits 1,3,5,7,9,11: ? _ 1 _ 0 0 1 _ 1 0 1 0. Even parity so set position 1 to a 0: 0 _ 1 _ 0 0 1 _ 1 0 1 0 • Position 2 checks bits 2,3,6,7,10,11: 0 ? 1 _ 0 0 1 _ 1 0 1 0. Odd parity so set position 2 to a 1: 0 1 1 _ 0 0 1 _ 1 0 1 0 • Position 4 checks bits 4,5,6,7,12: 0 1 1 ? 0 0 1 _ 1 0 1 0. Odd parity so set position 4 to a 1: 0 1 1 1 0 0 1 _ 1 0 1 0 • Position 8 checks bits 8,9,10,11,12: 0 1 1 1 0 0 1 ? 1 0 1 0. Even parity so set position 8 to a 0: 0 1 1 1 0 0 1 0 1 0 1 0 • Code word: 011100101010. Here are some examples of input and output, your program must match the output exactly. $ perl gc2.pl 1110 0010110 $ perl gc2.pl 10011010 011100101010 $ perl gc2.pl 010011111110 10011001111111100 $ perl gc2.pl 1100011101100010 011110010111011100010 $ perl gc2.pl 00110111001110001000 0101011001110011110001000 $ perl gc2.pl 100111111000011010011100 00110010111110000011010011100 $ perl gc2.pl 0010100010000000011001000110 0000010110001000000000110010001110 $ perl gc2.pl 11110111010011011001100010011000 01101111011101010110110011000100011000 You must assume there will only be one argument on the command line, which will be a properly formatted string. It will also only contain "0"s and "1"s. It will match the pattern /^([01]{4}){1,8}\z/. The length of the argument will be a multiple of 4 digits. Minimum length of the argument will be 4 digits. Max length of the argument will be 32 digits.

3.5.2. Solutions 71, ton $_=pop;s#.#push@;,$;until$;++&$;;$@[$_]^=$;/$_&$&for@;,$;#eg;print@@,$/

3.6. TopMach’s "Arabic to Roman number translator" http://www.ardinternet.com/golf/roman/ (dead link) 20 April 2002. This hole has been replayed afterward (see 9.3).

Edition 2007-01-09 top secret / strictly confidential page 45 of 520 Perlgolf History

3.6.1. Rules Goal - Make a script that translates Arabic numbers to Roman numbers in the shortest amount of key strokes. Input numbers range - 0 - 5000 (0 must print a blank line with no spaces). This specific golf challenge is launched on the side while in wait of other more popular golf challenges to start. As I wish to be part of this golf game. there is no utilities to upload your solutions. Instead, I rely on your honesty to tell me your score and I'll just put your name here along with your score. All solutions shall be provided to me for display at the end of the challenge. Rules • Assume the name of the program is 'd2r.pl'. • External applications (except for perl itself) must not be used. The program may call itself. • Assume total memory is < 2**28 bytes. • No type of 'help' can be received by anyone but by me. • All programs must work on perl 5.6.1. • The #! line is not counted. If you use options on the #! line, the options themselves are counted, including the leading whitespace and '-' (dashes). • Modules and libraries must not be used. • Sockets must not be used. • STDERR must not be written to. • Your solution must complete the test program in a timely manner. i.e. less than an hour on my P1 233Mhz. • You must assume there will only be one argument on the command line, which will be a properly formatted number (matching the pattern /^[1-9]\d*$/ or 0). Numbers will range from 0 to 5000. • If two or more solutions with the same amount of characters are submitted, the winner will be the one with code with the greater number of /[^\w\s]/ characters. If two or more identical solutions are submitted, the winner will be the one who first submitted his solution. Example output Test program to test output of your program is provided here. Here are some examples of input and output, your program must match the output exactly. $ perl d2r.pl 0

$ perl d2r.pl 1 I $ perl d2r.pl 2 II $ perl d2r.pl 3 III $ perl d2r.pl 4 IV ...

Edition 2007-01-09 top secret / strictly confidential page 46 of 520 Perlgolf History

$ perl d2r.pl 4999 MMMMCMXCIX $ perl d2r.pl 5000 MMMMM

3.6.2. Solutions 95, tybalt89 $==pop;$_=M999CM899D499CD399C99XC89L49XL39X9IX8V4IV3I;s/\D+/$=- =$'+print$&while$=>$'/ge;print$/ 106, Alain "TopMach" Dupuis -l $n=I x+pop;s/\d+//&$n=~s|I{$&}|$_|gfor+M1000CM900D500CD400C100XC90L50XL40X10IX9V5 IV4=~/\D+\d+/g;print$n 112, Ido Trivizki -l $_=pop;while('1000M900CM500D400CD100C90XC50L40XL10X9IX5V4IV1I'=~/\d+(\D+)/g) {$_-=$&,$o.=$1while$_>=$&}print$o 121, Anarion -l $_=pop;for$-(I,V,X,L,C,D,M){++$.%2?s/(.)\1{8}/$1$-/+s/(.*)(\d)/$1.$- x$2/e:/(.)\1{8}/||s/(.)\1{4}|(.)\2{3}/$2$-/}print 124, owen_ -l $a=MDCLXV;$b=pop;{$_=($c||I)x chop$b;$d=chop$a;$c=chop$a;s/(.){9}/$1$c/;s/.{5}|(.){4}/$1$d/;$\=$_.$\;$a&&r edo}print"M"x$b 124, Timothy Whitman -l $.=('',1,11,111,12,2,21,211,2111,13)[$_],$_=$/-3?$.+2*$/++x length$.:7x$_,y/1-70/IVXLCDM/dfor reverse@z=pop=~/./g;print@z 130, Ken Rockot for($a=pop,@ARGV=I1IV4V5IX9X10XL40L50XC90C100CD400D500CM900M1000=~/\D+|\d+/g;$a ;){for($b=pop,$_=pop;$b<=$a;){$a-=$b;print}}print$/ 130, z0ned $a=shift;for(qw/999M 899CM 499D 399CD 99C 89XC 49L 39XL 9X 8IX 4V 3IV 0I/){/(\d+)(\w+)/;while($a>$1){$a-=$1+1;print$2;}}print"\n"; 131, Samy Kamkar -l $x=3;while($n||=pop){$n-=$l,$_.=(M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I)[$x- 3],while$n>=($l=(9,5,4,1)[$x%4]."0"x(3-int$x/4));$x++}print

3.7. TopMach’s "Odd Number Math Magic Square" http://www.ardinternet.com/golf/oddnumbermagicsquare/ (dead link) Deadline - May 17, 00:00:00 UTC 2002

3.7.1. Rules Goal - Make a script that creates math magic squares of odd numbers (i.e. 3x3, 5x5, 7x7, ...) in the shortest amount of key strokes. Argument Range - 3 - 25.

Edition 2007-01-09 top secret / strictly confidential page 47 of 520 Perlgolf History

All numbers between 1 and n2 must be used Here is a couple of examples of input and output. Your program must output single space seperated numbers with no leading or trailing spaces for each rows. Each rows must be properly newline terminated. Each rows, columns, and both diagonals must add up to the same amount. $ perl magicsquare.pl 3 816 357 492 $ perl magicsquare.pl 5 17241815 23571416 46132022 10 12 19 21 3 11 18 25 2 9 Help! Don't know how to build an odd number math magic square? No worries. Here are a few links that explain it very well. • http://mathforum.org/alejandre/magic.square/adler/adler.5x5math.html • http://nrich.maths.org/mathsf/journalf/aug98/art1/index.html • http://mathworld.wolfram.com/MagicSquare.html

3.7.2. Solutions 58, ton map{$_=++$_%@F+$p--%@F*@F+1for@F,$p;print"@F\n"}@F=-pop..-1 58, mtve print"@{[map+($_-=2)%@:+--$:[0]%@:*@:+1,@:]}\n"for@:=1..pop

3.7.3. Explanation http://www.xs4all.nl/~thospel/siamese.html

3.8. Ton’s Minigolf 2 "Closest Number" http://www.xs4all.nl/~thospel/golf/minigolf2.html 20020624

3.8.1. Rules You get on STDIN one integer per line. The first integer is the target. Find in the rest the number closest to the target and print it to STDOUT followed by a newline, nothing should go to STDERR. No values will be equally close to the target. Each line matches /^[1-9]\d{0,3}\n\z/. Input will be at least two lines. Example input: 8 12 6 13 5 here 8 is the target number, 6 is closest (distance two), so the output should be:

Edition 2007-01-09 top secret / strictly confidential page 48 of 520 Perlgolf History

6

3.8.2. Solutions 35, ton, tybalt89, darek -p ($_)=sort{abs$a-$_<=>abs$b-$_}<> 37, mtve -p $??$\x=abs$?-$\

3.9. Ton’s Midigolf 1 "Labyrinth" http://www.xs4all.nl/~thospel/golf/midigolf1.html 20020628

3.9.1. Rules You get on STDIN 10 strings of length 10, where each character is either space or x, so each line matches /^[ x]{10}\n\z/. Print "1\n" to STDOUT if there is a path of x's from top to bottom (the path may twist and turn), "0\n" otherwise. (only vertical and horizontal contacts count, not diagonal). Nothing should appear on STDERR. Multiple paths, dead ends, loops and disconnected pieces are possible. example input: x x x x x xxx xx xxxxxx xxx x xxx xxxxx x x xxx xx x xxx xxx x Clearly there is at least one path of x's from top to bottom (e.g. the one in red), so the result should be: 1

3.9.2. Solutions 54, ton+mtve (post-mortem) -lp0 $_%=s#.#s/(\S)(|.{10})(?!\1)\S|$/y$+y/s;?^.*y?#eg

3.10. Ton’s Irongolf 1 http://www.xs4all.nl/~thospel/golf/irongolf1.html 20020718

3.10.1. Rules There are three computers connected by a network. One of them is a server and the other two are clients. The server has some files, each with a different name. The full name of each file consists of two parts, a name and an extension. Both clients know the full names of all of the files stored on the server. From among its files, the server chooses a single file and sends the name part of that file's full name to one of the clients and the extension part of the full name to the other client.

Edition 2007-01-09 top secret / strictly confidential page 49 of 520 Perlgolf History

The clients then begin communicating in an effort to determine which file was selected by the server (they want to learn the file's full name). However, the clients have to communicate in a very restricted manner. Clients take turns sending messages to each other, but they can only say when they don't know the full name of the file. If one client does not know the full name of the chosen file, that client will send a message saying "I don't know the full file name" to the other client when it's his turn. The two clients alternate, sending only this message back and forth. The client that received the name part of the full file name always waits for the client that received the extension part to send the first message. This continues either until one of the clients figures out the full file name (so it won't say anything on its turn and the conversation falls silent), or they forever keep saying "I don't know the full file name". The clients are very smart and always completely use all available information. So some files chosen by the server would cause the clients to fall silent after a certain number of steps, while other files lead to infinite denials. You are to find the file(s) that give rise to the longest finite conversation. On STDIN you get the list of files, one full name per file. The full names are restricted to something like MS-DOG 8.3 format. Each full file name is represented in name.extension form, where both the name and the extension consist of only capital, alphabetic characters and decimal digits. The name part will have at least one character and at most eight. The extension part will have at most three characters and may be empty. If extension is empty then separating dot may be omitted. So each line matches /^[A-Z0-9]{1,8}(\.[A-Z0-9]{0,3})?\n\z/. Each filename will appear in the input no more than once. There will always be between 1 and 1000 (inclusive) files on the list. On STDOUT you should write the files leading to the longest finite conversation, one file per line, in exactly the same order and spelling as these files appeared in input. Nothing should be written to STDERR. The returncode of your program does not matter. Example input: LICENCE.TMP WIN32.LOG FILEID. PSTOTEXT.TXT GSVIEW32.EXE GSVIEW32.ICO GSVIEWDE.HLP LICENCE GSVIEWEN.HLP GSVW32DE.DLL FILEID.TMP GSVW32EN.DLL PSTOTXT3.DLL PSTOTXT3.EXE GSV16SPL.EXE GVWGS32.EXE ZLIB32.DLL PRINTER.INI README.TXT Four files (LICENCE.TMP, FILEID., LICENCE and FILEID.TMP) will lead to an infinite conversation. Three files (WIN32.LOG, GSVIEW32.ICO and PRINTER.INI) lead to immediate silence, Two files (PSTOTXT3.DLL and PSTOTXT3.EXE) lead to two messages exchanged, for all other files only one message will be sent. So the longest finite conversation is two messages, and the output should be:

Edition 2007-01-09 top secret / strictly confidential page 50 of 520 Perlgolf History

PSTOTXT3.DLL PSTOTXT3.EXE This challenge is based on, but different from an old ACM challenge1.

3.10.2. Solutions 89, ton (post-mortem) -0p s>\n>$|--;s%(\w+).?(.* )%(map$|?/^\w+\b.?$2/m:/^$1\b/m,$`,$')?$&:!($\=$@.=$&)%eg>eeg}{

3.11. Terje’s Cryptoanalysis Finished at 2002/07/19 22:00:00 UTC

3.11.1. Rules Cryptanalysis is the process of breaking someone else's cryptographic writing. This sometimes involves some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which performs a simple analysis of a given text. Input The input will consist of one or more lines. Each line will match /^[\t -~]{1,1000}\n\z/ Output Each line of output contains a single uppercase letter, followed by a single space, then followed by a positive decimal integer. The integer indicates how many times the corresponding letter appears in the input text. Upper and lower case letters in the input are to be considered the same. No other characters must be counted. The output must be sorted in descending count order; that is, the most frequent letter

1 http://www.acm.inf.ethz.ch/ProblemSetArchive/B_EU_NERC/1999/d.htm

Edition 2007-01-09 top secret / strictly confidential page 51 of 520 Perlgolf History

is on the first output line, and the last line of output indicates the least frequent letter. If two letters have the same frequency, then the letter which comes first in the alphabet must appear first in the output. If a letter does not appear in the text, then that letter must not appear in the output. Sample Input This is a test. Count me12345. Wow!!!! Is this question easy? Sample Output S7 T6 I5 E4 O3 A2 H2 N2 U2 W2 C1 M1 Q1 Y1

3.11.2. Solutions 59, mtve, dave, ton, tybalt89 -n0 for$a(A..Z){$;[y///c-$b].="$a $b\n"if$b=()=/$a/ig}print@ 59, ton -n0 for$n(A..Z){$;[pos=-split/$n/i].="$n $#_\n"x!!$#_}print@ 60, tybalt89 -n0 for$L(A..Z){$;[$n].="$L $n\n"if$n=s/$L//ig}print reverse@ 55 (rejected) -ln0 for$a(A..Z){s/$a/$&/gi-$^T||print"$a $^T"}--$^T&&redo 58 (post-mortem) -n0 for$a(A..Z){$;[pos=-$b].="$a $b\n"if$b=s/$a/./ig}print@

3.12. Ton’s Maxigolf 1 "Stones" http://www.xs4all.nl/~thospel/golf/maxigolf1.html 20020725

3.12.1. Rules Consider a 2x2 square where each position can be filled (represented by a O (that's not a zero)), or empty (represented by a “.”). You can then look how many elements are filled on each row and column, for example:

Edition 2007-01-09 top secret / strictly confidential page 52 of 520 Perlgolf History

OO -> 2 filled .O -> 1 filled ^^ || /\ 1 2 filled Which we could write in several ways. The two we will consider are: 1. 21 (row sums, top first) 12 (column sums, left first) 2. 12 (column sums, left first) 21 (row sums, top first) Your program will get as commandline arguments the row and column sums in the form /^[012][012]\z/. You are to output exactly one pattern that has these row and column sums or nothing if there is no way to satisfy the input. Nothing should go to STDERR. The output should match /^([O.][O.]\n){2}\z/ or /^\z/. Example arguments: 11 11 Example Output: O. .O or .O O. You are free to interpret the arguments as row-sums first or column-sums first. But you should be consistent. If your program assumes one order for a certain input, you must assume that order for all inputs. You may assume the current directory is empty.

3.12.2. Solutions 85, mtve map/../*$&+$'-"@ARGV"|$&%9 .$'%9-$ARGV[1]||y/01/.O/|s//$& /g|print|exit,glob'{0,1}'x4 96, ton $_=pop;s/./{${\(0 x2,"01,10",11)[$&]}}/g;map{$_%99-"@ARGV"or s/../$& /g,y/01/.O/,exit print}glob 99, tybalt89 s/.//,s/../$&\n/g,/.\n(.)/,$`+$&.($1+$').$".($`+$1).($&+$')ne"@ARGV"|y/01/.O/- 4||pop^print for 1..2e4 77 (post-mortem) -l "\377\373\340\334\362\356\323\317\327\323\270\264\312\306\253\247"=~~chr 3*(pop)+pop&&map{print}(glob'{.,O}'x4)[@-]=~/../g 77 (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 53 of 520 Perlgolf History

-l print for(0,glob'{.,O}'x4)["\377\373\340\334\362\356\323\317\327\323\270\264\312\3 06\253\247"=~~chr 3*(pop)+pop,@+]=~/../g

3.13. Ton’s Maxigolf 2 "Map coloring" http://www.xs4all.nl/~thospel/golf/maxigolf2.html 20020729

3.13.1. Rules

It's well known to cartographers that you can color a (planar) map using only 4 colors1 so that no neighboring countries get the same color. Your job is to find such a coloring for a given 10x10 map. on STDIN you will get a representation of a map, each country represented by a capital letter (a country will not contain any disconnected pieces). The input will match /^([A-Z]{10}\n){10}\z/, for example: AAAAAAAAAA ABBDDAAAAA BBBDDHAAAA ACCDDHAAAA ACCDDHAAAA AAAAAHAAAA AEEFFHAAAA AEEFFHAAAA AGGFFAIAAA AAAAAAAAAA So we have countries A, B, C, D, E, F, G, H and I. A is a neigbour of every other country, I is a neighbour of only A (not of H, diagonal connections don't count). So if we give A color 0, none of the other countries can get color 0. (The topology is not a torus, so the outer edges of the input have no neigbours). On STDOUT you should print a valid color-assignment so neighbouring countries never get the same color. You may use at most 4 colors, represented by 0, 1, 2 and 3. You may use more colors than

1 http://www-gap.dcs.st-and.ac.uk/~history/HistTopics/The_four_colour_theorem.html

Edition 2007-01-09 top secret / strictly confidential page 54 of 520 Perlgolf History

strictly needed (e.g. use 4 colors where 3 are sufficient), but never more than 4. The output has each country character replaced by its color, so something like: 1111111111 1223311111 2223301111 1003301111 1003301111 1111101111 1332201111 1332201111 1002210111 1111111111 As you can see the output matches /^([0-3]{10}\n){10}\z/. Nothing should appear on STDERR. The returncode of the program does not matter. some other inputs you can try: AAAAAAAAAA AAAAAAAAAA AJJJKKLLLA AJEEEFFFLA AJEEBBFFLA AGGCBBDIIA AGGCCDDIIA AGGGHHIIIA AAAAAAAAAA AAAAAAAAAA

AAAAAAAAAA AAANNNNAAA AJJJKKLLLA AJEEEFFFLA AJEEBBFFLA AGGCBBDIIA AGGCCDDIIA AGGGHHIIIA AAAMMMMAAA AAAAAAAAAA

SBCDEFGHJJ SBCDEFGHJJ KKLLMMNOOJ KKLLMMNNOJ PPPQQQRRRJ PPPQQIIRRJ TTTTUUUUVJ TTTTUUUUVJ WWWWWXXXXJ WAAWWXYZZJ

3.13.2. Solutions 70, tybalt89 (rejected) -0p $$3++while/(.)(\C{10})?(?!\1)(.)(??{$$1%4!=$$3%4})/;s/(.)/$$1%4/ge 75, mtve

Edition 2007-01-09 top secret / strictly confidential page 55 of 520 Perlgolf History

-p0i(.{10}|) $Q=$_;$==rand 4,/$&$^I$=|$=$^I$&/s?$_=$Q:s/$&/$=/gwhile/[A-Z]/ 75, mtve -p0aF% $==rand 4,/$&(.{10}|)$=|$=(.{10}|)$&/s?($_)=@F:s/$&/$=/gwhile/[A-Z]/ 78, tybalt89 -0p $${$.^=2}^=rand 4while/(.)(\C{10})?(?!\1)(.)(??{$$1!=$$3})/;s/(.)/3-$$1/ge 80, mtve -p0i(.{10}|) $Q=$_;$==rand 4,/$&$^I$=|$=$^I$&/s?$=||=$_=$Q:s/$&/$=/gwhile/[A- Z]/ 83, ton -n0i(.{10}|) for$n(!s/$&/$n/g..3){s#$#/\pL/?!/$&$^I$n|$n$^I$&/s&&do$0:exit print#e} 90, tybalt89 -0p s/./$&0/g;$==rand 4,s/(${1+3*$|-- })./$1$=/gwhile/(.)(\d)(\C{19})?(?!\1)(.)\2/;y/A-Z//d 102, ton -n0i(.{10}|) sub f{y/0-3/1230/;/$&$^I0|0$^I$&/s||map{s/$&/0/g*/[A- Z]/?&f+&f+&f+&f:exit print}"$_"}f/./ 73 (post-mortem) -p0i(.{10}|) $Q=$_;$==rand 4,/$&$^I$=|$=$^I$&/s?$_=$Q:s/$&/$=/gwhile/\pL/

3.14. Ton’s Minigolf 3 “Boxes” http://www.xs4all.nl/~thospel/golf/minigolf3.html Finished at 2002/06/30 23:00:00 UTC

3.14.1. Rules You get on STDIN a sequence of integers, each representing the size of a stack of boxes. Each stack is lower than 10, but can not be empty, so the input lines match /^[1-9]\n\z/. Print on STDOUT how many there boxes are at each level starting from above, each number properly terminated with a \n. Nothing should be printed on STDERR. There will be between 1 and 1000 (inclusive) boxes. example input: 5 3 1 3 So the stacks look like:

Edition 2007-01-09 top secret / strictly confidential page 56 of 520 Perlgolf History

+--+ | | <- 1 box +--+ +--+ | | <- 1 box +--+ +--+ +--+ +--+ | | | | | | <- 3 boxes +--+ +--+ +--+ +--+ +--+ +--+ | | | | | | <- 3 boxes +--+ +--+ +--+ +--+ +--+ +--+ +--+ | | | | | | | | <- 4 boxes +--+ +--+ +--+ +--+

5313 Therefore the output should be: 1 1 3 3 4

3.14.2. Solutions 35, ton -0p $\="$a\n".$\while$a=y/1-9/0-8/}{ 35, ton -0p $\=~s//$a\n/while$a=y/1-9/0-8/}{ 35, tybalt89 -p $_=1+$_.$/for@;[9-$_..8]}{print@ 36, m.thelen -ln0 ($~+=s~$=~~g)&&print$~while--$= 36, m.thelen -ln0 $~+=s~$=~~gand print$~while--$= 36, ton

Edition 2007-01-09 top secret / strictly confidential page 57 of 520 Perlgolf History

-p $_=++$_.$/for@a[9-$_..8]}for(@a){ 36, ton -n $_=++$_.$/for@a[9-$_..8]}{print@a 36, dave -ln0 ($,+=s/$=//g)&&print$,while--$= 37, p.haworth, q.huo, [VI]Kille -pl $_++for@s[1..$_]}while($_=pop@s){ 37, d.hoover -pl ++$_[--$_]while$_}for(reverse@_){ 37, andys -n map$_=++$_.$/,@p[9-$_..8]}{print@p 37, banshee -nl ++$$[--$_]}{map{print$t+=pop@$}@$ 37, juuso -ln0 /$=/?print s//$=-1/eg:3while--$= 38, suo -p $x[--$_]++while$_}{$\=$_.$/.$\for@x 38, dave -p $k[--$_]++while$_}{$\=~s//$_\n/for@k 40, c.dolan -nl $_[9-$_]++for 1..$_}{$_&&print for@_ 40, terje -p $d[$_-1]++for 1..$_}{$\=$_.$/.$\for@d 33 (post-mortem) -pl ++$;[--$_]}while(@;){$_+=pop@ 33 (post-mortem) -pl ++$a[$_]}while($#a){$_+=pop@a

3.15. Ton’s Minigolf 4 "Missing Numbers" http://www.xs4all.nl/~thospel/golf/minigolf4.html 20020820

3.15.1. Rules You get on the commandline a set of natural numbers (integers greater than or equal to zero). Find the smallest natural number not on the list, and print it to STDOUT followed by a newline. Nothing should appear on STDERR, the returncode does not matter. There will be 0 to 30 arguments, matching /^0\z|^[1-9]\d{0,5}\z/. The numbers can appear in any order and there can be duplicates. example input:

Edition 2007-01-09 top secret / strictly confidential page 58 of 520 Perlgolf History

37131501042151313139101286 Some missing numbers in this sequence are 2, 11, 14 ... The smallest of these is 2, so the output should be: 2

3.15.2. Solutions 34, ton @a=0..30;@a[@ARGV]=();print<@a>.$/ 34, mtve $-+=$_==$-for(@ARGV)x30;print$-,$/ 34, suo @x=0..30;@x[@ARGV]=();print<@x>.$/ 34, s.turner -l $^C+=$_==$^Cfor(@ARGV)x30;print$^C 36, tybalt89 -l $-++while map/^$-$/,@ARGV;print$- 36, Beowulf -l $?++while map/^$?$/,@ARGV;print$? 36, m.wrenn -l $?++while map/^$?$/,@ARGV;print$? 36, ton -l $%++while grep!$_--,@ARGV;print$% 37, k.c.ivey -l $%++while" @ARGV "=~/ $% /;print$% 37, TopMach -l $%++while"@ARGV"=~/\b$%\b/;print$% 37, ya -l ++$%while"@ARGV"=~/\b$%\b/;print$% 37, banshee

Edition 2007-01-09 top secret / strictly confidential page 59 of 520 Perlgolf History

-l $%++while"@ARGV"=~/\b$%\b/;print$% 37, e.a.zachs $%++until"@ARGV"!~/\b$%\b/;print$%,$/ 37, terje -l $%++while" @ARGV "=~/ $% /;print$% 37, h.pazdziora -l $-++while grep$-==$_,@ARGV;print$- 37, autrijus -l $?++while" @ARGV "=~/ $? /;print$? 33 (post-mortem) print<@{q[@b,@ARGV]=@b=0..30}>.$/ 33 (post-mortem) print<@{h{@a,@ARGV}=@a=0..30}>.$/

Edition 2007-01-09 top secret / strictly confidential page 60 of 520 Perlgolf History

4. Games - TPR «The Perl Review» golfs http://perlgolf.sourceforge.net/

4.1. TPR(0,0) "Base 36 Converter" The game started Friday 1st February 2002 and ended Friday the 15th. Referees: Jérôme Quelin, Dave Hoover.

4.1.1. Rules Given a base 36 number as first argument, you are to convert it to its base 10 representation

4.1.2. Solutions 33, Tim Gim Yee, Ton Hospel, Jukka Suomela, F Xavier Noria, Tony Bowden, Tony Bowden, John W Krahn -l use POSIX;print~~strtol pop,36 33, Andrew Savige, Gimbo use POSIX;print strtol(pop,36).$/ 46, Karsten aka Spifff map$.=36*$.-55+/\d/*7+ord,pop=~/./g;print$..$/ 44, tybalt89 (post-mortem) $\=ord(lc)%87%48+36*$\.$/for pop=~/./g;print

4.2. TPR(0,1) "Numerology" The game started March 1st 2002 and ended March 8th 2002. Referees: Dave Hoover, Jérôme Quelin

4.2.1. Rules Goal Reduce an integer to its ``Secret Number''. Enter the mystical world of numerology to find the true soul of an integer! OK, we are not numerologists, but we did find this process in a magazine and thought it could provide some interesting solutions. Actually, the only aspect of numerology that we appreciate is the Perl-Monk-like name of its originator, Edgar Cayce, the Sleeping Prophet of Virginia Beach. Example Here is the process: The first and only argument will be a number. Step through the digits two by two in sequence, adding each pair together. The number 1234 would be handled this way: 1+2, 2+3, 3+4. If a pair's result is higher than 9, add the digits of the results to obtain a number between 0 and 9 (inclusive). Concatenate all of the results to obtain a new number. The new number should be shorter by one digit than the previous number.

Edition 2007-01-09 top secret / strictly confidential page 61 of 520 Perlgolf History

Repeat steps 1 to 3 until you get a single digit (this is the ``Secret Number''). Here is an example, let's begin with 8169. Step 1: 8+1=9, 1+6=7, 6+9=15 Step 2: 15 is higher than 9, so 1+5=6 Step 3: Result = "9"."7"."6" = 976 Step 1: 9+7=16, 7+6=13 Step 2: 16 is higher than 9, so 1+6=7 Step 2: 13 is higher than 9, so 1+3=4 Step 3: Result = "7"."4" = 74 Step 1: 7+4=11 Step 2: 11 is higher than 9, so 1+1=2 Step 3: Result = "2" = 2 Step 4: Done Thus, the ``Secret Number'' of 8169 is 2.

4.2.2. Solutions http://archive.develooper.com/[email protected]/msg01916.html 47, ton -l print while+s/./hex($`%10+$&)%15/eg^s//pop/e 47, ton -l s//pop/e;print^s/./hex($`%10+$&)%15/eg&&do$0 50, suo -l $_=pop;s#.#print;s//$`&&($&+$`%10)*1.1%10/ge#ge 51, tybalt89 -l $_=pop;s#.#print,s/.?/$`>9&&$`%100*1.11%10/ge#ge 46 (post-mortem) -l $_=pop;s;.;print,s,,$&*1.11%10if/../g,eg;eg

4.3. TPR(0,2) "Anagrams" The game started April 1st 2002 and ended April 8th 2002. Referees: Dave Hoover, Peter Makholm, Jérôme Quelin

4.3.1. Rules Find all the anagrams in a given input stream and display them in the specified format. An anagram is a word (or phrase, but we'll stick with words for this contest) formed by rearranging the letters of another word (or phrase). For example, elvis and lives. Other rules: • The input file is a text file of words, one word per line. Each word consists of [a-z] only. • Each input line consists of the word only, with no leading or trailing whitespace, and no empty lines (unless the file is empty).

Edition 2007-01-09 top secret / strictly confidential page 62 of 520 Perlgolf History

• All input lines are properly newline terminated, and do not contain binary 0. • You may assume ASCII as the character set but you may not use Unicode-specific semantics. • You may not assume that input file will be sorted. • You are to print the anagrams found, one line for each set. • You are to print the anagrams and only the anagrams: you are to discard standalone words with no anagrams. • A line of output consists of all the words that anagrams the others: each word is separated by one space (no leading/trailing space allowed). • Each set of anagrams will not exceed 15 words per anagram. • The words on each output line will be sorted alphabetically. • The output lines are first sorted by number of words (the fewer first), then alphabetically using the first word of the line (after the line itself is sorted alphabetically). Example Given the input: hack snooped tables salt spiff feeling spooned last grep bleats gas ablest fleeing stable slat drive You are to output the following: feeling fleeing snooped spooned last salt slat ablest bleats stable tables

4.3.2. Solutions 61, Lars Mathiesen map!s/ ^/ /m|//||print,sort%0for map$0{0,sort/./g}.=$_,sort<> 63, Stephen Turner $s{o,sort/./g}=~s/.*/~$& $_/for sort<>;print/ (.* ) /for sort%s 63, Ton Hospel

Edition 2007-01-09 top secret / strictly confidential page 63 of 520 Perlgolf History

$_{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/ (.* ) /for sort%_ 63, Jasper McCrea $o{1,sort/./g}=~s/.*/1$& $_/for sort<>;print/ (.* ) /for sort%o 64, Adam Spiers $g{g,sort/./g}=~s/.*/~$& $_/for sort<>;print/~~ (.* )/for sort%g 64, Alma Media Golf Team $f{f,sort/./g}=~s/.*/~$& $_/for sort<>;print/~~ (.* )/for sort%f 64, MeowChow $o{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/__ (.* )/for sort%o 66, Ari Kauppi $p{p,sort/(.)/g}=~s/.*/%$& $_/for sort<>;print/%% (.* )/for sort%p 67, Rick Klement map$n^s/\s\b/ /g||print,sort%a,$n++for map$a{r,sort/./g}.=$_,sort<> 67, Colm Dougan map$s{1,sort/./g}=~s/(.*) */1$1 $_/,sort<>;map{/11 /;print$'}sort%s 68, Mtv Europe map$a{a,sort/./g}.=$_,sort<>;map$p[split].="@_ "x/ ./,sort%a;print@p 70, Amir Karger $o{join"",sort/./g}=~s/.*/~$& $_/for sort<>;print/\w+ .*\n/gfor sort%o 71, Terje K map$a{a,sort/./g}.=-$_,sort<>;map{/.-/&&print$'}sort map{s/ -/ /g.$_}%a 72, Josef Drexler $o{g,sort/./g}.=$_ for sort<>;$g[split].="@_$/"for sort%o;print@g[2..$.] 74, Juho Snellman -p $a{a,sort/./g}.=$_}for(sort map"}"x(@a=sort/.+/g)."@a ",%a){/}}+/,$_=$' 74, Eugene van der Pijll map$o{o,sort/./g}.=$_,sort<>;map{/}+/.print$'}sort map'}'x s/ \b/ /g.$_,%o 74, Keith Calvert Ivey

Edition 2007-01-09 top secret / strictly confidential page 64 of 520 Perlgolf History

map$%{join _,sort/./g}.=$_,sort<>;map$_[s] ^] ]gm].=/ /&&$_,sort%%;print@_ 74, Keith Calvert Ivey map$%{join _,sort/./g}.=$_,sort<>;map$@[s] ^] ]gm].=$_ x/ /,sort%%;print@@ 74, Marko Nippula -p $_{1,sort/./g}.=$_}for(sort+map{@_=sort/.+/g;1x$#_." @_ "}%_){s/\C.* // 74, Honza Pazdziora $h{"@{[sort/./g]}"}=~s/(.*) ?/{$1 $_/for sort<>;print grep s/{{+ //,sort%h 75, Eirik Berg Hanssen map$_{_,sort/./g}.=$_,sort<>;print grep{s/}+//}sort map"}"x s/ \b/ /g.$_,%_ 75, Andrew Savige map$>{o,sort/./g}.=$_,sort<>;@}{s+ (?=.)+ +g}.=$_ for sort%>;print@}{1..$=} 75, Andrew Savige map$>{o,sort/./g}.=$_,sort<>;$>{s+ (?=.)+ +g}.=$_,for+sort%>;print@>{1..$=} 75, Jay Tilton -p $h{i,sort/./g}.=$_}for(sort map{chr(@_=sort split)|"h@_ "}%h){s/i.*|.//s 76, Chris Dolan map$a{o,sort/./g}.=_.$_,sort<>;map{s/.._//&&print}sort map{9+s,\n_, ,g.$_}%a 76, Yanick Champoux map$1{join$|,sort/./g}.=$_,sort<>;map$g^s/\s\b/ /g||print,sort%1while++$g<99 78, Rick Myers map$i{a,sort/./g}.=$_,sort<>;map{/{+/,print$'}sort map{'{'x s/ (?=.)/ /g.$_}%i 78, Geoff Hubbard ++$m^map{$m^s/ (?!$)/ /g||print}sort%a=%.for map$.{join$m,sort/./g}.=$_,sort<> 79, John McNamara map$j{join"",sort/./g}.=$_,sort<>;print+grep{s/.\d//}sort+map+8+split."@_\n",%j 79, Joost Diepenmaat $f{z,sort/./g}.=$_ for<>;s/.\d//&&print for sort map{@r=sort/.+/g;8+@r."@r "}%f 81, Eric Roode

Edition 2007-01-09 top secret / strictly confidential page 65 of 520 Perlgolf History

$_{"@{[sort/./g]}"}.=$_ for sort<>;$_[s/ (.)/ $1/g].=$_ for sort%_;print@_[1..99] 82, Philippe Bricout $s{2,sort/./g}.=$_ for sort<>;for$s(2..22){$s-split||print"@_\n"for sort values%s} 83, Sec -pl push@{$p{8,sort split//}},$_}for(sort map{8+@$_.join$",sort@$_}%p){s/..//||last 85, Arnaud ASSAD -nl push@{$&{1,sort/./g}},$_;END{map{/ /,$`&&print$'}sort map{join$",$#$_,sort@$_}%&} 85, Michael Wrenn map{$s{join'',sort/./g}=~s/.*/1$& $_/}sort<>;map{y/ //s;s/.1+ //&&print}sort values%s 86, Zephyr McLaughlin map{$s{join"",sort split//}=~s/(.*) ?/~$1 $_/}sort<>;map{s/~~+ //&&print}sort values%s 87, gimbo -ln push@{$a{join"",sort/./g}},$_}{map{/ /,$`>0&&print$'}sort map"@{[$#$_,sort@$_]}",%a 88, Samy Kamkar map{$x{x,sort/./g}.=$_}sort<>;map{s/ \b/ /g&&print}sort{$a=~y/ //-$b=~y/ //||$a cmp$b}%x 88, Piers Cawley -pl @$g=sort@{$g=join 0,sort/./g},$_}for(grep/ \w/,sort map"{"x@$_."@$_",keys%::){y/{//d 89, Tom Hargreaves -pl push@{$_{join"",sort/(.)/g}},$_}for(grep/ /,sort map{"}"x(@_=sort@$_)."@_"}%_){s/}//g 91, Petri Mikkelä -ln $w{1,sort/./g}.=" $_"}{$x{/ /g,sort/\w*/g}=1for%w;s/ . \W*//&&s/\W/ /g&print for sort%x 91, Jay Lyerly -ln $a=join'',sort split//;@$a=sort@$a,$_;$p{$a}=8+@$a."@$a";END{map{s/.\d//&&print}sort%p} 91, Peter Haworth -pl push@{$w{0,sort/./g}},$_}@$_>1&&push@{$x[@$_]},"@{[sort@$_]}"for%w;for(map{s ort@$_}@x){ 92, dragonchild

Edition 2007-01-09 top secret / strictly confidential page 66 of 520 Perlgolf History

map{$j{"@{[sort/./g]}"}.=$_}sort<>;map{/^[^a]/&&print$'}sort map{(a..t)[s!$/(?=.)! !g].$_}%j 93, Dave Tweed -ln push@{$a{1,sort/./g}},$_;}{s/.//s,print for sort map chr(@$_)."@{[sort@$_]}",grep@$_>1,%a 93, Steve Rushe -l $m{1,sort/./g}.=$_ for sort<>;push@{$a[y/ / /]},$_ for%m;map{chop;/ /&&print}sort@$_ for@a 94, Alain "TopMach" Dupuis -ln $o{1,sort/./g}.="$_ "}{for(%o){@a=sort split;push@{$#a},"@a"}for(1..15){print for sort@$_} 95, Eike Grote #!perl -nl push@{$h{join'',sort/./g}},$_;END{map{s/. //s;print if/ /}sort map"@{[chr@$_,sort@$_]}",%h} 96, Martin Raspe push@{$s{1,sort/./g}},/.+/g for sort<>;@$_>1&&print"@$_\n"for sort{@$a<=>@$b||$$a[0]cmp$$b[0]}%s 98, Daniel Parshall -l map{$a{join"",sort split//}.=$_}sort<>;map{y/~//d&&print}sort map{chop;"~"x y/\n/ /.$_}values%a 98, Daryl Olson -an0 map{push@{$s[$j{join"",sort/./g}||=++$i]},$_}sort@F;for$h(2..99){map{print"@ $_ "if@$_==$h}@s} 98, Colin Meyer -ln push@{$o{"@{[sort/./g]}"}},$_;END{s/\d+//,print for sort map@$_>1?10+@$_."@{[sort@$_]}":(),%o} 99, Steve Grazzini chop,push@{$p{join'',sort/./g}},$_ for sort<>;@$_>1&&print"@$_\n"for sort{@$a- @$b||"@$a"cmp"@$b"}%p 99, japhy -nl @$$s=sort$_,@${$s=\$s{_,sort/./g}}}{@$_>1&&print"@$_"for sort{@$a- @$b||$$a[a]cmp$$b[a]}values%s 100, Smylers chop,$s{join"",sort split//}.="$_ "for sort<>;/ $/,$a[y/ / /].=$`.$/for sort values%s;print@a[2..@a] 100, Jon Honeycutt -l push@{$p{chop,sort/./g}},$_ for sort<>;$#$_&&print"@$_"for sort{@$a<=>@$b||"@$a"cmp"@$b"}values%p 101, Eric Wright

Edition 2007-01-09 top secret / strictly confidential page 67 of 520 Perlgolf History

-nl push@{$n{join'',sort split''}},$_;END{$j{8+@$_.join' ',sort@$_}=8for%n;s'.\d''&&print for sort%j} 102, Ala Qumsieh -nl push@{$_{"@{[sort/./g]}"}},$_}{map{@$_>1&&print"@$_"}sort{@$a<=>@$b||"@$a"cm p"@$b"}map[sort@$_],%_ 102, Ido Trivizki push@{$a{sort(/(.)/g),a}},/(.+)/for+sort<>;print"@$_\n"for+sort{@$a<=>@$b||"@$a "cmp"@$b"}grep@$_>1,%a; 103, Trevor Leffler -ln push@{$a{join"",sort split//}},$_;END{map{s/~//g>1&&print}sort map{@a=sort@$_;"~"x@a."@a"}values%a} 104, Antti Lankila map$_{"@{[sort/./g]}"}.=$_,sort<>;@$_>1&&print"@$_$/"for sort{@$a-@$b||"@$a"cmp"@$b"}map[split],values%_ 105, pom -ln push@{$p{join0,sort/./g}},$_}{print"@$_"for sort{@$a- @$b||"@$a"cmp"@$b"}grep{--(@$_=sort@$_)}values%p 106, Michael Robinson -ln END{@$_>1&&print"@$_"for sort{@$a<=>@$b||@$a[0]cmp@$b[0]}map[sort@$_],%w}push@{$w{"@{[sort/./g]}"}},$ _ 107, Gareth McCaughan -l map{$_{join'',sort split//}.=' '.$_;}<>;map{s/.//s-/ /||print}sort map{chr(tr/ //).join' ',sort split}%_ 107, Sheldon Fuchs -l map{chop;$a{join'',sort/./g}.="$_ "}sort<>;map{chop;/ /&&print}sort{$a=~y/ / /<=>$b=~y/ / /||$a cmp$b}%a 107, Robert Mah -l chop,push@{$g{join"",sort/./g}},$_ for sort<>;$#$_&&print"@$_"for sort{@$a<=>@$b||"@$a"cmp"@$b"}values%g 107, Marcelo E. Magallon, Marcelo E. Magallon -nl $w{1,sort/./g}.=" $_"}{$,=' ';@$_>1&&print@$_ for sort{@$a<=>@$b||$a- >[0]cmp$b->[0]}map{[sort split]}%w 108, Prakash Kailasa -ln END{$#$_&&print"@$_"for sort{@$a- @$b||@$a[0]cmp@$b[0]}values%a}$a{$a}=[sort$_,@{$a{$a="@{[sort/./g]}"}}] 108, John W. Krahn -nl push@{$s{join"",sort/./g}},$_}{@$_>1&&print"@$_"for sort{@$a<=>@$b||"@$a"cmp"@$b"}map{[sort@$_]}values%s 108, Ben Goldberg

Edition 2007-01-09 top secret / strictly confidential page 68 of 520 Perlgolf History

-nl push@{$a{join'',sort/./g}},$_;END{$#$_&&print"@$_"for sort{@$a- @$b||"@$a"cmp"@$b"}map[sort@$_],values%a} 108, Gabor Szabo -nl $k{$w=join'',sort split//}++;@$w=sort@$w,$_}for(sort{@$a<=>@$b||$$a[0]cmp$$b[0]}keys%k){print" @$_"if$#$_ 110, Erik Johansen -ln END{map{@_=sort@$_;push@{$s[@_]},"@_"}values%s;map{/ /&&print}map{sort@$_}@s}push@{$s{"",sort+split//}},$_ 110, Paul Seamons map{chomp;push@{$t{join"",sort/(.)/g}},$_}<>;push@{$r[@$_]},"@{[sort@$_]} "for%t;print grep{/ /}sort@$_ for@r; 111, tinita map{chomp,push@{$s{"@{[sort split//]}"}},$_}<>;map{@_=sort@$_;push@{$t[@_]},"@_$/"if@_>1}%s;print sort@$_ for@t 111, Benoît Chauvet -nl END{push@{$r{@{$_}}},join$",sort@{$_}for%t;$_&&print sort@{$_}for@r{2..99}}push@{$t{join$,=$/,sort/./g}},$_ 111, Qingning Huo -n $_{"@{[sort split//]}"}.=$_}{map/ /&&print,sort{$a=~y/ //-$b=~y/ //||$a cmp$b}map"@{[sort split]} ",values%_ 111, Michael Ching map{push@{$a{"@{[sort+split//]}"}},$_}sort<>;print"@$_\n"for+sort{@$a<=>@$b||@$ a[0]cmp@$b[0]}grep{chomp@$_>1}%a 111, Evan A. Zacks, Evan A. Zacks -lp @{$a{$b}}=sort@{$a{$b="@{[sort/./g]}"}},$_}{$\='';@$_>1and$\.="@$_\n"for sort{@$a<=>@$b||$$a[0]cmp$$b[0]}%a 111, Steffen Müller -nl push@{$a{join"",sort/./g}},$_;END{/ /&&print for sort{$a=~y/ //<=>$b=~y/ //||$a cmp$b}map"@{[sort@$_]}",%a} 113, Paul Gaborit -nl push@{$_{join"",sort/./g}},$_;END{map{@_=sort@$_;push@{$a[@_]},"@_"if($#_)}v alues%_;map{map{print}sort@$_}@a} 114, Dennis Haney map{chop;push@{$n{join"",sort split//}},$_}sort<>;@$_>1&&print"@$_\n"for sort{@$a<=>@$b||$$a[0]cmp$$b[0]}values%n; 114, Jeremy Madea -ln $s="@{[sort/(.)/g]}";$a{$s}=[sort@{$a{$s}},$_];END{(@$_>1)&&print"@$_"for(so rt{@$a<=>@$b||$$a[0]cmp$$b[0]}%a)} 114, Simon Whitaker

Edition 2007-01-09 top secret / strictly confidential page 69 of 520 Perlgolf History

-ln push@{$u{join0,sort split//}},$_;END{for(sort{@$a<=>@$b||$$a[0]cmp$$b[0]}map{[sort@$_]}%u){@$_>1 &&print"@$_"}} 115, chr0 -ln $j=join"",sort/./g;@{$p{$j}}=sort($_,@{$p{$j}})}{$#$_&&print"@$_"for sort{$#$a-$#$b||$a->[0]cmp$b->[0]}values%p 118, Jaakko Hyvätti -nl $a=\@{$a{join'',sort split//}};@$a=sort@$a,$_;if(eof){for(sort{$#$a<=>$#$b||"@$a"cmp"@$b"}%a){pri nt"@$_"if$#$_>0}} 121, Philippe 'BooK' Bruhat -n chop;push@{$s{join"",sort/./g}},$_}{y/ / /&&push@{$s[y/ / /]},$_ for map{"@{[sort@$_]}$/"}values%s;print sort@$_ for@s 123, Eric Timme map$l{join'',sort split//}.=$_,sort@l=<>;for(sort{(split' ',$a)<=>(split' ',$b)||$a cmp$b}values%l){print if s/\n(?!$)/ /g} 123, Dariusz Sznajder -anl push@{$a{join'',sort split''}},$_;END{for(sort{$#$a<=>$#$b||@$a[0]cmp@$b[0]}map{[sort@$_]}values% a){print"@$_"if$#$_}} 123, Ross Younger -nl push@{$a{join$,,sort split$,}},$_;END{$,=$";for(sort{@$a<=>@$b||$$a[0]cmp$$b[0]}map[sort@$_],valu es%a){$#$_&&print@$_}} 124, Phillip Pearson -l map{chop;push@{$w{join'',sort split//}},$_}<>;map{$#$_&&push@{$o[$#$_]},join' ',sort@$_}values%w;map{map{print}sort@$_}@o 124, Subhash Chandra -ln push@{$a{join'',sort split//}},$_;END{map{print"@$_"if$#$_}sort{@$a<=>@$b||$$a[0]cmp$$b[0]}map{@$ _=sort@$_;$_}values%a;} 126, Jean-Pierre Vidal -ln $h{a,sort/./g}.="$_ "}{push@t,join' ',sort split' ',$h{$_}for%h;/ /&&print for sort{$a=~s/ / /g<=>$b=~s/ / /g||$a cmp$b}@t 126, Gio -ln $n=join '',sort split//;$c=push(@$n,$_)-1;$c&&{$n{$n}=join ' ',sort @$n,$c};END{@f=sort values %n;for(@f){s/\d+ //;print}} 128, Mark Kvale -nl END{$,="\n";for(values%t){@w=sort split;$n[@w].="@w,"}for(@n[2..@n]){print sort split','if$_}}$t{join'',sort split//}.="$_ " 129, Chas Owens -ln END{$,=' ';for(sort{@$a<=>@$b||$$a[0]cmp$$b[0]}values%r){print@$_ if@$_-1}}$r=join'',sort split//;@{$r{$r}}=sort$_,@{$r{$r}}; 130, jynx

Edition 2007-01-09 top secret / strictly confidential page 70 of 520 Perlgolf History

chop,push@{$_{join"",sort/./g}},$_ for<>;print map"@$_$/",sort{ @$a-@$b||$$a[0]cmp$$b[0]}map[sort{$a cmp$b}@$_],grep$#$_,values%_ 130, Boris Prinz -l -n push@{$e{join'',sort split''}},$_;END{print for sort{$a=~y/ //<=>$b=~y/ //or$a cmp$b}grep/ /,map join(' ',sort@$_),values%e} 132, Tony Young -nl $b=join'',sort/./g;@{$a{$b}}=sort@{$a{$b}},$_}{$,=' ';for(sort{@{$a}<=>@{$b}||@{$a}[0]cmp@{$b}[0]}values%a){print@{$_}if@{$_}>1} 136, Josh Armour map{chop;$a=join"",sort split//;$w{$a}=[sort@{$w{$a}},$_]}<>;@{$_}>1&&print"@{$_}\n"for sort{@{$a}<=>@{$b}||${$a}[0]cmp${$b}[0]}values%w 137, nashdj -ln END{$$_[0]&&print$$_[1]for sort{$$a[0]<=>$$b[0]||$$a[1]cmp$$b[1]}map{[$#$_,join$",sort@$_]}values%u}pus h@{$u{join$&,sort split$&}},$_ 138, Andrew Molyneux -ln push@{$s{join'',sort split//}},$_;END{for$o(2..15){@$_==$o and push@{$r{$o}},join' ',sort@$_ for %s}print join$/,sort@$_ for values%r} 143, Agnes Lefranc -ln @k=sort split"";$h{"@k"}=[sort@{$h{"@k"}},$_];END{map{$h{$_}[1]&&print"@{$h{$_}}"}so rt{@{$h{$a}}<=>@{$h{$b}}||$h{$a}[0]cmp$h{$b}[0]}keys%h} 146, Daniel Cutter -ln @d=sort split//;$d{"@d"}=[sort(@{$d{"@d"}},$_)];END{for(sort{"@$a"cmp"@$b"}map{[$#{$ d{$_}},@{$d{$_}}]}keys%d){print"@$_[1..$#{$_}]"if$$_[0];}} 148, pizza_milkshake, pizza_milkshake, pizza_milkshake -nl push@{$h{join'',sort/./g}},$_;END{map{print$$_[2]if$$_[1]}sort{$$a[1]<=>$$b[ 1]||$$a[2]cmp$$b[2]}map{[$_,$#{$h{$_}},join$",sort@{$h{$_}}]}keys%h} 150, Jeremy Leader -l $,=' ';for(sort<>){chop;push@{$f{join'',sort split//}},$_}for(sort{@{$f{$a}}<=>@{$f{$b}}or$f{$a}[0]cmp$f{$b}[0]}keys%f){( @r=@{$f{$_}})>1&& print@r} 150, clkao -p chop;push@{$_{join('',sort{$a cmp$b}m/./g)}},$_}for(sort{@$a<=>@$b||$a- >[0]cmp$b->[0]}map{[sort{$a cmp$b}@$_]}values%_){$_=$#$_?join(' ',@$_).$/:'' 155, Olivier Blanchard $x=sub{join'',sort split//;};chop(@A=sort<>);for(@A){if($a=$_){$A=&$x;$c=0;$_='';for(@A){if($A eq&$x){$a.=" $_";$c++;$_='';}}$a[$c].="$a\n"if$c;}}print @a; 157, Mike G.

Edition 2007-01-09 top secret / strictly confidential page 71 of 520 Perlgolf History

-ln push@{$a{join"",sort/./g}},$_;sub a{$a{+pop}}END{$,=" ";print@{a$_}for sort{@{a$a}<=>@{a$b}||$a{$a}->[0]cmp$a{$b}- >[0]}grep{(@{a$_}=sort@{a$_})>1}keys%a} 159, Thomas Eibner -ln push@{$a{join"",sort split""}},$_;END{for(keys%a){@{$a{$_}}=sort@{$a{$_}}}for(sort{@$a<=>@$b||${$ a}[0]cmp${$b}[0]}values%a){print join" ",sort@$_ if@$_>1}} 162, Christoph Michl -l chop,push@{$w{join'',sort+split//}},$_ while<>;push@o,[sort{$a cmp$b}@{$w{$_}}]for%w;map{@{$_}>1&&print join' ',@{$_}}sort{@{$a}<=>@{$b}||$a->[0]cmp $b->[0]}@o 164, Jaska Kivelä -nl $a=join'',sort split//;@{$a{$a}}=sort(@{$a{$a}},$_);END{for(sort{@{$a{$a}}<=>@{$a{$b}}||$a{ $a}[0] cmp $a{$b}[0]}keys %a){$#{$a{$_}}&&print join(' ',@{$a{$_}})}} 165, Michael Wulff while(<>){chop;push@{$a{join"",sort split//}},$_} for(keys%a){$b=$a{$_};@$b=sort@$b} for(sort{$#$a<=>$#$b||@$a[0]cmp@$b[0]}values%a){print((join" ",@$_),"\n")if$#$_} 168, Ryan Zachry -n chop;push@{$h{$k=join'',sort split//}},$_;@{$h{$k}}=sort@{$h{$k}};END{for(sort{@{$h{$a}}<=>@{$h{$b}}||$h{ $a}[0]cmp$h{$b}[0]}keys%h){print"@{$h{$_}}\n"if@{$h{$_}}>1}} 172, Patrick Gaskill -ln push@{$p{join'',sort/./g}},$_;END{$,=' ';print@{$p{$_}}for sort{@{$p{$a}}<=>@{$p{$b}}||${$p{$a}}[0]cmp${$p{$b}}[0]}grep@{$p{$_}}>1,map{ $p{$_}=[sort@{$p{$_}}];$_}keys%p} 175, Steve Comrie open F,pop;for(){chomp;$w=join'',sort split//;push @{$z{$w}},$_;@a=sort @{$z{$w}};$h{$w}="@a"if@a>1}print map{"$h{$_}\n"}sort{@{$z{$a}}<=>@{$z{$b}}||$h{$a}cmp$h{$b}}keys %h 176, Jarkko Sonninen while(<>){push(@{$j{join("",sort split"")}},$_)foreach(split);} print join(" ",@$_),"\n"foreach(sort{@$a<=>@$b||$a->[0]cmp$b->[0]}map{[sort{$a cmp$b}@$_]}grep @$_>1,values %j); 179, Rene Luria -l for(<>){$o=join'',sort split//;$s{$o}=join' ',sort map{split}$s{$o},$_}for(sort{(split/ /,$s{$a})<=>(split/ /,$s{$b})or$s{$a}cmp$s{$b}}keys%s){print$s{$_}if(split/ /,$s{$_})>1} 180, Ole Tange -n chop;@k=sort split//;push@{$a{"@k"}},$_;$b{"@k"}++;END{%c=map{$_,$b{$_}>1?join(" ",sort(@{$a{$_}}))."\n":""}keys%a;print map{$c{$_}}sort{$b{$a}<=>$b{$b}or$c{$a}cmp$c{$b}}keys%c} 181, Vesa Takoja

Edition 2007-01-09 top secret / strictly confidential page 72 of 520 Perlgolf History

for(<>){chop;@b=sort split//;push@{$q{"@b"}},$_}for(keys%q){@{$z{$_}}=sort@{$q{$_}}if$#{$q{$_}}}prin t"@{$z{$_}}\n"for(sort{$#{$c=$z{$a}}cmp$#{$v=$z{$b}}||${$c}[0]cmp${$v}[0]}ke ys%z) 206, R. Lammel while(<>){chomp;push @{$A{join('',sort split('',$_))}},$_;} for(keys %A){if ($#{$A{$_}}>0){push @{$S[$#{$A{$_}}]},[sort @{$A{$_}}]}} for(@S){if ($_){for(sort {$a->[0] cmp $b->[0]} @{$_}){print "@{$_}\n";}}} 210, Joel Caughran while(<>){chomp;push@{$g{join "",sort(/(\w)/g)}},$_;}foreach(keys %g){if(@{$g{$_}}>1){@{$g{$_}}=sort@{$g{$_}};push@g,$g{$_};}}@g=sort{@$a<=>@$ b||$$a[0]cmp$$b[0]}@g;foreach(@g){print join(" ",@$_),"\n";} __END__ 223, Graham Wood while(<>){chop;push(@{$c{join("",sort(split""))}},$_);}for(values %c){$t=@t=sort @{$_};$f=shift @t;if(--$t){$p{$t}{$f}=[@t];}}for $t(sort{$a<=>$b}keys %p){for $s(sort keys %{$p{$t}}){print join(" ",$s,@{$p{$t}{$s}}),"\n";}} 254, Rick Cook @w=<>;chomp@w;@w=sort@w;while(@w){$i=pop@w;$r=0;for(0..$#w){$_=$i;$a=1;$y=@w[$r ];while($_){$z=chop;$a=0if$y!~s/$z//;if(!$y&$a&!$_){$e.="@w[$r] ";@w[$r]=""}}$r++}@p=(@p,$e.$i)if($e);$e=""}@c=sort{$a=~s/ / /g<=>$b=~s/ / /g||$a cmp$b}@p;for(@c){print"$_\n"} 273, Jan Löfvendahl -l @a=<>;foreach(@a){$e=join'',sort split//;$d{$e}+=1;}foreach $k(keys(%d)){if($d{$k}<2){delete $d{$k};}else{$d{$k}+=10;foreach(@a){if($k eq join'',sort split//){$d{$k}.=" $_"}}$_=$d{$k};push(@f,join' ',sort split/ /);}}foreach(@f=sort(@f)){$_=~s/\d* //;$_=~s/\n//g;print;}

4.3.3. Artistic/Unorthodox Solutions 102, Andrew Savige $_=('$>{exy}.=$_ for sort%>;'x2).'print@>{1..$=}';s;exy;fast,sort/./g;;s;exy;s+ (?=.)+ +g;;s;%;<;;eval 196, Gabor Szabo -nl $w=join'',sort split//;$k{$w}++;@$w=sort@$w,$_;}for(sort{@$a<=>@$b or$$a[0]cmp$$b[0]}keys%k){print"@$_"if$#$_ # not something very unorthodox but I like it :-) # see the order of { and } signs 2999, Andrew Savige

Edition 2007-01-09 top secret / strictly confidential page 73 of 520 Perlgolf History

''=~('('.'?'.'{'.('`'|'%').('['^'-').('`'|'!').('`'|"\,"). (( '"')).('`'|'&').('`'|'/').('['^')').'\\'."\$". (( ';' )).'('.('['^'(').('`'|'/').('['^')').('['^'/') .(( '<') ).'>'.')'.'\\'.'{'.'\\'.'$'.':'.'='.'\\'.'$' .';' .';'. '\\'.'@'.':'.'='.'('.')'.';'.('['^('+')).( "\["^ '.').( '['^'(').('`'|'(').'\\'.'@'.':'.','.'\\' ."\$". ('~').( '['^',').('`'|'(').('`'|')').('`'|',') .("\`"| '%').'(' .'\\'.'$'.'~'.'='.('`'|'#').('`'|'(' ).("\`"| '/').('[' ^'+').'\\'.'$'.':'.')'.('`'|'.').( '`'|'%'). '\\'."\"". '\\'.'"'.';'.'\\'.'$'."\>".'\\'. '{'.("\`"| '*').(('`')| '/').('`'|')').('`'|'.').('\\'). '"'.'\\'.'"' .','.('['^'(' ).('`'|'/').('['^')').('['^'/' ).'\\'.('@'). ':'.'\\'."\}". '.'.'='.'\\'.'$'.';'.('\\'). '}'.('!'^'+'). ('['^'+').('['^ ')').('`'|')').('`'|'.').( '['^'/')."\+".( '['^'(').(('`')| '/').('['^')').('['^'/') .'\\'."\{".'\\'. '$'.('`'|'!').'=' .'~'.('['^'"').('-').( '{'^'[').'-'.'-'. '-'.'\\'.'$'.('`'| '"').'=' ."\~".( '['^'"').'|'.('{'^ '[').'|'.'|'.('|'). "\|". '\\'. '$'.('`'|'!').('{'^ '[').('`'|'#').('`'| '-' ).('['^'+').'+'.'\\' .'$'.('`'|('"')). ( '\\').'}'.('`'|'-').( '`'|'!').(('[')^ '+').'\\'.'{'.('`'|'#' ).('`'|('(')).( '`'|'/').('['^'+').';' .('['^'"').';'.( '!'^'+').';'.('{'^'[') .';'.';'.'\\'.'$'.'_'. '.'.'\\'.'$'.'/'.'\\'. '}'.('`'|"'").(('[')^ ')').('`'|'%').(('[')^ '+').'\\'.'{'.(('[')^ '"').'>'.('!'^'+').'>' .'>'.'>'.('^'^("\`"| '/')).'\\'.'}'.'%'.'>' .'"'.'}'.(')'));$:= '.'^'~';$~='@'|"\(";$^= ')'^'[';$/='`'|'.'; $_='('^'}';$,='`'|'!';$\ =')'^'}';$:='.'^'~' ;$~='@'|'(';$^=')'^"\["; $/='`'|'.';$_="\("^ '}';$,='`'|'!';$\=(')')^ '}';$:='.'^"\~";$~= '@'|'(';$^=')'^"\[";$/= '`'|'.';$_='('^'}'; $,='`'|'!';$\=')'^'}'; $:='.'^'~';$~="\@"| '(';$^=')'^'[';$/='`'| '.';$_='('^('}');$,= '`'|'!';$\=')'^'}';$: ='.'^'~';$~='@'|'('; ( $^)=')'^'[';$/="\`"| '.';$_='('^"\}";$,= ( (( '`')))|'!';$\="\)"^ '}';$:='.'^'~';$~= (( '@' ))|'(';$^=')'^'['; $/='`'|'.';$_='(' ^'}'; ($,) ='`'|'!';$\="\)"^ '}';$:='.'^"\~"; $~='@'| "\("; $^=')'^('[');$/= '`'|'.';$_='('^ '}';$,='`' |"\!"; $\=')'^"\}";$:= '.'^'~';$~='@' |'(';$^=(')')^ '[';$/= '`'|'.';$_='(' ^'}';$,="\`"| '!';$\=')'^'}';$: ='.'^'~' ;$~='@'|"\("; $^=')'^"\["; $/='`'|'.';$_='('^'}';$,='`'|'!' ;$\=')'^'}'; $:='.'^'~'; $~='@'|'(';$^=')'^'[';$/='`'|"\."; $_='('^'}'; $, ='`'|'!';$\=')'^'}';$:='.'^('~');$~= (( ( '@')))|'(';$^=')'^'[';$/='`'|'.';$_= ( (( '(')))^'}';$,='`'|'!';$\=')'^('}');$:= (( '.' ))^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.'; $_= '('^'}';$,='`'|'!';$\=')'^'}';$:='.'^'~';$~='@'|'(';$^=')'

4.3.4. Explanation by Lars Mathiesen Newsgroups: perl.golf Date: 8 Apr 2002 14:22:23 -0000 Message-ID: <[email protected]> Subject: Let me count the ways... From: [email protected] (Lars Henrik Mathiesen) I've made a quick rundown of the methods used in the solutions that got under a score of 80 (as an arbitrary cutoff). First off, everybody in this group used a hash to collect anagram sets, generating the key with some moral equivalent of join '', sort split //, $_; the primary trick used here is to prepend some constant string to force the sort into array context and let the auto-join of hash keys help out. Most solutions also presort the input so that the anagram sets will be collected in sorted order. But a few people chose to collect anagram sets unsorted and sort them later, allowing the use of -p tricks to replace "for <>" and print. I'll go through the main groups of solutions in order of the lowest scoring member. The first group of course contains the Best of Breed - these entries all collect the anagram sets separated by newlines, and then traverse the whole hash multiple times, each time printing the ones

Edition 2007-01-09 top secret / strictly confidential page 74 of 520 Perlgolf History that have a specific number of words in them. Of course they need to replace all newlines except the last by a space before the print happens. One way to do that is to replace only one newline on each traversal, and printing an anagram set exactly when the last internal newline is replaced: 61.44, Best of Breed map!s/ ^/ /m|//||print,sort%/for map$/{_,sort/./g}.=$_,sort<> 61.46, Lars Mathiesen map!s/ ^/ /m|//||print,sort%0for map$0{0,sort/./g}.=$_,sort<> The other way is to replace all internal newlines or spaces on each run, and compare the number of replacements to an external counter: 67.42, Rick Klement map$n^s/\s\b/ /g||print,sort%a,$n++for map$a{r,sort/./g}.=$_,sort<> 76.46, Yanick Champoux map$1{join$|,sort/./g}.=$_,sort<>;map$g^s/\s\b/ /g||print,sort%1while++$g<99 78.41, Geoff Hubbard ++$m^map{$m^s/ (?!$)/ /g||print}sort%a=%.for map$.{join$m,sort/./g}.=$_,sort<> The next main group uses an s/// when collecting the sets, to turn newlines into spaces and add one dummy char at the start of the string for each word, allowing a single sort to handle the number of words as well as the words themselves. The final character got squeezed out here when three people realized that two or more words meant at least two newlines at the end. 63.46, Stephen Turner $s{o,sort/./g}=~s/.*/~$& $_/for sort<>;print/ (.* ) /for sort%s 63.46, Ton Hospel $_{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/ (.* ) /for sort%_ 63.48, Jasper McCrea $o{1,sort/./g}=~s/.*/1$& $_/for sort<>;print/ (.* ) /for sort%o 64.44, Alma Media Golf Team $f{f,sort/./g}=~s/.*/~$& $_/for sort<>;print/~~ (.* )/for sort%f 64.44, Adam Spiers $g{g,sort/./g}=~s/.*/~$& $_/for sort<>;print/~~ (.* )/for sort%g 64.44, MeowChow

Edition 2007-01-09 top secret / strictly confidential page 75 of 520 Perlgolf History

$o{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/__ (.* )/for sort%o 66.42, Ari Kauppi $p{p,sort/(.)/g}=~s/.*/%$& $_/for sort<>;print/%% (.* )/for sort%p 67.45, Colm Dougan map$s{1,sort/./g}=~s/(.*) */1$1 $_/,sort<>;map{/11 /;print$'}sort%s 70.43, Amir Karger $o{join"",sort/./g}=~s/.*/~$& $_/for sort<>;print/\w+ .*\n/gfor sort%o 74.49, Honza Pazdziora $h{"@{[sort/./g]}"}=~s/(.*) ?/{$1 $_/for sort<>;print grep s/{{+ //,sort%h The third main way of doing it: Collect anagram sets in an array, one entry for each set size, and print. Sets are collected with newlines, which are turned into spaces in the same operation where the set size is counted. Finding the set size with split puts the words in @_, and a string substitution puts in the spaces: 68.44, Mtv Europe map$a{a,sort/./g}.=$_,sort<>;map$p[split].="@_ "x/ ./,sort%a;print@p 72.39, Josef Drexler $o{g,sort/./g}.=$_ for sort<>;$g[split].="@_$/"for sort%o;print@g[2..$.] Turning the newlines into spaces with s/// gives you the count: 74.41, Keith Calvert Ivey map$%{join _,sort/./g}.=$_,sort<>;map$_[s] ^] ]gm].=/ /&&$_,sort%%;print@_ 75.41, Andrew Savige map$>{o,sort/./g}.=$_,sort<>;@}{s+ (?=.)+ +g}.=$_ for sort%>;print@}{1..$=} Note that two solutions filter out the hash keys and one-word 'sets' before collecting, while the other two have to omit printing the ones collected. The former approach seems to have an edge. The fourth main group: Adding a sortable prefix in a separate operation, showing the set size. All examples of -p tricks are here. First some that use a fixed-length prefix. The first one is actually wrong: It just prepends the number of internal spaces as an integer, which will sort sets with 11 to 20 members between those with 2 and 3. But the test program only has one case with sets of 2 and 10 members, and some with sets of 11. 71.38, Terje K map$a{a,sort/./g}.=-$_,sort<>;map{/.-/&&print$'}sort map{s/ -/ /g.$_}%a Converting the number with chr:

Edition 2007-01-09 top secret / strictly confidential page 76 of 520 Perlgolf History

75.41, Jay Tilton -p $h{i,sort/./g}.=$_}for(sort map{chr(@_=sort split)|"h@_ "}%h){s/i.*|.//s Adding 8 or 9 to make all numbers from 2 to 15 into two-digit integers: 76.36, Chris Dolan map$a{o,sort/./g}.=_.$_,sort<>;map{s/.._//&&print}sort map{9+s,\n_, ,g.$_}%a 79.39, John McNamara map$j{join"",sort/./g}.=$_,sort<>;print+grep{s/.\d//}sort+map+8+split."@_\n",%j 79.42, Joost Diepenmaat $f{z,sort/./g}.=$_ for<>;s/.\d//&&print for sort map{@r=sort/.+/g;8+@r."@r "}%f Then some more (group four prime, perhaps) that add a variable length prefix, to get the same picture as group two before the last sort. More -p tricks here, and some intense obfuscation of that fact by Juho, using } as the prefix. (It's interesting, FSVO, that only one solution in group two used { or } as prefix, and here it's only Marko who doesn't). 74.38, Juho Snellman -p $a{a,sort/./g}.=$_}for(sort map"}"x(@a=sort/.+/g)."@a ",%a){/}}+/,$_=$' 74.39, Eugene van der Pijll map$o{o,sort/./g}.=$_,sort<>;map{/}+/.print$'}sort map'}'x s/ \b/ /g.$_,%o 74.47, Marko Nippula -p $_{1,sort/./g}.=$_}for(sort+map{@_=sort/.+/g;1x$#_." @_ "}%_){s/\C.* // 75.40, Eirik Berg Hanssen map$_{_,sort/./g}.=$_,sort<>;print grep{s/}+//}sort map"}"x s/ \b/ /g.$_,%_ 78.38, Rick Myers map$i{a,sort/./g}.=$_,sort<>;map{/{+/,print$'}sort map{'{'x s/ (?=.)/ /g.$_}%i In conclusion: There's more than one way to skin a cat, but still only a finite number. But I was a bit surprised to see that noone else was using the same method as I was. I only wonder what the post mortem gamers will manage to do now. Lars Mathiesen (U of Copenhagen CS Dep) (Humour NOT marked)

4.4. TPR(0,3) "Mathemathics" The game started May 1st 2002 and ended May 8th 2002. Referees: Eugene van der Pijll, Yanick Champoux, Keith Calvert Ivey, Stefan `Sec` Zehl, Jason Henry Parker

Edition 2007-01-09 top secret / strictly confidential page 77 of 520 Perlgolf History

4.4.1. Rules Hole 1: Cantor Display the Cantor set. This is one of the simplest fractals, discovered by Georg Cantor. It is the result of an infinite process, so for this hole, printing an approximation of the whole set is enough. The argument passed to your script will be a single digit between 0 and 8 inclusive indicating the order of the approximation. The following steps describe one way of obtaining the desired output: Start with a string of dashes, with length 3**$ARGV[0]. Replace the middle third of the line of dashes with spaces. You are left with two lines of dashes at each end of the original string. Replace the middle third of each line of dashes with spaces. Repeat until ready. For example, if the argument is 3, start with a string of 27 dashes: ------Remove the middle third of the string: ------and remove the middle third of each piece: ------and again: ------The process stops here, when the lines of dashes are all of length 1. You should not print the intermediate steps. Only the final result, given by the last line above, should be displayed. Your output should be properly newline-terminated. Hole 2: Kolakoski Print a Kolakoski sequence. This is a sequence of numbers that describes itself. The string ``122112122122112...'' consists of alternating substrings of 1's and 2's: ``1'', ``22'', ``11'', ``2'', ``1'', ... . If you write down the lengths of these substrings: 1, 2, 2, 1, 1, ..., you get the numbers in the original string back. A string of numbers with this property is called a Kolakoski sequence. You can make a Kolakoski sequence of any two numbers from 1 to 9. For example, the following is the Kolakoski sequence of 3 and 4: ``33344433344443333...''. All Kolakoski sequences are uniquely defined by the two alternating numbers, and are infinitely long. Your script should take exactly three arguments. The first two are the numbers that should be used in the Kolakoski sequence. They are two distinct numbers between 1 and 9 inclusive, written as single digits. The third argument will be a number between 1 and 500 inclusive. It is the number of characters that should be printed. Your program must print exactly that number of characters, no more and no less, followed by a newline character.

4.4.2. Solutions “Cantor” 34, Rick Klement, Mtv Europe, Marko Nippula, Eirik Berg Hanssen, MeowChow

Edition 2007-01-09 top secret / strictly confidential page 78 of 520 Perlgolf History

s/./$& $&/gfor($\="- ")x pop;print 34, Jay Tilton s/./$& $&/gfor($_="- ")x pop;print 35, Lolly Pop s/$/$"$`/for($\="- ",$")x pop;print 36, Ton Hospel for$;(s//- /..pop){s!.!$& $&!g}print 36, Chris Dolan for$.(s//- /..pop){s/./$& $&/g}print 36, BoB (Best of Breed - referees) for$/(s//- /..pop){s!.!$& $&!g}print 36, Honza Pazdziora s!!- !;eval's/./$& $&/g;'x pop;print 36, Jasper McCrea s//- /;eval's/./$& $&/g;'x pop;print 36, Juho Snellman s;;- ;;eval';s;.;$& $&;g'x pop;print 36, Jerome Quelin s//- /;eval's/./$& $&/g;'x pop;print 36, Jerome Quelin s,,- ,,eval's,.,$& $&,g,'x pop,print 36, Jerome Quelin s//- /;s/./$& $&/gfor($_)x pop;print 36, Marcus Holland-Moritz s!!- !;eval's/./$& $&/g;'x+pop;print 36, Michiel van Leeuwen, Bass s//- /;eval's/./$& $&/g;'x pop;print 37, Philippe 'BooK' Bruhat

Edition 2007-01-09 top secret / strictly confidential page 79 of 520 Perlgolf History

s!!-$/!;eval's/./$& $&/g;'x pop;print 37, Taipei.pm $_="- ";eval's/./$& $&/g;'x+pop;print 37, Kevin Cline $_='- ';eval's/./$& $&/g;'x pop;print 37, Mickut s//-\n/,eval's/./$& $&/g,'x pop;print 38, Qingning Huo s//- /;for$.(1..pop){s/./$& $&/g}print 38, Beijing.pm, Beijing.pm s//- /;for$,(1..pop){s/./$& $&/g}print 38, Benoît Chauvet -li- s//$'$"/for($^I,$")x pop;print$^I 39, Adam Spiers $\="- ";$\=~s/./$& $&/gfor 1..pop;print 39, Dr. Mu -l $_='-';eval's/./$& $&/g;'x pop;print 40, Lars Mathiesen -la055 $/.=$".$/,$"x=3for 1..pop;print$/ 40, Stephen Turner -l s//-/;for$.(1..pop){s@.@$& $&@g}print 40, gimbo for$i(s..- ...pop){s,$,$"$`,,$"x=3}print 40, Greg Allen -l s//-/;for$c(1..pop){s/./$& $&/g}print 40, The Refs (pre-competition) -li- $^I=~s/./$& $&/gfor 1..pop;print$^I 40, tt -l s//-/;for$a(1..pop){s/./$& $&/g}print 41, Rafael Garcia-Suarez, Guillermo Sansovic -l s//-/;s/./$& $&/gwhile$ARGV[0]--;print 41, Alain "TopMach" Dupuis

Edition 2007-01-09 top secret / strictly confidential page 80 of 520 Perlgolf History

-055 $/.=$".$/,$"x=3for 1..pop;print"$/ " 41, Jean-Pierre Vidal $\="- ";$\=~s/(.)/$1 $1/gfor 1..pop;print 41, Karsten Sperling -l for$.(s..-...pop){s,,$_$",,$"x=3}print 41, Damien Neil -l $_="-";for$.(1..pop){s/./$& $&/g}print 41, Eike Grote -l s//-/;eval's//$_$"/;$"x=3;'x pop;print 41, Joost Diepenmaat -li- $^I.=$".$^I,$"x=3for 1..pop;print$^I 41, Simulants -l $_="-";for$x(1..pop){s|.|$& $&|g}print 42, Prakash Kailasa -l for$=(0..pop){s/ |-/$& $&/g^s//-/}print 42, Dave Tweed -l s//-/;s/./$& $&/g while$ARGV[0]--;print 42, Geoff Richards -l s//-/;[sort{s/./$& $&/g;0}0..pop];print 42, Amir Karger s//- /;eval's/$/$"x$+[0].$`/e;'x pop;print 42, Josef Drexler -l s/$/-/;eval's//$"$_/;$"x=3;'x pop;print 42, Jed Davis $_="-\n";for$i(1..shift){s/./$& $&/g}print 42, Boris Prinz -l s//-/;for$x(1..pop){s/(.)/$1 $1/g}print 43, John McNamara $..=$"x3**--$_.$.||'-'for$|..pop;print$..$/ 43, mathieu longtin, mathieu longtin $:='-';$:.=$".$:,$"x=3for 1..pop;print"$: " 43, Ala Qumsieh $*.=$"x3**--$_.$*||"-"for 0..pop;print$*.$/ 43, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 81 of 520 Perlgolf History

-l $.='-';$..=$".$.,$"x=3for 1..pop;print$. 43, seano -l print+map/[3-9]/?'':/1/?$":'-',0..2x pop 43, Petri Mikkelä s//- /;eval's/$/" "x(pos).$`/e;'x pop;print 43, Step McGorm s//-\n/;for($n=pop;$n--;){s/./$& $&/g}print 43, Andrew Savige -li- map$^I.=$"x3**$-++.$^I,1..pop;print$^I 43, Philippe Bricout, David Lowe -l $a='-';$a.=$".$a,$"x=3for 1..pop;print$a 43, Evan A. Zacks -l for$i(s//-/..pop){$_.=$"x y///c.$_}print 44, Eric Roode -l $.='-';$..=$".$.,$"x=3for(1..pop);print$. 44, Gareth McCaughan -l $_='-';s/./$& $&/g while$ARGV[0]--;print; 44, Steven Alexander -l for$,(0..pop){$_.=$"x y///c.$_||"-"}print 44, wickline -l $_.=' 'x y/- //.$_ for($_='-')x pop;print 44, Matt Nelson -l $c='-';map{$c=~s/./$& $&/g}1..pop;print$c 44, Michael Wrenn -l for$n(0..pop){s??$_.$"x y///c|'-'?e}print 45, Jon Coppeard $_="-";s/./$& $&/g while$ARGV[0]--;print$_.$/ 45, Michael Thelen -l for$i(0..pop){$_.=$"x y/- //.$_||'-'}print 45, Ross Younger -l $_="-";for$,(1..pop){$_.=$".$_;$"x=3}print 45, Daryl Olson -l for$a(0..pop){$_.=' 'x y///c.$_||'-'}print 45, Ronald J Kimball -l s//-/;for$a(1..pop){$_.=$"x y///c.$_}print 45, Ido Trivizki

Edition 2007-01-09 top secret / strictly confidential page 82 of 520 Perlgolf History

-l @0='-';push@0,($")x@0,@0for 1..pop;print@0 46, nashdj $;="-";$;.=$"x3**$_.$;for$!..-1+pop;print"$; " 46, Terje K -l for$,(0..pop){$_.=" "x y/ -//.$_||"-"}print 46, RRBuonanno map$#.=' 'x(3**$_/3).$#||'-',0..pop;print"$# " 46, Tom Hargreaves -l @/='-';@/=map{$_,$",$_}@/for 1..pop;print@/ 46, Ken Rockot -l for$n(0..- s//-/+pop){$_.=$"x3**$n.$_}print 47, Tony Young $.='-';$..=' 'x3**$_.$.for 0..-1+pop;print$..$/ 47, tinita -l $/="-";$/.=($"x3**--$_).$/for 1..pop;print$/ 47, Steve Rushe -l for$a(0..pop){y/-/ /;$_=$z.=$_.$z||'-'}print 47, Matthew Byng-Maddick -l s//-/;$_.=$"x y|||c.$_ while$ARGV[0]--;print 47, Alistair McGlinchy $s='-';map$s.=' 'x3**$_.$s,0..-1+pop;print"$s " 47, Rick Myers $p='-';map$p.=$"x$p=~y///c.$p,1..pop;print"$p " 47, Yoav Goldberg -lX $_=p;for$i(1..pop){$_.=uc.$_}y/pP/- /;print 48, Peter Makholm $,='-';$,.=' 'x3**$_.$,for(0..-1+pop);print"$, " 48, Robert Mah -l $a='-';$a.=' 'x3**$b++.$a for(1..pop);print$a 48, Colin Meyer -l $r='-';$r.=$"x3**($_-1).$r for 1..pop;print$r 49, Michael Robinson

Edition 2007-01-09 top secret / strictly confidential page 83 of 520 Perlgolf History

-l s//-/;$_.=' 'x3**$i++.$_ while$ARGV[0]--;print 49, giorgos zervas -l for$i(0..pop){$_.=$i?($"x length).$_:'-'}print 49, Phil Radden -l $_="-";$_.=" "x y///c.$_ while$ARGV[0]--;print 49, Bjørn Hee -l $_='-';for$a(1..pop){$_.=' 'x(length).$_}print 49, James Harvey -l $t='-';map$t.=' 'x3**--$_.$t,(1..pop);print$t; 49, mpiwg $s='-';for(1..pop){$s.=' 'x3**$b++.$s}print"$s\n" 49, Isaac Lin -l $c='-';map{$c.=' 'x(3**$_/3).$c}1..pop;print$c 50, Zephyr McLaughlin s//- /;while($ARGV[0]--){s/ / /g;s/-/- -/g}print 50, Pepik -l $x="-";for(1..pop){$x=$x." "x3**--$_.$x}print$x 50, Olivier Blanchard -l $o='-';$o.=' 'x 3**($_-1).$o for 1..pop;print$o 51, BigrTex -l $/='-';map{$_=$/;y/-/ /;$/.=$_.$/}1..pop;print$/ 51, Simon Whitaker -l $;=pop;$_='-';$_.=' 'x y/ -//.$_ while$;--;print 51, David Newcum -l $s='-';map{$s.=' 'x length($s).$s}1..pop;print$s 52, POOP $i=pop;$_="- ";while($i--){s/ / /g;s/-/- -/g}print 52, pizza_milkshake -l $_="-";for$n(1..pop){$_.=$"x3**--$n.reverse}print 53, z0ned -l $_='-';for($==pop;$=--;){$_.=' 'x(length).$_}print 53, Lucca -l $_="-";$_.=" "x(length).$_ while($ARGV[0]--);print 53, Gregory Vincic -l $_="-";for$e(0..--@ARGV[0]){$_.=" "x3**$e.$_}print 53, stefp

Edition 2007-01-09 top secret / strictly confidential page 84 of 520 Perlgolf History

$a='-';$a.=' 'x3**$_.$a for 0..shift()-1;print"$a\n"; 54, Thorbjørn Ravn Andersen -l $_="-";while($ARGV[0]--){$_.=" "x3**$i++.$_};print 54, bjelli $c="-";$c.=" "x3**$_.$c foreach 0..-1+pop;print"$c\n"; 55, Daniel Cutter $d="-";$f=" ";$d.=$f.$d,$f x=3for(1..shift);print"$d\n" 56, Jan Löfvendahl -l $_='-';for$i(1..pop){$_=$_.' ' x (3**($i-1)).$_}print 59, jynx -l sub a{my$a=pop;$a?a(--$a).$"x3**$a.a($a):'-'}print+a+pop 59, Joe Baldassini -l sub p{my$x=pop;$x--?p($x).$"x3**$x.p($x):'-'}print p pop 61, Phil Crow $b="-";for($i=pop;$i--;){$b.=" "x length($b).$b;}print"$b\n"; 62, Simon P -l $_="-";for$i(1..pop){s/(.)/(($1eq"-")?"- -":" ")/ge}print 63, Will Coleda for($*=1,$/="-";$*<3**$ARGV[0];){$/.=" "x$*.$/;$**=3}print"$/ " 64, pom -l for($_="-"x3**pop;s/(-+)\1\1/$1." "x(length$1).$1/ge;){}print 65, Phillip Pearson -l $x='-';for($i=0;$i<$ARGV[0];$i++){$x.=' 'x(3**$i).$x;}print$x; 66, Matt Diephouse -l $_="-"x3**shift;1while s!(-+)\1\1!$1." "x(length$1).$1!e;print; 68, Mike Schilli -l $_="-"x3**pop;1while s/(-+)(\1)(?=\1)/$1." "x length($2)/ge;print 69, Scott Hall -l $/='- ';for(0..9){($/x=2).=' 'x(2*3**$_)}print substr($/,0,3**pop) 70, Sami J. Mäkinen $t='-';$t.=' 'x$l.$t while (($l=length($t))<3**$ARGV[0]);print "$t\n"; 71, Dale Hagglund -l $_="-"x(3**pop);s@(-+)\1\1@$1.(" "x length $1).$1@eg while/--/;print

71, Boyd Nation -l print&a(3**pop);sub a{my$t=pop()/3;$t*3==1?'-':&a($t).' 'x$t.&a($t)} 71, Samy Kamkar

Edition 2007-01-09 top secret / strictly confidential page 85 of 520 Perlgolf History

-l $_="-"x($f=3**pop);do{$f/=3}while+s;--+;"-"x$f.$"x$f."-"x$f;eg;print 72, Mike Cramer -l sub c{if($l=pop){$_=c(--$l);$_." "x(length).$_}else{"-"}}print c(pop) 73, Ryan Zachry -l $_="-"x3**pop;{s,--+,$l=(length$&)/3;"-"x$l.$"x$l."-"x$l,e&&redo}print 76, Joe Cullin -l $_='-'x3**pop;s:--+:$l=1/3*length$&;'-'x$l.$"x$l.'-'x$l:ewhile/--/;print; 80, Rick Cook $_='-'x($s=3**shift)."\n";for(;$s;){$s/=3;$h=' 'x$s;s/(-{$s})- {$s}/$+$h/g}print; 81, Patrick Gaskill, Patrick Gaskill -l $_='-'x3**pop;s,(-+),$b=(length$1)/3;$a='-'x$b;$a.' 'x$b.$a,eg while/-- /;print 84, Andrew Farnsworth $r='-';while($ARGV[0]--){$w='';$l=length$r;while($l--){$w.=' '}$r.=$w.$r}print"$r\n" 86, Sigmund $a=3**$ARGV[0];s//"-"x$a."\n"/e;while($a>1){$a/=3;s/\-+/"-"x$a." "x$a."- "x$a/eg}print; 88, Oliver Maul -l sub c{$_=pop;my$n=length()/3;$n<1?$_:c("-"x$n)." "x$n.c("-"x$n)}print c("- "x(3**pop)) 101, Richard Rognlie @a=3**pop;while(@a){$a=pop@a;$o.=$a<0?" "x-$a:$a==1?"-":"";push@a,$a/3,- $a/3,$a/3if$a>1;}print"$o\n"; 102, Graham Collinson $a=3**$ARGV[0];$_='-'x$a;while($a>1){$b='-'x$a;$a=$a/3;$d='-'x$a.' 'x$a.'- 'x$a;s/$b/$d/g}print "$_\n"; 106, Subhash Chandra -l $_='- 'x3**pop;$l=length;while(($i=$l/=3)>=1){while($i

Edition 2007-01-09 top secret / strictly confidential page 86 of 520 Perlgolf History

-l print substr<<'RICK KLEMENT: 34. AAAAAARRRGH!',0,3**pop ------RICK KLEMENT: 34. AAAAAARRRGH!

4.4.3. Artistic/Unorthodox Solutions “Cantor” 37 (post-mortem) -l print map'-'^O&$_,glob"{,-,}"x pop 43, Dr. Mu -l print map{/1/?$":'-'if!/[3-9]/}0..2x pop 52, MeowChow $_='s!-| !$& $&!g;$c++?eval:print"- "';$c=-pop;eval 37, Jerome Quelin $\="- ";s/./$& $&/gfor($\)x pop;print 43, Greg Allen -l print map{/1/?$":'-'if!/[3-9]/}0..2x pop 49, Ton Hospel -l print eval'map{'x($n=pop).'$_,$",$_}'x$n.'"-"' 53, Alistair McGlinchy -l /[3-9]/ or$k.=/1/?' ':'-'for 0..-1+10**pop;print$k 54, MeowChow $_='s!-| !$& $&!g;$c++?eval:print"- "';$c=-pop;eval 144, Eric Roode use Math::BigInt; $d=new Math::BigInt 2; $b=new Math::BigInt 3; $d*=4**($b**$i++)+1while$i<$ARGV[0]; print($d%2?'-':' ')while($d/=2); print "\n" 348, Max Tie

Edition 2007-01-09 top secret / strictly confidential page 87 of 520 Perlgolf History

s||t|e|s^^n^e|s||i|e|s||r|e|s||p|e|s^^d|Y^e|s^^g^e^s||a^N|e|s||a^G|e^s||a^E|e^s ||a^A|e^s||a^G|e^s||a^E|e|s||a^N|e|s||a^O|e|s||a^N|e^s^^a|r^e^s^^a|z^e^s||a^H|e |s||p|e|s^^o^e|s||p|e^s||a^O|e^s||a^O|e^s^^a|r^e^s||a^N|e^s||a^k|e^s||a^L|e^s|| a^N|e^s||a^K|e|s||a^O|e^s||a^N|e|s^^a|r^e^s||a^I|e|s||a^E|e^s||a^E|e^s||r|e^s|| o|e|s||f|e^s||LZ^Ea^ad^L|eee 1503, Jerome Quelin

Edition 2007-01-09 top secret / strictly confidential page 88 of 520 Perlgolf History

#undef fff /* n 50fp 00ep a9+y >#v_ 0> \ : #v_ $v " ^ < ^+-0'\*a\< v< > 1ep>1eg0eg- v q,a_ v#!-'< 0 v-'< > ^ 2 v ,< |-4 < : $e^':2eg:1+2ep^ > :4\ > :! #v_ 3eg :1+ 3ep 0eg f+ p v > $ 2eg 1+ 2ep ^ ^< */ //"; #include #define ARGV argv

#define ord #define $ /* $code = <<'FOO'; unshift @ARGV, "foo"; "*/ main (int argc, char *argv[]) //"; { char $ buf[8192]; char $ tmp[8192]; int $ i, $ j, $ offset;

$ buf[0] = '2'; $ buf[1] = 0; for($i=0;$i

Edition 2007-01-09 top secret / strictly confidential page 89 of 520 Perlgolf History

#undef fff /* n 50fp 00ep a9+y >#v_ 0> \ : #v_ $v " ^ < ^+-0'\*a\< v< > 1ep>1eg0eg- v q,a_ v#!-'< 0 v-'< > ^ 2 v ,< |-4 < : $e^':2eg:1+2ep^ > :4\ > :! #v_ 3eg :1+ 3ep 0eg f+ p v > $ 2eg 1+ 2ep ^ ^< */ //"; #include #define ARGV argv

#define ord #include #define $ /* $code = <<'FOO'; unshift @ARGV, "foo"; "*/ main (int argc, char *argv[]) //"; { char $ buf[8192]; char $ tmp[8192]; int $ i, $ j, $ offset;

$ buf[0] = '2'; $ buf[1] = 0; for($i=0;$i

Edition 2007-01-09 top secret / strictly confidential page 90 of 520 Perlgolf History

#undef fff /*^>,------"---->>+++++++++++++++++++++++++++++++++++++++++++++<<[[>>[> ]>+<<[<]<-]>>[[>]>>>[>]+>++++++++++++++++++++++++++++++++>+[ <]<<<<[<]>[[>]>>>[>]<+<<+[<]<<<<[<]>-]>[>]>>>[>]<-<<-[<]<<<< [<]>]>>-]>>[.>][-]++++++++++.[-][ */ //"; #include #define ARGV argv #define ord #include #define $ /* $code = <<'FOO'; unshift @ARGV, "foo"; "*/

main (int argc, char *argv[]) //"; { char $ buf[8192]; char $ tmp[8192]; int $ i, $ j, $ offset;

$ buf[0] = '2'; $ buf[1] = 0; for($i=0;$i n 50fp 00ep a9+y >#v_ 0> \ : #v_ $v ^ < ^+-0'\*a\< v< > 1ep>1eg0eg- v q,a_ v#!-'< 0 v-'< > ^ 2 v ,< |-4 < : $e^':2eg:1+2ep^ > :4\ > :! #v_ 3eg :1+ 3ep 0eg f+ p v > $ 2eg 1+ 2ep ^ ^< ^ <]*/

Edition 2007-01-09 top secret / strictly confidential page 91 of 520 Perlgolf History

4.4.4. Solutions “Kolakoski” 51 (post-mortem) -l print map$_=$ARGV[($.+=!--$.[$.])%2],@.=(0)x pop 52, BoB (Best of Breed - referees) -l print map$.[$!++]=$ARGV[1&($.+=!--$.[$.])],1..pop 54, Jerome Quelin -l print map$$[$.++]=$ARGV[--$$[$;]||++$;,$;&1],1..pop 54, Rick Klement s/.?/$ARGV[1&pos]x$&||2/ge>>9?print$_&'?'x pop,$/:do$0 56, Chris Dolan print$_?$.[$!++]=$ARGV[--$.[$.]||++$.,$.%2]:$/for-pop..0 56, Mtv Europe -l for$$(1..pop){$_.=$ARGV[1&grep$|<($$-=$_),/./g]}print 57, Ton Hospel -l print eval'($_.=chop()x$+.$ARGV[$|--])=~/$&(.)/,'x pop 57, Eirik Berg Hanssen s/.?/$ARGV[1&pos]x($&||1)/geuntil/.{$ARGV[2]}/;print$&,$/ 58, Jay Tilton $;=pop;s/.?/$ARGV[1&pos]x($&||1)/eguntil/.{$;}/;print"$& " 58, Greg Allen -l s/.?/$ARGV[1&pos]x($&||1)/eg until/.{$ARGV[2]}/;print$& 58, Lars Mathiesen -l $_.=2while$|=s/./$ARGV[--$|]x$&/ge<999;print$_&'?'x pop 58, MeowChow s/.?/$ARGV[1&pos]x$&||2/ge<999?do$0:print/(.{${\pop}})/,$/ 59, Marko Nippula s/.?/$ARGV[$|--]x($&||1)/eguntil$|=/.{$ARGV[2]}/;print"$& " 59, Lolly Pop map{@;[0..@;]=map{($ARGV[$|--])x$_}@;,@;;print}@;=1..pop,$/ 59, Daryl Olson s/.?/$ARGV[1&pos]x$&||1/eg until/(.{$ARGV[2]})./;print"$1 " 60, Bass s/.?/$ARGV[$-[0]%2]x($&||1)/ge until/.{$ARGV[2]}/;print$&,$/ 60, Beijing.pm

Edition 2007-01-09 top secret / strictly confidential page 92 of 520 Perlgolf History

s/.|/$ARGV[(pos)%2]x$&||9/ge<999?do$0:printf"%.${\pop}s ",$_ 61, Josef Drexler $%[$_]=$ARGV[$"],$*||=$%[++$.],$"^=!--$*for 1..pop;print@%,$/ 61, Michiel van Leeuwen $_=2;{s/./$ARGV[$-[0]%2]x$&/eg;/.{$ARGV[2]}/?print"$& ":redo} 62, Juho Snellman -l print map{-@@+push@@,($==$ARGV[$|--])x($@[$.++]||$=)}1..pop 62, Jasper McCrea s/.?/$ARGV[$"++%2]x($&||1)/eg until$"=/.{$ARGV[2]}/;print$&.$/ 62, Ala Qumsieh $_[$_]=$ARGV[$|-=!--$z],$z>0or$z=$_[++$*]for 1..pop;print@_,$/ 63, Qingning Huo -l print map{@.=(($?=$ARGV[$|--])x($.[-1]||$?),@.);pop@.}1..pop 63, The Refs (pre-competition) -l print map{(map@/=(($_)x($/[--$%]||$_),@/),@ARGV)[-$_]}1..pop 64, Amir Karger -l print map{push@@,($%=$ARGV[--$_%2])x($@=$@[$_]||$%);$@}1..pop 64, Benoît Chauvet -li1 map{push@,,$ARGV[$^I^=!$h];($h||=$,[$m++])--}1..pop;print@, 64, Matt Nelson -l print map{push@_,($n=$ARGV[$i%2])x($c=$_[$i++]||$n);$c}1..pop 65, Taipei.pm -l print+map+chop($*=($.=$ARGV[1&~$_])x chop($_=$..$*).$*),1..pop 65, Joost Diepenmaat -l $_.=($d=$ARGV[$|--])x(/./g,$d)[$f++]until/.{$ARGV[2]}/;print$& 65, gimbo -l $_.=($k=$ARGV[$i&1])x(/./g,$k)[$i++]until/.{$ARGV[2]}/;print$& 65, Adam Spiers -l print map{push@a,($%=$ARGV[$_%2])x($n=$a[$_]||$%);$n}0..-1+pop 65, seano -l $n=pop;push@_,($_)x(@_,$_)[$i++]for(@ARGV)x$n--;print@_[0..$n] 66, Peter Haworth -l push@,,($.=$ARGV[$|--])x($,[$_]||$.)for@/=0..-1+pop;print@,[@/] 66, John McNamara print+(map{push@_,($-=$ARGV[$|--])x($==$_[--$_]||$-);$=}1..pop),$/ 66, Guillermo Sansovic

Edition 2007-01-09 top secret / strictly confidential page 93 of 520 Perlgolf History

-l push@r,($/=$ARGV[1&$i])x($s[$i++]=$r[$i]||$/)for 1..pop;print@s 66, Philippe Bricout -l $l=pop;push@s,($_)x($s[$i++]||$_)for(@ARGV)x$l;print@s[0..--$l] 66, Ido Trivizki -l $o=pop;push@_,($_)x($_[$l++]||$_)for(@ARGV)x$o--;print@_[0..$o] 67, Tony Young push@>,($.=@ARGV[$|--])x(@>,$.)[$_]for 0..500;print@>[0..-1+pop],$/ 67, Petri Mikkelä -l $$=pop;s/.?/$ARGV[1&pos]x$&||$ARGV[0]/eg until/(.{$$})./;print$1 68, Eike Grote $_.=($,=$ARGV[$%%2])x((/./g)[$%++]||$,)until/.{$ARGV[2]}/;print$&.$/ 68, Stephen Turner push@$,($$=$ARGV[$|--])x($$[$_]||$$)for 0..500;$#$=-1+pop;print@$,$/ 68, tinita -l print map{push@_,($%=$ARGV[$/^=1])x($\xa7=$_[$_-1]||$%);$\xa7}++$/..pop 68, Marcus Holland-Moritz push@_,($"=$ARGV[$_&1])x($_[$_]||$")for+0..500;$#_=-1+pop;print@_,$/ 69, Mickut push@@,($@=$ARGV[$_%2])x($@[$_]||$@)for 0..333;print@@[0..(pop)-1],$/ 69, Prakash Kailasa $_=11;s!.!$ARGV[$-[0]%2]x$&!eg,s!(.{$ARGV[2]}).*!$1 !swhile--$=;print 70, Ronald J Kimball, Ronald J Kimball -l push@_,($~=$ARGV[$|--])x($_[$-++]||$~)for a..kn;print@_[0..pop()-1] 70, RRBuonanno -l map{push@_,($%=$ARGV[$_%2])x($_[$_]||$%)}0..500;print@_[0..(pop)-1] 70, Dr. Mu -l print map{push@v,($_)x($v[0]||$_);shift@v}map$ARGV[$_%2^1],(1..pop) 71, Damien Neil -l @.=@ARGV;$.=1,s/./$.[$.^=1]x$&/ge,$_.=$.[!$.]until/.{$.[2]}/;print$& 71, Alain "TopMach" Dupuis for$"(1..pop){/.$/;$_=($-=$ARGV[$"-1&1])x($&||$-).$_;print chop}print$/ 71, Michael Thelen -l $_.=($x=$ARGV[$i%2])x(/./g,$x)[$i++]while$i<500;print substr$_,0,pop 72, Honza Pazdziora $$=pop;$.=$ARGV[$|--],$_.=$.x substr$_.$.,$*++,1while!/.{$$}/;print$&,$/ 72, nashdj

Edition 2007-01-09 top secret / strictly confidential page 94 of 520 Perlgolf History

-l /.{$i}(.)/,$;=$ARGV[$i++%2],$_.=$;x($1||$;)until/.{$ARGV[2]}/;print$& 72, Terje K -l push@a,($ARGV[$_%2])x($a[$_]||$ARGV[$_])for 0..999;print@a[0..-1+pop] 73, Alistair McGlinchy -l $l=pop;@l=(@l,($m=$ARGV[$|--])x($l[$_]||$m))for 0..$l;print@l[0..$l-1] 74, jynx push@1,($ARGV[$|--])x($1[$_]or$ARGV[$;++])for$1..332;print@1[0..-1+pop],$/ 74, Simulants @t=@ARGV;for(1..pop){print$u=$f[$p++]||$t[$|];push@f,($t[$|--])x$u}die"\n" 75, Karsten Sperling -l print map{$.=~s/.//;$..=($=^=$%||=($==pop)^pop)x($&||$=-1);$&||$=}1..pop 75, Eric Roode -l $.=pop;push@*,($==$ARGV[$%%2])x($*[$%++]||$=)while$%<$.;print@*[0..$.-1] 75, Philippe 'BooK' Bruhat -l substr($@.=$ARGV[$|--],-1)x=substr$@,$_,1for 0..500;print substr$@,0,pop 76, Tom Hargreaves -l print map{$x=$a.$x;$e||=chop$x;--$e?$a:($a^=$b)^$b}2..pop,$b=pop^($a=pop) 76, Boris Prinz -l push@b,($ARGV[$_%2])x($b[$_]||$ARGV[$_%2])for(0..500);print@b[0..pop()-1] 76, Isaac Lin -l ($a,$b)=@ARGV;print map{push@s,($l=$_%2?$a:$b)x($s[0]||$l);shift@s}1..pop 77, Michael Wrenn -l until(/.{$ARGV[2]}/&&print$&){/.{$b}(.)/;$^=$ARGV[$b++%2];$_.=$^x($1||$^)} 77, mathieu longtin $/=$ARGV[1-$_%2],$*.=$/x($2||$/),$*=~s/(.)(.?)/$2/,print$1for 1..pop;print' ' 77, David Newcum -l map{$s.=($a=$ARGV[$_%2])x(substr($s,$_,1)||$a)}0..999;print substr$s,0,pop 78, Jed Davis -l $n=pop;@l=@a=@ARGV;$i=0until(@l=map{($a[$i++&1])x$_}@l)>$n;print@l[0..--$n] 79, David Lowe -l --$|,push@l,map$ARGV[!$|],1..$l[$_]||$ARGV[$_]for 0..500;print@l[0..pop()-1] 79, Step McGorm @a=@ARGV;s//@a/;while($i<666){$i=0;s/./$a[$i++&1]x$&/ge}s|.{$a[2]}|print$&,$/|e 80, Matthew Byng-Maddick -l *,=*ARGV;($,.=$,[$|])=~s,.,,,$,.=$,[$|--]x($&- 1),$_.=$&while$,[2]>y|||c;print 80, Michael Robinson

Edition 2007-01-09 top secret / strictly confidential page 95 of 520 Perlgolf History

-l @A=@ARGV;push@a,($A[$_%2])x($a[$_]||$A[$_%2])for 0..$A[2];print@a[0..$A[2]- 1] 80, Michael Robinson -l @A=@ARGV;$z=$A[$_%2],push@a,($z)x($a[$_]||$z)for 0..$A[2];print@a[0..$A[2]- 1] 81, Yoav Goldberg, Yoav Goldberg -l for(0..pop){@s=(@ARGV)x999;push@a,($s[$i++])x($a[$_]||$s[$_])}print@a[0..$i- 2] 81, giorgos zervas -l @K=@ARGV;for$i(0..500){for(1..$K[$i]){$K[$p++]=$ARGV[$i%2]}}print@K[0..- 1+pop] 81, Dale Hagglund -l @a=@ARGV;print map{$n=$a[$_%2];push@d,$n for 1..$d[0]||$n;shift@d;}0..$a[2]- 1;

82, z0ned -l @d=@ARGV;while($d[2]--){$b[$n++]=$d[$m%2];if($i++==$b[$m]- 1){$i=0;$m++}}print@b 82, Evan A. Zacks -l ($a,$b,$t)=@ARGV;map{push@a,($c=$|-- ?$b:$a)x($a[$_]||$c)}0..$t;print@a[0..$t-1] 83, Ken Rockot -l $?=pop;$_.=($"=$ARGV[$x&1])x($:=($/=(/./g)[$x++]||$")>$??$?:$/)while$?- =$:;print 83, Patrick Gaskill -l for(;@o<501;++$c,$|--){push@o,($ARGV[$|])x($o[$c]||$ARGV[$|])}print@o[0..- 1+pop] 83, Robert Mah -l $n=pop;do{/.{$i}(.)/,$b=$ARGV[$i%2],$_.=$b x($1||$b)}while$i++<$n;print/(.{$n})/ 83, Steve Rushe -l @a=@ARGV;map{$/=$a[$_%2];push@d,$/for 1..$d[$_]||$/}0..$a[2];print@d[0..$a[2]-1] 84, Jean-Pierre Vidal -l sub x{push@t,$ARGV[$i%2];$;--}$;=pop;while($;){x;$;&&x for 2..$t[$i];$i++}print@t 84, Dave Tweed -l ($s,$t,$n)=@ARGV;$_=$s.$t;$p="$t$s"x$n,s/./chop($p)x$&/eg until/(.{$n})./;print$1 85, Peter Makholm -l ($x,$y,$a)=@ARGV;push@f,($|--?$y:$x)x($f[$_]||$|*$x||$y)for 0..$a;print@f[0..$a-1] 86, Phil Radden

Edition 2007-01-09 top secret / strictly confidential page 96 of 520 Perlgolf History

-l ($%,$.,$=)=@ARGV;($.,$%)=($%,$.),push@.,($.)x($.[$_]||$.)for 0..$=;print@.[0..$=-1] 86, Jon Coppeard @a=@ARGV;push@c,($a[$e&1])x@{$e<=@c?@c:@a}[$e++]while(@c<$a[2]);print@c[0..-- $a[2]],$/ 91, Andrew Savige -l $==pop;push@],($_)x($-++?$-<3?$%>1?$%:$_:$][$-- 1]:($%=$_))for(@ARGV)x$=;print@][0..$=-1] 92, Scott Hall -l ($/,$b)=@ARGV;for(0..999){$;=$_%2?$b:$/;$k.=$;x(substr($k,$_,1)||$;)}print substr$k,0,pop 92, Mike Cramer -l $l=pop;@s=@ARGV;while(@l<$l){@l=(@l,($s[$c%2])x($l[$c]||$s[$c%2]));$c++}prin t@l[ 0..--$l] 92, Geoff Richards -l @x=@ARGV;$i=shift;$z.=$x[$_%2]x$i,$i=substr$z.$x[1],$_+1,1for 0..567;print substr$z,0,pop 93, Kevin Cline ($a,$b,$n)=@ARGV;$b^=$k=$a;$k||($a^=$b,$k=$R[++$p]||$a),(push@R,$a),$k-- while$n--;print@R,' ' 93, André Savigne -l print+map{$c--||($v=$ARGV[$|--],$c=$_<1?$v:$_-1?$s[$_-$d]:$v,$d+=-- $c);$s[$_]=$v}0..-1+pop 93, Colin Meyer ($a,$b,$l)=@ARGV;push@a,($_%2?$b:$a)x($_<2?$a<2*$_?$b:$a:$a[$_])for 0..$l;print@a[0..$l-1],$/ 94, Ryan Zachry ($a,$b,$c)=@ARGV;for$i(0..$c){pos=$i;/./g;$_.=($i%2?$b:$a)x($_==1?$b:$&||$a)}pr int/(.{$c})/,$/ 94, Samy Kamkar -l ($a,$b,$c)=@ARGV;while(@_<$c){map{push+_,$a}1..$_[$l++]||$a;$a^=$b^=$a^=$b}p rint@_[0..$c-1] 95, Zephyr McLaughlin b:if(@b==$ARGV[2]){print@b," ";exit}push @b,$ARGV[$i%2];$k++;$k<$b[$i]&&goto b;$k=0;$i++;goto b 95, Josh Schulz ($a,$b,$c)=@ARGV;for(0..$c){$s.=($_%2?$b:$a)x(substr($s,$_,1)||shift)}print substr($s,0,$c)." " 96, pom

Edition 2007-01-09 top secret / strictly confidential page 97 of 520 Perlgolf History

-l ($,,$;,$")=@ARGV;$_=$,x$,;$_.=(/$,$/?$;:$,)x(substr($_,++$i,1)||$;)while$i<$ ";/.{$"}/;print$& 100, Rafael Garcia-Suarez -l ($:,$;,$%)=@ARGV;$_=$:x$:;$_.=$; x(substr$_,++$x,1or$;),($:,$;)=($;,$:)while$%>$x;/.{$%}/;print$& 100, Jan Löfvendahl -l @a=@ARGV;@b="";for$i(1..$a[2]){for$j(1..($b[$i]||$a[$t])){push(@b,$a[$t])}$t =!$t;$_.=$b[$i]}print 101, James Harvey -l ($a,$b,$l)=@ARGV;$b+=$a;for(1..$l){$p=$a- 1;$s.=@n?($p=pop@n):$a;@n=(($a)x$p,@n);$a=$b-$a;}print$s; 105, Gregory Vincic -l ($n,$s,$i)=@ARGV;$l=0;map{push@r,(@ARGV[$l])x$n;$l=$l?0:1;$n=@r[$_]?@r[$_]:$ s;}1..500;print@r[0..--$i] 106, Ross Younger -l ($.,$/,$")=@ARGV;split'',$.x$..$/;for(0..$"){$_[$%++]=$- ?$/:$.for(1..$_[$?++]);$-=1-$-}$#_=$"-1;print@_ 106, Joe Baldassini -l @k=@ARGV;for(0..pop){splice(@k,$o,$k[$i],($x=shift)x$k[$i]),$o+=$k[$i++],pus h@ARGV,$x}print @k[0..$i-2] 106, Bjørn Hee -l ($a,$b,$c)=@ARGV;for$d(0..$c){push@e,$a;$f=$e[$d];for(2..$f){push@e,$a}($a,$ b)=($b,$a)}print@e[0..$c-1] 107, Thorbjørn Ravn Andersen -l ($a)=@a=@ARGV;@s=($a,$a[$a- 1?0:1]);map{$e.=$d=$s[$x];map{$s[$j++]=$a[$x%2]}1..$d;$x++}1..$a[-1];print$e 107, Olivier Blanchard -l ($a,$b,$c)=@ARGV;$o=$a x$a.$b x($a>1?$a:$b);$o.=$ARGV[$_%2]x substr$o,$_,1 for 2..$c;print substr$o,0,$c 108, BigrTex -l ($%,$/)=@ARGV;$@=$%x$%.$/x($%==1?$/:$%);map{$@.=($_%2?$/:$%)x substr $@,$_,1}2..500;print substr $@,0,pop 108, Rick Myers @a=@ARGV;while($a[2]--){if($_){s/.//;print$&;$_.=$a[$|-- ]x$&}else{$_=$a[$|]x$a[$|--];s/.//;print$&}}print" " 108, Lucca -l ($b,$a,$d)=@ARGV;do{push@l,split//,$b x($l[$c++]?$l[$c- 1]:$b);($a,$b)=($b,$a)}while@l<$d;print@l[0..$d-1] 108, mpiwg

Edition 2007-01-09 top secret / strictly confidential page 98 of 520 Perlgolf History

@t=shift;$b=shift;for(1..pop){for(1..$t[$n]){@t[$i++]=$n%2?$b:$t[0]}$t[1]=$t[1] ||$b;$f.=$t[$n++]}print"$f\n" 109, Sami J. Mäkinen @t=@ARGV;$l=pop@t;$"='';for($s="@t";$n<999;$i=0){$s=~s/(.)/$t[++$n,$i++%2]x$1/g e;}print substr($s,0,$l),"\n"; 110, Simon Whitaker -l ($.,$/,$,)=@ARGV;$_=($;=$.)x$.;while((length)<$,){$;=$:++%2?$.:$/;/.{$:}(.)/ ;$_.=$;x($+||$;)}print/(.{$,})/ 110, Will Coleda for(@*=@ARGV;@/<$*[2];){@/<2?push@/,($*[$/])x$*[$/++]:push@/,($*[$*%2])x$/[$/++ ];$*++;}print@/[0..$*[2]-1]," " 114, Mike Schilli -l (@n[0,1],$c)=@ARGV;while($c>0){$c- =$l=(substr($o,$j,1)||$n[$i]);$o.=$n[$i]x$l;$i=!$i;$j++;}print substr$o,0,pop 118, wickline -l @z=((@0=@ARGV)[0])x$0[0];$#z or@z=(1,($0[--$|])x$0[++$"]);@z=(@z,($0[-- $|])x$z[++$"])for 0..666;print@z[0..--$0[2]] 118, wickline -l @z=(@0=@ARGV)[0]==1?(1,($0[--$|])x$0[++$"]):($0[0])x$0[0];@z=(@z,($0[-- $|])x$z[++$"])for 0..666;print@z[0..--$0[2]] 121, Daniel Cutter ($a,$b,$c)=@ARGV;do{$r=substr$k,$i++,1;$r=$a if!$r;$k.=$a x$r;($a,$b)=($b,$a)}until$c

Edition 2007-01-09 top secret / strictly confidential page 99 of 520 Perlgolf History

-l while($l=$ARGV[2]- length($s)){$d=$ARGV[($e++)%2];push@l,split//,"$d"x($l[0]||$d) ;$n=shift@l||$d;$s.="$d"x($n>$l?$l:$n)}print$s 130, Subhash Chandra -l $h=($n=shift)+shift;$l=pop;do{if(@s>1){$j=$s[$i++];}else{$j=$n;++$i;}push@s, ($n)x$j;$n=$h-$n;}while(@s<$l);splice@s,$l;print@s; 131, Phil Crow $l=pop;@A=@ARGV;L:$a.=$A[$j%2]x$A[$j++%2];goto L if($a<2);while($j<$l){$a.=$A[$j%2]x substr($a,$j++,1);}print substr($a,0,$l)."\n"; 136, POOP $c=pop;$b=pop;$a=pop;$_=$a;while($c--){print;@s=((split//,$a x--$_),@s);($#s==-1)?$_=$b:($_=pop@s,@s=($b,@s));$t=$a;$a=$b;$b=$t}print" " 141, Rick Cook ($A,$R,$G)=@ARGV;$_=$A x$A;if($A<2){$_.=$R x$R;$x++}for(;$x<$G;$x++){$t=$R;$t=$A if$x%2;$_.=$t x substr$_,$x+1,1}print((substr$_,0,$G),"\n"); 160, Sigmund $x=$ARGV[0];$y=$ARGV[1];$p=0;while(length($_)<=$ARGV[2]){$_.=$x;m/(.{$p})(\d)/; $_.=$x x($2-1);($x,$y)=($y,$x);$p++}chop while(length($_)>$ARGV[2]);print$_."\n"; 185, Graham Collinson $a=$ARGV[0];$b=$ARGV[1];$c=$ARGV[2];$d=0;$e=$a;$f=$a;$o='';while(length $o<$c){$o.=$e x$f;if($e==$a){$e=$b}else{$e=$a};$f=substr $o,++$d,1;if(!$f){$f=$b}}$o=substr $o,0,$c;print "$o\n"; 193, Jorrit Kronjee ($a,$b,$c)=@ARGV;sub w{$e=$_[0];$d[$_]=$e for(@d..@d+$_[1]- 1);}w($a,$a);if($a<2){w($b,$b);$f++}while(@d<$c){$f++;if($e!=$a){w($a,$d[$f] )}else{w($b,$d[$f])}}print substr(join("",@d),0,$c),"\n"; 211, bjelli ($x,$y,$c)=@ARGV;if ($x==$y&&$y==1){print"1"x$c,"\n";exit;}$o=$x x$x;$z=$y;$i=1;if($x==1){$o.=$y x$y;$i++;$z=$x}while(length($o)<=$c){$o.=$z x substr($o,$i,1);$i++;$z=($z eq $x)?$y:$x}print substr($o,0,$c),"\n"; 251, Andrew Farnsworth ($o,$e,$n)=@ARGV;for($x=0;$x<$o;$x++){g($o);$p++;}if($o==1){for($x=0;$x<$e;$x++ ){g($e);$p++;}}$c=substr$s,$p,1;while($l<$n){g($c);$p++;$c=substr$s,$p,1;}pr int substr$s,0,$n;print"\n";sub g{($z)=@_;$l+=$z;$r=$ARGV[$w++%2];for($x=0;$x<$z;$x++){$s.=$r;}}

4.4.5. Artistic/Unorthodox Solutions “Kolakoski” 54, Jerome Quelin -l print map@@[$.++]=$ARGV[--@@[$@]||++$@,$@&1],1..pop 81, Jasper McCrea

Edition 2007-01-09 top secret / strictly confidential page 100 of 520 Perlgolf History

-l eval'$l=@a;map$l-=$_*!!$l,@a;push@a,$d=$ARGV[!!$l^$d==$ARGV[0]];'x pop;print@a 82, Jasper McCrea -l eval'$l=$s++;map$l-=$_*!!$l,/./g;s/$/$d=$ARGV[!!$l^$d==$ARGV[0]]/e;'x pop;print 83, Jasper McCrea -l eval'$l=@a=/./g;map$l-=$_*!!$l,@a;s/$/$ARGV[!!$l^$a[-1]==$ARGV[0]]/;'x pop;print 87, Philippe 'BooK' Bruhat -l $,=pop;$a=\substr$_="@ARGV "x$,,0,$,;s/(.) /$+x substr$_,$i++,1/ewhile$i<$,;print$$a 88, Philippe 'BooK' Bruhat -l $c=pop;$a=\substr$_="@ARGV "x$c,0,$c;eval's/(.) /$+x substr$_,$i++,1/e;'x500;print$$a 91, Philippe 'BooK' Bruhat -l $_=\substr$@=1x pop,0;$@="";substr($@.=$ARGV[$|--],- 1)x=substr$@,$_,1for$"..500;print$$_ 100, Jasper McCrea -l eval'if($l=@a=/./g){$i++until($l-=$a[$i])<1} $i=!s/$/$ARGV[($a[-1]==$ARGV[0])^!!$l]/;'x pop;print 520, Max Tie -l s||a^G|e^s||a^E|e|s||t|e^s^^n^e^s||i|e^s^^r^e|s^^p^e^s||a^Z|e^s||a^N|e|s^^d| Y^e |s^^D|Y^e|s||a^S|e^s^^A|Z^e^s||V|e|s^^G^e^s||R|e^s^^A^e^s||a^E|e|s^^a|z^e^s||a^ O|e^s||a^N|e^s^^l^e|s^^i^e^s^^t^e|s^^n^e^s^^u^e^s||g|e|s||e|e^s||a^N|e^s||a^H|e ^s||a^P|e|s^^d|x^e|s^^d|x^e|s||a^G|e|s||a^E|e^s||a^I|e|s||x|e^s^^D|Y^e^s^^a|r^e |s^^o^e|s^^p^e^s||a^G|e|s||a^P|e|s^^A|Z^e^s^^V^e|s||G|e^s^^R^e|s^^A^e^s||a^E|e^ s||a^N|e^s||e^Z|e^s||a^O|e^s||a^N|e^s^^a|r^e|s||a^Z|e^s||a^F|e^s||a^F|e|s||d^Y |e|s^^E|Z^e^s||a^E|e^s||LZ^Ea^ad^L|eee 949, Jerome Quelin

Edition 2007-01-09 top secret / strictly confidential page 101 of 520 Perlgolf History

#undef fff /* n a9+y >#v_ 0> \ : #v_ $ :0ep :0fp '0+, v " ^ < ^+-0'\*a\< >\a*\'0-+v ve50pe40pe30 pe2 $ _v#!:\<0 pe1$_^#!:\<0< p >\a*\'0-+^ > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4ep v a ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q */ //"; #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { int $ tab[atoi( $ ARGV[3])]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); printf("%d", $ tab[1]); for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } printf("\n"); } 2255, Jerome Quelin

Edition 2007-01-09 top secret / strictly confidential page 102 of 520 Perlgolf History

#undef fff /*v>> >,------"------[>+>> >>>>+>+<<<<<<<<-]>>,------>+>>>>>+++++++++++++++++++++++++++++++ +++++++++++++++++.------>+<[>- <[>>+<<-]]>[-<<<<<+<-<[<<+>>-]<<[>>+>>>>>>>>+< <<<<<<<<<-]>> >>>>>>>>[>+>+<<-]>[<+>-]<-<]>[<<+>>-]<<<<<<<<< <<<<,------>,------>,------<<[>++++++++++<-]>>>>>>>>+< <<<<<[[>+<-]> >>>>>-<<<<<<]>[<+>-]>>>>>[-<<<<<<++++++++++<-> >>>>>>]<<<<<<-<<>[>>+<<-]>>[<<+<+>>>-]<<<[[-]>->++++++++++<< ]>>[<<+>>-]<< [>>+>+<<<-]>>>[[-]<<<>>>>>>>>>>>>>>>[+++++++++ +++++++++++++++++++++++++++++++++++++++.<<<<<<<<<<<<<->>>>>> >>>>>>>[-]]<< <<<<<<<<<<<<<>+[->[->>>>>>>>[>]>[>]+[<]<[<]<<< [->>>+<<<<<[<+>-]<[>+>>>>+<<<<<-]>>>]>>>[<<<+>>>-]<<[->>+<<< <[<<+>>-]<<[> >+>>>+<<<<<-]>>>>]>>[<<+>>-]<[>>[>]>[>]<+[<]<[ <]<-]>>[>]>[> ]<++++++++++++++++++++++++++++++++++++++++++++ +++.------[<]<[<]< +>>[>]<-[[>+<-]<<[<]<->>[>]]>[<+>-]<<[<]<[<<<<<+>>>>>-]<<<<< [->>>[->>>+<< <]>[->+<]>[<<+>>-]>[<<+>>-]>[>]+>>[<+>-]<[<]<< <<<<]<]++++++n++++<][-]<]++++++++++.[-][ > a9+y >#v_ 0> \ : #v_ $ :0ep :0fp '0+, v ^ < ^+-0'\*a\< >\a*\'0-+v ve50pe40pe30 pe2 $ _v#!:\<0 pe1$_^#!:\<0< p >\a*\'0-+^ > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4ep v a ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q */ //"; #include #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { int $ tab[atoi( $ ARGV[3])]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); printf("%d", $ tab[1]); for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } printf("\n"); } #define BLAHBLAH /* ] */

Edition 2007-01-09 top secret / strictly confidential page 103 of 520 Perlgolf History

4.4.6. Explanation by Ton Hospel Newsgroups: perl.golf Subject: Re: TPR(0,3) in review Date: Thu, 9 May 2002 03:24:14 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) As requested, here is my unorthodox cantor. Except I'm not going to talk about the 49 one Eugene requested but the much more elegant shorter one that somehow I don't find back in pgas. Anyways, I wanted to do a purely functional version without any assignments (even to function globs). So I decided to use the by now standard algorithm of starting with one "-" and then repeatedly replacing a char by "char space char". And what is more functional than the "apply to everything" map operator? A bunch of values go in, and another bunch of values come out the other side. (Notice that the $_ you implicitly get in a map is a bind, not an assign (as you can see from that changing $_ will change the list you are iterating over)) So the basic step had to be: map{$_,$",$_} ($" is a space). Then I wanted to apply this n times to an initial "-". so we get: 0 -> print "-" 1 -> print map{$_,$",$_}"-" 2 -> print map{$_,$",$_}map{$_,$",$_}"-" the repeated maps after another we can do by evalling a something that represents the map n times (yes! how functional) representing n maps is easy: 'map{$_,$",$_}'x pop Now to append that extra "-" is a bit tricky, since pop."-" gives a warning: Warning: Use of "pop" without parens is ambiguous However, it does work. The normal technique is to add () for pop()."-", but the other way is to shut up the warning using -X. And since we will need a -l anyways for the newline, the options can be cuddled and we get: -Xl print eval'map{$_,$&,$_}'x pop.'"-"' for a total length of 40. Not even too bad for such a silly method. Anyone wants to try a pure lambda calculus one? As an exercise I leave this silly 41: $~=$~x3&"- "x1e5|"-"for$*..pop;print$~,$/ Though I prefer this 42: -l print map$_&349525?$":"-",0..2/3*4**pop (it only has the slight drawback that it's wrong. But the output looks right)

4.4.7. Explanation by Rick Klement Newsgroups: perl.golf Date: Thu, 09 May 2002 11:29:43 -0700 Subject: Re: TPR(0,3) in review

Edition 2007-01-09 top secret / strictly confidential page 104 of 520 Perlgolf History

Message-ID: <[email protected]> From: [email protected] (Rick Klement) Eugene van der Pijll wrote: > > Among the entries, there were some that had something extra. They used a > new, unique or surprising technique, used an unusual method, or were > just ununderstandable. Some of these are: > > Kolakoski: Rick Klement (54.25) > > I'd like to invite the authors of these solutions to explain these > solutions to the public, or at least the original bits. OK, I'll give it a shot (pun intended). Here it is: s/.?/$ARGV[1&pos]x$&||2/ge>>9?print$_&'?'x pop,$/:do$0 A little google searching leads me to this page: http://www.research.att.com/cgi-bin/access.cgi/as/njas/sequences/eisA.cgi?Anum=A001083 which has an example that will "generate sequence of sequences by recursion using next1()". It shows the sequence generated, a program that prints it, and the recursive function nextl(), given as: next1(v)=local(w); w=[]; for(n=1,length(v),for(i=1,v[n],w=concat(w,2-n%2))); w Converting this to perl gives: s/./$ARGV[1&pos]x$&/ge with the outer loop controlled by the s///g, the inner loop implemented by the 'x' repetition operator, and $_ being used for both v and w. The mod function was used to flip between 1 and 2 in the result string, and since we had to do Kolakoski for any two digits, some changes were required. I started using $|-- (the golf friendly toggle special variable), and while it worked, it had to be cleared each time through the cycle, and that costs at least seven strokes (see Lars 58.21 for a good example). The $|= part always seemed to be in the way when I was shuffling things around, so I went looking for alternatives, and found one of the same length in [$-[0]%2]. This got me thinking about pos() (especially since pos() is mentioned in the perlvar description of @+, the close cousin to @-. I knew Mtv Europe used /\G/ inside a s///g, so it was worth a shot. So I changed the code to [pos%2], which gives a warning, but [pos()%2] worked :) It does have a hated pair of parentheses, though, so that was the next attack. Fortunately, %2 has a cousin, &1 which does close to the same thing, and when [pos&1] produced the same warning, I could flip the two and that's how I wound up with [1&pos]. I now had the process body. I could do s/./$ARGV[1&pos]x$&/ge enough times, and I would have a Kolakoski string containing the required answer. That only left three things to settle, the initialization, the loop control, and printing the first $ARGV[2] digits of the resulting string. -l $_=2;1until s/./$ARGV[1&pos]x$&/ge>500;print substr$_,0,pop would be one version of this, it's a 62.25. Let's look at it. The initialization is done with $_=2; - why 2? I saw 2 in the web page :) I thought it was there because the two digits were 1 and 2, and they started with the off digit. That turns out to be wrong, 2 will serve as a general purpose seed for any two digits, if you do enough cycles. OK, we now have an initialization that takes five strokes (that's pretty long, we'll get back to it).

Edition 2007-01-09 top secret / strictly confidential page 105 of 520 Perlgolf History

Let's print. "substr" is a pretty long word, so let's try to do better. Close to print in perlfunc is printf: $_=2;1until s/./$ARGV[1&pos]x$&/ge>500;printf"%.$ARGV[2]s ",$_ 62.24. Slightly better, but wait, look closely, and there's a field width limiting value for strings that takes an argument: "%.*s" so: $_=2;1until s/./$ARGV[1&pos]x$&/ge>500;printf"%.*s ",pop,$_ Cool, three strokes better to 59.23 It's not enough - it's never enough! Keep scanning through the docs - and perlfunc gives a positive: pack. Hmmm pack 'a20', $_ will give a string of length 20 - OK: -l $_=2;1until s/./$ARGV[1&pos]x$&/ge>500;print pack a.pop,$_ 61.26 - longer, bummer :( Keep looking - scan the perlop chart for the thousandth time - notice '&', which on strings, will shorten the longer string to the shorter. How do I make the shorter string? Look around some more and spot 'x', let's replicate a mask character that will pass all the digits of the starting string without change, but is the desired length. A quick trip to "man ascii" (and having done the masking on another golf) shows that '?' is the one printable character that will not change a digit. Let's try it: $_=2;1until s/./$ARGV[1&pos]x$&/ge>500;print$_&'?'x pop,$/ 58.25 - better. The next thing to look at is the loop control: "1until ;". This is a count of eight strokes, partly because I can't nest the until and the s///. Let's see what we need in loop control, and if there isn't something shorter. First of all, where does that >500 come from? The 500 comes from the rules "The third argument will be a number between 1 and 500 inclusive." If I do more than 500 replacements, I'm sure the result string is longer than that, since one of the numbers must be greater than 1. A documented, but little used, fact is that s///g has a return value, the number of substitutions made, which in this case is the length of the original string. That 500 is pretty long, so we'll have to get back to it again. Let's look for short looping structures. 'for' and 'map' are pretty short, but require that the number of iterations be known - which they are not in this solution. I have to loop the s/// until I have a "long enough" string, and that can take over 100 cycles, yet 100 cycles of a 8,9 is horribly long string. So I looked for loop controls with a test in them. Both 1until ; and 1while ; take eight strokes. Sometimes, though, the 1 can be replaced by something useful, and that applies in this case. The $_=2; can replace the 1, leading to: $_.=2until s/./$ARGV[1&pos]x$&/ge>500;print$_&'?'x pop,$/ a 57.23, where I had to change the straight assignment to an append, because the $_.=2 now gets executed each time through. It still initializes when $_ is empty, and adding a 2 to the end of the string each time doesn't hurt, because we're generating a longer string than required. It's still seven strokes for the loop control, though. Hmmm, time to look at one of my favorites, the ?:do$0, cleverly used by Ton in SecretNumber. This one is only six strokes (if all the conditions can be met). One of the rules is "no assignments" because of precedence problems, and I have that $_.=2 in there. It could be left as a separate statement, though, leading to:

Edition 2007-01-09 top secret / strictly confidential page 106 of 520 Perlgolf History

$_.=2;s/./$ARGV[1&pos]x$&/ge>500?print$_&'?'x pop,$/:do$0 a 57.26, because the ';' is back, so no overall strokes are saved. Now (note: big step coming) since the initialization has changed from "do once" to "do each time", can some advantage be taken of that? That $_.=2; takes six strokes, and I wondered if the s/// could be made "self-starting", which it currently is not, because the '.' pattern requires that $_ contain at least one digit. Time to steal^Wborrow the pattern Eugene used to pass me in even.pl, using a pattern of '.?', which matches each character, and then the empty string at the end. For a string of length zero, it will match once (that sounds good), and for a string of length three, it will match each character, then match once more at the end (that could be OK). How do I know it's matching the empty string at the end? That turns out to be easy - all the digits in the Kolakoski are greater than zero, so I could check $& with a simple test. Let's see: s/.?/$&?$ARGV[1&pos]x$&:2/ge>500?print$_&'?'x pop,$/:do$0 57.24 - but wait, if $& is empty (has value zero), replicating by zero gives a result of length zero, so this can be reshuffled to: s/.?/$ARGV[1&pos]x$&||2/ge>500?print$_&'?'x pop,$/:do$0 a 55.25 - wheee - a saving of two whole strokes. These latest two came about by asking the question "can the iteration be made self-starting?". I promised to get back to that "horribly long" 500. Going slowly, operator by operator, through perlop, I paused for a second on the << >> line, and a bell went off in my head. By shifting a number several bits to the right, I could test for greater or equal to some power of two. Cool... Well, that 500 could be any value larger than 500. The next power of two larger than 500 is 512 (29) where 9 is only one stroke. That means I could replace the >500 with >511, and >>9 is exactly the same as >511. This leads to: s/.?/$ARGV[1&pos]x$&||2/ge>>9?print$_&'?'x pop,$/:do$0 which is the 54.25 this story started with. To sum up: • find an initial algorithm: s/./$ARGV[1&pos]x$&/ge • find the shortest "print first part": print$_&'?'x pop,$/ • find the shortest loop control: ?:do$0 • make it self-starting: .? with ||2 • shorten anything that looks long: >>9 I hope this helps someone... (no, I don't, there are already too many excellent golfers). -- Rick Klement

4.4.8. Explanation by Mtv Europe Newsgroups: perl.golf Date: 10 May 2002 12:31:16 -0000 Message-ID: <[email protected]> Subject: Re: TPR(0,3) in review From: [email protected] (Mtv Europe)

Edition 2007-01-09 top secret / strictly confidential page 107 of 520 Perlgolf History

Hello Eugene! [email protected] (Eugene Van Der Pijll) wrote: > Kolakoski: Rick Klement (54.25) > Mtv Europe (56.18) > Rick Klement (57.20) > Marko Nippula (69.23) > Philippe 'BooK' Bruhat (87.21) > Jerome Quelin (2255.06) > > I'd like to invite the authors of these solutions to explain these > solutions to the public, or at least the original bits. Ok, since all others explain their solutions already, now you'll have to listen to my bad English. As you can see, I start with 66.27 straightforward array manipulations: push@a,($j=$ARGV[$_&1])x($a[$_]||$j)for@b=0..-1+pop;print@a[@b],$/ Then I play for a while with algorithm that wasn't mentioned here before and wasn't used by players as far as I know, so I tell more about it: -l $.=$_.=$ARGV[$.=~s/(.)\1*/length$&/eg%2-!/^$./]for($_)x pop;print It's stateless method that uses main property of Kolakovski sequence in backward fashion - if in infinite sequence you squeeze repeated digits to its count $.=~s/(.)\1*/length$&/eg, you'll get back your sequence. With finite sequence, if after this operation you get in result beginning of your initial string /^$./, then you'll need to switch to other generating digit. Then I start numerous modifications of this algorithm, and found nice 1&grep variant with about the same functionality and same length 68: -l $.=$_.=$ARGV[1&grep$.=~s/(.{$_})|.*//&&$1,/./g]for($_)x pop;print At this moment I decide to throw away regexps (if someone read to this place, I'll appreciate explanation of "regex or regexp") Ok, I throw away bigger /regexp?/ and I got 61: -l for$$(1..pop){$?=0;$_.=$ARGV[1&grep$$>($?+=$_),/./g]}print Residuary peace of superfluity was obviously addition counter $?, and then I remember that I can modify loop variable and it will receive new next value each iteration, so I quickly take 56: -l for$$(1..pop){$_.=$ARGV[1&grep 0<($$-=$_),/./g]}print The rest of story is small. I optimized tiebreaker, but didn't submit it, because it mightn't help me in leaderboard at those moment while I comfortably sit with MeowChow of fourth place. Than I was hit upon Cantor and than I resubmit Kolakovski to finish this story - the only difference from previous line is $| instead of 0: -l for$$(1..pop){$_.=$ARGV[1&grep$|<($$-=$_),/./g]}print Moreover I used my older experiments with obfuscation (see here http://www.frox25.no- ip.org/~mtve/code/eso/perl/yaoe/ or here http://www.perlmonks.com/index.pl?node_id=162538 ) to increase job to referees and to achieve maximum tiebreaker - you can find it in post-mortem 'Max Tie'. Of course this is not maximum possible tie, you can always improve it with addition ^0^0^0^0 etc, but it's very fair balance between min length and max tie. Thanks for attention!

Edition 2007-01-09 top secret / strictly confidential page 108 of 520 Perlgolf History

4.4.9. Multilingual Solution by Jérôme Quelin http://slashdot.org/article.pl?sid=02/05/12/0051259 http://www.if.insa-lyon.fr/eleves/jquelin/quadri.html (dead link) © Jérôme Quelin, Sat May 11 2002 /!\ Caution: the following text contains material that can hurt your mental health. Read at your own risks! Perl Golf Maybe you don't know about it, but there's a Perl Golf tournament each month. What is Perl Golf? You are given a problem, and you must solve it (in Perl) with the fewest amount of characters. The shortest program wins. The analogy with real Golf is obvious (the fewer the better), hence the name. This kind of contest leads to very much fun, and really crazy solutions. If you feel offended when you saw some code with no alphanumerical characters, then don't go there: you'll loose your mental health! The Kolakoski problem As usual, a new contest began on the 1st of May 2002. There were two problems submitted, and one of them was the "Kolakoski" numbers problem (self describing numbers). The program was to print the n first numbers of the Kolakoski number build with two digits provided. Anyway, I won't go into details about this Perl Golf contest and its solutions - there is a mailing list for those nifty grifty details. This page is about a particular experience I had within this tournament. One Ring To Rule Them All... It all began because of Philippe 'BooK' Bruhat. I sent him an entry for the $A++ obfuscation page1 that worked either in Perl or C. But, for an unknown reason (in fact, I learned afterwards that it was because my solution was a full-blown program), this one wasn't added. More, it's very tough to be stuck at a given score in Perl golf, and see other golfers improve their score and take you some places on the leaderboard. Thus, in a moment of intense , I decided to write a bilingual entry for Kolakoski and Cantor, that would work either in C or in Perl. The beginning I started with the stub: #include #include #define $ /* "*/ main (int argc, char *argv[]) //"; { } The CPP preprocessor lines are comments for Perl.

1 http://paris.mongueurs.net/aplusplus.html

Edition 2007-01-09 top secret / strictly confidential page 109 of 520 Perlgolf History

As Perl vars begin with a dollar sign ($), I had to define it to the empty string. Since Perl allows to access the variable $var as $ var (you can include a space between the dollar and the name of the var), by defining $ in C as the empty string will allow: $ foo to access the var $foo in Perl and foo in C. I then open a C comment, in which I place a quote (") in order to declare the main function in C. This way, Perl will see the instruction: "*/\nmain (int argc, char *argv[]) //"; which is valid although would raise a "Useless use of a constant..." if we were running warnings. But since we're not, we're safe. We can close the Perl string transparently for C with the new C-style comment //. We then open the braces, which begin the main function in C, and an anonymous bloc in Perl, so far so good. A few tricks to address This was a good start, but I needed more thinking. First, arguments can be accessed with ARGV in Perl, but they are stored in argv in C. That's why I'm forced to: #define ARGV argv and then I can access the ARGV variable in C. One more trick with the ARGV var: C's first argument is argv[1], but Perl's first argument is in $ARGV[0]. No problem, I just need to unshift an argument in @ARGV in Perl. I need to include this instruction in the C comment, since this is not valid C syntax. A last problem: C argv is a string array, and since I'm waiting for integers, I need to transform them into integers, using atoi(). But Perl does not care about such hacks: a string can be interpreted as a number (and vice-versa) without adding extra stuff. So I need to declare: sub atoi{ $_[0] } that will return the first argument. This way, atoi( $var ) will be a no-op in Perl. Okay, let's recapitulate so far. My program stub now looks like this:

Edition 2007-01-09 top secret / strictly confidential page 110 of 520 Perlgolf History

#include #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { } Filling in the stub Now, we just need to fill in the program. And it's kinda easy, since C and Perl share quite the same syntax. First, let's declare our C vars: int $ tab[atoi( $ ARGV[3] )]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); Those are valid Perl instruction (although they would issue a warning "Useless use..." if we were under warnings), so Perl won't complain. The last two lines show you an example of accessing vars both in C and Perl. Let's next use the printf() function (Perl and C valid): printf("%d", $ tab[1]); And a for loop à-la-C: for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } This is really straight-forward once the beginning has been explained (and once you realize that auto- in/decrement are valid both in Perl and C). So I won't go in too much details (the algorithm itself is the one I used for my Perl-only solution, and I won't explain it here, I assume you're smart enough to understand it :-) )... We just need to print the final \n: printf("\n"); And here we are, with a bilingual Perl/C program:

Edition 2007-01-09 top secret / strictly confidential page 111 of 520 Perlgolf History

#include #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { int $ tab[atoi( $ ARGV[3] )]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); printf("%d", $ tab[1]); for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } printf("\n"); } The results This way, you can take this file, and treat it like this: $ perl kola.pl or: $ gcc kola.c -o kola $ ./kola I was pretty satisfied, but in fact, I realized that this wasn't too much a work since another guy made such a program for a past tournament (even if this problem was a little bit trickier). That's why I did not submit it. You said weird? But I was in my weird-mood. As a Befunge fan, I thought it would be fun to propose a Befunge version of the program. Once said, I ran into it. For those of you who don't know what Befunge1 is, it's a topological language on a 2D cartesian Lahey space. Waow, what does it mean? This simply means that in Befunge, you can move your instruction pointer as you want: from left to right (as in other regular languages), from right to left, from top to bottom, from bottom to top, and even in diagonal.

This allows us for a whole new dimension in coding (and obfuscation by the same way ;) ). In Befunge, every character is an instruction. I won't go in details about the set of instructions available, but I wrote a straight-forward implementation of the Kolakoski problem in Befunge (you will need a Befunge-98 compliant interpreter):

1 http://catseye.mine.nu:8080/projects/befunge93/

Edition 2007-01-09 top secret / strictly confidential page 112 of 520 Perlgolf History

2ep1ep:0ep :0fp '0+, v > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4epv v pe30 < a > 04ep 05ep ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q Warning, the number of spaces is important, since if the columns are not aligned, you break the instruction flow! I was pretty much happy with this. In fact, I was so happy, I wanted to submit it to the referees. But the refs need a Perl solution! Dilemma? Not really, since I wrote the Inline::Befunge . I just needed to wrap my Befunge solution, like this: #!perl use Inline Befunge => <<'END_OF_CODE'; v;alok:; >2ep1ep:0ep:0fp'0+, v > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4epv v pe30 < a > 04ep 05ep ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q END_OF_CODE kola(@ARGV); I tried it, and it worked. But as I was submitting it, I realized that Inline::Befunge is not a standard module of Perl (ie, included with the core), and the refs will reject it since the contest only allows standard modules... Uh, I was desperate! One Ring to Find Them... Then, I came with the big idea: what about including the Befunge solution in my bilingual solution, making it a trilingual solution? That was really a terrific idea! And it wasn't such a difficult idea: I only needed to include it in a C / Perl comment, and move my Befunge instruction pointer at the beginning of the Befunge code. The tricky part is to move the instruction pointer before doing anything. A short explanation of Befunge To understand what's going on, please remember that in Befunge: every character is an instruction Another important rule is: if the instruction pointer encounter an unknown instruction (an unknown character), then the velocity (the direction in which the instruction pointer moves) is reversed That is, if running from left to right, it will go from right to left, and vice-versa. Idem for other velocities (vertical and diagonal). The last important rule is: the instruction pointer begins at the top-left corner (coordinates (0,0)) with a velocity of (1,0) (ie, from left to right) Back to our problem All I have to do now, is to write a line at the top of my file (remember, Befunge starts at (0,0)), with valid Befunge instructions (otherwise the direction would be changed). This line should be ignored by both C and Perl. The solution was to include a C preprocessor line, followed by a C comment, such as the one we saw earlier. I could use

Edition 2007-01-09 top secret / strictly confidential page 113 of 520 Perlgolf History

#ifdef ... or #ifndef ... but those would force me to close the comments with #endif. I could use #define ... but the i instruction (remember, all Befunge instructions are characters) will try to include a file which name is on the stack (Befunge is a stack based language), and if the file does not exist, the instruction pointer's velocity would be reversed... Damn, #define was not a good choice. Then I thought about #include ... You'll say that we run in the same problem, because of the i. In fact, we're not, since the # instruction (yes, # is a valid Befunge instruction) makes Befunge skip the next instruction. So #include is in fact understood as nclude by Befunge. This seems pretty interesting, but alas! the u instruction allows us to play with the stacks stack (we can have a stack of stacks in Befunge-98), and if there's only one stack defined (we start with only one stack, and we create stacks with the { instruction), then u will reverse the velocity... Argh, we don't have much choice left... Must I find another way of doing it? No, because #undef is there! # will cause the u instruction to be skipped, and ndef only play with the stack. Hurrah! :-) So, I just need to insert the following: #undef fff /* n Befunge code goes here... I had to choose the indentifier to be undef carefully, in order for Befunge to work the way I want. That's why capital letters were forbidden. / and * are valid instructions who perform multiplication and division (with values popped from the stack). The only thing I need to add is a n in order to clear the stack. And my Befunge code inserted after runs very smoothly, great! I just reformatted the Befunge part, taking advantage of the facility to play with the velocity, in order to present a code fitting in 80 columns. Then, I proposed my trilingual solution to the refs:

Edition 2007-01-09 top secret / strictly confidential page 114 of 520 Perlgolf History

#undef fff /* n a9+y >#v_ 0> \ : #v_ $ :0ep :0fp '0+, v " ^ < ^+-0'\*a\< >\a*\'0-+v ve50pe40pe30 pe2 $ _v#!:\<0 pe1$_^#!:\<0< p >\a*\'0-+^ > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4ep v a ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q */ //"; #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { int $ tab[atoi( $ ARGV[3] )]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); printf("%d", $ tab[1]); for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } printf("\n"); } This solution can now be interpreted with a Befunge-98 compliant interpreter (such as the one I provide with the Language::Befunge Perl module), and run with: $ jqbf98 kola.bf One Ring To Bring Them All... Then, one of the referee sent me a mail, telling me how excited he was about this solution, and that I'll receive an O'Reilly book if I can add a Malbolge version... But Malbolge was really too hard to play with. For those of you who don't know it, Malbolge is a language created with the idea that programming should be hard. But in fact, it was so well designed that it's almost impossible to write a program in Malbolge. I then forgot this idea, but I thought within myself: what a great idea if Ican provide a quadrilingual working solution for tpr03! I went then on BrainFuck. BrainFuck is a minimalist language (it only recognizes eight instructions!), but is said to be Turing-complete. I knew the theory about it, but never programmed with it before. I decided to try it. I won't tell you how hard it was to provide a working solution of the Kolakoski problem. BrainFuck is a nasty language. Really. I'll just talk about two problems I had to deal with. BrainFuck, a really well-chosen name... Command-line arguments... what's that?

Edition 2007-01-09 top secret / strictly confidential page 115 of 520 Perlgolf History

BrainFuck does not allow command line arguments - sigh -. I had to add a minor tweak in order to allow this: I simply decided to prompt for the args. This wasn't really too much trouble, since one can pipe the args with echo: $ echo | aidbf kola.bfk (aidbf being a BrainFuck interpreter) But in fact, since prompting is done character by character in BrainFuck, I had to prompt 5 times: one for the first digit, one for the second, and three for the number of digits to display. I had to prompt three times for the last argument, since it could range from 0 to 500. But, since I prompt three times, user has to enter a properly-formatted number on three digits. That is, if the user wants only 3 digits, he'll have to enter 003. Last thing about this minor tweak: since one prompt eats one character, you'll have to concatenate arguments (ie, no space allowed). That is, for the 20 first digits of the Kolakoski number made of 1 and 3, you'll need to issue the following command: $ echo 13020 | aidbf kola.bfk It wasn't such a big deal, and I thought the overall meaning of the program would stay the same. And as if it wasn't enough... This was the first problem I had to deal with. The second one was more, erm, challenging. In BrainFuck, you can only work with numbers ranging from 0 to 255 (ie, stored on a byte). Imagine how surprised I was, when I realized that I had to deal with numbers up to 500! I won't go in gory details, but I solved this problem by using three bytes, one for each power of ten, and then combined them into two bytes, and then playing and transferring tens to units and such dirty^Wfunny things like this. BrainFuck was here Finally, I got my BrainFuck version. Here it is (presented as a rectangle, it's way more impressive like this :-) ): >>>,------[>+>>>>> >+>+<<<<<<<<-]>>,------>+>>>>>++++++++++++++++++++++++++++++++++++++++++++++++ .------>+<[>-<[>> +<<-]]>[-<<<<<+<-<[<<+>>-]<<[>>+>>>>>>>>+<<<<<<<<<<-]>>>>>>> >>>[>+>+<<-]>[<+>-]<-<]>[<<+>>-]<<<<<<<<<<<<<,------>,------>,------<<[>++++++++++<-]>>>>>>>>+<<<<<<[[>+<-]>>>>>>- <<<<<<]>[<+>-]>>>>>[-<<<<<<++++++++++<->>>>>>>]<<<<<<-<<>[>> +<<-]>>[<<+<+>>>-]<<<[[-]>->++++++++++<<]>>[<<+>>-]<<[>>+>+< <<-]>>>[[-]<<<>>>>>>>>>>>>>>>[++++++++++++++++++++++++++++++ ++++++++++++++++++.<<<<<<<<<<<<<->>>>>>>>>>>>>[-]]<<<<<<<<<< <<<<<>+[->[->>>>>>>>[>]>[>]+[<]<[<]<<<[->>>+<<<<<[<+>-]<[>+> >>>+<<<<<-]>>>]>>>[<<<+>>>-]<<[->>+<<<<[<<+>>-]<<[>>+>>>+<<< <<-]>>>>]>>[<<+>>-]<[>>[>]>[>]<+[<]<[<]<-]>>[>]>[>]<++++++++ +++++++++++++++++++++++++++++++++++++++.------[<]<[<]<+>>[>]<-[[>+<-]<<[<]<->> [>]]>[<+>-]<<[<]<[<<<<<+>>>>>-]<<<<<[->>>[->>>+<<<]>[->+<]>[ <<+>>-]>[<<+>>-]>[>]+>>[<+>-]<[<]<<<<<<]<]++++++++++<][-]<]+ +++++++++. (if you really want a more described version of the BrainFuck script, just ask) And In The Darkness Bind Them.

Edition 2007-01-09 top secret / strictly confidential page 116 of 520 Perlgolf History

Now, all I needed was to include it in my trilingual solution... In fact, it was really easy. Remember that my program begins with a #undef then the Befunge code. BrainFuck will superbly ignore all the chars that are not valid BrainFuck instructions (and BrainFuck only recognizes the characters [ ] < > + - , . ). So far, so good, I just need to move the Befunge instruction pointer elsewhere. Let me present you the v instruction in Befunge, which makes Befunge read the flow from top to bottom. I just need to include a v and get back the instruction pointer later. Something like this: #undef fff /*v>>>,------"------[>+>>> >>>+>+<<<<<<<<-]>>,------>+>>>>>+++++++++++++++++++++++++++++++ +++++++++++++ ++++.------>+<[> -<[>>+<<-]]>[-<<<<<+<-<[<<+>>-]<<[>>+>>>>>>>>+ <<<<<<<<<<-]> >>>>>>>>>[>+>+<<-]>[<+>-]<-<]>[<<+>>-]<<<<<<<< <<<<<,------>,------>,------<<[>++++++++++<-]>>>>>> >>+<<<<<<[[>+ <-]>>>>>>-<<<<<<]>[<+>-]>>>>>[-<<<<<<+++++++++ +<->>>>>>>]<< <<<<-<<>[>>+<<-]>>[<<+<+>>>-]<<<[[-]>->+++++++ +++<<]>>[<<+> >-]<<[>>+>+<<<-]>>>[[-]<<<>>>>>>>>>>>>>>>[++++ +++++++++++++ +++++++++++++++++++++++++++++++.<<<<<<<<<<<<<- >>>>>>>>>>>>> [-]]<<<<<<<<<<<<<<<>+[->[->>>>>>>>[>]>[>]+[<]< [<]<<<[->>>+< <<<<[<+>-]<[>+>>>>+<<<<<-]>>>]>>>[<<<+>>>-]<<[ ->>+<<<<[<<+> >-]<<[>>+>>>+<<<<<-]>>>>]>>[<<+>>-]<[>>[>]>[>] <+[<]<[<]<-]> >[>]>[>]<+++++++++++++++++++++++++++++++++++++ ++++++++++.------[<]<[<]<+>>[> ]<-[[>+<-]<<[<]<->>[>]]>[<+>-]<<[<]<[<<<<<+>>> >>-]<<<<<[->> >[->>>+<<<]>[->+<]>[<<+>>-]>[<<+>>-]>[>]+>>[<+ >-]<[<]<<<<<< ]<]++++++++++<][-]<]++++++++++. > n Befunge code goes here By the way, I'm sure you've understood that the > instruction in Befunge makes the instruction pointer in Befunge move from left to right... That's how we put our instruction pointer back on the right path. Note the empty column under the v. This way, Befunge can find its way down to the >. We are to leave this empty column since >, <, [ and ] change the instruction pointer velocity. The . and , both outputs something in Befunge, and we don't want to mess with output, do we? But we can leave the + and - in the column, because they will just diddle the stack, and since we perform a n (clear stack) instruction before the Befunge code... So, we can be a little more obfuscated with the following:

Edition 2007-01-09 top secret / strictly confidential page 117 of 520 Perlgolf History

#undef fff /*v>> >,------"------[>+>> >>>>+>+<<<<<<<<-]>>,------>+>>>>>+++++++++++++++++++++++++++++++ +++++++++++++++++.------>+<[>- <[>>+<<-]]>[-<<<<<+<-<[<<+>>-]<<[>>+>>>>>>>>+< <<<<<<<<<-]>> >>>>>>>>[>+>+<<-]>[<+>-]<-<]>[<<+>>-]<<<<<<<<< <<<<,------>,------>,------<<[>++++++++++<-]>>>>>>>>+< <<<<<[[>+<-]> >>>>>-<<<<<<]>[<+>-]>>>>>[-<<<<<<++++++++++<-> >>>>>>]<<<<<<-<<>[>>+<<-]>>[<<+<+>>>-]<<<[[-]>->++++++++++<< ]>>[<<+>>-]<< [>>+>+<<<-]>>>[[-]<<<>>>>>>>>>>>>>>>[+++++++++ +++++++++++++++++++++++++++++++++++++++.<<<<<<<<<<<<<->>>>>> >>>>>>>[-]]<< <<<<<<<<<<<<<>+[->[->>>>>>>>[>]>[>]+[<]<[<]<<< [->>>+<<<<<[<+>-]<[>+>>>>+<<<<<-]>>>]>>>[<<<+>>>-]<<[->>+<<< <[<<+>>-]<<[> >+>>>+<<<<<-]>>>>]>>[<<+>>-]<[>>[>]>[>]<+[<]<[ <]<-]>>[>]>[> ]<++++++++++++++++++++++++++++++++++++++++++++ +++.------[<]<[<]< +>>[>]<-[[>+<-]<<[<]<->>[>]]>[<+>-]<<[<]<[<<<<<+>>>>>-]<<<<< [->>>[->>>+<< <]>[->+<]>[<<+>>-]>[<<+>>-]>[>]+>>[<+>-]<[<]<< <<<<]<]++++++n++++<][-]<]++++++++++. > Befunge code goes here And here we are. Note how the n is included in the BrainFuck code. In fact, I could have included more Befunge code in the BrainFuck one (and vice-versa), but I was a bit tired, so I decided to let it this way. I went to test it, and... it failed! The BrainFuck version failed... It waited forever... In fact, it was obvious, since I was using chars that were valid BrainFuck instructions after the "main" BrainFuck program. But BrainFuck does not understand what is a main program. The interpreter slurps the whole file, discarding the non-valid chars. So it kept all the instructions that came after... I was desperate. And even more hopeless because BrainFuck does not understand comments. Well, in fact, it understands comments: everything that is not an instruction is a comment. But, there's no way to hide a valid instruction. What to do, my friends... Then, the magic idea: I'll just write a loop that BrainFuck won't enter, and hide the offending instructions in it! Once I had this cool idea, it was very simple to implement it: [-] to zero the current cell (urkl, that's... that's BrainFuck ;) ) [ enter a while loop if the current cell is non-zero Easy, isn't it? Since we just zeroed the current cell, we don't enter the while loop... But, we still need to close the loop (with a ] instruction). Piece of cake, we just need to add the following at the end of the code: #define BLAHBLAH /* ] */ And that's all folks! Here's the final quadrilingual version of the Kolakoski problem:

Edition 2007-01-09 top secret / strictly confidential page 118 of 520 Perlgolf History

#undef fff /*v>> >,------"------[>+>> >>>>+>+<<<<<<<<-]>>,------>+>>>>>+++++++++++++++++++++++++++++++ +++++++++++++++++.------>+<[>- <[>>+<<-]]>[-<<<<<+<-<[<<+>>-]<<[>>+>>>>>>>>+< <<<<<<<<<-]>> >>>>>>>>[>+>+<<-]>[<+>-]<-<]>[<<+>>-]<<<<<<<<< <<<<,------>,------>,------<<[>++++++++++<-]>>>>>>>>+< <<<<<[[>+<-]> >>>>>-<<<<<<]>[<+>-]>>>>>[-<<<<<<++++++++++<-> >>>>>>]<<<<<<-<<>[>>+<<-]>>[<<+<+>>>-]<<<[[-]>->++++++++++<< ]>>[<<+>>-]<< [>>+>+<<<-]>>>[[-]<<<>>>>>>>>>>>>>>>[+++++++++ +++++++++++++++++++++++++++++++++++++++.<<<<<<<<<<<<<->>>>>> >>>>>>>[-]]<< <<<<<<<<<<<<<>+[->[->>>>>>>>[>]>[>]+[<]<[<]<<< [->>>+<<<<<[<+>-]<[>+>>>>+<<<<<-]>>>]>>>[<<<+>>>-]<<[->>+<<< <[<<+>>-]<<[> >+>>>+<<<<<-]>>>>]>>[<<+>>-]<[>>[>]>[>]<+[<]<[ <]<-]>>[>]>[> ]<++++++++++++++++++++++++++++++++++++++++++++ +++.------[<]<[<]< +>>[>]<-[[>+<-]<<[<]<->>[>]]>[<+>-]<<[<]<[<<<<<+>>>>>-]<<<<< [->>>[->>>+<< <]>[->+<]>[<<+>>-]>[<<+>>-]>[>]+>>[<+>-]<[<]<< <<<<]<]++++++n++++<][-]<]++++++++++.[-][ > a9+y >#v_ 0> \ : #v_ $ :0ep :0fp '0+, v ^ < ^+-0'\*a\< >\a*\'0-+v ve50pe40pe30 pe2 $ _v#!:\<0 pe1$_^#!:\<0< p >\a*\'0-+^ > 2eg 1- : 2ep !#v_ 4eg : fg 1- \ fp 4eg fg #v _ 3eg ! 3ep 4eg 1+ 4ep v a ^ pf pe5 :+1 ge5 , +0' : ge ge3 < < q */ //"; #include #include #define ARGV argv #define $ /* unshift @ARGV, "foo"; sub atoi{ $_[0] } "*/ main (int argc, char *argv[]) //"; { int $ tab[atoi( $ ARGV[3] )]; int$i; int $ which, $ offset; $ which = $ offset = 1; $ tab [1] = atoi( $ ARGV[ $ which ] ); printf("%d", $ tab[1]); for($i=2;$i<=atoi( $ ARGV[3]);$i++){ $ tab[ $ offset ] -= 1; if ( $ tab[ $ offset ] ==0){ $ offset++; $ which=(!(--$which))+1; } printf("%d", $ tab[$i]=atoi( $ ARGV[ $ which])); } printf("\n"); } #define BLAHBLAH /* ] */ Now, we can interpret it as yet another language: $ echo | aidbf kola.bfk Remember that the args are concatenated, and that arg3 is zero padded on the left.

Edition 2007-01-09 top secret / strictly confidential page 119 of 520 Perlgolf History

Needless to say, I also provided a quadrilingual solution for the Cantor problem. Globally, I used the same hacks. There are a few minor differences, such as I'm using the wrap facility of Befunge (if the instruction pointer goes out of bound on the top of the file, it comes back from the bottom) in order to include the Befunge code at the end of the file. I also changed the way I'm handling atoi() between C and Perl, via a big eval, but it's not that much different. Moral of the story Writing a multilingual solution of a problem isn't that difficult, if you choose your languages carefully. You are to choose languages which don't have the same set of comments. In fact, the difficult part was to write the solutions in the esoteric languages. The BrainFuck version caused me the most problems. In fact, I think that BrainFuck is fun, but boring. On the other hand, Befunge is fun, and really fun to program with. Moral of the story (bis) Since this month, Perl Golf is sponsored by O'Reilly1. They offer a book of his/her chosing to the winner. Unfortunately, I finished second at the overall tournament (althought I provided the best Kolakoski Perl script). This means no book for me :-( But the referees were so impressed by my efforts (one of them told me that I deserve a book. And a straightjacket. And a padded room. He forgot the funnel! =<:o) ) that they decided to grant me a book for this. Who said esoteric languages were useless? ;-)

4.5. TPR(0,4) "Interlinear Counts" The game started June 1st 2002 and ended June 8th 2002. Referees: Samy Kamkar, Ala Qumsieh, Lars Mathiesen, Dave Hoover, Jérôme Quelin

4.5.1. Rules Goal For each sentence in an input stream, display the count of words, of vowels, and of alphanumeric character. Also display the count of vowels and of alphanumerics for each of as many words as will fit on a line. Specification • The program is a filter: it must read from STDIN, and send output to STDOUT. • The input will consist of zero or more paragraphs. Blank lines can occur anywhere in the input, outside of paragraphs. • A paragraph consists of one or more sentences, separated by sequences of whitespace characters (spaces and/or at most one newline). • A sentence consists of one or more words, separated by sequences of whitespace characters, where the last one ends in a period. • A word contains at least one alphanumeric character (letter or digit), and optionally some punctuation (.,;:'"()&/). Note: This means that punctuation characters can never

1 http://www.oreilly.com

Edition 2007-01-09 top secret / strictly confidential page 120 of 520 Perlgolf History

occur alone. But except for the period, which must end a sentence, punctuation can occur anywhere in a word. • An underscore is not a letter. • All input lines are properly newline terminated, and do not contain binary 0. • All input files have a total size so that they will fit comfortably in memory and still allow you ample memory to play with. Please note that the input file can be empty. • You may assume ASCII as the character set but you may not use Unicode-specific semantics. • All sentences will be less than 200 characters long and contain less than 100 vowels. • For each sentence in the input, you are to print two lines. 1) A line containing the number of words in the sentence, a colon, a horizontal tab, and up to 60 characters of text from the sentence, including the final period. Case must be preserved, and the words of the text must be separated by spaces to conform to the alignment described below. If the whole sentence, thus aligned, cannot be printed in the given width, the last three characters of that width must be replaced by periods. 2) A line containing the total number of vowels (aeiouy, regardless of case) in the sentence, a slash, the total number of alphanumeric characters in the sentence, a colon, and a horizontal tab, and similar counts for the words in the preceding line. That is, for each word of which at least one character was printed on the previous line, you must print the number of vowels and alphanumerics in the whole word, again separated by a slash. These pairs of counts must be aligned with spaces to begin in the same columns as the corresponding words, and must be separated by at least one space; if that is not possible (because they would touch or overlap), extra spaces must be inserted in the text line instead. Example Given the input: I am just a poor sample paragraph. Please don't treat me too hard as you split and separate me into vowels and stuff. You are to output the following: 7: I am just a poor sample paragraph. 11/27: 1/1 1/2 1/4 1/1 2/4 2/6 3/9 16: Please don't treat me too hard as you split and separat... 27/65: 3/6 1/4 2/5 1/2 2/3 1/4 1/2 3/3 1/5 1/3 4/8

4.5.2. Solutions 149 (post-mortem) -ap056 sub t{lc=~y/aeiouy//.v47.s/\w/$&/g}$_=/\./&&(@z=map//?t:$_^t^($_^=t^t),@F).":\t@ F ".t.":\t@z ";y/\0/ /;s/(\t.{57})...+(.\n.*\t.{0,56}\S+).*/$1..$2/ 150, Ton Hospel

Edition 2007-01-09 top secret / strictly confidential page 121 of 520 Perlgolf History

-ap056 @Q=map{lc^lc^lc=~y/aeiouy//.-map/\w/g,$_^=v0 x3}lc,@F;$_="@F"&"\x7f"x60;s/[^.]{3}$/^I^I^I/;s/.+/$#Q $_ @Q[0..split] /;y!\0^I-! ./!;s/ +(.*\S) */:^I$1/g 150, BoB (Best of Breed - referees) -ap056 @Q=map$_^($_^=v0 x3)^lc=~y/aeiouy//.v47.s/\w/$&/g,$_,@F;$_="@F"&"\x7f"x60;s/[^.]{3}$/^I^I^I/; s!.+!$#Q $& @Q[0..split] !;y/\0^I/ ./;s/ +(.*\S) */:^I$1/g 151, Eugene van der Pijll -ap056 sub t{lc=~y/aeiouy//.v47.s//$&/g}$_=/\w/&&(@z=map$_^t^($_^=t^t),@F).":^I@F ${\t}:^I@z ";y/\0/ /;s/ +$//m;s/(^I.{57})...+(. .*^I.{0,56}\S+).*/$1..$2/ 160, Marko Nippula -ap056 @f=map{$_|=$:^$:;$"x+y|| ^A- z|c|y|youYOUaiIEeA||.'/'.s|\w|$&|g}$_,@F;s,(.{57})..+\w.*,$1...,,$#f=@R=/\w\ S*/g,$_=@F." $_ @f "if$_="@F";s; +(.*?) *$;:^I$1;mg 161, Rick Klement -056ap @c=map{s!$!$"x(3-/\./-pos)!e;$"x$- [0]|lc=~y/aeiouy//.'/'.s/\w/$&/g}$_,@F;$_="@F";s/(.{57}).{4,}/$1.../;s!.+!$# c:^I$& @c[0..s/[ .]+//g] !;s/ +(.*?) *$/:^I$1/ 162, Lolly Pop -ap056 @q=map{s/$/ /until/\.|...$/g;$"x++pos|($Q=lc=~y/aeiouy//."/".y/0-9A- z//)}@F,$_;s/(.{57}).{4,}/$1.../,$_=@F.":^I$_ $Q:^I@q[0..s/ [^ .]//g] ",s/ +$// if$_="@F" 164, seano -ap056 $_=lc,$_=y/aeiouy//.'/'.s/\w//gfor$g=$_="@F",@F;$_&&=1+s/\S+ /$"^$"x4|$&/eg.(s/(.{57}).{4,}/$1.../,":^I$_ $g:^I").(s/[^ .]+ */shift@F|$"x18&$&/eg,/\D*$/,"$` ") 172, Stephen Turner -lpa056 sub b{lc=~y/aeiouy//.'/'.s/\w/$&/g}$m=b$_=sprintf'%-3s 'x@F,@F;s/ +$//?s/(.{57})...+/$1../:last;@0=map{A.y///c}/\S+ +(?!\.)/g;$_=@F.":^I$_. $m:^I".pack"@0A*",map b,@F 174, Mtv Europe -ap056 sub B{lc=~y/aeiouy//.v47.(@Q=/\w/g)}$B=$Z=$C=v9;$C^=$C=($C!~/.{58}/|/\./&($Z|=$C .$_)!~s/(.{58}).{4,}/$1.../?$B|=$C.B:0).1^$Z.1for@F;$_=@F?@F.":$Z ".B.":$B ":$T;y/\0/ / 175, Martin Carlsen, Martin Carlsen

Edition 2007-01-09 top secret / strictly confidential page 122 of 520 Perlgolf History

-056npa sub c{y/aeiouyAEIOUY//."/".y/a-zA-Z0- 9//}$_=(@c=map{$_.=$"x($p=/\./?0:length(c)-length);c.$"x-$p}@F)?@F.":^I@F ".c.":^I@c ":"";s/(^I.{57}).{4,}( .*^I.{0,56}\S+).*/$1...$2/ 176, Juho Snellman -p056 @d=map{$_|=$"x3&"$_ ";$"x y...c|(@z=/[aeiouy]/ig).'/'.s/\w/$&/g}@w=/\S*\w\S*/g,$_;s/(.{57})...+\S/$1.../, $_=@w.":^I$_ $d[-1]:^I@d[0..s/ +[^.]//g] "if$_="@w";s/ +( |:)/$1/g 176, Guillermo Sansovic -pa056 sub c{uc=~y/AEIOUY//.'/'.s/\w//g}$w=c;@s=map{sprintf"%- 3s",$_}@F;$_="@s";s/(.{57})...+\S/$1.../;$_&&=(@c=map{pack"A".y///c,c}@s).": ^I$_ $w:^I@c[0..s/ +[^.]//g] ";s/ +$//gm 176, Alexander Onokhov, Alexander Onokhov -ap056 ($x,@D)=map{$_.=$"x(3- length);y/aeiouyAEIOUY//."/".s/\w/$&/g}$_,@F;$_="@F ";s/(.{57})...+\./$1.../;$_=@F.":^I$_ $x:^I${s/\S+[ .]+/A.length$&/ge,\pack$_,@D} "if@F;s/ +$//mg 178, Amir Karger -pa056 sub g{y/aeiouyAEIOUY//."/".s/\w/$&/g}$t=g;@r=map{$_=sprintf"%- 3s",$_;pack A.y///c,g}@F;s/ +$//,s/(.{57})....+/$1.../,$_=@F.":^I$_ $t:^I@r[0..s/ +[^.]//g] ",s/ +$// if$_="@F" 180, Keith Calvert Ivey -pa056 sub c{lc=~y/aeiouy//.'/'.(()=/\w/g)}$p=c;$_=sprintf'%-3s 'x@F,@F;s/ +$//and$f=$/x3x s/(.{57}).{4,}/$1/,$_=@F.":^I$_$f $p:^I".pack"@{[map A.y///c,/\S+ */g]}9",map c,@F;s/ +$/ / 189, Michiel van Leeuwen -anp056 @F=($_="@F",@F);s/\S+ /$&|"\0"x4/ge;y/\0/ /;@F=map{$_=lc;" "x y///c|y/aeiouy//."/".s/\w//g}@F;$_&&="$#F:^I$_ @F ";s/( \S*) +/$1:^I/;s/(^I.{57}).{4,}( .*:.+?.{56}) .*/$1...$2 /s;s/ +$// 190, Yanick Champoux -p056 sub t{map y/aeiyou//.'/'.s/\w//g,lc}@q=map$_.$"x(3- tr///c),split;@w=t$_="@q";s/(.{57})...+\./$1.../;$_=@q.":^I$_ @w:^I@{[map{sprintf'%-'.y///c.'s',t}@q[0..$#z]]} "if@z=/\w\S*/g;s/ *$//gm 191, Andrew Savige

Edition 2007-01-09 top secret / strictly confidential page 123 of 520 Perlgolf History

-ap056 $s=$t=0;@n=map{$t+=($s+=@q=/\w/g,$_.=$"x(3-tr)))c),$z=pack A.y)))c,lc=~y)aeiouy)).v47.@q);$z}@F;s@(.{57})..[^.].+@$1...@,$_=@F.":^I$_ $t/$s:^I@n[0..-1+split/[. ]+/] ",s, +$,,mg if$_="@F" 192, Jay Tilton -ap056 sub c{$_=lc;y/aeiouy//.'/'.s/\w//g} $s=$t=":\t";($s.=$_.$")|=($t.=c."\0")^($t|=$s^$s)for@F;$_=($v=@F)?"$v$s ${\c}$t ":'';y/\0/ /;s/(:.{58})...+\./$1.../&&s|(:.{57,}?) \d.*|$1|;s/ +$//mg 195, Josef Drexler -pa056 sub c($){()=/@_/gi}$v=$t=0;@Q=map{$v+=$V=c"[aeiouy]";$t+=$T=c"\\w";$_.=$"x(3- c$/);pack A.c$/,"$V/$T"}@F;s/(.{57}).{4,}(?

Edition 2007-01-09 top secret / strictly confidential page 124 of 520 Perlgolf History

-ap056 sub b{$_=lc;y/aeiouy//."/".y/a-z0- 9//}$c=$b=':^I';map{$c.=pack$l=A.(($l=y///c)>3?++$l:4),$_;$b.=pack$l,b}@F;$c =~s/(.{59})...+\S.*/$1.../&&$b=~s/(.{58}\S*).*/$1/;$_=(@F."$c ".b."$b ")x!!@F;s/ *$//mg 207, Chris Dolan -056pa @v=map{$V+=$v=y/aeiouyAEIOUY//."/".(@n=/\w/g);$N+=@n;$v.$"x(length($_.=$"x(3 -length))-length$v)}@F;$_="@F";s/ *$//;s/(.{57})....+/$1.../;$#v=s/\w+/$&/g- 1;$_=/\./&&@F.":^I$_ $V/$N:^I@v ";$V=$N=!s/\s+$/ / 208, Benoît Chauvet -n056a sub p{@{[/[ouyaie]/gi]}."/".s/\w/$&/g}@v=map{57>shift@z||$z<62and$"x length|p}grep{/\./ or$_|="\0 ";push@z,$z++;$z+=length}@F;$p=p$_="@F";s/(.{57})....+/$1.../;$_=@F.":^I$_ $p:^I@v ";s/ +$//;$z&&=!print 212, Bret Victor -an056 reset"V-Z";@Z=map{$V+=$v=y/aeiouyAEIOUY//;$W+=$l=s/[^\W_]/$&/g;$_.=' 'x(3-length)if++$X<@F;y///c,"$v/$l"}@F;$_="@F";s/(.{57})....+/$1.../;$Z.="%- *s "for/ [^ .]/g;@F&&printf"%s$Z%n%s ","$X:\t$_ $V/$W:\t",@Z 215, David Lowe -na sub g{y///c}sub f{lc=~y#aeiouy##.'/'.y# -/:-@##c}map{$m=/\./?0:g>3?g:3;push@{--$|},$_.$"x($m- g)for$_,f;if(/\./){$_="@1";$_=@0.":\t$_ ".f.":\t@0 ";@0=@1=();s/(\t.{57})....+(\n.+\t.{0,56}\S+).*/$1...$2/;print}}@F 219, Qingning Huo -n056 $x=$z=$v=$l="";$x=~s/(.{57}).{4,}/$1.../&&$z=~s/ *(?<=.{56}) +.+//,print"$w:^I$x $v/$l:^I$z "if$w=map{$z.=$".$"x($0=$x=~y///c-length$z),$x.=$".$"x- $0if$x;$v+=$V=lc=~y/aeiouy//;$x.=$_;$l+=$L=s/\w//g;$z.="$V/$L"}split 219, jacoph -n0 map{$n=0;@w=map{sprintf"%-3s",$_}split;$_="@w";s/ *$/./;s/(?<=.{57}).{4,}/.../;@w&&printf@w.":^I$_ %*s:^I"."%-*s"x($q=grep/[^.]/,split)." ",map{!$n++||!--$q||1+length,(@x=/[aeiouy]/ig).'/'.s/\w//g}"@w",@w}split/\.\s+/ 220, Honza Pazdziora -056n sub d{lc=~y!aeiouy!!.'/'.s!\w!$&!g}@w=/\S+/g;$"=' 'x60;$_="@w @{[d]}:^I@{[map{d}@w]}";for$x(0..80){$h=".{$x}) +(.*)";s/^($h( .*^I$h/$1 $2$3 $4/}s/^(.{57}).{4,}( .*^I.{56,}? )?.*/$1...$2/;s/\s*$//;print@w+0,":^I$_ "if@w 225, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 125 of 520 Perlgolf History

-ap056 reset'a-z';for(@F){$c+=$C=()=/\w/g;$v+=$V=()=/[aeiouy]/gi;$w.="$_ ";$n.="$V/$C ";($_|=$n^$n^$w^$w)=~y/\0/ /for$w,$n}$_=$w;s/ +$//;s/(.{57})....+/$1.../;$n=~/\S+/gfor/[^.\s]\S*/g;$n=~s/\G.*//;$_=$n&&@F. ":^I$_ $v/$c:^I$n " 226, Jasper McCrea -0 map{$T=$V=$w=$s='';$c=map{$V+=@v=/[aeiouy]/ig;$T+=@t=/\w/g;$w.=$_.=$".$"x(3- tr///c);y// /c;$s.=@v.'/'.@t|$_}/\S+/g;s/ *$/ /,$w=~s/(.{57}).{4,}/$1.../&&$s=~s/(.{56}\S*).*/$1/for$w,$s;$c&&print"$c:^I$w$V /$T:^I$s"}<>=~/[^.]*.?/g 228, Alain "TopMach" Dupuis -0 for(<>=~/[^.]+/g){my(@r,$p,$t,$v);$t+=@b=/\w/g,$v+=$@=y/aeiouyAEIOUY//."/".@ b,$p.="$_ ".' 'x(3-tr// /c),$j=push@r,$_|"$@"for/\S+/g;$_=$p;s/ +$//;s/(.{57})...+/$1../;$#r=(()=/\w+/g)-1;"@r"=~/ *$/;$t&&print"$j:^I$_. $v/$t:^I$` "} 230, Scott Hall -nla0056 if(@F){y/ / /;s/\S+/A.(($!=length$&)<3?4:$!+1)/ge;s/\d+$/*/;print@F.":^I",map{s/(.{57}). ...+ ((.*?[^^I]{56}) ..+|(.*))/$1... $3$4/;s/ *$//;$_}pack($_,@F).". ".pack"A*$_",map{y/aeiouyAEIUOY//."/".s/\w//g.(":^I"x/#/)}"@F#",@F} 239, Eike Grote -ln for(/\S+/g){$t++;$q+=@v=/[aeiouy]/ig;$r+=@c=/[a-z\d]/ig;$w=length($p.=$_)- length($s.=@v."/".@c);/\./ or$s.=$"x$w.$",$p.=$"x- $w.$",next;$_=$s;$p=~s/(.{57}).{4,}/$1.../&&s/(.{56,}?) .*/$1/;s/ +$//;print"$t:^I$p $q/$r:^I$_";$$_=''for(p..t)} 241, RRBuonanno -n0 map{$n=0;$r=$_;@w=map{sprintf"%-3s",$_}split;$_="@w";s/ *$/./;substr($_,57)='...'if length>60;$q=@x=/ \S(?!\.\.$)/g;@w&&printf@w.":^I$_ %*s:^I"."%-*s"x($q+1)." ",map{(!$n++||!$q--||1+length,(@x=/[aeiouy]/ig).'/'.s/\w//g)}$r,@w}split/\.\s+/ 241, Petri Mikkelä -n map{$j++;$k+=@x=/\w/g;$n+=@p=/[aeiouy]/ig;($l,$m,$q)=map{y///c}$c,$_,$w=@p.' /'.@x;$c.=$_.$".$"x($q-=$m);substr($c,57)='...'if$m+$l>60;$g.="$w ".$"x-$q if$l<57||/\./&&$m+$l<61;s|\.|$_="$j:^I$c $n/$k:^I$g ";s: * : :g;print;reset'b-z'|e}/\S+/g 247, Bjørn Hee

Edition 2007-01-09 top secret / strictly confidential page 126 of 520 Perlgolf History

sub a{y/aeiouyAEIOUY//.'/'.y/a-zA-Z0-9//}for(map{/\S+/g}<>){$b++;$_.=$".$"x(3- length);$c.=a.$"x(y///c-length a);$_=($d.=$_);if(/\./){s/ *$//;s/(.{57}).{4,}/$1.../;/\S+ ?\./;$e=length$`;$c=~/.{$e}\S+/;print"$b:\t$_ ".a($_=$d).":\t$& ";$b=$c=$d=''}} 251, Sander Brandenburg -na056 ~~@F||next;$r=$s=0;$t=join$",map{$r+=$a=@x=/[aeiouy]/gi;$s+=$b=@y=/\w/g;s/$/ /while 3>length;pack"A".length,"$a/$b"}@F;$_=join$",@F;s/\s+$//;s/^(.{57}).{4,}$/$1 .../;$t=~s/\s+\S*$//while(2+rindex$t,$")>index$_,$/;print~~@F.":\t$_\n$r/$s: \t$t\n"; 277, Damien Neil -n0 sub X{local$_=lc$_[0];y/aeiouy/a/."/".y/a-z0- 9/b/}for(split/(?<=\.)\s*/){$o=X $_ ;$c=s/\s*(\S+)/sprintf"%-3s ",$1/ge;($x=$_)=~s/\S+\s*/sprintf"%*s",$-[0]- $+[0],X ($&)/ge;s/(.{57})...+\S/$1.../&&$x=~s/(.{57})(?<= )\S.*/$1/;for($_,$x){s/\s*$//} $c&&print"$c:\t$_\n$o:\t$x\n"} 290, Ross Younger -ln $b.=$".$_}map{if(s/\s*(\S.*)/$1\./){split/\s+/;$x=@_.":^I";$z=&Q.":^I";map{$ c=y///c-length&Q;$x.=$_.$"x($c<0?1-$c:1);$z.=&Q.$"x($c<0?1:1+$c)}@_;$_="$x $z";s/ * / /;s!(^\d+:^I.{57}).{4,}!$1...!&&s,(/.+:^I.{56}[^ ]*).*$,$1,;s, *$,,;print}}split/\./,$b;sub Q{y/aeiouyAEIOUY//.'/'.y/a-zA-Z0-9// 302, nashdj $/=$;;for(<>=~/[^\n ]+/g){$v+=@a=/[aeiouy]/gi;$t+=@z=/\w/g;@q=/./g;$,=' ';$,x=3if@q==1;$,x=2if@q==2;$x.=$_.$,;push@;,@a.'/'.@z;$n++;if(/\./){$_=$x;s / +$//&s/^(.{57}).{4,}/$1.../;$y=$_;$y=~s/.*?[. ]+/sprintf'%- '.(length$&).'s',shift@;/ge;s/ +$//for$y,$_;print"$n:\t$_\n$v/$t:\t$y\n";($n,$v,$t,$x,@;)=0}} 305, Erik Johansen -n map{$a.=" ",$b.=" "if$a;$f=length($a)-length$b;$a.=" "x-$f;$b.=" "x$f;$u+=$v=y*aeiouyAEIOUY**;$c+=$l=y*a-zA-Z0- 9**;$w++;$a.=$_;$b.="$v/$l";/\./&&do{substr($a,57)="..."if 60L$s){$_=shift@@;$s.= $_.$";$n.=v.'/'.b.$";$n.=$"x($d=L($s)- L$n);$s.=$"x- $d}$s=~s/\s+$//;60

Edition 2007-01-09 top secret / strictly confidential page 127 of 520 Perlgolf History

-056 sub p{y/aeiouyAEIOUY//."/".&l}sub z{y#-,;:'"()&/ ##d}sub l{length}while(<>){s/[. ]/ /g;next if!/\w/;print 0+(@x=split);z;$b=p;$_=sprintf"%-3s "x@x,@x;s/\s+$//;$_=substr($_,0,57).".."if 59;while($_){my($w,@x,$p,$u,$c);s/\s+/ /g;s/^ ?(.+?\.) ?|$//;map{$c++;$u+=@v=/[aeiouy]/gi;$p+=@n=/\w/g;$k=y///c- ($q=@v."/".@n)=~y///c;$w.="$_ "." "x-$k;push(@x,$q." "x$k);$w=~s/(.{57})([^.]{3}|\.{3}).*/$1.../}split/ /,$1;$w=~s/((.*?)[ .]*?) *$/$1/;$#x=-1+split/ +/,$2;$x[-1]=~s/ //g;print"$c:^I$w $u/$p:^I@x "} 336, Will Coleda for(join('',)=~/(.*?\.)/gs){my(@n,$v,$t,$d,$j,$r);for(split){$v+=@x=/[aei ouy]/gi;$t+=@c=/[a-z0-9]/gi;$k=@x.'/'.@c;$g=1+length()-length$k;push@n,$k.=' 'x($g>0?$g:1);$d.=$_.' 'x($g>0?1:$g<0?2-$g:2)}$d=~s/ +$//;if(length$d>($s=60)){substr($d,$s-=3)='...'}for(@n){last if$j>=$s;$j+=length;$r.=$_}$r=~s/ +$//;print@n.":^I$d $v/$t:^I$r "} 344, Rick Cook undef$/;map{$t=$w=$h=$p=$l="";for$n(split){$d=0;$h++;$p.=" "x(3-$g)." $n";$g=length$n;$w+=$f=$d+=$n=~s/[aeiouy]//ig;$t+=$f+=$n=~s/\w//g;$g-- if$f>9;$l.="$d/$f "." "x($g- 3)}$_=$l;$p=~s/\s+(.*)/$1\./;$p=substr($p,0,57)."..."if length$p>60;$p=~/.* [^\.]/g;pos=75;while(pos>pos$p||/\s$/){chop;/.* \d/g}print"$h:\t$p\n$w/$t:\t$_\n"if$h}split/\.\s/,<> 347, Ryan Zachry map{s/ / /;$x.=$_}<>;for$d($x=~/.*?\./g){$q=$z=$c=$_=$p="";for$w($d=~/\S+/g){$q++;$l= $v=0;for$e($w=~/\w/g){$l++;$z++;map{$v++if/$e/i}"aeiouy"}$c+=$v;$_.=($t=leng th($f="$v/$l"))>($y=length$w)?$w.$"x($t-$y+1):"$w ";$p.=$t>$y?"$f ":$f.$"x($y-$t+1)}s/ *$//;if(length>60){s/(.{57}).*/$1.../;$p=~s/(.{56}\s).*/$1/}$p=~s/ *$//;print"$q:\t$_ $c/$z:\t$p "} 355, ouch $/=4;map{if(!/^$/){s/^\s*//;map{$w=l($c=$_)-tr/- .,;:'"()&\///;$q=tr/aeiouyAEIOUY//;$d="$q/$w ";$c.=' '.' 'x(l($d)-&l($c)- 1)if$c!~/\./;$d.=' 'x(l($c)- &l($d));$m.=$c;if(l($m)>60){substr($m,57)="...";$n.=$d if l($n)<57}else{$n.=$d}$r+=$q;$p+=$w;$j++}split/\s+/;$n=~s/\s*$//;print"$j:\t$ m\n$r/$p:\t$n\n";$m=$n=$j=$r=$p=''}}<>=~/(.*?\.)?/msg;sub l{length@_[0]} 362, Piotr Klaban

Edition 2007-01-09 top secret / strictly confidential page 128 of 520 Perlgolf History

print join'',map{$^A=$v=$n=$l='';s/^\s+//;s/\s+/ /g;s/(?; 371, BigrTex sub d{$_=lc join'',@_;$p=y/a-z0-9/a-z0- 9/;$q=y/aeiouy//;return"$q/$p"}undef$/;for(<>=~/([^.]*\.)/g){$j=d@x=split;$b =$c=$w=$t="";$s=$x[0];map{$s.=' 'x(3-length$x[$_-1]).' '.$x[$_]}1..$#x;length$s>60?substr($s,57)='.'x3:1;while($c<60&&$b<@x){$z=d$x [$b];$f=length$x[$b++];if(substr($s,$c,1)ne'.'){$t.=$w.$z;$c+=$f=++$f<4?4:$f ;$w=' 'x($f-length$z)}}print$#x+1,":^I$s $j:^I$t "} 376, Tom Hargreaves -0n map{split&&do{($m,@a,@b,$z)=map[$_,($x=@x=/[aeiouy]/gi).'/'.($y=@y=/\w/gi)], $_,@_;$z++<63and$z+=$q=(sort{$a<=>$b}map y///c,@$_)[1],$r=push@b,[- $q,@$_]for@a;$b[- 1][0]=0;($v="@{[map{sprintf'%*s',@$_}@b]}.")=~s/(.{56})(.)(.{4,6}).*/$1$2... /and$r-=@q="$2$3"=~/\s\S/g;$b[--$r][0]=0;print++$#_.":\t$v $m->[1]:\t@{[map{sprintf'%*s',@$_[0,2]}@b[0..$r]]} "}}$e=$1while s/(.*?)\.//s 452, Sheldon Fuchs sub a{$_=pop;length==1?s/$/ /:length==2?s/$/ /:s/$/ /;$_}$a.=$_ for<>;for(split/\./,$a){!/^\s+$/||next;my(@a,$s,$p,$t,$u,$m);map{$p.=a($_);$ s++;$v=s/[aeiouy]/1/gi||0;$w=s/[A-z0- 9]//g||0;$u+=$v;$m+=$w;push@a,"$v/$w"}split;$d="$u/$m";$p=~s/\s+$//;if(lengt h($p)>59){$p=~s/(.{57}).+/$1../}$e=$p;$p=~s/\.+$//;map{$a=shift@a;$b=length( $a);$_=a($_);s/.{1,$b}(.+)/_$1/;s/[^_]/ /g;s/_/$a/g;$t.=$_;}split' ',$p;print"$s:\t$e.\n";$t=~s/\s+$//;print"$d:\t$t\n"} 466, Matthias Schoder sub a{length pop}local$/;$_=<>;s/^\s*//;@i=split//;for(@i){$s=0,++$l,$t++if/\w/;++$w,$v++ if/[aeiouy]/i;$z.=$_ if!/[\s.]/;if(/[\s.]/&&!$s){$x++;$s++;$c=0+$w.'/'.$l;$m=a($c)- a$z if!/\./;push@z,$z;@u=split//,"@z";push@c,$c;$z='';if(/\./){if(@u>59){$u[57]= $u[58]='.';splice@u,59,@u-59;$u=join'',@u;$u=~s/ [ .]*$//;splice@c,split/ +/,$u}print$x,":^I",@u,".\n";$c[-1]=~s/ *$//;print 0+$v,'/',$t,":^I@c\n";@z=@c=();$x=$v=$t=0}else{$c[-1].=' 'x-$m;$z[-1].=' 'x$m}$m=$w=$l=0}} 467, Subhash Chandra -l $/=".";map{s/\n+/ /g;s/^\s+//g;push@$p,[split/\s+/]}<>;push@$d,[map{0+s/[aeiouy]/$&/ig."/".s/[ a-z0-9]/$&/ig}@$_]for@$p;map{sort{map{$l=length($$a[$_])- length($$b[$_]);$l>0?$$b[$_].=' 'x$l:$$a[$_].=' 'x-$l;}0..@$a- 2;$s="@$a";$i=$t=0;for(@$b){/(\d+)\/(\d+)/;$i+=$1;$t+=$2;}if(length$s>60){su bstr($s,57)='...';$k=0;for(0..@$b- 1){$k+=length($$b[$_])+1;if($k>56){$#$b=$_;last;}}}($s2="@$b")=~s/ +$//;print scalar@$a,":\t$s";print"$i/$t:\t$s2";}$$d[$_],$$p[$_]}0..@$p-2; 500, Erik Beatty

Edition 2007-01-09 top secret / strictly confidential page 129 of 520 Perlgolf History

@w=split/\s+|\n/,join"",<>;sub p{print"$c:\t$l\n$u/$v:\t$z\n";$l="";$z="";$c=0;$u=0;$v=0}sub l{length shift}for$w(@w){next if$w!~/\w+/;$c++;$u+=$x=(lc$w)=~y/aeiouy//;$v+=$y=(lc$w)=~y/0-9a- z//;if($p){if($w=~/\./){$p=0;p}next;}$l.="$w";$z.="$x/$y";if($l!~/\.$/){whil e(l($l)60){$p=1 if$w!~/\.$/;if(l($l)>60){$l=~/($w\s*)$/;$z=~s/$x\/$y\s*$// if 60-(l($l)- l($1))<4;$l=substr($l,0,57)."...";}$l=~s/\s*$//;$z=~s/\s*$//;p if!$p;}} 2836, André Savigne

eval eval '"'.

'\\'.'$'.'/'.('='). "'".'.'."'".';'.('['^(',')).( '`'|'(').('`'|')').('`'|',').("\`"| '%').'('.'<'.'>'.')'.'\\'.'{'.'\\'.('@'). ':'.'='.('['^'(').('['^'+').('`'|',').(('`')| ')').('['^'/').';'.('!'^'+').'\\'.'@'.('`'|"\."). '='.('`'|'-').('`'|'!').('['^'+').'\\'.'{'.'\\'.'$' .('['^'/').'+'.'='.'('.'\\'.'$'.('['^'(').'+'.'='.''. '\\'.'@'.'='.'='.'/'.'\\'.'\\'.('['^',').'/'.('`'|"'"). ','.'\\'.'$'.'_'.'.'.'='.'\\'.'$'.'\\'.'"'.('['^'#').'('. ('^'^('`'|'-')).'-'.('`'|',').('`'|'%').('`'|'.').('`'|"'") .('['^'/').('`'|'(').')'.','.'\\'.'$'.';'.'='.('['^('+')).( '`'|'!').('`'|'#').('`'|'+').('{'^'[').('`'^'!').'.'.('['^'"' ).')'.')'.')'.('`'|'#').','.('`'|',').('`'|'#').'='.'~'.('['^ '"').')'.('`'|'!').('`'|'%').('`'|')').('`'|'/').('['^"\.").( '['^'"').')'.')'.'.'."'".'/'."'".'.'.'\\'.'@'.'='.')'.';'.'\\'. '$'.';'.'\\'.'}'.'\\'.'@'.':'.';'.('!'^'+').'\\'.'$'.':'.('='). '~'.('['^'(').','.('{'^'[').'\\'.'$'.','.','.','.'\\'.'$'."\:". '='.'~'.('['^'(').'\\'.'@'.'('.'.'.'\\'.'{'.('^'^('`'|('+'))).( '^'^('`'|')')).'\\'.'}'.')'.'.'.'\\'.'{'.('^'^('`'|'*')).(','). '\\' .'}'.'\\'.'@'.'\\'.'$'.('^'^('`'|'/')). '.'. '.'. '.'.'\\'.'@'.','.'\\'.'@'.(('`')| '.') .'=' .'\\'.'@'.('`'|'.').('[').( '^'^ ('`'| '.')).'.'.'.'.'-'.('^'^ ('`'| '/')) .'+'.('['^'(').("\["^ '+'). ("\`"| ',').('`'|"\)").( ('[')^ '/'). '/'.'['.('.').( "\{"^ "\["). ']'.'+'."\/". (','). '\\'.+ '$'.':'.']' ."\,". '\\'. '$'."\~". "\=". '\\'.+ '@'."\:". ('.'). '('.''. ('\\'). ('$').( '['^'(' )."\=". ('\\'). '$'.('[' ^'/') .'='.''. '\\'.'"'. ':'.( '*'^'#'). '\\'."\$". ':'.( '!'^"\+"). '\\'.('$').( '['^'/' )."\/".'\\'. '$'.('['^'(').':'.('*'^'#').'\\'.'@'.("\`"| '.').('!'^'+').'\\'.'"'.')'.','.'\\'.'$'. '~'.'='.'~'.('['^'(').','.('{'^'[').'+' .'\\'.'$'.','.','.','.('['^'+').('['^ ')').('`'|')').('`'|'.').('['^'/' ).'\\'.'$'.'~'.('`'|')').("\`"| '&').'\\'.'$'.':'.'='.('\\'). '"'.'\\'.'@'.':'.'\\'.'"' .('!'^'+').'\\'.'}'.( '!'^'+')."\"";$:= 'ton hospel'; '@'|"\(";

4.5.3. Artistic/Unorthodox Solutions 154, Ton Hospel -ap056 @Q=map$_^($_^=$:^$:)^lc=~y/aeiouy//."/".s/\w/$&/g,$_,@F;$_="@F";s/(.{57})... +\./$1.../;s!.+!$#Q $& @Q[0..s/[ .]+//g] !;s/\0/ /g;s/ +(.*\S).*/:^I$1/g 159, Marko Nippula

Edition 2007-01-09 top secret / strictly confidential page 130 of 520 Perlgolf History

-ap056 @f=map{$_|=$:^$:;$"x+y|| ^A- z|c|y|youYOUaiIEeA||.'/'.s|\w|$&|g}$_,@F;s,(.{57})..+\w.*,$1...,,$#f=@R=/\w\ S*/g,$_=@F." $_ @f "if$_="@F";s; +(.*?) *;:^I$1;g 169, Marko Nippula -ap056 $_=pack+u,'Y\xbbX\xa9\xebx^S\xff\x98^Q_\x84Ua^B\xd4\xbd\x8f=$\xcd\xe4\xf89@\ xbc^O\xefk2zh\xbdC^D\xfd \x84›-\xb7N^I!?\xf5\xbb} h\xc4\xfd\x80›t%\xb0?\xcc^K \xe2\x9a%"\xbd=_1^P\xbf+>@\xc0';y/1-Z/7 ^A9-@5Fa- }/;eval 175, seano -ap056 ($g,@v)=map{map y/aeiouy//.'/'.s/\w//g,lc}$_="@F",@F;$n=1+s/\S+ /$&|"\0 "/eg;s/(.{57}).{4,}/$1.../;$x=$_;s/[^ .]+ */shift@v|$"x length$&/eg;s/(.*\d).*/$n:^I$x $g:^I$1 / 176, seano -ap056 ($g,@v)=map{map y/aeiouy//.'/'.s/\w//g,lc}$_="@F",@F;$n=1+s/\S+ /$&|"\0 "/eg;s/(.{57}).{4,}/$1.../;$x=$_;s/[^ .]+ */shift@v|$"x length$&/eg;s/^(.*\d).*/$n:^I$x $g:^I$1 / 244, Sec -ap056 ($_=pack u,q{^S\xf7D\xd9\xd1^ZtN^]^P^GD\xc1\xd0\x82n\x99\x88\x83'@\x87^H\x84\xfc\xe7D ^K\x82^S(^S\xfc8\xf3l\x96\xe9\xf4\xa0\x96\xc4j8\xdd^S^CH^Sg\x95X\x93H^Sg\x96 @\x9af \x81^Pv\xc9n\x9fJ^IxGM^Sb[^S^B\xcblM‹u^R\xc4A\xb1 - \xd8$t\xff7>v\xc4\xe0\xb7`\x8d\xd3\xfb\x86Zo\xd7\x9fO\xa6v\xf3\xc3*n\xd2`\x8 54D3^H\xc8#8#\xc2:^I$\x83\xa2b^P<\x9d^Q\xaaf^Q\xa6\xc4\xfd\xd0\xa0\xe8&\xf3< \x83\xa2Uy^I8\xe3\x8e,\xf1^Q8\xe3\x8flO\xdd^HL^Z\xacO\xea^S\x83\xc4^A\xaa\xe 0\xca\xa0›\xcc\xf1\xcb^P\xf3\xe4\xaa})=~y/'A-Z`/ a{-}e-i\n\tl n-yFm/;eval 666, Lucifer Sam -ap056 #ooiiiooiiiooiiiooooiiiooiiio io oy sub baphomet{1*y/aeiouyAEIOUY//. #oiooooiooooiooooooiooooioooo oeoo uyyy v47.(@Q=/\w/g)}*cthulthu=*F; #oiiiooiiiooiiiooooiiiooiiioo oeuuoyy $leviathan=69-9.6|0;$behemoth= #oiooioiooioiooioooiooioiooio uuiiioy $satan=":\t";$behemoth^=($belial=#ooiioooiioooiiooiooiioooiioo uuioiiiyeoo ($satan^$behemoth).$behemoth=~v47&v0 x666).baphomet, # aooooooooyooooe ($satan^=$belial.$_)=~s/(.{$leviathan}).{4,}/$1.../&&# aeiouy oay $behemoth=~s/\0+(??{$+[0]<$leviathan&&v69}).*//for@cthulthu;# oay $_=@cthulthu?@cthulthu."$satan\n".baphomet."$behemoth\n":$astaroth; y /\0/ / 5004, Bret Victor

Edition 2007-01-09 top secret / strictly confidential page 131 of 520 Perlgolf History

$^='$#/$=;"%>&"(;;:{(`)`<`%`()(* $#%{=;<;>;)$)%;{@@&@=;#{@{<`)`${ (&:(@): *<#$$%{)%;;$&( [=;$(& [=;$ ) :[=;$**[=;"#" $;;@@*[=;( % ) &;;&`/`"{$(! `()@@&@)* ; {$# &[;$=;$%&{= ;$&!`=;> { ){/(! `%`)`/`%{) {!@%@)@ / @%[)[/) /*;;$#:[; $=; $%<`=;$& !`=;> { #{/(;[>[<[: [/[=[/) $*&# / $:`;;$%!`>&=; :(@):* ({(## ;=$<`%`>`:`${ (`$%! `) &)`&`;(;)$ *([ <;@@&@;;@{%{#{(`@#@@*[<$<`%`>`:` ${(`$%!`<&"($)&{/*$#<`"$={$%%{=; "&@@&@"(;;$)%{=;>{#{/*(#>$;{%;:; ={)%>&>(>)>*;#/$$%!;>&>(>)/*;;$# *[>$ =;"%% &=( *) # {@*" i s #&`/`" { ($$%%{=;>{/& @(;[ >[@)>* = [/#:`) $;;@@& @&%& f o r &@{"{) ` >`${& `"(%)#{$**[ %#>` %$#{<[>`"%< AUTOSPLIT &"($)([ *;<[$ {$*%{<[>`$# &[/$$% : [*;<[$ {"&<(@ @*[= {';'$# / $=;"%>&"(;;:{ ()<% ()( *$ # %{=; <;>;)$)%;{@@&@=;#{@{<)${(&:(@):* <#$$ %{)% ;;$&([=;$(&[=;$):[=;$**[=;"#"$;; @@*[=;(%)&;;&/"{$(!()@@&@)*;{$#& [;$= ;$%&{ =;$&!=;>{){/(!%)/%{){!@%@)@/@%[) [/)/ *;;$ #:[; $=;$%< = ;$&!=;> {#{/ i s (;[> [<[:[/[ = [/)$*&#/ $:;; $%!>&=;:(@): * ({(##;=$<%>:$ f o r {($%!)&)&;(; ) $*([<;@@&@;;@ {%{#{(@#@@*[ < $<%>:${($%!<& E V A L "($) &{/*$#< " $={$%%{= ;"&@ @&@" (;;$)% { =;>{#{/ *(#> $;{% ;:;= [['; $~=' $:="";$^=~'.("]"^'$').'*:*\'*;$^ =~'.('['^'(').'|([@!-*/:->]).*?' .'([#-*;@[`{])|;;$:.=$'.++$%.'&( "!"&"\\""^"/")\|$'.++$%.'&(("_"^ "/"))|'.('[ >)>*;#/$$%! ;>&>(>)/ *;;$#*[> i s $=;"%% &=(*)#{ @*"#&/ "{($$ % %{=;>{/& @(;[> f o r [@)> *= [/#:)$;; @@&@ &%&& @{" {)>${&"( %)#{ IN-PLACE $**[ %#>%$#{<[> "%<& "($)( [*; <[${$* %{<[> $#&[/$ $% :[*; <[${"& <(@@*[={ $#/$=;"% >&"(;;:{()<%()(*$#%{=;<;>;)$)%;{ @@&@=;#{@{< )${(&',""). ('@[%@%]@,'^'\'(@{@+!@').'$:';;' (@):*<#$$%{)%;;$&([=;$(&[=;$):[= ;$* *[=;"# "$;; @@*[=;(%)&;;&/"{$(!()@@&@)*;{$#& [; $= ; $%&{=;$&!= ;>{){/ (!%)/ % {){!@%@)@/ @%[)[/ i s )/*;; $ #:[;$=;$%< =;$&!= ... sort of ... ;>{#{ / (;[>[<[:[/ [=[/)$ f o r *&#/$ : ;;$%!>&=;: (@):*( {(##; =$<%>:${($% !)&)&; INPUT RECORD (;)$* ( [<;@@&@;; @{%{#{ (@#@@* [<$<%> :${($%! SEPARATOR <&"($)& {/*$#<"$ ={$%%{=;"& @@&@"(;;$)% *%($';''=~('(?{'.('%]@,'^'@+!@') .'$~})');'*$#%^*^%&#$^&%$*^%$^&*

is

for

CORE DUMP and SOMETIMES

(>)>*;#/$$%!;>&>(>)/*;;$#*[>$=;" %%&=(*)#{@*"#&/"{($$%%{=;>{/&@(; [> [@)>*=[/ #:) $ ;;@ @ &@&%&&@{"{ )>${& "(%)# { $**[%#>%$# {<[>" i s %<&"( $ )([*;<[${$ *%{<[ >$#&[ / $$%:[*;<[$ {"&<( f o r @@*[= { $#/$=;"%>& "(;;: {()<% () (*$#%{= ;<;>; )$)%; { @@&@ =;#{@ {<)${( &:( @ ):*<# " WHY am I $$%{)%;; $& ([=;$ (&[=;$):[=; $**[ =;"#" getting $;;@@*[=;(%)&;;&/"{$(!( )@@&@ )*;{$#&[;$=;$%&{=;$&!=; >{){/ WHUPPED (!%) /%{) in this {!@%@) @/@%[ )[/) /*;;$#:[;$= competition!? " ;$% <=; :) $& / =;>{#'

Edition 2007-01-09 top secret / strictly confidential page 132 of 520 Perlgolf History

4.6. TPR(0,4b) "Topological Sort" The game started July 1st 2002 and ended July 8th 2002. Referees: Rick Klement, Steffen Mueller, Ido Trivizki, Jérôme Quelin

4.6.1. Rules Goal Perform a topological sort (partial ordered sort). For all the partial ordering relationships given between nodes in an input file, output each node in an order that obeys the partial order. (from "Mastering Algorithms with Perl") "A Topological sort is a listing of the vertices of a graph in such an order that all the ordering relations are respected. ... More precisely: topological sort of a directed acyclic graph is a listing of the vertices so that for all edges u-v, u comes before v in the listing." Specification The program is a filter: it must read from STDIN, and send output to STDOUT. • The input will consist of one or more lines. Each line will consist of a pair of node names separated by a space character. A node name will consist of printable characters (it will match /^[!-~]+\z/), and the entire input will match the following: /^([!-~]+ [!-~]+\n)+\z/. Any line may appear more than once. A node name can occur in both a relationship and as an "isolated" node (same name twice on the same line). • Each input line represents a before/after relationship between two nodes, and implies that the node on the left will occur in the output before the node on the right (unless it's the same node). • An isolated node (one with no ordering relationship) can be included by having an input line with the same node name on both the left and right hand side. • The output shall contain the name of each unique node once and only once, and those names shall be in an order that satisfies the input partial order requirements. • The output shall match the following: /^([!-~]+\n)+\z/ • There may be more than one order of nodes that satisfies the input line requirements. Don't worry about it, find any one. • There may be no possible order of nodes that will satisfy the input line requirements (the nodes contain a cycle). In this case, the program shall exit with a non-zero exit code. • All input files have a total size so that they will fit comfortably in memory and still allow you ample memory to play with. Please note that the input file cannot be empty. • You may assume ASCII as the character set but you may not use Unicode-specific semantics. Examples Given the input:

Edition 2007-01-09 top secret / strictly confidential page 133 of 520 Perlgolf History

code test design code You are to output the following: design code test Given the input: code test design write_tests design code write_tests test You are to output one of the following two possible solutions: design code write_tests test or: design write_tests code test Given the input: code test design code test design You are to exit with a non-zero exit code because this input contains a cycle. (The output does not matter.)

4.6.2. Solutions 64, Ton Hospel -ln0 / \Q$&/||print$1while s/( |(?= ?\G))\Q$&/ /g,/(\S+) /g/$#+ 64, Ton Hospel (alternative) -ln0 /(?<= )\Q$& /||print$1while s/( |\G)\Q$&/ /g,/(\S+) /g/$#+ 68, Mtv Europe -ln0 / \Q$& /||print$&while s/^\Q$&\E\s|^(.+) \1$/$1/mg,/\S+/g;a%!?? 73, Albert Dvornik -ln0 s/\G \Q$& / /./ \Q$& /||s/^(\Q$&\E)\s//gm-print$1while/\S+/g;lc&&die 74, Wladimir Palant

Edition 2007-01-09 top secret / strictly confidential page 134 of 520 Perlgolf History

-ln0 $a="\Q$&",s/\G $a$//m|/ $a$/m||(print$&)&s/^$a\s//gmwhile/\S+/g;a%!$_ 74, pom -ln0 s/^(.+) \1$/$1/m|/ \Q$& /||print($&)^s/^\Q$&\E\s//gmwhile/\S+/g;1/!$_ 75, Ala Qumsieh -ln0 s/^(.*) \1$/$1/mg;/ \Q$& /||print($&),s/^\Q$&\E\s//mgwhile/\S+/g;$_&&& 76, Qingning Huo -ln0 $*=qr/\Q$&/,s/^($*) $* //,/ $* /||s/^($*)\s//g&print$1while/\S+/g;a/!$_ 78, Juuso Salonen -ln0 S//\S+/g,/(?

Edition 2007-01-09 top secret / strictly confidential page 135 of 520 Perlgolf History

-nal push@{$a{pop@F}},@F}map&a,keys%a;sub a{$z eq$_||0/$.-- *&a*$.++for@{$a{$z=$_}};$p{$_}++||print 106, Lars Mathiesen $_=join'',<>;s/^(.*) \1$/$1/mg;s/^\Q$y\E\s//mg,print"$y "while$x=$_,($y)=grep$x!~/ \Q$_\E /,split;/ /&&die 108, David Lowe -lna @w{@F}=@F;push@g,$_}{&%if map{print,delete$w{$w},redo if$w=$_,!grep/ \Q$w\E$/&&$`ne$w&&$w{$`}ne'',@g}%w 108, Sec -lap @t{@q{@F}=@F}.=" $F[0] "x!/^\Q$F[1] /}for(keys%q){1/(($_)=grep!$t{$_},%q);$t{$w=$_}+=map{s/ \Q$w //g}%t 111, Honza Pazdziora -n0 s/\S+$/$& $& $&/gm;X:for$x(/\S+/g){/^(?!\Q$x\E ).+ \Q$x /m or s/^\Q$x\E .*$//mg,(print"$x "),goto X}/./&&&g 112, Terje K -nl $h{_}{$'}=/ /;$h{$'}{$`}=1if$`ne$'}{sub z{$u{$_}++&&die,$y{$_}||=z($_)+print,$u{$_}--for keys%{$h{+pop}}}z _ 114, Jasper McCrea -lp0 @e{@a=split}=1;$o=join$\,keys%e;1/!eval'grep/ /&$o=~s#^(\Q$\'\E)$((.| )* )(\Q$`\E)$#$4$2$1#m,/.*/g;'x@a;$_=$o 117, Andrew Savige -aln / /,@n{@F}+=$`ne$'&!$p{$_}++}{0-$n{$x=$_}or$z+=print,map{/ /,$n{$'}- =$`eq$x}%p,"$x $x"for(@m=keys%n)x@m;$z-@m&&& 118, Yanick Champoux -lpa push@;,[@F[$F[0]eq$_..1]]for@F}while(/.+/,map{@$_=grep$&ne$_,@$_}@;){($_)=ma p{(($x)=@$_)x!grep$$_[1]eq$x,@;}@;or& 122, Scott Hall -nl / /;$f{$_}++||push@{$a{$'}},$`eq$'?():$`}sub v{$b{$_}++?die:&v,-- $b{$_}for@{$a{$_}};$p{$_}++||print}for(keys%a){my%b;v 123, Jonathan Stimmel -ln / /;$`ne$'?$r{$'}{$`}:$x=$r{$`}||={}}while(@n=grep!%{$r{$_}}&&print,keys%r or%r&&exit 1){map delete@$_{@n},\%r,values%r 123, Aj -l map{/ (.*)/,($o{$`}+=0)<$o{$1}or$`eq$1or$o{$1}=$o{$`}+1,o/($o{$1}<$.)}(<>)x++$.;fo r$i(0..$.){map$o{$_}^$i||print,keys%o} 125, Jon Coppeard -n / /;$p{$a=$`.$/}+=0;$' eq$a or$p{$'}++,push@$a,$'}{delete$p{$_},print,map-- $p{$_},@$_ while($_)=grep!$p{$_},keys%p;%p&&die 127, Martin Carlsen

Edition 2007-01-09 top secret / strictly confidential page 136 of 520 Perlgolf History

-p0 $n++>8*y///c&&die while s/^((\S+) \S+ )(.*^(?!\2 )\S+ \2 )/$3$1/sm||s/( \S+)( .*\1 )/$2/s||s/ / /||s/^(\S+ )(.*^)\1/$1$2/ms 127, Geoff Hubbard -ln $r{$1}{$`}=/ (.*)/}{sub v{$c{$"=$_}=2;$_ ne$"and$c{$_}?$c{$_}^2||die:&v for keys%{$r{$_}};$c{$_}=print}$c{$_}||v for keys%r 130, TheodoreYoung -lan END{map{print;delete$C{$_}}grep{!grep{$C{$_}}keys%{$C{$_}}}keys%C or die while%C}($l,$r)=@F;$C{$l}{\n}=$l ne$r?$C{$r}{$l}=1:1 130, Peter Haworth -nla push@v,($,,$r)=@F;$,eq$r||push@{$e{$r}},$,}sub v{$v{$_}=2;$v{$_}?$v{$_}&2&&die:&v for@{$e{$_}};$v{$_}=print}{$v{$_}||&v for@v 132, Michael Robinson -nl @n{/(.+) (.+)/}|=n;$n{$2}+=$1ne$2;push@{$g{$1}},$2}{(map{$n{$_}-- for@{$g{$_}};delete$n{$_};print}grep!$n{$_},keys%n)?redo:exit%n 137, Benoît Chauvet -ln / /;$p{$'}+=$`ne$';$p{$`}|=0;$n{$`}.=$'.$;;END{{}while grep{$a+=print;map{$p{$_}--}$_,split$;,$n{$_}}grep!$p{$_},@a=keys%p;exit$a- @a} 144, Bruce Gray -lan ($l,$r)=@F;$s{$r}{$l}=1if$l ne$r;$s{$l}||={};END{while(($l)=grep!%{$s{$_}},keys%s){print$l;delete$s{$_}{ $l}for keys%s;delete$s{$l}}%s&&die} 145, Dr. Mu -l -0 ($s=$\.<>)=~s/^(\S+) \1$/\1/gm;$s=~s/(\s)\Q$t[0]\E(?=\s)/$1/gm&&print$t[0]while@t=grep$s!~/\S \Q$_\E$/m,$s=~/^ *(\S+)(?:\s)/gm;exit$s=~/\S/ 146, Philippe Bricout @h{(split)}++for@t=<>;$v=join$/,keys%h,'';{($a,$b)=split,$c+=$v=~s/^\Q$b\E$(.*) ^\Q$a\E$/$a${1}$b/msfor@t;$c?$c=0:last;++$h{$v}>1&¨redo}print$v 147, Ross Younger -alp @U{($a,$b)=@F}=0;$R{$b}{$a}=1if$a ne$b}@U=keys%U;while(@U){@U=sort{%{$R{$a}}<=>%{$R{$b}}}@U;%{$R{$a=shift@U}}&&di e;delete$R{$_}{$a}for@U;$_=$a 151, Damien Neil -lna $M{$F[0]}||={};@{$M{$F[1]}}{@F}=1;END{while(keys%M>0){($n)=grep{keys%{$M{$_} }<=1}keys%M or die;print$n;delete$M{$n};map{delete$_->{$n}}values%M;}} 152, Josef Drexler

Edition 2007-01-09 top secret / strictly confidential page 137 of 520 Perlgolf History

-lna @v{($@,$b)=@F}=0;push@{$e{$@}},$@ne$b?$b:()}sub d{my($x,$o)=@_;$r{$x}++&¨$o+=1+d($_)for@{$e{$x}};$r{$x}--;$o}map print,sort{d($b)- d$a}keys%v;{ 155, FatPhil -n / (\S+)/;$p{$1}.=" $` "if$`ne$1;$p{$`}x=1}for(;;@f=()){map{@f||$p{$_}||print+@f=$_,$/}keys%p;@f?de lete$p{$f[0]}:each%p?die:last;map s/ \Q@f //g,values%p 157, Brad Jones -nl ($",$b)=split;$"ne$b&&$l{$b}- >{$"}++;$l{$"}||={};END{while(%l){(($c)=grep{!%{$l{$_}}}keys%l)||die;print$c ;delete$l{$c};for(keys%l){delete$l{$_}->{$c};}}} 157, Michael Wrenn -lan @u{@F}=@_=(@_,$_)}{@u=keys%u;while(!@g&(++$h<1E4||die$h)){for(@_){@c{@u}=0.. @u;@g=($x,$y)=@c{+split};if($x>$y){@u[@g]=@u[$y,$x];@g=();last}}}print for@u 158, Daniel Cutter -na $a{$_}++for($a,$b)=@F;push@r,qr/( \Q$b\E\n)(.*)( \Q$a\E\n)/s;END{$e.=" $_\n"for keys%a;for(@r){$e=~s/$_/$3$2$1/for@r}$e=~$_&&die for@r;$e=~s/ //g;print$e} 159, Prakash Kailasa -lan push@{$h{$F[0]}},$F[1];$h{$F[1]}||=[]}{sub d{my($w,$x)=@_;$c{$w}||=1+do{map{$d++>$.&&&,,$x+=d($_)if$_ ne$w}@{$h{$w}};$x}}map{print}sort{d($b)<=>d$a}keys%h 159, Philippe 'BooK' Bruhat -lna END{do{for(@a=grep{!$a{$_}}keys%a){$a{$_}--for$a=~/$;\Q$_\E (\S+)^I/g;delete$a{$_};print}%a&&!@a&&die}while%a}$a{pop@F}+=$_ for($F[0]ne$F[1],0);$a.="$;$_^I" 167, Marcelo E. Magallon -ln @p{($a,$b)=split}||={};next if$a eq$b;$p{$b}{$a}=1}{L:while(@k=keys%p){for(@k){next if keys%{$p{$_}};for$k(@k){delete$p{$k}{$_};}delete$p{$_};print;next L}exit 1;} 190, Boyd Nation -l while(<>){chomp;($a,$b)=split;if($a ne$b){push(@{$s{$a}},$b);$p{$b}++}if(!$p{$a}){$p{$a}=0}}&H;sub H{for$v(keys%p){if(!$p{$v}){print$v;for$w(@{$s{$v}}){$p{$w}-- }delete($p{$v});&H}}exit%p} 197, BigrTex -lna ($l,$r)=@F;exists$p{$_}?next:x;$v{$l}+=0;if($l ne$r){++$v{$r};push@{$s{$l}},$r}}@t=grep{!$v{$_}}keys%v;while(@t){print$z=po p@t;map{push@t,$_ unless--$v{$_}}@{$s{$z}}}if(grep{$v{$_}}keys%v){die 199, Erik Beatty while(<>){($p,$s)=split;$h{$s}.="\"$p\""if$p ne$s;$h{$p}.="";}$c=@k=keys%h;while(@k){$k=shift@k;if($h{$k}eq""){$c=@k;prin t"$k\n";map{$h{$_}=~s#"\Q$k\E"##g}@k;}else{push@k,$k;last if$c-- <0;}}exit($c); 208, Matthias Schoder

Edition 2007-01-09 top secret / strictly confidential page 138 of 520 Perlgolf History

-lan012 ($x,$y)=@F;$X{$x}{$y}=$Y{$y}{$x}=1if$x ne$y;map{$N{$_}++}@F;END{exit map{map{if(!$Y{$_}){print;for$y(keys%Y){delete$Y{$y}{$_};delete$Y{$y}if!%{$Y {$y}}}delete$X{$_};delete$N{$_};exit if!%N}}keys%N}%N} 380, Kristen Thelen, Kristen Thelen sub visit{my$z=$_[0];return if@{$l{$z}}[0]eq 2;exit 1if@{$l{$z}}[0]eq 1;@{$l{$z}}[0]=1;$c=0;foreach(@{$l{$z}}){visit($_)if$c ne 0;$c++}@{$l{$z}}[0]=2;unshift(@o,$z);}while(<>){($f,$s)=split;push@{$l{$f}}, 0if!@{$l{$f}};push@{$l{$s}},0if!@{$l{$s}};if($f ne$s){$g=0;$c=0;for (@{$l{$f}}){$g=1if($c ne 0)&&($_ eq$s);$c++}push @{$l{$f}}, $s if!$g;}}visit($_)for keys%l;print "$_ "for@o; 3786, André Savigne

eval eval '"'.

('['^',').('`'| '(').('`'|')').("\`"| ',').('`'|'%').'('.('<'). '>'.')'.'\\'.'{'.('!'^('+')). '\\'.'$'.('`'|')').'='.('`'|')' ).('`'|'.').('`'|'$').('`'|'%').( '['^'#').'\\'.'$'.'_'.','."'".('{'^ '[')."'".';'.('!'^'+').'\\'.'$'.('['^ '#').'='.('['^'(').('['^'.').('`'|'"'). ('['^'(').('['^'/').('['^')').'\\'.('$'). '_'.','.('^'^('`'|'.')).','.'\\'.'$'.("\`"| ')').';'.('!'^'+').'\\'.'$'.('['^'"').('=').( '['^'(').('['^'.').('`'|'"').('['^'(').('['^'/' ).('['^')').'\\'.'$'.'_'.','.'\\'.'$'.('`'|"\)"). '+'.('^'^('`'|'/')).';'.('`'|'#').('`'|'(').('`'| '/').('['^'+').'\\'.'$'.('['^'"').';'.("\!"^ '+'). '\\'.'@'.('`'^'&').'='.'('.'\\'.'$'.(('[')^ '#') .','.'\\'.'$'.('['^'"').')'.';'.('!'^('+')). '\\'. '$'.('['^'+').'\\'.'{'.'\\'.'$'.'_'.'\\'.'}'. ('+'). '+'.('`'|'/').('['^')').'\\'.'@'.('`'|'.').'\\'.'{'.''. '\\'.'@'.('`'^'&').'\\'.'}'.'+'.'='.'\\'.'$'.('['^'#'). ('{'^'[').('`'|'.').('`'|'%' ).'\\'.'$'.('['^'"').'&'.'&' .'!'.'!'.('['^'+').('['^'.' ).('['^'(').('`'|'(').'\\'. '@'.'\\'.'{'.'\\'.'$'.('['^ '(').'\\'.'{'.'\\'.'$'.('[' ^'#').'\\'.'}'.'\\'.('}'). ','.'\\'.'$'.('['^('"')).( '!'^'+').'\\'.'}'.(('!')^ '+').'\\'.'@'.('`'|"\,"). '='.('`'|"'").('['^')').( '`'|'%').('['^'+').('!'). '\\'.'$'.('`'|"\.").'\\'. '{'.'\\'.'$'.'_'.'\\'.'}' .','.('`'|'+').('`'|'%'). ('['^'"').('['^'(').'%'.( '`'|'.').';'.('!'^('+')).( '['^'+').('['^')').(('`')| ')').('`'|'.').('['^('/')). '('.'\\'.'$'.'_'."\.".'\\'. '$'.'/'.')'.','.('[' ^'+') .('[' ^'.').('['^'(').('`' |'(').'\\'.'@'.('`' |',' ).(( ',')).('`'|("'")).( '['^')').('`'|'%') . ( '['^'+').'!'."\-". '-'.'\\'.'$'.('`'| '.').'\\'.'{'.'\\' .'$'.'_'.'\\'.'}'. ','.'\\'.'@'.'\\'. '{'.'\\'.'$'.('['^ '(').'\\'.'{'.'\\' .'$'.'_'.'\\'.('}'). '\\'.'}'.('`'|'&').( '`'|'/').('['^"\)"). '\\'.'@'.('`'|"\,"). ';'.('!'^'+') .'\\' .'@'. ('`'|',').'-' .('`'|'+').( '`'| '%') .('['^'"').( '['^('(')). ( '%').('`' | '.').('&'). '&'.(('`')| '%').('['^'#') .('`'|')'). ('['^"\/"). '('.('^'^('`'|'/' )).')'.('!' ^'+').'"';$: ='.'^'~';$~='@'|'('; $^=')'^"\["; $/='`'|'.';$_ ='('^'}';$,='`'|'!';$\ =')'^"\}";$:= '.'^('~');$~= '@'|'(';$^=')'^('[');$/= '`'|('.');$_= ('(')^ "\}"; $,='`'|'!';$\=')'^"\}";$:= "\."^ '~';$~ ='@'| '('; $^=')'^"\["; $/= '`'| "\."; ($_) = '('^"\}";$,= '`' | '!'; $\= (( ')'))^"\}"; $:= '.' ^+ '~' ;( ($~))= '@' |+ ( '(' ) ;$^= ')' ^ (( ( ( ( ( ( ( ( (( ( ( ( ( ( '[' ))) ) )) )) )) )))) )) ; $/ = ( ( ( '`')) ) | (( '.'));$_='(' ^ ( '}');$,=('`')| ( '!');$\="\)"^ '}' ;$:='.'^'~'; $~='@'|'(';

Edition 2007-01-09 top secret / strictly confidential page 139 of 520 Perlgolf History

4.6.3. Artistic/Unorthodox Solutions 119, Eugene van der Pijll -wlap0 $SIG{__WARN__}=[@g{@F}=$x=$_]}sub a{map{(1)x("@_"eq$_||a($_))}$x=~/(.*) \Q@_ /g,@_}for(sort{a($a)<=>a$b}keys%g){ 167, Philippe 'BooK' Bruhat -lna END{@a=keys%a;T:$b=~/\Q@a/&¨map{($c,$d)=@$_;@a{@a}=0..@a;$b.="^I@a",@a[@ a{@$_}]=@a[@a{$d,$c}],goto T if$a{$c}>$a{$d}}@r;$"=$/;print"@a";exit}push@r,[@a{@F}=@F] 192, Philippe 'BooK' Bruhat -lna @n{@F}=push@r,$_;$"=$/;sub p{my (@p,%s)=@{+pop};if(@p==keys%n){ print"@p";exit}@s{@p}=1..@p;for (@r){($a,$b)=split;return if$s{ $a}>$s{$b}}map{p([$_,@p])}grep{ !$s{$_}}keys%n}END{p[];die}

220, Philippe 'BooK' Bruhat -lna @n{@F}=push@r,$_;$"=$/;sub p{my @a;return[@_]if@_==1; for$0(@_){push@a,map{[$0,@ $_]}p(grep{$0ne$_}@_)}@a}; END{T:for(p(keys%n)){@s{@s }=0..(@s=@$_);for(@r){($a, $b)=split;next T if$s{$a}> $s{$b}}print"@s";exit}die} 784, Max Tie eval pack'b*','^I ^I ^I ^I^I^I ^I ^I ^I ^I^I ^I^I^I^I ^I ^I ^I^I^I^I^I^I ^I ^I^I^I^I ^I ^I ^I ^I ^I ^I^I^I^I^I ^I ^I ^I^I^I^I ^I ^I ^I^I^I^I ^I^I ^I^I^I ^I^I ^I^I ^I^I^I ^I ^I ^I^I^I^I^I ^I ^I ^I^I^I^I ^I^I^I^I ^I^I^I^I^I ^I^I ^I^I^I ^I^I ^I^I^I ^I^I^I^I ^I ^I^I^I^I ^I ^I ^I ^I^I^I ^I ^I^I ^I ^I ^I^I ^I ^I ^I ^I ^I ^I ^I^I^I ^I ^I ^I^I ^I ^I ^I^I^I^I ^I ^I ^I ^I ^I^I ^I^I^I^I ^I ^I ^I^I ^I^I ^I^I^I ^I^I ^I^I ^I^I^I ^I^I^I^I ^I ^I ^I^I^I ^I ^I ^I ^I ^I ^I ^I^I ^I ^I ^I ^I^I^I^I ^I ^I^I^I^I^I ^I^I^I^I^I ^I^I^I ^I ^I^I^I ^I ^I ^I^I ^I^I^I ^I^I ^I ^I^I^I ^I ^I ^I ^I ^I^I ^I ^I ^I ^I ^I ^I^I^I ^I^I^I ^I ^I^I ^I ^I ^I^I ^I^I ^I^I ^I ^I ^I^I ^I ^I^I ^I^I^I ^I^I^I^I ^I ^I^I^I^I ^I ^I^I^I ^I ^I ^I ^I ^I ^I ^I^I ^I ^I^I^I ^I ^I ^I ^I ^I^I^I ^I ^I^I ^I^I^I ^I^I^I^I ^I ^I^I^I^I ^I ^I ^I^I ^I^I ^I^I^I ^I^I ^I^I ^I ^I^I^I^I ^I ^I^I^I ^I ^I^I ^I ^I ^I^I ^I ^I ^I^I^I^I ^I ^I^I^I ^I^I ^I^I ^I^I^I ^I ^I ^I ^I ^I ^I^I^I^I ^I^I^I^I^I^I ^I^I^I^I^I^I ^I ^I '

4.6.4. Explanation by Chris Dolan Newsgroups: perl.golf Message-ID: <[email protected]> Date: Tue, 09 Jul 2002 14:02:45 -0500 Organization: Clotho Advanced Media Subject: Re: My solution annotated From: [email protected] (Chris Dolan)

Edition 2007-01-09 top secret / strictly confidential page 140 of 520 Perlgolf History

My favorite solution was by Jukka Suomela at 97.47. No disrespect intended toward Ton et al., but I think Jukka's approach is the most clever and interesting in the competition. My explanation is below. -alp ($_,my$y)=map{bless$x{$_}||=[$_]}@F;$_- $y&&push@$_,$y}DESTROY{$d?dump:print$_[0][0]}{$d=%x=q The principle behind this solution is that Perl already has a topological sorter for graphs built in: the garbage collector. The GC takes hierarchical data structures and deletes them by finding the parts that are referred to by no other parts and deleting them, and then recursing (literally or virtually, I have no idea) to other parts of the data structure. The GC must destroy the object in the proper order to preserve the integrity of the data structure at each stage. Happily, this order is the topological order. Jukka's solution creates a nested data structure and forces the GC to take it apart, and print output along the way. There are three parts to the solution: 1) Construction -alp ($_,my$y)=map{bless$x{$_}||=[$_]}@F;$_-$y&&push@$_,$y} Loop over the input lines, using the autosplit to create an array of the leading node ($F[0]) and the trailing node ($F[1]) for each edge. Every node becomes an array reference containing (1) the name of the node itself and (2) a list of child nodes. The former is added as soon as the new node is discovered, while the latter are pushed onto the array as they are encountered. The "$_-$y" compares the nodes to make sure they are different. If they are the same, the push() does not happen. This removes the isolated node problem. The bless() call is crucial for the deconstruction phase described below. The "my" is needed to make $y be a new scalar every time (otherwise the scalar is reused and $_-$y doesn't work right). $_ is already local in scope, so there is no need to use a "my" with that node. At the end of the input loop, %x refers to all of the nodes, with all of their interconnections implied by the nested references. In the example of test #1 ab cd bc we get (via Data::Dumper) %x=( 'a' => bless( [ 'a', bless( [ 'b', bless( [ 'c', bless( [ 'd' ], 'main' ) ], 'main' ) ], 'main' ) ], 'main' ), 'b' => $VAR1->{'a'}[1], 'c' => $VAR1->{'a'}[1][1], 'd' => $VAR1->{'a'}[1][1][1] ); In this data structure, one can already see that the nodes are sorted. The -p will not actually be used to print, but it is crucial to shorten the solution a bit, as described below.

Edition 2007-01-09 top secret / strictly confidential page 141 of 520 Perlgolf History

2) Resolution {$d=%x=q First, the "q" is a clever hack to shorten the entry by one character. All that is needed is to set %x to any non-false scalar, so something like $. could be used. But that's two strokes. To shave one stroke, Jukka used the q() operator, with the newline as the enclosing character. Thus, deparsed with the -p option, this looks like: { $d = %x = '}continue{print or die qq(-p destination: $!\\n)'; } which is, of course, a non-false scalar. Thus, the expansion of -p is an arbitrary string. %x=q causes the %x hash to be destroyed and garbage collected. All collectable nodes will be destroyed. Any circular references will not be destroyed. Upon completion of the garbage collection process, the previously-undefined variable $d is set. This variable is a flag to indicate whether or not the garbage collection should have completed or not. If the graph is acyclic, all the nodes should be collected before $d is set. If there are any cycles, the cyclic nodes will be garbage collected (upon termination of the program, I think) after $d gets set. 3) Deconstruction DESTROY{$d?dump:print$_[0][0]} Because the nodes are blessed, each time one is garbage collected, the DESTROY function in the current namespace is called. Jukka overrides the default no-op DESTROY function with one that does useful work for this problem. The node to be destroyed is passes in via @_, so that node is $_[0]. The first step is to check if we are in the resolution phase (garbage collecting acyclic nodes) or in the program termination phase (garbage collecting cyclic nodes). As described above, $d is the flag that indicates the phase. If we are in the latter phase, we call dump() which immediately terminates the program and dumps core. We must use dump() since it is too late to call die() or other constructs while the program is in the process of terminating. If we are still in the acyclic phase, then print the first element of the array that is contained in this node. Since the node is $_[0], the first array element is $_[0][0], which is the name of the node. Thus, the de-obfuscated solution might look like:

Edition 2007-01-09 top secret / strictly confidential page 142 of 520 Perlgolf History

%allnodes = ();

while ($line = ) { chomp $line; @labels = split(/\s+/, $line);

foreach my $label (@labels) { if (!exists $allnodes{$label}) { $allnodes{$label} = bless [$label]; } } my $node1 = $allnodes{$labels[0]}; my $node2 = $allnodes{$labels[1]};

if ($node1 != $node2) { push @$node1, $node2; } }

%allnodes = 'any old non-false value'; $end_of_program = 1;

sub DESTROY { if ($end_of_program) { dump; } else { my ($node) = @_; print $node->[0], "\n"; } } Chris

4.6.5. Explanation by Ton Hospel Newsgroups: perl.golf Subject: Re: My solution annotated Date: Mon, 8 Jul 2002 16:10:56 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) In article , Stephen Turner writes: > So, last month I annotated all the top 12 solutions. People seemed to > appreciate it, but there's no way I've got time to do it again this month! > > So I thought it would be interesting if players annotated their own > solutions this month. I for one would like to see what people say about > their own solutions. > my solution: -ln0 / \Q$&/||print$1while s/(\n|(?= ?\G))\Q$&/ \n/g,/(\S+) /g/$#+ -n0 slurps the whole string.

Edition 2007-01-09 top secret / strictly confidential page 143 of 520 Perlgolf History

The first time the while is entered, $& is empty, and s/(\n|(?= ?\G))\Q$&/ \n/g will add a space newline in front (the (?= ?\G) triggers), and add a space at the end of every line (the \n triggers). So a typical line "ab" can now be read as "\n ab", and "cc" can be seen as "cc \n" The /(\S+) /g is the core of the solution. This will repeatedly try each successive word in the string, but if any changes are done during the loop, it will restart. So it functions as a "try for every word as long as we are making progress". It sets up $1 as the word, and $& as the word followed by a space. / \Q$&/||print$1 Checks if the word is both preceded and followed by a space. In that case it appears as follower (or singleton), we don't print and $& is changed to " word ". If it's not a follower, we print the word $1 (the -l adds the newline), and $& is unchanged. We now get to s/(\n|(?= ?\G))\Q$&/ \n/g again. \G will be at the place /(\S+ ) / stopped matching, even in the case that / \Q$&/ matched (the change of pos is localized, but the change of $& isn't). So there are two cases: • / \Q$&/ did not match, $& is "word ", and \G is just at the end of the "word " under consideration. The \G cannot match because that would imply the line under consideration is "word word ", which would have caused / \Q$&/ to match. So the substitute is essentially s/\nword / \n/. This removes all cases of "word" at the beginning (and adds an extra space to the previous line). So "\nef\nword b \n" becomes "\nef \nb \n". A line like "\nb \n" is a placeholder for later output when all cases with b as follower have been eliminated: it will match the /(\S+) /, not match the / \Q$&/ and get safely eliminated by the s/\nword / \n/ to become " \n\n" • / \Q$&/ did match, now $& is " word " and \G is just at the end of the "word " under consideration. Since we never have "\n word " in the input, the \n branch can never match, therefore we effectively are doing s/(?= \G) word / \n/. This will change one singleton "word word ...." to "word \n...." (where the ... is any number of spaces followed by a newline) or do nothing. So singletons slowly get removed from the input and replaced by placeholders. As long as the /(\S+) / matches, $#+ will be 1. The whole process runs until no more words make any progress. At that point, the last thing that ever matched will be either the s/(\n|(?= ?\G))\Q$&/ \n/g if the last thing we did was removing the last word ($#+ will be 1) or the / \Q$&/ if there are still words but we can make no progress (which means loops and $#+ will be 0). So $#+ is only ever zero at the end of processing and if the input contained loops. And in that case the division by $#+ causes an error. My 65 solution before this was less twisted, but mtve was quickly catching up in a way that made me certain he was just a cat's whisker away from finding the s/// unification in that solution (he was, but he used an inferior unification). So I did an extra effort on Saturday to get at least one non-obvious weirdness ahead of the storming mtve. There might be a solution which mangles the original input in a more clever way so the lookahead won't be needed. I found some tempting 60's and 61's that pass several tests, but couldn't make it all come together. If anybody would have gotten to 65, I'd have started exploring that branch systematically. -- old (pre-golf) conversation on ircnet #perl: Just imagine we are meeting the aliens for the first time. Most people would just shoot them to see how many points they are worth.

Edition 2007-01-09 top secret / strictly confidential page 144 of 520 Perlgolf History

4.7. TPR(0,4c) "Ciphers and Letters" The game started August 1st 2002 and ended August 8th 2002. Referees: Ton Hospel, Michael Thelen, F. Xavier Noria, David Lowe

4.7.1. Rules This month we play a two hole course again, one about numbers and one about strings. Hole 1: Factorial As n grows large, n factorial (n!) begins to accumulate a string of trailing zeroes. Your job is to determine the last non-zero digit of n! for n in the range 0..9999. Examples 0! is 1 by definition, and the last non-zero digit is 1. 1!=1*0!=1* 1= 1,last non-zero digit is 1 2!=2*1!=2* 1= 2,last non-zero digit is 2 3!=3*2!=3* 2= 6,last non-zero digit is 6 4!=4*3!=4* 6= 24,last non-zero digit is 4 5!=5*4!=5*24=120, last non-zero digit is 2 6!=6*5!=6*120=720, last non-zero digit is 2 The number n will be given as the only command line argument, and it will match either /^[1- 9]\d{0,3}\z/ or /^0\z/. On STDOUT you must print the last non-zero digit of n! followed by a newline. Nothing should appear on STDERR. The program's return code will be ignored. For once you may not use any modules. Hole 2: Trees by postorder When traversing a binary tree depth-first from left to right, and writing down the nodes, there are three major ways to do this: 1. Preorder: Write down the topnode, then write down the left subtree in preorder, followed by the right subtree in preorder. 2. Inorder: Write down the left subtree in inorder, write down the top node, write down the right subtree in inorder. 3. Postorder: Write down the left subtree in postorder, then the right subtree in postorder, finally followed by the top node. Example B preorder: BCQSTAZDE / \ inorder: SQTCBZAED / \ postorder: STQCZEDAB CA //\ //\ QZD /\ / /\ / STE When given such a string, it's generally not possible to reconstruct the original binary tree. However, if you are given preorder and inorder or inorder and postorder, the tree can be reconstructed (assuming all nodes had a different name).

Edition 2007-01-09 top secret / strictly confidential page 145 of 520 Perlgolf History

The program will receive two strings as command line arguments: the preorder and inorder traversals of a binary tree. Given this input, the program must print the postorder traversal of the binary tree followed by a newline to STDOUT. You may assume the command line arguments to be in any order, either the preorder string first or the inorder string first. However, the interpretation must be consistent. If you assume one order for one input pair, you must asume that order for all pairs. Nothing should appear on STDERR. The program's return code will be ignored. It is possible to specify a preorder and inorder string such that no binary tree can satisfy both traversals. You do not need to worry about this possibility; the command line arguments are guaranteed to represent a valid binary tree (binary here means that each node has at most 2 subtrees and never has two left subtrees or two right subtrees). The nodes of the tree will be named using different uppercase letters (so the tree will have at most 26 nodes). The strings won't be empty (so you don't have to handle the empty tree). As you can see, the commandline arguments will match /^[A-Z]{1,26}\z/.

4.7.2. Solutions Hole 1 (Factorial) 44, Juho Snellman -l $_*=$`%9e9,??for~4=~?0*$?..pop;print$`%10 46, Eugene van der Pijll -l $_*=$~%9e8,$~=/0*$/.$`for@~..pop;print$~%10 48, Rick Klement $}=substr$}*".$_",~6for++$}..pop;print+chop$},$/ 48, Bass -l $_*=$},/0*$/,$}=$`%1e9for++$}..pop;print$}%10 48, Wladimir Palant -l $_*=$}%1e6,/0*$/,$}=$`for++$}..pop;print$}%10 48, Markus Laire -l $_*=$z%9e9,/0*$/,$z=$`for++$z..pop;print$z%10 48, Michael Rybakin -l $_*=$z%1e9,/0*$/,$z=$`for++$z..pop;print$z%10 49, Mtv Europe for$~(0..pop){$_=$`%9e9*$~||1;s~0*$~ ~}print/. /g 49, Stephen Turner -l ($}=$}%1e9*$_)=~s~0+$~~for++$}..pop;print$}%10 49, Chris Dolan -l ($z=$z*$_%1e9)=~s^0*$^^for++$z..pop;print$z%10 49, Honza Pazdziora -l ($z=$z*$_%1E6)=~s/0*$//for++$z..pop;print$z%10 49, Jukka Suomela

Edition 2007-01-09 top secret / strictly confidential page 146 of 520 Perlgolf History

-l ($y=$y*$_%1E8)=~s/0*$//for++$y..pop;print$y%10 49, Pepik -l ($}=$}*$_%1e6)=~s/0*$//for++$}..pop;print$}%10 49, Josef Drexler -l ($z=$z*$_%1e9)=~s/0*$//for++$z..pop;print$z%10 50, Terje K -l $_=$_*++$z%1e6,s~0+$~~for($_=1)x pop;print chop 50, Ross Younger -l ($~=$_*$~%1e9||1)=~s~0+$~~for~0..pop;print$~%10 50, James Harvey -l ($z=$z*$_%1e6||1)=~s~0*$~~for 0..pop;print$z%10 50, Greg Allen -l $z=$z*++$y%1e6,s~0*$~~for($z=1)x pop;print$z%10 50, Greg Allen -l $~=$~*++$z%1e6,s|0*$||for($~=1)x pop;print$~%10 50, Petri Mikkelä -l ($~=$~*$_%9e9||1)=~s/0*$//for 0..pop;print$~%10 50, Alexander Onokhov -l ($a=$_*$a%1e6||1)=~s/0*$//for$|..pop;print$a%10 50, Jasper McCrea -l ($o=$_*$o%1e7||1)=~s/0*$//for 0..pop;print$o%10 50, Qingning Huo -l $_*=$~,/0*$/,$~=$`%1e9for($~=1)..pop;print$~%10 51, Prakash Kailasa -l for$~(0..pop){$_=$_%1e6*$~||1;s~0+$~~}print+chop 51, Amir Karger -l $p=($p*$_)=~/0*$/*$`%1e6||1for 0..pop;print$p%10 51, gimbo -l for$k(++$_..pop){$_=$k*$_%1e6;s/0*$//}print$_%10 51, Eike Grote -l ($}=$}*$_%1e9)=~s/0+$//for(++$}..pop);print$}%10 51, Martti Laitinen ($r=$r*$_%1e6)=~s/0*$//for($r=1)..pop;print$r%10,$/ 52, Eric Roode -l $z=1;($z=$z*$_%1e7)=~s/0+$//for 2..pop;print$z%10 53, tinita

Edition 2007-01-09 top secret / strictly confidential page 147 of 520 Perlgolf History

-l ($~=$~*$_%10**6)=~s~0*$~~for($~=1)..pop;print$~%10 53, me ELOISE -l $_=1;for$i(1..pop){$_=$i*$_%1e7;s/0*$//}print$_%10 53, Jasvir Nagra -l for(++$p..pop){$_*=$p;/0*$/;$p=$`%10**6}print$p%10 53, Aj -l $_*=$a,/0*$/,$a=$`%10**9for($a=1)..pop;print$a%10; 54, Marko Nippula -l $_++;$_*=$~--,s/0$//,$_%=1e5while$~+=pop;print$_%10 54, Alistair McGlinchy -l $n=1;($n*=$_)=~s/0*$//,$n%=1e8for 1..pop;print$n%10 54, Keith Calvert Ivey -l $_*=$z,($z)=/(.{0,6}?)0*$/for($z=1)..pop;print$z%10 55, Michael Robinson -l $_=1;for$i(2..pop){$_*=$i;s/0*$//;$_%=1e6}print$_%10 55, Guillermo Sansovic -l for$n(++$_..pop){s/(.{1,6})0*$/$1*$n/e}print/(.)0*$/ 55, Stanislav Svirid -l $_=1;for$.(1..pop){$_=$_%10**6*$.;s/0*$//}print chop 56, Michael Wrenn -l for$~(0..pop){$_=substr$_*$~||1,-9;s/0*$//}print chop 56, Yanick Champoux -l ++$_;$_*=$x--,s/0*$//,$_%=1E5while$x||=pop;print chop 56, Ala Qumsieh -l for$i(0..pop){/(.{0,8})0*$/;$_=$i*$1||1}print/(.)0*$/ 57, Matthias Schoder -l $_++;for$i(1..pop){s/(.{1,6})0*$/$1*$i/e}print/(.)0*$/ 58, Brad Jones -l $z=pop;$_=1;while($z){s|0$||;$_=$_*$z--%1e9}print chop; 59, Tom Hargreaves for$~(++$_..pop){$_*=$~,($_)=/(.{0,6}?)0*$/}print$&x/.$/,$/ 60, Roberto Natella -l for$n(++$_..pop){$_*=$n,($_)=/(.{0,9}[^0])0*$/}print chop 60, Dave Hoover -l for$a(++$_..pop){$_*=$a;($_)=/(.{0,5}[^0])0*$/}print/.$/g 61, Scott Hall

Edition 2007-01-09 top secret / strictly confidential page 148 of 520 Perlgolf History

-l $Z=1;map{($Z)=($Z*=$_)=~/(.{1,9}?)0*$/}1..pop;print chop$Z 61, zImage -l $_=1;for($b=pop;$b;){/(.{0,6}?)0*$/;$_=$1*$b--}print/(.$)/ 63, Oleg $_=1;for($m=pop;$m;){s/([^0]{1,5})0*$/$1*$m--/e}/.$/;print"$& " 65, entropie -l $f=$_=$ARGV[0]||1;while(--$f){$_*=$f;s/0$//;$_%=1e6}print$_%10 66, Martin Carlsen -l map{until($_%5){$_/=5;$p/=2}$p=$p%10**5*$_}++$p..pop;print$p%10 67, Andrew Farnsworth -l $z=1;for(1..$ARGV[0]){$z=$_*substr$z,-6;$z=~s|0*$||}print chop$z 67, Phil Radden -l $z=1;for(2..pop){$_/=5,$z/=2until$_%5;$z=$z%100000*$_}print$z%10 67, Nik L -l for(($t=1)..pop){$_*=$t;$t=(/(\d*[^0])0*/)[0]%1000000}print$t%10 69, Erik Beatty ++$p;for(1..pop){until($_%5){$_/=5;$p/=2}$p=$p%10**5*$_}print$p%10,$/ 69, Ryan Zachry -l $n=pop;$_=1;while($n){$_*=$n--;s/0*$//;s/.*(.{5})/$+/}/.$/;print$& 75, Danny Rathjens -l for$n(0..pop){($_*$n+$`)=~/.$/,$_=$&for@t;$t[@t]=1}"@t"=~/[1-9]/;print$& 83, Artem Baranov $a=pop;$a+=$a?0:1;$_=100001;for$b(1..$a){$_*=$b;/(\d{6})0*$/;$_=$1}print/(.)0*$ /,$/ 89, W Geldenhuys -l $i=pop;$_=$i?$i:1;while(--$i>0){$_*=$i;s/.*(\d{4}[1-9])0*/$1/}s/.*([1- 9])0*/$1/;print 93, Kristen Thelen -l $n=pop;$p=1;for($i=1;$i<=$n;++$i){$f=$i;while($f%5==0){$f/=5;$p/=2}$p=$p%1e5 *$f}print$p%10 99, Dr. Mu -l $r=1;for(2..pop){$_/=5,$t-- until$_%5;$_/=2,$t++until$_%2;$r=$r*$_%10}$r=$r*2%10while$t--;print$r 126, Jeremy Madea -l $}=1;for(1..shift){while(not$_%2){$_/=2;$i++}while(not$_%5){$_/=5;$i-- }$}=($}*$_%10)%10}while($i){$}=($}*2)%10;$i--}print$}

4.7.3. Artistic/Unorthodox Solutions Hole 1 (Factorial) 66, pom

Edition 2007-01-09 top secret / strictly confidential page 149 of 520 Perlgolf History

for($a=$ARGV[$_++];$a>0;$_=s/0*$//*$_%100000*$a--){}print$_%10,$/; 85, Artem Baranov $b=pop;$b+=$b?0:1;$_=100001;for$i(1..$b){$_*=$i;/(\d{6})0*?$/;$_=$1}print/(.)0* ?$/,$/ 98, Markus Laire $z=pop;sub g{vec"^P\xd7\xa9\x98b\xef",pop,2} print$z<2||(1+g$z%25)*(1,3,2,4)[g 24-$z/25%25]*6*(1+g$z/625)%10,$/

4.7.4. Solutions Hole 2 (Postorder) 49, Stephen Turner s~~ @ARGV~;print$1until!s~(.)(?= |(.).+\2.*\1)~~s 49, Stephen Turner s~~ @ARGV~;print$1until!s~(.)( |(.).+\3.*\1)~\2~s 49, Rick Klement s~~ @ARGV~;print$1until!s~(.)(?=(.).*\2.*\1| )~~s 49, Eugene van der Pijll s~~ @ARGV~;print$1until!s~(.)(?=(.).*\2.*\1| )~~s 49, BoB (Best of Breed - referees) s~~ @ARGV~;print$1until!s~(.)(?=(.).*\2.*\1| )~~s 50, Wladimir Palant -l for$}(pop,pop=~/./g){s~$}(.*)|$~ $1 $}~}print// 51, Juho Snellman -l $_=pop;for$~(pop=~?.?g){s|$~(.*)| $1 $~|}print?? 51, Chris Dolan -l @ARGV[$_=pop]=~s^.^s~($&)(.*)~ $2 $1~^ge|print// 51, tinita -l $ARGV[$_=pop]=~s|.|s~($&)(.*)~ $2 $1~|eg;print// 51, Markus Laire

Edition 2007-01-09 top secret / strictly confidential page 150 of 520 Perlgolf History

-l $_=pop;for$~(pop=~/./g){s/$~(.*)/ $1 $~/}print// 53, Prakash Kailasa -l $_=pop;for$~(pop=~/./g){s|$~(.*)| $1 $~|}print/./g 53, Eric Roode -l $_=pop;for$z(pop=~/./g){s/$z(.*)/ $1 $z/}print/./g 54, Qingning Huo -l $_=pop;($~=pop)=~s}.}s~($&)(\w*)~ $2 $1~}eg;print// 55, Jukka Suomela -l $y=pop;$_=pop;$y=~s/$_(.*)/ $1 $_/for/./g;print< $y> 55, Mtv Europe s~~@ARGV~;$/=$1.$/,s~$1~ ~gwhile/(.)\D+\1.* *$/;print$/ 57, Michael Rybakin -l $_=pop;for$z(pop=~/./g){s|$z(\w*)|~\1~$z|}s|~||g^print 57, James Harvey -l s~.~@z=map/$&/?($`,$',$&):$_,pop||@z~egfor pop;print@z 57, Honza Pazdziora $_="@ARGV";s/$+/ /g,$/=$&.$/while/(\S).*\1\S* *$/;print$/ 57, Amir Karger -l $_="@ARGV";s/($&)(.*)/ $2 $1/while s/^.//;y/ //d;print 57, Ala Qumsieh $_="@ARGV";s/[$&]//,$/=$&.$/,s/$&/ /while/\w+ *$/;print$/ 58, Josef Drexler -l $_=pop;for$x(pop=~/./g){s/(.*)$x(.*)/$1 $2 $x/}print//g 59, Ross Younger -l for$}(pop=~/./g){@~=map/$}/?($`,$',$&):$_,@~,pop}print@~ 59, Jasper McCrea

Edition 2007-01-09 top secret / strictly confidential page 151 of 520 Perlgolf History

print eval'/((\w)(.*)\2(\w*))? *$/s;$_="$2$`$3 $4".pop;'x29 62, Dr. Mu -l $_=pop;for$x(pop=~/./g){s/(\w*)$x(\w*)/$1 $2 $x/}print/\w/g 63, Matthias Schoder -l $_=pop;for$a(pop=~/./g){s/^(.*)$a(.*)$/$1 $2 $a/gm}print/./g 76, Eike Grote $~=pop;sub'z{$~=~/./g;my$z=$&;$_&&z($_)for split$z,pop;print$z}z pop;print$/ 76, Bass -l $_=pop;while(/./g){$~=$&;/\G.?/;s|$~||,$o.=$~if$ARGV[0]=~/$&.*$~/}print$o 78, Alexander Onokhov -l sub f{"@_"&&(s/.//&&pop=~/$&/&&eval"f('$`').f('$'').$&")}$_=pop;print f pop 82, Aj $_="@ARGV ";print($y=$5||$1||$&),s/$y//gwhile/(.)(.)(.).*(\2\1|\1(\2)(?!.*\3))|. / 87, Guillermo Sansovic -l sub f{$_=pop;$ARGV[0]=~/[ $_]/;my$r=$&;$_&&join('',map{f($_)}split$&).$r}print f pop 88, gimbo -l s//@ARGV/;$=+=26*s/^(.)(.{$=})(.*) (.{$=})\1(.*)/$2 $4 $3 $5 $1/mwhile$=--;print/\w/g 89, me ELOISE sub f{s/.//;my($e,$o,$i)=split/($&)/,pop;$e&&f($e);$i&&f($i);print$o}$_=pop;f pop;print$/ 91, Martin Carlsen -l sub f{$i=pop||return;/[$i]/;$i=~/$&/;my($m,$r)=($&,$');f($`).f($r).$m}$_=pop;pri nt f pop 96, Keith Calvert Ivey -l s~~@ARGV~;s~(.*)(.)(.*) \2((??{"[|$1]*"}))(.*)| ~$\=$2.$\;$2&&"$3 $5 $1 $4"~ewhile/./;print@} 97, Michael Wrenn -l split//,pop;$_=pop;1while++$}<@_&/$_[$z].*$_[$}]/&&(@_[$z,$}]=@_[$},$z])||($ }=++$z)<@_;print@_ 99, Petri Mikkelä

Edition 2007-01-09 top secret / strictly confidential page 152 of 520 Perlgolf History

-l sub x{($z,$_)=@_;$z=~s/./"s~$&~\$w=$&.\$w;x substr('$'',pos),\$';x '$'',\$`~e"/ee}x@ARGV;print$w 100, Marko Nippula -l sub z{z(@_[0,3]),z(@_[2,4]),@_[1]if(@_=("@_"=~/(.*)(.)(.*) \2/,$'=~/([_$1]*)/,$'))>4}print z@ARGV 102, Jasvir Nagra sub r{pop=~/./;my$r=$&,$s=$';pop=~/$r/;my$t=$';push@_,$`,$s;$`&&&r;$t&&r($t,$s); print$r}r@ARGV;print$/ 106, Erik Beatty sub p{if(my$t=pop){$p=~s/^\w//;my$c=$&;$t=~/$c/;my$l=$`;my$r=$';p($l);p($r);$a.= $c}}$p=pop;print p(pop),$/ 108, Michael Robinson -l while(@ARGV){$_=pop;s/(.)//&&do{$o=$1.$o;pop=~/$1/;push@ARGV,$`,substr($_,0, length($`),''),$',$_}}print$o 110, Yanick Champoux sub t{if(@p&&(my$k=pop)>($m=index$ARGV[0],$p[0])){my$x=shift@p;t($m);t($k);print$x} }t 1+(@p=pop=~/./g);print$/ 121, Roberto Natella -l sub n{local($_)=@_;return if!s/.//;@_=split my$e=$&,pop;$m=length$_[0];s/.{$m}//;n($&,shift).n($_,pop).$e}print n@ARGV 125, Nik L -l sub c{my$j=shift@p;for(pop=~/(.*)$j(.*)/){if(/^.$/){$o.=$_;shift@p}else{c($_)if/ ./}}$o.=$j}@p=split//,shift;c(pop);print$o 127, Brad Jones -l sub z{if(@_>1){my($y,$x)=split/$_[0]/,pop;z(@_[1..length$y],$y).z(@_[1+length$y. .$#_],$x).$_[0]}}print z((split//,pop),pop); 131, Stanislav Svirid -l while(@ARGV){$i=pop;$_=pop;next if!$i&!$_;s/^.//;$i=~/$&/;push@ARGV,substr($_,0,$-[0]),$`,substr($_,$- [0]),$';$r="$&$r";}print$r 139, Phil Radden -l sub z{my($x,$y)=@_;my$t=substr$y,0,1;my($l,$r)=split$t,$x;return$x?z($l,substr$y ,1,length$l).z($r,substr$y,-length$r).$t:""}print z@ARGV 141, Danny Rathjens

Edition 2007-01-09 top secret / strictly confidential page 153 of 520 Perlgolf History

-l sub f{my($i,@p)=@_;$i=~/$p[0]/;my($l,$r,$t,$j)=($`,$',$&,$- [0]);@p>2?f($l,@p[1..$j]).f($r,@p[$j+1..$#p]).$t:$l.$r.$t}print f pop,pop=~/./g 156, Alistair McGlinchy -l sub t{my ($p,$i)=@_;my$f=substr$p,0,1,''or return;my($j,$k)=$i=~/(.*)$f(.*)/;$n=$j=~y///c;my($q,$r)=$p=~/(.{$n})(.*)/;t ($q,$j).t($r,$k).$f}print t(@ARGV) 165, zImage -l sub p{return$_ if length($_=shift)<2;/^./;my($a,$o,$b)=pop=~/(.*)($&)(.*)/;my($c,$d)=$_=~/$o([ $a?$a]*)([$b?$b]*)/;return p($c,$a).p($d,$b).$o}print p(shift,shift) 190, Oleg $p=pop;$i=pop;sub t{my$n=pop;$k.=$c=substr($p,$n,1);$d[$n]=1;map{$a=$_;map{$t=substr($p,$_,1); t($_)if$i=~/$c.*$t/&&!$a||$i=~/$t.*$c/&&$a and!$d[$_]}$n..length$p}0,1}t 0;print reverse($k)." " 474, Kristen Thelen ($f,$s)=@ARGV;$t=e($f,$s,length($f));p($t);print" ";sub e{my($i,$c,$d,$p,$r,$g,$h);my($k,$l,$m)=@_;return 0if($m<=0);$p- >{V}=substr($l,0,1);$p->{L}=0;$p->{R}=0;return$p if($m==1);for($i=0;substr($k,$i,1)ne substr($l,0,1);$i++){}$c=$m-$i-1;$d=$m- $c-1;$g=substr($l,1);$r=$d+1;$h=substr($k,$r);if (!$g){$p->{L}=0;}else{$p- >{L}=e($k,$g,$d);}if (!$h){$p->{R}=0;}else{$p- >{R}=e($h,substr($l,$r),$c);}return $p}sub p{my($y)=@_;return unless $y;p($y->{L});p($y->{R});print $y->{V};}

4.7.5. Artistic/Unorthodox Solutions Hole 2 (Postorder) 209, pom ($_,$i)=@ARGV;push(Q,$i);while(@Q){if(/(.)/&&($x=index($q=$Q[$#Q],$1))>=0){$l=l ength($q)-1;push(Q,substr($q,$x+1,$l- $x))if$x<$l;push(Q,substr($q,0,$x))if$x;s/(.)//;push(O,$1);}else{pop@Q;print pop@O;}}print$/;

4.7.6. Explanation by Stephen Turner Newsgroups: perl.golf Date: Fri, 9 Aug 2002 09:22:48 +0100 (BST) Subject: Re: Reflections Message-ID: From: [email protected] (Stephen Turner) On Fri, 9 Aug 2002, Tina Mueller wrote: > > i like the postorder solutions, because there are quite efficient. > the normal approach would be (what i did first, too) to > write a recursive function, because trees somehow belong to > "recursive". function(root) = root . function(child) . function(child2).

Edition 2007-01-09 top secret / strictly confidential page 154 of 520 Perlgolf History

> but then i realized that the declaration of a sub > just takes away too many space, and i remembered that a) every > algorithm can be done non-recursive and b) perl regexes are > more powerful than one might think. > the regex solution might be a little bit slower than recursive > but it needs less memory. > I liked the postorder problem because there are so many different approaches. I started with a recursive solution too (79.10): $_|=pop;$z|=pop;/[$z]/;$}+=$z=~/$&/;do$0if$z=$`;do$0if$z=$';--$}or$\=$/;print$& But you have to do everything twice for the recursion. And it's a pain to print the \n only at the end - 16 strokes are dedicated to that! People were already on about 50 by this time, so I knew I had to look for something else. Then I used the following algorithm, which is pretty much what you'd do by hand: Find the first node in the preorder. That's the last node in the postorder. Also change it to a * in the inorder. Now find the last block of letters in the inorder - that's the rightmost remaining tree. The first of those letters in the preorder is the penultimate node in the postorder. Change it to a * in the inorder as before, and repeat until you've got no more letters left. Here it is in Perl, except with \n used instead of * -l $_=pop;$ARGV[0]=~/[$&]/,$}=$&.$},s~$&~ ~while/.+ *$/;print$} It was at this point that I realised that it was better to shove the preorder and inorder together in a single string. (Incidentally, when I first read the rules, I thought the lack of specification as to the order of preorder and inorder on the command line was very odd. But it worked very well to avoid prejudicing certain algorithms.) So putting the two orders together in a single string and letting a regexp sort it out got me down to -l $_="@ARGV";$}=$1.$},s~$1~ ~gwhile/(.)\C+\1.* *$/;print$} It's a pretty good improvement from the recursive solution, but I was still 10 off the lead so I looked for a third algorithm. One of the problems with the above solution is that you're compiling the postorder back to front. Could you find the first node in the postorder first, rather than the last node first? Well, yes you can. Here's how, although I found it by staring at letters, and didn't formulate it in this language until later. The first node to be printed in the postorder is the leftmost leaf. The preorder and the inorder also print the leaves from left to right, so we just need to find a criterion for leafness. And the following turns out to be a necessary (but not sufficient) criterion for leafness: the immediately following node in the inorder, if any, must be earlier in the preorder - the point is that in the inorder, after a leaf you come back up, and in the preorder, ancestors come earlier, descendants later. Now although this isn't a sufficient condition for leafness, it turns out that the leftmost node in the inorder which satisfies this condition is always a leaf. So you can just find that node, print it out, delete it from the inorder, and repeat. This gave me 54.12:

Edition 2007-01-09 top secret / strictly confidential page 155 of 520 Perlgolf History

print s~(.)( |(.).+\3.*\1)~$2~?$1:$/while$2||s//@ARGV/ And finally, we're still going to too much effort to print the \n on the end. There's a neat trick you can play: put the \n at the beginning of the inorder, and it never satisfies the leafness condition until it's the last character left. (If you want to think of it another way, you've defined a new tree which has \n as the top node and the original tree as its right tree, which gives the correct postorder). This leads to my final solution of 49.0913: s~~ @ARGV~;print$1until!s~(.)( |(.).+\3.*\1)~\2~s Well, I didn't mean to write the whole history of my postorder solution. It just happened! But hopefully it's interesting to someone to see not only what I did but a little bit of how I thought about it. -- Stephen Turner, Cambridge, UK http://homepage.ntlworld.com/adelie/stephen/ "This is Henman's 8th Wimbledon, and he's only lost 7 matches." BBC, 2/Jul/01

4.8. TPR(0,5a) "Infix to RPN" The game started September 1st 2002 and ended September 8th 2002. Referees: Yanick Champoux, Terje Kristensen, F. Xavier Noria, Juho Snellman

4.8.1. Rules Goal The program will be given a mathematical expression written in traditional infix notation, and has to convert it to reverse polish notation (RPN). Specification The program is a filter: it must read from STDIN, and send output to STDOUT. • Input will consist of a single line, which will match /\A[\d() \t*\/+-]{1,9999}\n\z/. The input will always be a valid infix expression, as described below. • An infix expression is one of the following: 1) An integer (negative, positive or zero). Clarification: The numbers may have leading 0’s. Negative numbers will have a leading -. Positive numbers won't have a leading +. 2) Two infix expressions separated by an operator (one of * / + -). 3) An infix expression surrounded by parens. • The expression may contain whitespace in any position except between two digits. (I.e. the expression won't match /\d\s\d/). Clarification: there may be whitespace between the leading - and the first digit of a negative number. • The operators follow the standard precedence conventions of infix notation. That is, * and / have higher precedence than + and -. All operators are left-associative. • The output must consist of the same integers and operators as the input. Every integer/operator must be separated from the following one by exactly one space. The output must also be

Edition 2007-01-09 top secret / strictly confidential page 156 of 520 Perlgolf History

properly newline-terminated. No other whitespace is allowed in the output. Clarification: "the same integer" means "having the same integer value". That is, for the input token 007 you may output any of 7, 07, 007, 0007, etc. All numbers (both input and output) are considered to be in base-10. Yes, this means that 0 is valid output for -0 and vice versa. • The RPN expression must be equivalent to the original input expression. For the purposes of this hole, equivalency means that evaluating the two expressions using integer arithmetic must produce the same results. • A RPN expression is evaluated by handling the tokens of the expression from left to right. 1) A integer-token causes the value of the token to be pushed to the top of the stack. 2) An operator-token pops the two values from the top of the stack, applies the operator to the values, and pushes the result to the top of the stack. • Once all of the operators have been evaluated, there should be exactly one item on the stack. The value of that item is the result of the evaluation. Examples Input Example output 1+1 11+ 2*2+3*3 22*33*+ 2*(2 + -3)*3 2 2 -3+*3* Note that there are multiple valid solutions to most inputs.

4.8.2. Solutions 98, Eugene van der Pijll -p sub w{s/ ([@_^+-])(.*)/ $2 $1/g}sub f{s/\(([^()]+)\)/f($_=$+)/e?&f:w~w;$_}f s/\s//g/s/\d+/$& /g 99, BoB (Best of Breed - referees) -p sub w{s/ ([@_^+-])(.*)/ $2 $1/g}sub f{s/\(([^()]+)\)/f($_=$1)/e&&&f;w~w;$_}s/\s//g+s/\d+/$& /g+f 102, Rick Klement -p s//m/;y/ ^I//dwhile s^(([+-])M(?![*/])|([*/])M|m(-*\d+))(?{push _,$+})|.M\)^M^||s/m(.)/$+m/i;s/M/@_/ 103, Ton Hospel -Xlp sub c{($|--&&/\s/*s///g%/^./+/^-*\d+/?$&:c()).pop.($|--?/^[+-]/:s/// x/^[*\/]/and$".c(" $&"))}$_=c 109, pom

Edition 2007-01-09 top secret / strictly confidential page 157 of 520 Perlgolf History

-p y/ ^I//d;s/\b\D/x$&/g;s--$_=$1;s// $2 $1/while/x(.)(\PL+)/+/x([*\/])(\PL+)/;$_-ewhile/(.+)x/+/\(([^()]+)\)/ 109, Alexey Rudenko -lp $p=qr'(([^() ]|\(( |(??{$p}))*\))+)';s/\s//g;s//$1 $3 $2/while/(.*)([*\/])$p/|/(.*[\d)])([-+])$p/;y/()//d 112, Michael Thelen -lp y/()^I /^I_/d+s@^I|(?<=\w)\D@($"=" $&$\"")=~s#_(.*?)^I|(\S)([ */${":"x/\G[+-]/}]*)#$2 #;$+@eg;$_.=$";y/ //s+chop 116, Qingning Huo -p s/\s//g/s/(?/d;for(s/(?|\d)- ?\d+/<$&>/g;s/<(<[^>]+>)>/$1/||s@>([*/]|(.))<([^<>]+)>(?(2)(?![*/]))@ $3 $1>@;){}y/<>//d 121, Mark Hillebrand -lp $_="($_)";y+(-9 ^I+b-s+d;1while s*b([^b]+?)c*$_=$1;for$/qw(di eg){s- (?<=\S)([$/])(g?[^eg$/]+)- $2 $1-g}y+b-s+(-9+;$_*e 121, Chia-chi Yeh -pl s/\s//g;$_="($_)";0while s!\(([^()]*)\)!$a=$1;for(qw(*/ +- )){0while$a=~s#(\S)([$_])(.*?\S)([*/+-]|$)#$1 $3 $2$4#}$a!e 125, Mtv Europe

Edition 2007-01-09 top secret / strictly confidential page 158 of 520 Perlgolf History

-p y/) ^I/ /d;$a.=/\d/?!push o,$_:/[^(0]/+/[*\/]/&&do{push o,$/while($/=chop$a)=~//;$/.$_}x/./for/(?

Edition 2007-01-09 top secret / strictly confidential page 159 of 520 Perlgolf History

-p sub f{s/^-?\d+//?push@t,$&:s/.//+e("+-")+s///}sub e{eval$x;while(s/^[@_]//){my$p=$&;eval$x;push@t,$p}}$x='$_[0]=~/- /?e("*/"):f';s/\s//g;e"+-";s/^/@t / 162, Prakash Kailasa -lp $t='(=[^=]+=|(?<=[*-/])-\d+|\d+)';sub r{for$o(qw|*/ -+|){1while s~$t([$o])$t~$_="$1 $3 $2";y/=//d;"=$_="~e}$_}s/\s//g;1while s~\(([^()]+)\)~$_=$1;r~e;r;y/=//d 165, tinzo (berlin.pm) -pl $*='(\w+)';$/='([()+-]|^|$)';1while s/\($*\)|\s/$+/|s#([^\d)])(-\d+)|$/$*(([*/])$*|([+- ])$*$/)#"$1$3_".(push@/,$5?"$4 $7$9 $6$8":$+).$10#e;1while s#_$*#$/[$+-1]# 172, Jasper McCrea -lp sub r{$_=pop;for$r(qw{?)(\+ )(& )(\*|/}){$_="@_[0,2,1]"if@_=map r($_),/(.*$r)(.+)/}y#&-/#a-j#;$_}s/\s//g;s#(\)|\d)-#$1&#g;1while s#\(([^()]+)\)#r$1#e;$_=r$_;y#a-j#-'-/# 176, Jonathan Wang $_=<>;$_="($_)";y/ \t//d;s/\d+/ $& /g;s#([^ )])([+-]) #$1 $2#g;while(s#\(([^()]+)\)#$_=$1;foreach$a('/*','+-'){while(s! (\S+) ([$a]) (\S+) ! $1s$3s$2 !){}}$_#e){}y/s / /d;print 177, Jed Davis -l sub n{my($x)=@_;bless\$x,'main'}use overload(map{my$o=$_;$o,sub{n($_[2]?"$o$_[0]":"$_[0] $_[1] $o")}}qw{+ - * /}),'""',sub{${$_[0]}};$_=<>;s/-/- /g;s/\d+/n("$&")/g;print eval 203, Eike Grote -lp s/\s//g;s/(?);$_="($_)";1while s!\(\s*([^(]+?)\)!$a=$1;map{1while$a=~s#((^|[*/+-]\s*)(- ))?\s*(\w+)\s*([$_])\s*(-?)\s*(\w+)\s*#$h{A.++$i}="$3$4 $6$7 $5";"$2A$i"#e}'*/','-+';$a!e;1while s|A\d+|$h{$&}|;print 209, nashdj

Edition 2007-01-09 top secret / strictly confidential page 160 of 520 Perlgolf History

-l $e=qr{(??{$t})(([+- ])(??{$t})(?{push@_,$2}))*};$t=qr{(??{$f})(([*/])(??{$f})(?{push@_,$2}))*};$ f=qr{\((??{$e})\)|((-|)\d+)(?{push@_,$1})};$_=<>;s/ |\t//g;1while(s/\(\(([^)])\)\)/($1)/);$_=~$e;$,=' ';print@_ 210, Ala Qumsieh -pl s/\s//g;%p=qw|*2/2+1- 1|;/\d/?push@_,$_:/\(/?push@@,$_:/\)/?do{push@_,$*while'('ne($*=pop@@)}:do{p ush@_,pop@@while$p{$@[-1]}>=$p{$_};push@@,$_}for/(?<=[\d)])[*\/+-]|- ?\d+|./g;@_=(@_,reverse@@);$_="@_" 267, Honza Pazdziora -n close STDERR; s!(^|[(*/+-])\s*(-?)\s*(\d+)!$1 d("$2$3")!g; $_=`$^X -MO=Deparse,-p -e'$_'`; print map({ if (/\d/) { ' 'x($i++>0).$_; } elsif (/\)/) { $i++;shift@a; } else { /\(/?(unshift@a,''):($a[0]=" $_");(); } }/-?\d+|[-*+\/()]/g),@a,' ' 292, Constantin M $s='-+*\/'; $d='-?\d+'; $_=<>; s/\s+//g; @_=(m/(^$d|(?)=~s/\s//g;s/(^|[-+\/*(])- (\d+)/$1_$2/g;@l=split/([-+\/*()])/;for(@l){s/_/- /g;/\d/&&push@o,$_;/\(/&&push@s,$_;if(/\)/){while(defined($x=pop@s)and'('ne$ x){push@o,$x}}if(/^[- +\/*]$/){while($p{$s[$#s]}>=$p{$_}){$x=pop@s;push@o,$x}push@s,$_}}while($x=p op@s){push@o,$x}print join' ',@o 1666, André Savigne

Edition 2007-01-09 top secret / strictly confidential page 161 of 520 Perlgolf History

eval eval '"'.

'\\$_=\\"\\@\\{[<>=~/\\\\'.('`'|'$').'+|\\\\'.('{'^'(').'/'.('`' |"'").']\\}\\";'.('['^'(').';(?<=[^\\\\'.('`'|'$').')]'.('{'^'[' ).(( '-') ).(( ')') ).(# Ovian Joy `/anick Champoux '{'^ '{'^ '[') .';' .';' .''. ('`' |"\'"). (';').( '['^"\("). ';^-'.('{' ^'[').';-;;'. ('`'|('-')).( '`'|'!').("\["^ '+').'\\{\\$'.( '['^'#').'.=/\\'. '\\'.('`'|('$')). ('/?\\$_.\\$\\":'). "'"."'".';\\$,=/\\' .'\\(/.\\$,;/\\\\)/' .'&&(\\$,=~'.(('[')^ '(').'/(.*?)'.("\^"^( '`'|"\/")).'//,\\$'.( '['^"\#").'.=\\$+);'.( '`'|')').('`'|'&').'(' .'/[-+*\\\\/]\\$/)\\{'. '\\$,=~'.('['^'(').'/.' .'.//,\\$'.('['^'#').'.' .'=\\$&'.('['^',').('`'| '(').('`'|')').('`'|','). ('`'|'%').'\\$,&&\\$,

4.8.3. Artistic/Unorthodox Solutions 141, Rick Klement -p sub o{print$"x$|++,shift} sub f{s/^-*\d+//?o$&:e(s/.//)+s/.//} sub t{f;o$&x1,f while s+^[*/]++} sub e{t;o$&x1,t while s/^[+-]//} ey/^I//d 142, Rick Klement -p sub o{print$"x$|++,shift} sub f{s/^-*\d+//?o$&:e(s/.//)+s/.//} sub t{f;o$&x1,f while s+^[*/]++} sub e{t;o$&x1,t while s/^[+-]//} ey/^I//d 158, Eugene van der Pijll -lpX use base B::Deparse;s/-/$:/g;s/\d+/a$&/g;sub maybe_parens{$_=$_[1];s/ (.*) (.*)/ $2 $1/;y/ /_/;$_}$_=main->new- >coderef2text(eval"sub{$_}");y/_ -';-}/ /d 193, TheodoreYoung

Edition 2007-01-09 top secret / strictly confidential page 162 of 520 Perlgolf History

-l package A; use overload '""'=>sub{${$_[0]}}, 'neg'=>sub{n A "-$_[0]"}, 'nomethod'=>sub{n A "@_[0,1,3]"}; sub n{my $c=$_[1];bless \$c} $_=; s/(-?)[0 ]*(\d+)/ $1 A->n($2)/g; print eval;

4.8.4. Explanation by Michael Thelen Newsgroups: perl.golf Date: Mon, 9 Sep 2002 13:11:51 -0600 Subject: Explanation of solution Message-ID: <[email protected]> From: [email protected] (Michael W Thelen) Hi all, Here's an explanation of my solution. Sorry this is so long, but hopefully it's clear. It might not be, because in the course of analyzing it, I discovered that I didn't understand every detail of my solution as well as I thought I did. Corrections are welcome! I went with the first algorithm I found in a Google search, which uses an stack of operators and operands. Like pom, at some point I realized that the desired output could be achieved just by moving the operators around, so my stack deals only with operators and parentheses (no operands). Here's the full solution, which I will break down into parts. I've replaced literal tab characters with \t for readability. #!perl -lp y/()\t /\t_/d+s@\t|(?<=\w)\D@($"=" $&".$")=~s#_(.*?)\t|(\S)([ */${":"x/\G[+- ]/}]*)#$2 #;$+@eg;$_.=$";y/ //s+chop Part 1, #perl -lp -l Use line processing (strips newline from input, adds newline to output). -p Automatically loop over <>, and print $_ after each iteration (i.e., once). Part 2, y/()\t /\t_/d Delete all whitespace, and convert "(" to "\t", ")" to "_". The reason for converting parentheses will become clear later. Part 3, s@\t|(?<=\w)\D@ ... @eg; The main processing happens inside this substitution. The left-hand side of the substitution looks for operators and parens. These will be replaced with whitespace and operators off the stack. Remember that \t represents opening parens. All operators and closing parens must be non-digits that follow a digit or a closing paren. This avoids matching unary -, which must follow an operator or an opening paren. A single-char lookbehind does the trick. Here is the reason why ")" was converted to "_"... so this lookbehind could simply match \w to get digits and closing parens. Part 4, ($"=" $&$\"")=~s#_(.*?)\t|(\S)([ */${":"x/\G[+-]/}]*)#$2 #;$+ $" is used as a string representation of the stack. The stack grows in reverse order (to the left) so that operators can easily be "popped" from the beginning of the string using a simple substitution. The

Edition 2007-01-09 top secret / strictly confidential page 163 of 520 Perlgolf History

current operator is in $&, and it's pushed on the stack with ($"=" $&$\""). ($"=" $&".$") does the same thing, but I like the weird interpolation of $". Then the stack is popped in one of two ways: 1. If $" contains a closing paren ("_"), then $& must have contained a closing paren, so pop everything up to the most recent opening paren. Place everything but the parens back in the original string by matching them and returning $+. 2. Otherwise, $& contains either an operator or an opening paren ("\t"). a. If $& is an operator, then pop all operators with equal or higher precedence. Do not pop opening parens. (\S) matches the operator that was just pushed (we don't want to pop that one yet). Always pop "*" and "/". Only pop "-" if $& is "+" or "-". "+" does not need to be popped from the stack (discovered by accident) because addition is commutative. Since $& is overwritten at this point, check for "+" or "-" using /\G[+- ]/. The ${...} construction will interpolate the contents of either $: or ${''} (" \n-" or undef, respectively), depending on whether the match is true. $: is used in order to get the character class to match "-" (there are no newlines on the stack, and matching whitespace is fine). $+ will contain all the matched operators and whitespace. b. If $& is an opening paren, then leave it on the stack and return only whitespace. (\S) will match the first operator if there are any on the stack (this is why "(" was changed to "\t", because it must not be matched here, and \S is very short). The character class will only match [ */]. Since two consecutive * / ops cannot be on the stack, and the whitespace will be replaced on the right-hand side, this is okay. $+ will only contain whitespace, or undef if there were no operators on the stack. Part 4, $_.=$";y/ //s+chop The final cleanup stage. If there is anything left on the stack at the end, append it to $_. Since whitespace was handled rather sloppily, we must also squash consecutive space characters into single spaces. Finally, chop off the final character, which is always a space. This is why $" was chosen to represent the stack... it will contain whitespace even if the regex was never evaluated (i.e., the input contained no operators). And the right-hand side of the main regex ensures that the stack will always have whitespace at the end. -- Mike -- Michael W. Thelen eval unpack u,'M*"1C/22\A+48O82UZ+SME=F%L*"1C+B(G=2HGM+"

4.8.5. Explanation by Eugene van der Pijll Newsgroups: perl.golf Date: Mon, 9 Sep 2002 00:07:01 +0200 Subject: Re: Some random reflections on tpr05a Message-ID: <[email protected]> From: [email protected] (Eugene van der Pijll) En op 08 september 2002 sprak Tina Mueller: > the thing which is interesting for me with every new hole is > the algorithm. (i have yet to understand eugene's one =)

Edition 2007-01-09 top secret / strictly confidential page 164 of 520 Perlgolf History

The algorithm is nothing special. It's just hard to see what's happening because of the compactness of my shortest solution. The winning solution: -p sub w{s/ ([@_^+-])(.*)/ $2 $1/g}sub f{s/\(([^()]+)\)/f($_=$+)/e?&f:w~w;$_}f s/\s//g/s/\d+/$& /g Rewritten: -p sub w{ s/\n([@_^+-])(.*)/ $2 $1/g } sub f{ s/\(([^()]+)\)/$_=$+;&f/e ? &f : w(~w); $_ } s/\s//g; s/\d+/$&\n/g; f What happens is this: First, all whitespace is removed. Then every operator is marked by a newline. This newline indicates that this operator has not yet been put into RPN: 1+2*3+4*(5+6)+7 => 1\n+2\n*3\n+4\n*(5\n+6\n)+7\n The "\n" precedes each operator, but not always directly. When there are parens, it's inside them. This is not a problem for my algorithm, since it deletes the ()'s and leaves the \n's alone. Now the parenthesised expressions are resolved, starting with the innermost expressions. The logic is similar to that of 1 while s/\(([^()]+)\)/$_=$+;&f/e; The result is: 1\n+2\n*3\n+4\n*56+\n+7\n The function w is called twice: once without arguments, and once with an argument. w() without argument puts the multiplications (but only those preceded by \n's) in the proper order: 1\n+23*\n+456+*\n+7\n and w called with an argument treats the additions: 123*+456+*+7+\n Interestingly, this use of \n as a marker was not my idea at all, it just haoppened. My idea was to use two markers, to indicate the parts of the expression that were already in RPN. To start with, this would mean only the numbers: a1z + a2z * a3z + a4z * (a5z + a6z) + a7z and then to remove those markers as soon as a part of the expression was put into RPN:

Edition 2007-01-09 top secret / strictly confidential page 165 of 520 Perlgolf History

=>a1z+a2z*a3z+a4z*a56+z+a7z =>a1z+a23*z+a456+*z+a7z =>a123*+z+a456+*z+a7z ...=>a123*+456+*+7+z Look at my 175.67 solution to see how that worked. This solution contained the regexp m#z([*/])a(.*?)z# . Notice the non-greedy match, which could also be written as a([^z])z. When I replaced the end marker with a newline, I could just use (.*). And then I didn't need the –l command switch. And it had a better tie-break score. And later, I tried to remove the begin marker 'a', and it worked! This was a big but not unwelcome surprise. So my final solution used a different algorithm than my first, and that happened purely by coincidence. I didn't even know how my solution actually worked before I started writing this mail. OK, this is probably more than you wanted to know, but "To write is to delete, and this post wasn't worth the effort to delete", as a wise man once said [1]. (-ugene [1] Herman Finkers -- The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague. -- (-dsger |)ijkstra

4.9. TPR(0,5b) "String to Number" The game started October 5th 2002 and ended October 12th 2002. Referees: Ala Qumsieh, Geoff Hubbard, Jasper McCrea, Eugene van der Pijll

4.9.1. Rules Goal Your program will receive one number on the standard input, written out, e.g. 'one', 'two' or 'sixteen thousand'. It should convert this string to a number, and write it to the standard output. Specification The program is a filter: it must read from STDIN, and send output to STDOUT. • Input will consist of a single line, which will match /\A[a-z]+( [a-z]+)*\n\z/. This means that the input will consist of one or more words separated by single spaces, and each word will only contain lowercase letters. • The input will be an American-English name of a whole number between zero and nine hundred ninety nine billion nine hundred ninety nine million nine hundr ed ninety nine thousand nine hundred ninety nine. These numbers will satisfy the following conditions: 1) hundred, thousand, million and billion are separate words. They are always preceded by a lower number (for example one hundred), never by the word 'a'. 2) A billion is a thousand millions, 109.

Edition 2007-01-09 top secret / strictly confidential page 166 of 520 Perlgolf History

3) Numbers between twenty one and ninety nine are not hyphenated. This also holds for compound numbers like twenty one thousand. 4) Numbers above one thousand will not be written as multiple of 100: nineteen hundred is invalid input. 5) The word and is not used. • Your program need not test the input for validity, and its behavior on invalid input is not important. • The output should be a single line, matching /\a[,\d]+\n\z/, and be the numerical representation of the input number. The digits should be separated in groups of three by commas, starting at the back. Examples Input: zero Output: 0 Input: eight Output: 8 Input: twenty four Output: 24 Input: one hundred sixty Output: 160 Input: twelve million three hundred thousand Output: 12,300,000

4.9.2. Solutions 109, ton (post-mortem) -lp040 $^+=$^%1e3*(9x(3*y/dbl/W/- 4*/e/))||/te|W/.vec(crypt(DjcSj30,$_),12,4).e./y/}$_=$^;{s/\B(?=(...)*$)/,/g 112, BoB (Best of Breed - referees) -lp040 $@+=$@%1e3*(9x(3*y/dbl/\xe4/- 4*/e/))||/te|\xe4/././*$+['^A^S^\^I^O^Z^V^L^G'!~($&^o&$')].e./y/}{$_=$@;s/\B (?=(...)*$)/,/g 115, Ton Hospel -lp040 $^+=$^%1e3*(9x(3*y/dbl/\xe4/- 4*/e/))||/te|\xe4/././*$+['^A^S^\^I^O^Z^V^L^G'!~($&^o&$')].$[x/y/}$_=$^;{s/\ B..\d\b/,$&/&&redo 116, Rick Klement -lp040 $@+=y/ma- d/6392/?$@%1e3*/\d/*(9x$&):/.{5}e/.'\x87\xd0\xd1\xf8\xf2\xc2\xce\xe2r\xde\xe 5'=~pack(H2,$_)*$+[0].e./y/}{$_=$@;s/\B(?=(...)+$)/,/g 119, Mtv Europe -lp040 $a=/a|ll/?($b|='000,'x y/bis//.$a)x0:0*y/htfsleno/025- 9/x/y/.$_%98%38%23%17 ./28|7/|0 x2x/d/.$a}{$_=reverse$b|$a 130, Juho Snellman

Edition 2007-01-09 top secret / strictly confidential page 167 of 520 Perlgolf History

-lp071 s/te|lv/ q/g;s%(.*?)$&\w*%+($+)*1E0$/ %gi,--$/while b__m__THoHuyzOnwThFofSisEiiqv=~/[(-^]*./g;$_-=eval;s/.(?=(...)+$)/$&,/g 131, Stephen Turner -pal $*+=9x(3*/b|d/+6*/ll/- /^h/)*($*%1e3)||/te|l/.2*/s|w|th/+/ne|fi|ev|th/+4*/s|f/+8*/g|^n/.$|x/y/for@F ;s/\B..\d\b/,$&/for($_=$*)x3 139, Michael Thelen -lpa /[a- dm]/?$;=3*$+[amb!~$&]||$;+2:($,+=/te|l/.$+[/../,ontwthfofisiseeini!~$&]/2+/l e/.$?x(/y/+$;))while$_=pop@F;$_=$,;s/\B(?=(...)+$)/,/g 139, Alma Media Golf Team -pl s/[bam]/)*1E$&+(/g;for$,(qw/one w h.?r fo fi x se g in te|lv le/){++$";s/$,/+$"/g}y/zyma-x /00639 0/d;$_=eval"($_)";s/\B(?=(...)+$)/,/g 140, Keith Calvert Ivey -lpa $*+=/a|io/?($@+=$**1e3**y/bit//,- $*):/te|l/.8*/g|^n/+4*/f|s/+2*/s|w|th/+/ne|th|fi|ev/.$%x/y/+99*/d/*$*for@F,a ;$_=$@;s/\B(?=(...)+$)/,/g 141, Michael Rybakin -apl /(b|li|nd$)/?$^+="$~e".(9-$- [$~=0]):$~+=/d/?$~*99:/(te|lv)/.(1+index"\x87\xd0\xd1\xf8\xf2\xc2\xce\xe2r- \xe5",pack+H2,$_)*10**/y/for@F;$_=$~+$^;s/.(?=(...)+$)/$&,/g 149, Greg Allen -pla s~.*d|ll~$:*=/o/?!($;+=$:*1e3**y/bid//):100~e,$:+=/.[nwvf]./+/w|f/+/th|f/*3+ /s/*6+/[en]i/*8+10*/te|el/.$?x/y/for@F;$_=$;+$:;s/.(?=(...)+$)/$&,/g 152, Jeff Moore -pal /b|mi|ho/and$y=12-3*$+[0]or$z+=/te|lv/.(/../+index onthfisenielztwfosiei,$&)%0xc.e.(($y+=y~d~~)+/y/)for reverse@F;$_=$z;{s~\w+(?=\w{3})~$&,~&&redo} 156, Josef Drexler -pal $r.=/tho|mi|b/g?")*1E".3*(4- pos)."+(":/hu/?E2:'+'./tee|lv/.index(zeontwthfofisiseeiniteel,/../&&$&)/2*10 **/y/for@F;$_=eval"($r+0)";s/.(?=(...)+$)/$&,/g 160, Philippe Bricout -pl s!(.*?)(b|mi|tho)!"+($1)*1E".(4-length$2)*3!eg;s/ h/00/g;y/y/0/;s#[a- z]+#$_=$&,'+'./te|lv/.(1+index"x^]\x8f/,\xec.'_^",pack h2,$_)#eg;$_=eval;s/.(?=(...)+$)/$&,/g 162, Karsten Sperling -pal $,=($==4- index+fCclHpD5tmbz14vJr6dLQRyUE0ZFSkwi,unpack+x8a,crypt$_,BJ)<0?$,-($=<- 19?18+$=.0:$=):$=<4&&($"|=reverse$,,",000"x$=)?0:"$,00"for@F,ai;$_=reverse$" 164, Wladimir Palant

Edition 2007-01-09 top secret / strictly confidential page 168 of 520 Perlgolf History

-lap /(..)./,thomilbil=~$&?($,+=$~*10**$+[0],$~=0):(zeontwthfofisiseeiniteel=~$1? $~+=$-[0]/2*10**/y/+10*/lv|een/:($~*=100))for(@F);$_=$,+$~;$,while s/\B\d{3}\b/,$&/ 166, Alexey Rudenko -lp $q=$2,s/((.*?)$1[a-z]*|(.*;))/$+$q/g while'z0 bi; mi; tho;;,1000tee+10 h00y0te10lv+10tw2el11th3fo4si6f5s7o1n9e8 +'=~/(.+?)([^a-z ;]+|;)/g;$_=join',',eval;s/,1/,/g 169, Amir Karger -lp y/ /+/;for$=(qw/\+h b m tho lv|teeyzotwthf1fsiseinte E/){s/$=\w*/(qw(y.y E9 E6 E3 +t *t),0..11,"0)*1$&+(")[$;]/ge,$;++}$_=eval"($_)";s/\B(?=(...)+$)/,/g 171, Danny Rathjens -lap y/mb/sn/,/../,$@+=zeontwthfofisiseeiniteel!~/$&/?$@*=50:($;=$- [0]/2,/y/?10*$;:/lv|een/?10+$;:/.{7}/?([email protected] x$;,-$@):$;)for@F;$_=$n+$@;1 while s/(?<=\w)\w{3}\b/,$&/ 174, Arne Georg Gleditsch -lp ($~='( h00bE9mE6thoE3tw2th3fo4se7ei8z0o1f5s6n9t10e)11y0een|lv+10 +')=~s/[+- E]+/push@_,$&;')|('/ge;s/\b($~.)/$_[$#-- 2]/g;s/E./0)*1$&+(0/g;$_=eval"($_)";s/\B(?=(...)+$)/,/g 179, Michael Wrenn -lap map{s/te*n/+10/;s/fo/d/;y/ysieth/0/d;s/lv.*/o+10/;s/[bla][^l]*/000/g&&s/\D*/ )*1$'+(/;s/^(\w)[a-z]*/+$+/;y/zowrdfxvgn/0- 9/;s/.u/*100/}@F;$_=eval"(@F)";s/.(?=(...){1,}\b)/$&,/g 179, Sheldon Fuchs -pl for$0(qw~^/( te|lv/+10 le/11 b|m|tho/)*10**$&+( hu/*100+ $/) w/2 th/3 fo/4 fi/5 m|si/6 se/7 g/8 b|in/9 ne/1 y|z/0+ [a-z\s]/ \+\)/) .+/$&/ee \d(?=(\d{3})+$)/$&,~){eval"s/$0/g"} 181, tanma -pl @e{ze,on,tw,th,fo,fi,si,se,ei,ni,te}=0..10;y/amb/369/;s/(.+?)\S*(\d)/+($1)*1 :$+/g;s/ h/yy/g;s/el/onte/g;s/\b[a-z].|te/+$e{$&}/g;y/:ya- z/e0/d;$_=eval;pos=y///c%3||3;s/\G.../,$&/g 183, Prakash Kailasa -lp @@{zeontwthfofisiseeiniteelm=~/..?/g,a,b}=(0..11,6,3,9);@:=map'*100'x/^h/||/ a|m|b/&&")*1e$@{$&}+("||'+'.1x/lv|.te/.@@{/../,$&}.0 x/y/,/\w+/g;$_=eval"(@:)";1while s/\B...(,|$)/,$&/ 185, Eike Grote -lp s/hu/00/g;s/een/+10/g;s/wel/12/g;$_="\$_=( $_)";for$b(ho,mi,b){$k+=3,s/$b/)*1E$k+(/}for$u(zeontwthfofisiseeiniteel=~/.. /g){s/ $u/+$%/g,$%++}y/ya-z /0/d;eval;s/.+?(?=(\d{3})+$)/$&,/g 192, Michiel van Leeuwen

Edition 2007-01-09 top secret / strictly confidential page 169 of 520 Perlgolf History

-apl map{s/ho|^m|^b/${$&}=$r;$r=0/e;$t=11;for$q qw(el te ni e se s fi f th tw o z){s/^$q/$t/;$t-- }$r=($r+($_+/te|lv/*10)*10**/y/)*100**/hu/}@F;$_=sprintf",%03d"x4,$b,$m,$ho, $r;s/[0,]+//;$_||=0 193, TheodoreYoung -lp $"='|';@_{@_=qw/thombhtwelzotwthfofsiseint e/}=(map(")*10**$_+(",3,6,9),'*100',map"+$_",12,0..11);s/een/+10/g;s/y/*10/g ;s/(@_)\w*/$_{$1}/g;s/.+/"($&)"/ee;s/.(?=(...)+$)/$&,/g 196, Benoît Chauvet -pla @,{'JZ^X\xbc\xaaT)^Q\xb2O\x87\x97kp\xe9^H\xd5Q^\xb3\xa44"A^V\x8a\x9f\xf2\xfc n\xf1'=~/./g}=(1..20,map$_.0,3..10,1E5,100,1E8);map{$,=$,{$_=chr 8*/n/+unpack'%8C*',$_};$*=y!\xfcn\xf1!!?!($;+=$**$,):/\xf2/?$**$,:$*+$,}@F}{ $_=$*+$;;s;.(?=(...)+$);$&,;g 197, Isaac Lin -pl map{for$.(o,tw,th,fo,fi,'si|m',se,ei,'n|b',te,el){$~=$-if$- ++,/^$./}(/y/?$~.=0:/een|lv/?$~+=10:!/d|ll/)?$^+=$~:/^h/?$^*=100:($:+=$^*10* *$~,$^=0);$-=0}split;$_=$:+$^;1while s/(\d+)(\d{3})/$1,$2/ 204, Scott Hall -alp $,=join"|",%,=se7x6g8w2hr3hi3fo4f5ni9ne1le1=~/(\D+)(.)/g;%@=(ho,1,'m',6,b,9) ;map{/$,/;$;+=$,{$&}*10**/y/+10*/te|el/;$;*=100**/d/;/ho|m|b/and$;*=10**$@{$ &},$:+=$;,$;=0}@F;$_=$;+$:;s!.(?=(...)+$)!$&,!g 208, gimbo -lap map{$.=0;$_=$.+=20..80?10:1for@t{'l\xbe\0^D\xbc\x94\x83\xe1\x84\x87?WaB3J\xb 9\xcd^Rw(pZA\xa04\xa9$^PPE"RL\xc7'=~/./g};$.=$.*3+ord for//g;$s=($n=$t{chr$.%248})<91?$s+$n:$s.0 x($n- 89);$t+=$s,$s=0if$n>91}@F;$_=$t+$s;1while s/(\d)(...($|,))/$1,$2/ 210, tinita -lp @\xa7=(qw{?y ?e.nhzo.wo|.wen th[^o] fo f si s ei n te e twtmb*10 +10 *100},(map"+".$_,0..12),map")*1e$_+(",3,6,9);s/\b$\xa7[$\xa7++]\w*/$\xa7[$\xa7+ 18]/gwhile$\xa7<19;$_=reverse eval"($_)";$_=reverse join",",/..?.?/g 211, Yanick Champoux -pl for(reverse split){$y.=0 x(/ed/*(2-($i=length$y)%3)+/y/*!($i%3)or 3*/b|a/+6*/io/- $i);for$i(%n=z0one1wo2hr3fo4fi5x6se7g8ni9ten01le11lv21wen2ir3een1=~/\d+|\D+/ g){$y.=$n{$i}x/$i/}}$y=~s/...\B/$&,/g;$_=reverse$y 222, Ross Younger -lap sub F{my$x;++$x,$_[0]=~/$_/&&last for qw{on wo th fofxsgiteev t}}$t+=$b=$c*(/b/?1e9:/m/?1e6:/a/?1e3:0),$c=$b?0:/d/?$c*100:/y/?$c+10*F($_)% 100:/een/?$c+10+F$_:$c+F$_ for@F;$_=$t+$c;0while s/(?<=\d)...(?!\d)/,$&/ 231, Matt Johnson

Edition 2007-01-09 top secret / strictly confidential page 170 of 520 Perlgolf History

-alp @~=qw~h thombtwelzotwthfofsiseinte~;@:{@~}=(qw~*100+ )*1e3+( )*1e6+( )*1e9+(~,12,0..11);for(@F){s/y/*10+/;s/een/+10/}for$~(@~){map{s/^$~\w+/$:{$~ }/}@F}$_="(@F)";s/\+ *\)/)/g;$_=eval;1while s/(\d+)(\d{3})/$1,$2/; 234, Eric Roode -apl %v=split/(\d)/,on1tw2th3fo4fi5si6se7ei8ni9el1tho1mil2bil3;*q=\$a[0];for(@F){ /((..).)/;if($m=$v{$1}){$a[$m]=$q;$q=0;$b||=$m}else{$a=$v{$2}+10*/te|l.?v/;$ q+=$a+$a*9*/ty/;$q*=100if/dr/}}$_=$a[$b];$_.=sprintf',%03d',$a[$b]while$b-- >0 237, Marius Ascheberg -lpa $f=1;@h{z,o,'tw(o|en)','th[^o]',fo,fi,si,se,ei,n,te,el,twel,h,tho,mi,b}=(0.. 12,1e2,1e3,1e6,1e9);map{/^$r/and$t>12?($f=$t>$f?$t:$f*$t):($g+=$f*(/een/?10+ $t:$t)*(/y/?10:1))while($r,$t)=each%h}reverse@F;$_=$g;s/[\d,](?=(\d{3})+$)/$ &,/g 246, Joe Baldassini -apl for(@F){$e=/^b/?9:/^m/?6:/sa/?3:0;$a+=$e?$c*10**$e:0;$c*=/^h/?100:$e?0:1;$d= /le/?11:/^te/?10:/^n/?9:/^e/?8:/^se/?7:/x/?6:/^fi/?5:/^fo/?4:/hr|hi/?3:/w/?2 :/^o/?1:0;$d*=/y$/?10:1;$d+=/lv|een/?10:0;$c+=$d}$_=$a+$c;1while s/^(- ?\d+)(\d{3})/$1,$2/ 253, Chris Dolan -lp y/euhi//d;s/ty/0/g;s/(\w+)tn/1$1/g;split/ /," zro on tw.n? tr for ff|fv sx svn gt? nn tn lvn twlv";s/$x/$#_/gwhile$x=pop@_;split/ /," n t m b";($x=pop@_)&&s/([^^I]*) $x/($1)*1e$#_^I/gwhile@_;s/\s+([^)])/+$1/g;$_=eval;1while s/(\d)(..\d)\b/$1,$2/ 258, Phil Radden -lp $~=$,="";1while s# ?\b(\S.)\S*$#($_=$&)=~/ed/&&($,=substr("00$~",- 2).$,,$~="");/ho|il/&&($}=",000"x(/s/?1:/m/?2:3),$,=$}|substr((" "x20).$~.$,,- length$}),$~="");$}=index('zeontwthfofisiseeiniteel',$1)/2,$~+=/lv/?12:/y$/? $}*10:/ee./?$}+10:$},""#e;$_=$~.$, 278, entropie -l $s=<>;for$a(" b"," m"," tho",''){$k=($s=~s/(.*)$a\w*//?$1:'');$i=12;for$,qw(twel el tenesesifi fo th tw o z){$k=~s/\b$,[^t ]*(ty|teen)?/$i$1/g;$i--}$_=$k;$o.=','.(s/(.) h\w+//?$1:'0');s/(.)teen/1$1/;s/(.)ty( .)?/$1*10+$2/e;$o.=sprintf"%02d",$_}$o=~s/^[0,]*//;print $o||0 285, Danny Sadinoff -lap for(@F){/(ho)|(mi)|(bi)/&&do{$$_ and$n*=1e3**$_ for 1..3;$a+=$n;$n=0;next};s/hu/$n*=100;next/e;$o=0;/te[ne]/and$o=10;/(on)|(wo)| (th)|(fo)|(fi)|(si)|(se)|(ei)|(ni)|()(le)|(lv)/&&do{$$_ and$o+=$_ for 1..12};/ty/&&do{$o=2if/tw/;$o*=10};$n+=$o}$_=$n+$a;1while s/^(- ?\d+)(\d{3})/$1,$2/ 302, Stanislav Svirid

Edition 2007-01-09 top secret / strictly confidential page 171 of 520 Perlgolf History

-nl @d=qw(z o tw th fo fi si se ei n te el);%h=qw(tho3m6b 9);for(split/\s/){$r+=$s*"1e$h{$1}",$s=0,next if/\b(tho|m|b)/;$s*=100,next if/\bh/;$f=1;$q=$_;$e=grep{$f&&($q=~/^$_/?$f=0:1)}@d;$e*=10 if/ty\b/;$e+=10 if/(een|lve)\b/;$s+=$e if$e>=0;}$r+=$s if$e>=0;1 while$r=~s/(\d+)(\d{3})/$1,$2/g;print$r; 310, Jeremy Leader -apl %n=(6,3,34,6,79,9);map{$x*=100if/^h/;$s=$j=248;map{$s^=++$j*ord}split//;$s%= 90;for($q=20;$q*((map{-32+ord}split//,"`+5EHa!8\"*?#Tn32(Ck]")[$q- 1]ne$s);$q--){};$q=$q||{5,30,49,40,87,50,0,60,30,70,42,80,38,90}- >{$s};$x+=$q if$q;$y+=$x*10**$n{$s},$x=0if$n{$s}}@F;$_=$y+$x;while(s/([^,])(...)(,|$)/$1, $2$3/g){} 315, Matt Diephouse -l %s=qw(d2y1t3m6b9);map{$$_=2+$s++}qw(tw th fo fi si se ei ni);$_=<>;s/\n/ /;while(s/(.+?(m|t|b)\S+(on|d)|.+)\s//){$n=$1;$p=$2;$f+=10**($s{$p}+$s{$4})* (($1=~/z/?0:$$2||1)+($1=~/ten|([^s]..en|lve)/&&($1?10:9))||0)while$n=~s/((.. )(.*?(y|d|n)|\S+))\s//}$_="$_,$1"while$f=~s/(.+?)((...)*)$/$2/;s/ ?,//;print; 315, IainT -lp $"='\w+';s/b/1e9/;s/m/1e6/;s/il$"//g;s/tho$"/1e3/;s/(($" hu$" )?$"( $")?) (1e.)/($1)*$4+/g;s/hu$"/*100/g;s/ty/*10/g;s/tee?n/+10/;s/twel$"/+12/g;s/tw$" /+2/g;s/el$"/+11/;s/ni$"/+9/g;s/ei$"/+8/;s/six/+6/g;s/s$"/+7/;s/fi$"/+5/g;s/ f$"/+4/g;s/th$"/+3/g;s/one/+1/g;s/(z.+|\+)$/+0/;$_=eval;1while s/^(\d+)(\d{3})/$1,$2/ 332, ocbMaurice $_="zeontwthfofisiseeiniteel";$n{$&}=$C++while s/..//;%o=(hun=>100,tho=>1000,mil=>10**6,bil=>10**9);foreach(split(" ",<>)){$w=$o{substr($_,0,3)};if($w){if($l>$w){$z+=$c;$c=0}$c=($c+$p)*$w;$p=0 ;$l=$w}else{$m=$n{substr($_,0,2)};$m*=10if/ty$/;$m+=10if/een|wel/;$p+=$m}}$_ =($z+$c+$p);while(s/\d{1,3}$//){$q=$&.$Q.$q;$Q=','}print$q."\n"; 346, GONZO -lap %e=qw(zr 0 oe 1 to 2 tr 3 fu 4 fv 5 sx 6 sv 7 eg 8 nn 9 tn 0 ee 1 te 2 ti 3 fr 4 ff 5 b 9-$s m 6-$s o 3-$s u 2-$s%3 y 1-$s%3,$e{$k},2-$s%3 1 0,"1$e{$k}",2 0 0,$e{$k},1);while($_=pop@F){/(.).(.)/;$k=$1.$2;$K=/(b|m|y)|h(u|o)/?$+:/el|te /?1:0;eval"r($e{$K})"}sub r{($a,$b,$c)=@_;$o=$b.0 x$a.$o;$s+=$c?$c:$a}$_=$o;1while s/(\d)(\d{3}(,|$))/$1,$2/ 369, Johannes Singler

Edition 2007-01-09 top secret / strictly confidential page 172 of 520 Perlgolf History

for(split/ /,<>){ ^I$i=1; ^Iforeach $d(qw/o tw(o|en) th(i|r) fo fi si se ei n te el twel/){ ^I^Iif(/^$d/){$x+=$i;} ^I^I$i++; ^I} ^Iif(/tee/){$x+=10;} ^Iif(/ty/){$x*=10;} ^Iif(/^h/){$y=$x*1e2;$x=0;} ^Iif(/^tho/){$n+=($x+$y)*1e3;$x=$y=0;} ^Iif(/^m/){$n+=($x+$y)*1e6;$x=$y=0;} ^Iif(/^b/){$n+=($x+$y)*1e9;$x=$y=0;} } $_=$n+$x+$y; s/\G(\d{1,3})(?=(?:\d\d\d)+(?!\d))/$1,/g; print $_,"\n"; 384, Mike Vyricheck $_=; $_=" $_"; ~s/(\w+)een/1$1/g; ~s/(\w+)ty/$1*10/gx; foreach $k (map qr/$_/, map '([\s\d])'.$_.'\w{0,}', qw(z o tw(o|en) th[ri] fo fi si se ei n ten el twel)){ ~s/$k/$1$i/gx;^I $i++; } ~s/\sh\w+/*100/g; ~s/(\d)\s(\d)/$1+$2/g; ~m/((.*?)b\w+\s?)?((.*?)m\w+\s?)?((.*?)t\w+\s?)?(.*)?/; map eval('$r.=",".sprintf("%03d",'.$_.")"),($2,$4,$6,$7); $r=~s/^[0,]+(.+)/$1/; print $r."\n"; 462, pk -ln @p=split/ /,'bi mi tho hu irty rty fty xty venty hty ety wen et hte nte xte ft urt rt twe el te ni ei se si fi fo th tw on z'; @l=split/ /,'))*1000000000+((+0 ))*1000000+((+0 ))*1000+(+0 )*100+(+0'; for$i(30..90){push@l," +$i"if($i%10==0)};for$i(0..20){push @l," +".(20-$i)}; for$r(@p){$l=shift@l;s/[a-z]*$r[a-z]*/$l/g;} $_=eval"(($_)"||eval"($_)"||eval"($_))"||eval"(($_))"; s/(.)(...)$/$1,$2/g; s/(.)(...,)/$1,$2/g; s/(.)(...,)/$1,$2/g if length>11; print; 482, Matthias Schoder -ln %n=(billion,1E9,eight,8,eighteen,18,eighty,80,eleven,11,fifteen,15,fifty,50, five,5,forty,40,four,4,fourteen,14,hundred,100,million,1E6,nine,9,nineteen,1 9,ninety,90,one,1,seven,7,seventeen,17,seventy,70,six,6,sixteen,16,sixty,60, ten,10,thirteen,13,thirty,30,thousand,1E3,three,3,twelve,12,twenty,20,two,2) ;$r=$n=0;while(/(\w+)/g){$t=$1;if($t =~ /^(m|b|tho)/){$r+=$n*$n{$t};$n=0;}elsif($t=~/^h/){$n*=100;}else{$n+=$n{$t}}} $r+=$n;$_="$r ";1while s/(\d)(\d\d\d) /$1 ,$2/;s/ //;print

Edition 2007-01-09 top secret / strictly confidential page 173 of 520 Perlgolf History

4.9.3. Artistic/Unorthodox Solutions 206, TheodoreYoung -lpa $"='|';@_{@_=qw/thombhtwelzotwthfofsiseint e/}=(map(")*10**$_+(",3,6,9),'*100',map"+$_",12,0..11);$_=eval'('.join('',ma p {@_{/^(@_)/},/een/&&'+10',/y/&&'*10'}@F).')';s/.(?=(...)+$)/$&,/g 386, GONZO -lap $_='zr0oe1to2tr3fu4fv5sx6sv7eg8nn9tn0ee1te2ti3fr4ff5b9-$sm6-$so3-$su2- $s%3y1-$s%3,2-$s%3,$e{$k}s0,2,"1$e{$k}"k0,1,$e{$k}';1 while s/^([a- z]+)(\d)|^((?:[-\d%{}",]|\$.)+)([a- z]+\d|$)/push@e,$1.$3;$+/e;%e=@e;while($_=pop@F){/(.).(.)/;$k=$1.$2;$K=/(b|m |y)|h(u|o)/?$+:/el|te/?'s':'k';eval"r($e{$K})"}sub r{($a,$b)=@_;$o=$_[2].0 x$a.$o;$s+=$b?$b:$a}$_=$o;1while s/(\d)(\d{3}(,|$))/$1,$2/

4.9.4. Explanation by Ton Hospel Newsgroups: perl.golf Subject: Re: I'll explain mine if you explain yours Date: Sat, 26 Oct 2002 18:00:51 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) In private mail I've gotten a request to explain my solution and what my "searcher" does in these postmortem solutions. I decided answer it here in case other people are interested. Let's start with the basic solution as I have it on the scoreboard The first observation is that input may looks like: xxx billion yyy thousand zzz so I'd like at some point to e.g. collect the yyy, then when I see the "thousand", I want to multiply it by 1000 and add it to the xxx billion I already have. After some experimenting and counting lengths, I decided I want to keep the "working value" in one variable, so at the moment I see the "thousand", the working variable will contain: xxx billion yyy and I want xxx billion yyy thousand which I can get by adding 999*yyy, and the yyy I can get with accumulator%1000 Shortly after that I realized this can handle "hundred" too, even if one hundred does not "finish" a group. so a basic core of my solution will be: if(thousand|million|billion|hundred) { $a += (number-1) * ($a%1000) } else { do normal < 1000 collection } The do_normal will also contain a $a+= (to add the xxx to the accumulator), so in more golfish style we get:

Edition 2007-01-09 top secret / strictly confidential page 174 of 520 Perlgolf History

$a+=$a%1000*(number-1)||normal_stuff which assumes that $a%1000 is never zero in the thousand|million|billion|hundred case. Which is ok since the input is things like "one thousand", not things like "thousand" or "zero thousand". It also assumes that (number-1) is zero in the "normal number" case. number-1 is respectively 9 nines, 6 nines, 3 nines or 2 nines. How to generate that ? Like I said, I was originally only considering billion, million and thousand, so I wanted to generate 3,2 and 1 times 999. And I noticed that billion and million had two l's, so I decided to go count unique characters, and came up with y/abl// to get the 3,2,1. Unfortunately "eleven" and "twelve" also contain the letter l. These two however also contain "e" and "v", so we can compensate for that if we subtract at least 1, so: y/abl/-/e/ However, now I also want to handle "hundred". 99 is not a multiple of 3, so instead of 3,2,1 i want 9,6,3 for the basic three cases. So multiply by 3 and get ( now add the 9 multiplier too): 9x(3*y/abl/-3*/e/) In this form it's clear that that "3" may also be a bigger number (it's ok if eleven and twelve lead to a negative number instead of to 0). The "hundred" contains an "e", so it will do the /e/ subtraction. That's good, since we don't want "hundred" to lead to a multiple of 3, so we can change the "3" to get some other values. Since we are going to subtract at least 4, the 3*y/// must lead to at least 6, so we need characters that are unique to "hundred" appearing at least twice in total. So that leads us to consider "d". However, "thousand" also has a "d". Oh! But that's just as useable as "a", so we get: 9x(3*y/dbl/-4*/e/) (And no other number like seventeen or twenty or whatever will make this expression non-zero) Next step is to handle the normal stuff (everything < 100). There is quite a bit of regularity there. • if it ends on "ty" (in fact, if it contains "y" at all), it's a number times 10. We can get that by e.g. putting a "0" at the end of our number. • if it ends on "teen" it's some number+10. In fact, if it contains "teen" at all. No! Even "tee" is enough. And if we consider "ten" a special case, even "te" is good enough. And the number in number+10 will be a single digit in all cases. So we can get that by simply putting "1" in front • All other numbers are either single digit (zero, one, etc), or we have (again) the exceptional cases of "eleven" and "twelve". Fortunately both are easy to recognize from e.g. the "l" in there. So that leads to something like: • If the middle term leads to 1 and 2 for "eleven" and "twelve": /te|l/.(handle_simple_number).0 x/y/ • If the middle term leads to 11 and 2 for "eleven" and "twelve": /te|lv/.(handle_simple_number).0 x/y/ (other cases exist but do not seem interesting) So let's look at the simple numbers:

Edition 2007-01-09 top secret / strictly confidential page 175 of 520 Perlgolf History

zero one two three four five six seven eight nine (ten) (eleven) (twelve) They are not unique in the first letter, but they are unique in the first two letters. But not from the third letter on, since we want to get e.g. 5 for both "five" and "fifty", and 2 for both "two" and "twenty". Twelve is interesting in that if we look only at the first two chars, it always is the same as "two", so will give us a 2 (that's why I only considered formulas that map 12 to 2 above). Ok, so the next step is a search for an expression that takes exactly the first two chars from a string, and returns the correct number for them. One obvious method is to make a little table, and just look it up. E.g. in one of my early attempts I used /..//2*$-[zeontwthfofisiseeiniQQel!~$&] However, it's clear to see that the constants string is very long. It would be nice if we could somehow combine the first two chars so the lookup table is twice as short and doesn't need the /2. Rick went for pack(H2,$_) as the combiner, I went for matching the first char with /./ and then doing bitoperations on $& and the first char of $' to create a unique character for each of thesimple numbers. The first idea is to simply use $&&$', but unfortunately that does not give a different char for each word. So I used some bitflipping to make them unique. In the end I went for: ($& ^"o")& $' Many other ways are possible, unfortunately whatever way I chose, the lookup table always contained non \w characters, so I could not drop the quotes around the lookup string. So I just went for the lowest tie-break. I'll use V instead of o here since it leads to more readable chars. My initial versions were: /./+index(')"4 &37%.Q!',$&^V&$') These leave out the "zero" lookup to make the table one shorter. They also map "ten" to a non-possible char, so I can use /te|lv/ instead of /tee|lv/. It would be nice if "eleven" automatically mapped to "1", since then I can simply leave out the last two characters. But in fact, we can! The y/dbl// allows us to replace the l by something else. "l" is the second letter of "eleven", so the combiner for "eleven" will change, but it's only the fourth letter in "twelve", so that one will not change. And we can choose this something else not to exist in any simple number and such that it will combine for "eleven" to the same character as "one" does. For better tiebreaker I also write the index as a $+ lookup, and get: y/dbl/\xe4/ and /te|\xe4/././*$+['^A^S^\^I^O^Z^V^L^G'!~($&^o&$')] The final step is to commify the resulting number, where I used the suboptimal $_=$a;{s/\B..\d\b/,$&/&&redo All that combined with a little tie break improvement leads to:

Edition 2007-01-09 top secret / strictly confidential page 176 of 520 Perlgolf History

-lp040 $^+=$^%1e3*(9x(3*y/dbl/\xe4/- 4*/e/))||/te|\xe4/././*$+['^A^S^\^I^O^Z^V^L^G'!~($&^o&$')].$[x/y/}$_=$^;{s/\ B..\d\b/,$&/&&redo Which was my final submission. However, I still was not very happy with how I went from "to first chars" to corresponding number, and I had noticed that in fact "crypt" sort of does what I want: crypt($pass, $salt) takes the first two chars from $salt, then does some des-like encryption on $pass (modified by the salt-chars) and then returns a string representation of this result. So the idea was to find some interesting $pass, such that if I somehow make a number out of the result string the same mapping is done. Making a number is not so hard with things like: vec(crypt($pass, $_), $o, $b) unpack(N, crypt($pass, $_)) unfortunately these numbers will be all over the map (especially in the unpack("N", ..) case). So to improve the chances to find a good $pass, I decided to add a modulo so that more output numbers can give the result we want. While the challenge was still running I decided to concentrate on vec(crypt($pass, $_), $o, 4)%$m So I wrote a program that tries all $pass strings consisting of \w chars and starting with a-zA-Z_ or - as $pass. It then does the crypt with "nine" and sees on which positions ($o) the result is exactly 9, and if there is such a case, continues with 8, 7 and 6. After that point we can make 5 either directly or with 15%10, so it also starts keeping track of possible modulos. Unfortunately "crypt" is pretty slow, even if you code this program in C. So while I had the idea a few days before the challenge ended, my searcher found nothing while it was still running. A few minutes after the end I found this very lucky hit: k= zrQ0W,o=16,b= 4,m=10:0,1,2,3,4,5,6,7,8,9,0,8 which you can check with the following perl code: perl -wle 'print join",", map vec(crypt(zrQ0W,$_),16,4)%10, qw(zero one two three four five six seven eight nine ten eleven)' And it indeed prints: 0,1,2,3,4,5,6,7,8,9,0,8 And we still have that trick to modify "eleven" in the y/dbl// up our sleeves, so we can use that fixup that last 8 to a 1. So we get: (adding a few Rick/Bob improvements): $^+=$^%1e3*(9x(3*y/dbl/Q//-4*/e/))||/te|Q//.vec(crypt(zrQ0W,$_),16,4)%10 .e./y/}$_=$^;{s/\B(?=(...)*$)/,/g Unfortunately this string has two big drawbacks: • the offset is 16, while it would be nice to need only one digit. • The 8 at the end causes us to need that Q as compensation. Another char lost After that I got interested in how fast you can make crypt, and in particular started looking at "john the ripper", http://www.openwall.com/john/ Unfortunately that program does not have a direct "crypt", but generates a kind of intermediate code. Then you also convert your target password string to that intermediate code and then do the compare.

Edition 2007-01-09 top secret / strictly confidential page 177 of 520 Perlgolf History

So I wrote some code to undo that, and for the rest stole the implementation from that code wholesale, and put that in a program that does a smart search over the possible $pass values (smart in the sense that it tries to give up on a particular key as fast as possible so it won't do useless crypts). Once I had that, I started searching for cases that would not have a two-digit offset or that would not need to fixup the "eleven" case. Unfortunately none of these exist in the 5-char $pass space. And to gain in the 6-char space, both must be true. I finished searching the 6-char space a few days ago, and no, none exist where both are true, though this one was close: k= _IEhBI,o=11,b= 8,m=10:0,1,2,3,4,5,6,7,8,9,0,1 (This is not yet completely certain. I have in fact not yet searched the space consisting of pure numbers like -1.2e-4 or 123456) So next I decided to try to get rid of the modulo at the end completely. Since the 6-char space was already completely searched, I'm now trying for vec(crypt($pass, $_), $o, 4) in the 7-char space. The search-space is so big, I didn't really expect success, but in fact after three hours I ran into: k=DjcSj30,o=12,b= 4,m=16:0,1,2,3,4,5,6,7,8,9,0,5 Which again has both drawback (offset two digits and eleven is wrong), but still gains because it has no modulo this time: $^+=$^%1e3*(9x(3*y/dbl/W/- 4*/e/))||/te|W/.vec(crypt(DjcSj30,$_),12,4).e./y/}$_=$^;{s/\B(?=(...)*$)/,/g Chances are good a string exists with a one-digit offset and not needing fixup for "eleven", but, if so, I haven't found it yet. I plan to keep running this program in the background as my private strtol@HOME though. If you are interested in the C-code of the current searcher, you can find it at: http://www.xs4all.nl/~thospel/ASIS/zlet5.tar.gz The current version is for x86-mmx, though it's easy enough to get it to work on other processors by compiling john the ripper and replacing arch.h by the processor specific arch.h file john will give you. This program might contain the fastest known existing implementation of full forward crypt (the pure crypt part does 530000 crypts/second on my Athlon XP1800+). I'm very interested if anyone knows anything faster (I'm in fact wondering about bryDES). (the openssl fcrypt does 120000/sec, glibc ultra- fast-crypt does 40000/sec) Compile it with some high optimisation, put a start string in a file (e.g. I used A000000) and run it with that filename as argument (it will update that file ever so often to mark where it will start now). On my athlon XP1800 it works through a 5-char block in about 1 hour. (the code I had during the challenge needed about 12 hours for that). The code does about 440000 crypts/second, so the overhead is reasonable. It can't be made much faster unless I improve the crypt().

4.10. TPR(0,6) "The Burrows-Wheeler Transform" The game started November 12th 2002 and ended November 19th 2002. Referees: Andreas Schaumeier, Mtv Europe, Prakash Kailasa, Ton Hospel PGAS Master: Yanick Champoux

Edition 2007-01-09 top secret / strictly confidential page 178 of 520 Perlgolf History

4.10.1. Rules This month we are going to decode a string mangled with the Burrows Wheeler Transform1. Please don't be scared by the somewhat long motivation that follows, even if you are a beginner. At the end you will be shown a few pretty simple algorithms Motivation The Burrows-Wheeler Transform (BWT) is a method that takes a block of text as input and rearranges it using a sorting algorithm. The unexpected thing is that the transform is reversible (which you normally don't expect. "Sort" rarely comes with an "unsort"). The result of the transform is a block of text where consecutive letters are very often the same, so it can be easily compressed with even very naive algorithms. The bzip22 program is based on this. So how does it work? It's pretty easy in fact. Let's assume the input text is "DRDOBBS". Write the string and all rotated versions under each other like this: DRDOBBS(row 0) RDOBBSD(row 1) DOBBSDR(row 2) OBBSDRD(row 3) BBSDRDO(row 4) BSDRDOB(row 5) SDRDOBB(row 6) Next sort rows: BBSDRDO(row 4) BSDRDOB(row 5) DOBBSDR(row 2) DRDOBBS(row 0) OBBSDRD(row 3) RDOBBSD(row 1) SDRDOBB(row 6) And finally, write down the last column: "OBRSDDB". Also note that the D in the last column of the second-last row (that's the new row 5 or the old row 1) is the D that starts the word "DRDOBBS". These two together are the result of the transform: "OBRSDDB" and 5. It's pretty unexpected that this transform is reversible. One way to do that is to recover the (row n) lines in the sorted table. Let's first try to recover the sorted table a bit. We obviously already know: ...... O ...... B ...... R ...... S ...... D ...... D(row 1) ...... B In fact, we also know the first column, because it's just the letters in the last column, but sorted:

1 http://www.wikipedia.org/wiki/Burrows-Wheeler_transform 2 http://sources.redhat.com/bzip2/

Edition 2007-01-09 top secret / strictly confidential page 179 of 520 Perlgolf History

B.....O B.....B D.....R D.....S O.....D R.....D(row 1) S.....B But this helps a lot! From the row labeled with "(row 1)" we now know that R follows that D (remember that the strings were rotated, so the letter in the first column follows the letter in the last column). So if we know that the R is the first letter in row 1, we also know it's the last letter in row 2. So we can now extend our table to: B.....O B.....B D.....R(row 2) D.....S O.....D R.....D(row 1) S.....B Now repeat the same reasoning for the row labeled "(row 2)" We see that the letter after R must be a D which corresponds to row 3. We already have one of the D's labeled, so it must be the other one. And let's repeat this process: B.....O(row 4) B.....B D.....R(row 2) D.....S O.....D(row 3) R.....D(row 1) S.....B Oops, here we run into a problem. We know from the row labeled "(row 4)" that the letter after O is a B, but there are two of them in the last column. After which one should we write "(row 5)"? To answer that, consider the letters that follow each B. By looking at a B in the last column and looking at the corresponding letter in the first column, we know they are B and S respectively. And since all rows are sorted, we in fact know: BB....O(row 4) BS....B D.....R(row 2) D.....S O.....D(row 3) R.....D(row 1) S.....B This B and that S in the second column of course also occur in the first column somewhere (on the second and last row in fact), and since the first column is also sorted, they occur in the same order, B first (on the second row) and the S later (on the last row), and they each have a B in their last column). So after this subtle bit of reasoning we get to a very simple rule: if you have repeated letters in the first row (the B in BB and BS), they correspond to that same letter in the last row in exactly the same order. So the lines in a picture like this will never cross:

Edition 2007-01-09 top secret / strictly confidential page 180 of 520 Perlgolf History

The B in the first column of row one corresponds to the B in the last column of the second row, and the B in the first column of the second row corresponds to the B in the last column of the last row. Let's go back to our question. We had O which was followed by B due to the top row. This is the first B in column 1, so it corresponds to the first B in the last column, the one on the second row. Therefore that's the one we must label with "(row 5)". So we get: B.....O(row 4) B.....B(row 5) D.....R(row 2) D.....S O.....D(row 3) R.....D(row 1) S.....B The rest is simple (don't forget that after row 6 we get row 0, not row 7): B.....O(row 4) B.....B(row 5) D.....R(row 2) D.....S(row 0) O.....D(row 3) R.....D(row 1) S.....B(row 6) And finally we write down the first letters from the rows labeled "(row 0)", "(row 1)", ..., "(row 6)" and we get "DRDOBBS" Algorithms Algorithm 1 Wow, that was hard! Or was it? Let's redo the exercise using the special rule we found: "All occurrences of the same letter in the first column will correspond to all occurrences of that letter in the last column in the same order" (see the picture where this rule is demonstrated if the letter is B). Then we can start with the encoded string with below it the sorted string and position 5 marked: OBRSDDB BBDDORS In the sorted string at the bottom we see the first R marked. Now mark the first R in the top string (and the D below it): OBRSDDB BBDDORS So now we have the first D below marked. Now mark the first D at the top and the O below it (forget the old mark):

Edition 2007-01-09 top secret / strictly confidential page 181 of 520 Perlgolf History

OBRSDDB BBDDORS First O at the bottom marked, mark first O at the top: OBRSDDB BBDDORS First B at the bottom marked (this also happens to be the first time we are processing a B, but "first" here means it's the first B in the string "BBDDORS"), mark the first B at the top (that is, the first B in the string "OBRSDDB"): OBRSDDB BBDDORS Second B at the bottom marked, so mark the second B at the top: OBRSDDB BBDDORS First S at the bottom marked, mark first S at the top: OBRSDDB BBDDORS Second D at the bottom marked, but when we mark the second D at the top, we see we are back at the original: OBRSDDB BBDDORS When we look at each of the letters we marked at the top in order, we see: "DRDOBBS" Algorithm 2 Another way is to observe that if you know the first few columns in the sorted table, you can fill in the last column too. And since the letters in the last column are prefixes of the string you already have in a row, you can move that letter to the front, and you get a set of strings that must also be in the sorted table (but not sorted yet). Sort them, and we are in the start situation again, but all strings are one letter longer. This leads to the following method: First write down a column consisting of the encoded string: O B R S D D B Then sort it: B B D D O R S Now write the encoded string in front of that again:

Edition 2007-01-09 top secret / strictly confidential page 182 of 520 Perlgolf History

OB BB RD SD DO DR BS And sort it again: BB BS DO DR OB RD SD Repeat prefixing and sorting until you get: BBSDRDO BSDRDOB DOBBSDR DRDOBBS OBBSDRD RDOBBSD SDRDOBB Now take row 5, and move the D at the end to the front, giving: DRDOBBS Many more algorithms exist of course. Maybe they even lead to shorter programs... Specification On STDIN you get one line consisting of a number (representing the start offset), a tab and a string consisting of uppercase characters and commas with a length between 2 and 999 (this is the string you have to decode) followed by a newline. So the input matches /^(0|[1-9]\d{0,2})\t[A- Z,]{2,999}\n\z/. The offset number represents the character that will be the first character of the output (counting starts at zero, and the number will be less than the string length, you don't have to handle invalid input). You must write the properly newline terminated decoded string to STDOUT. Nothing should appear on STDERR. The returncode of the program does not matter. We use normal ASCII sorting, so a comma sorts before all letters. So if you get on STDIN: 5\tOBRSDDB The output should be: DRDOBBS

4.10.2. Solutions XXXXXXXXXXXXXX?, ton XXXXXXXXXXXXXXXXXXXX? 54, Stephen Turner

Edition 2007-01-09 top secret / strictly confidential page 183 of 520 Perlgolf History

-pl @==sort@$=map$_.shift@=,@@for@@=/\pL|,/g;$_=@$[$_] 54, Rick Klement -lp @p=sort@@=map$_.shift@p,@=for@==/\pL|,/g;$_=@@[$_] 54, Jeff Moore -lp @==sort@p=map$_.shift@=,@@for@@=/,|\pL/g;$_=@p[$`] 55, Petri Mikkelä -lp @_=sort@$=map$_.shift@_,@@for@@=/[,=-_]/g;$_=$$[$_] 55, Jasper McCrea -lp @==sort@$=map$_.shift@=,@@for@@=/[=-o,]/g;$_=@$[$_] 55, Michael Rybakin -lp @@=sort@$=map$_.shift@@,@=for@==/[,=-_]/g;$_=@$[$_] 55, Alexey Rudenko -lp /\D/g;@s=sort@t=map$_.shift@s,@/for@/=//g;$_=$t[$`] 57, Terje K -pl @@=map$_.(sort@@)[$@++%@=],@=for@==/\pL|,/g;$_=@@[$_] 58, Michael Wrenn -lp @@=map$_.(sort@@)[$@++%@=],@=for@==/[A-Z,]/g;$_=@@[$_] 59, Chris Dolan -pl @==sort@_=map$_.@=[$@++%@@],@@for@@=/[,=-_]/g;$_=@_[$_] 62, Michael Robinson -pl @$=@$?map@@[$@++%@@].$_,sort@$:@@for@@=/[A-Z,]/g;$_=$$[$_] 62, Benoît Chauvet -lp @==@=?map$@[$c++%@@].$_,sort@=:@@for@@=/[^^I\d]/g;$_=$=[$_] 62, gimbo -lp @,=@,?map$.[$l++%@.].$_,sort@,:@.for@.=/[A-Z,]/g;$_=$,[$_] 63, Amir Karger -lp @@=map@_[$@++%@@].$_,sort@@for@@=@_=/\pL|,/g;$_=@@[$_];chop 63, Amir Karger, Amir Karger -lp @@=map@_[$@++%@@].$_,sort@@for@@=@_=/\pL|,/g;$_=@@[$_];chop 64, Bass -pl @;=map$$[$;++%@$].$_,sort@;for@;=@$=/[;-o,]/g;$_=$;[$_];chop 64, Eugene van der Pijll -pl @$=sort map$_.shift@$,@@for@@=/\pL|,/g;$$[$_]=~/.$/,$_=$&.$` 64, Eugene van der Pijll -pl @$=sort map$_.shift@$,@@for@@=/,|\pL/g;$$[$_]=~/.$/;$_=$&.$` 65, Qingning Huo

Edition 2007-01-09 top secret / strictly confidential page 184 of 520 Perlgolf History

-pl map{s=^=$o[$o++%@$]=for+sort@$}@o=@$=/[A-Z,]/g;$_=$$[$_];chop 65, Danny Rathjens -lp @$=sort map$_.shift@$,@@for@@=/[A-Z,]/g;$$[$_]=~/.$/;$_=$&.$` 66, szeryf -pl @$=sort^Imap$_.shift@$,@_^Ifor/^I/+1..split//,$';$_=$_[$`].$$[$`] 66, Adam Antonik -lp /^I/g;{@_=sort map$_.shift@_,@@for@@=/./g}$_[$`]=~/.$/;$_=$&.$` 67, Paul van Eldijk -alp split//,@F[1];@@=map$_.(sort@@)[$@++%@_],@_ for@_;$_=@@[@F[0]] 67, Mark Hillebrand -lp @B=@A=/[A-Z,]/g;@B=map$A[$i++%@A].$_,sort@B for 2..@A;$_=$B[$_] 68, pom -lp /^I/;@==sort map$_.shift@=,@;for@;=$'=~/./g;$=[$_]=~/.$/;$_=$&.$` 68, Daniel Tuijnman -lpa split//,$F[1];@$=map{@$=sort@$;$_.shift@$}@_ for@_;$_=$$[$F[0]] 69, Ala Qumsieh -pl @$=sort map$_.$$[$i++%@@],@@for@@=/[A-Z,]/g;$$[$_]=~/.$/;$_=$&.$` 72, Smylers -lp s/.+^I//;split//;@,=sort map$_.shift@,,@_ for@_;$,[$&]=~/.$/;$_=$&.$` 72, Giovans -lp /\t/;split??,$';@b=sort map$_.shift@b,@_ for@_;$_=$_[$`].$b[$`];chop 73, Lars Mathiesen -lp /^I/g;map$_=$l++.$_,sort@_=/./cg;s/\d+/$_[$&]/while~$l--;s///;s/.^I.*// 74, Jaska Kivelä -pla map{$t=0;@o=sort@o;$o[$t++]=~s/^/$_/for@s}@s=$F[1]=~/./g;$_=$o[$F[0]] 74, Jasvir Nagra -lp /^I/;@n=@l=split//,$';@l=map{$n[$i++%@n].$_}sort@l for@n;$_=$l[$`];chop 75, Eike Grote -lp ($@,$_)=split;$j=0,@@=map$$[$j++].$_,sort@@for@@=@$=/./g;$_=$@[$@],chop 75, Martien Verbruggen -lp /\t/;@_=sort map$_.$_[$/++%@;],@;for@;=split'',$';$_[$`]=~/.$/;$_=$&.$` 76, Peter Haworth -pla for(@y=@x=$F[1]=~/./g){$q=0;s/^/$x[$q++]/for@y=sort@y}$_=$y[$F[0]];chop 77, Joe Baldassini -alp @s=@p=split//,pop@F;for(2..@s){$s=0;s//$p[$s++]/for@s=sort@s}$_=$s["@F"] 78, Scott Hall

Edition 2007-01-09 top secret / strictly confidential page 185 of 520 Perlgolf History

-nla print map$.[@F=$a[$a="@F"],$a],@a=map{y.1..}sort map$_.1x$a++,@.=/,|\pL/g 83, Alain "TopMach" Dupuis -lpa for(@o=/[;- r,]/g){$r[$r++%@o]=~s/^/$_/for@o;@r=sort@r}$r[$F[0]]=~/.$/;$_=$&.$` 83, Olivier Blanchard -l $_=<>;/\t/;{@r=@t=$'=~/./g}for(2..@r){$r=0;@r=map{$t[$r++].$_}sort@r}print$r [$`] 85, BigrTex -lp @s=/[,A-Z]/g;for(@s){@_=sort map{$s[$_].$_[$_]}0..$#s}$_=substr$s[$_].$_[$_],0,-1 85, TilRMan -alp split//,$F[1];for(@_){my$i;$a[$i++]=~s//$_/for@_;@a=sort@a}$a[$_]=~/.$/;$_=$ &.$` 86, Nicolas Mendoza -pla for($F[1]=~/./g){@o=sort@o;$r=0;for($F[1]=~/./g){$o[$r]=$_.$o[$r];$r++}}$_=$ o[$_] 87, Marius Ascheberg -pl s/.+^I//;eval'$a[pos]=$&.$a[pos]while/./g;@a=sort@a;'x y///c;$_=chop($a=$a[$&+1]).$a 93, Jacco Braat -011 $x=<>;for(@_=sort map"$_"x++$!,@x=split/|\n/,<>){print$x[$x];$x=- 1+length$_[$x]}print' ' 94, Erik Beatty -an007 @a=sort map{$b[$_].$a[$_]}0..$#b for@b=split"",$F[1];print chop$a[$F[0]],$a[$F[0]],"\n" 95, pieman $_=<>;($o,$_)=split;@e=/./g;for(1..@e){@w=sort@w;$w[$_]=~s/^/$e[$_]/for 0..$#e}print$w[$o],"\n" 96, Mike Barton -pa for(@s=split//,$F[1]){$j=0;map{$r[$j++]=$_.$r[$j];}@s;@r=sort@r;}$_=$r[$_];s /(.*)(.)/$2$1\n/ 99, Andrew Williams -lnapF\t split//,$F[1];for(@s=("")x@_){$i=0;@s=sort map{$_[$i++].$_}@s}$_=$s[$F[0]];s/(.+)(.)/$2$1/ 103, Frantisek Darena -pa ($n,$_)=@F;@b=sort@a=/./g;for$r(2..@a){$i=0;$_=$a[$i++].$_ for@b;@b=sort@b}$b[$n]=~/.$/;$_="$&$`\n" 109, Thomas Bätzler

Edition 2007-01-09 top secret / strictly confidential page 186 of 520 Perlgolf History

-na $j=$_;@f=sort{$a->[0]cmp$b- >[0]}@l=map{[$_,$i++]}split//,$F[1];map{print$l[$j][0];$j=$f[$j][1]}@l;print $/ 114, Jason Carter -lna split//,$F[1];@o=sort@_;for(2..@_){$o=0;for(@o){s/.*/$_[$o++]$&/;}@o=sort@o; }for($o[$F[0]]){/.$/;print$&,$`;} 130, IainT -ln ($t,$s)=/(\d+)\t(.*)/;@x=0..(length$s)- 1;for(@x){$t[$_]=substr($s,$_,1).$t[$_]for(@x);@t=sort@t}$_=$t[$t];print/(.) $/,/(.*).$/ 185, Jason Purdy -l ($n,$e)=(=~/(.+)\t(.+)\n\z/);@o=split'',$e;@m=sort split'',$e;while(++$w<@m){for($i=0;$i<@m;$i++){$m[$i]=$o[$i].$m[$i];}@m=sort @m;}$m[$n]=~s/(.+)([A-Z,]{1})/$2$1/;print$m[$n];

4.10.3. Artistic/Unorthodox Solutions 88, Bass -pl for$f(sort{$s[$i++]=$a cmp$b}@c=/[;-o,]/g){$o.=$c[$_];$i=0;@c=sort{$s[$i++]}@c}$_=$o 131, Benoît Chauvet -lp s/.*^I//;$==$&;@==sort@@=/./g;$_=join'',map{$_=$l;$l=$$l;/./;$&}map{${$:=$_. ${$_}}=$;.push@{$;=shift@=},${$_}++;$l=$=--?$l:$:}@@ 136, Terje K -pl $i=$_; $p[$x++]=$c{$_}++for@i=/\pL|,/g; $c{$_}=$s+0+!($s+=$c{$_})for",",A..Z; $o=$i[$i].$o,$i=$p[$i]+$c{$i[$i]}for@i; $_=chop($o).$o

Edition 2007-01-09 top secret / strictly confidential page 187 of 520 Perlgolf History

5. Games - Terje’s PGAS season 0 Terje Kristensen’s http://terje.perlgolf.org/ and lately http://terje2.frox25.no-ip.org/

5.1. The Archeologists' Dilemma http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=0&season=0 The game started 2002-08-17 00:00:00 and ended 2002-08-20 00:00:00.

5.1.1. Rules An archeologist seeking proof of the presence of extraterrestrials in the Earth's past, stumbles upon a partially destroyed wall containing strange chains of numbers. The left-hand part of these lines of digits is always intact, but unfortunately the right-hand one is often lost by erosion of the stone. However, she notices that all the numbers with all its digits intact are powers of 2, so that the hypothesis that all of them are powers of 2 is obvious. To reinforce her belief, she selects a list of numbers on which it is apparent that the number of legible digits is strictly smaller than the number of lost ones, and asks you to find the smallest power of 2 whose first digits coincide with those of the list. Thus you must write a program such that given an integer, it determines the smallest exponent E such that the first digits of 2**E coincide with the integer (remember that more then half of the digits are missing). ex: input = 1. 4 is not a solution (2**4 = 16) because since more than half the digits are missing the number must be of 3 digits or more. 7 (2**7 = 128) is the first valid solution. Input The input will consist of one argument ( @ARGV ) 1 < arg < 1e7. The input will be of such value that there is a solution with E < 50. Output the smallest possible exponent E such that the first digits of 2**E are precisely the digits of N. 1 < output < 50 Sample Input 10 Sample Output 20

5.1.2. Solutions 40, tybalt89 -l 2**++$_=~/^@ARGV/.$'>2 .$&?print:do$0 41, mtve -l 2**++$_=~/^@ARGV/until$'>9x$+[0];print 41, mtve (alternative)

Edition 2007-01-09 top secret / strictly confidential page 188 of 520 Perlgolf History

-l 2**++$_=~/^@ARGV/until$'>(v7|$&);print 41, ton -l 2**++$_=~/^@ARGV/until$'>9x$+[0];print 46, mtve (alternative) -l 2**++$_=~/^@ARGV/&($&^$'^$')ne$&?print:do$0 46, m.thelen -l 2**++$_=~/^@ARGV/&$+[0]2*$+[0];print$; 50, mtve (alternative) $_=pop;s/.?/./g;1while 2**++$x!~/^$`$_/;print$x,$/ 50, pom -l $_=$a=pop;y//./cuntil 2**++$p=~/^$a.$_/;print$p 50, huo -l $_=$y=pop;y//./cwhile 2**++$z!~/^$y.$_/;print$z 50, p.kailasa -l $_=$i=pop;y//./cuntil 2**++$o=~/^$i$_./;print$o 51, dkr -l $_=pop;/$_/until 2**++$q=~/^$_..{$+[0]}/;print$q 52, e.a.zacks {$_=2**++$%,/^@ARGV/&&y///c>2*$+[0]?print$%.$/:redo} 52, e.a.zacks (alternative) {$_=2**++$%,/^@ARGV/&&y///c/2>$+[0]?print$%.$/:redo} 53, dkr (alternative) -l ($n=$a=pop)=~y//./c;2**++$_=~/^$a.$n/until$&;print 53, Jasper -l ($r=$n=pop)=~y//./c;1until 2**++$_=~/^$n.$r/;print 54, banshee -l ($l=$r=pop)=~y//./c;$_++until 2**$_=~/^$r$l./;print 55, e.a.zacks (alternative) {$_=2**++$i,/^@ARGV/&&y///c>2*$+[0]&&print$i.$/or redo} 56, m.wrenn -l $_=pop;1while($q=2**++$p)!~/^$_/|$q<99x y///c;print$p 57, Ryan Zachry -l $n=pop;$_=2**++$;until/^$n/&&length>2*length$n;print$; 58, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 189 of 520 Perlgolf History

-l $h=pop;$h.="..{".length$h;$_=2**++$.until/^$h}/;print$. 59, e.a.zacks (alternative) {$_=2**++$i,/^${\pop}/o&&y///c>2*$+[0]&&print$i.$/ or redo} 60, me ELOISE -l for($z=1+length($a=pop);!/^$a.{$z,}/;$_=2**++$i){}print$i 61, e.a.zacks (alternative) $_=2**++$i,/^${\pop}/o&&y///c>2*$+[0]&&exit print$i.$/while 1 67, jp vidal -l $n=pop;map 2**$_=~/^$n(.+)/&length$1>length$n&&print&&exit,1..49

5.2. Godzillagolf "Laser Beam" http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=2&season=0 The game started 2002-08-20 12:00:00 and ended 2002-08-22 23:00:00.

5.2.1. Rules Your goal is to draw ascii-art simulation of a laser beam. Input will be a maze of mirrors '/', '\' and walls '#'. Output should be the same maze with the correct path '-', '|', '+' of the laser beam drawn. Beam is emitted from left top corner and initially goes to the right. Board size is 10x10. Example of input (spaces replaces with dots only for clearness on this page): ...\...... /...\...... \./.... .#...... Output: ---\...... /-+-\.... .|.\-/.... .#...... The input will come from STDIN and match m!^([\\/# ]{10}\n){10}\z! Output goes to STDOUT and matches m!^([-|+\\/# ]{10}\n){10}\z!

Edition 2007-01-09 top secret / strictly confidential page 190 of 520 Perlgolf History

5.2.2. Solutions 80, ton (post-mortem) -p0 pos=$?+=(2,~9,12)[$%^=$&^o^s^\G\w^+^==s^\G ^$%^]-1while/\G[^# ]/;y^0-3^-||-^ 81, ton (post-mortem) -p0 pos=$?+=(2,-10,12)[$%^=$&^o^s^\G\w^+^==s^\G ^$%^]-1while/\G[^# ]/;y^0-3^-||-^ 86, ton -p0 pos=$?+=(2,12,-10)[$%^=s/\G\w/+/==s/\G /$%/&&/\G\//+1]-1while/\G[^# ]/;y/0-3/-||-/ 92, ton (alternative) -p0 $%+=(2,12,-10)[$?^=s#\d\G#+#==s# \G#$?#&&/\/\G/+!/q/g]-1while/^.{$%}[^# ]/sg;y/0-3/-||-/ 95, ton (alternative) -p0 1until/\G[# ]/||$p-(pos=$p+=(1,11,-11,-1)[$d^=s#\G[-|]#+#==s#\G #$d%3?"|":"-"#e&&/\G\//+1]) 96, mtve -p0 pos=$;+=(1,11,-1,-11)[$d^=m^\G/^?3:l^$&?/\G /?$d%2?!s//|/:!s//- /:!s//+/:1]while/\G[^ #]/^0>$ 96, tybalt89 -p0 $%-=s~\\\G|(/)\G~$-^=@-;$&~e+s/ \G/$-%3?'|':'-'/e+s/.\G/+/-(2,12,-10)[$- ]while/^.{$%}[^#]/sg 101, tybalt89 (alternative) -p0 s!(?<=^\C{$%})[^# ]!$%+=(2,12,-10)[$d^=$a=1+index'\/',$&]-1;$a?$&:$&eq$"?$d%3?'|':'-':'+'!e&&redo 114, m.thelen -p0 ++$x;pos=$p+=$x+$y*11while$p>=0&&s~\G(/|(\\)|(\d| ))~$3?$&+2- !$y:(($x,$y)=map$2?$_:-$_,$y,$x)&&$&~e;y/123/-|+/ 114, terje (post-mortem) -an0F|a $a++;$|?y/ |-/|+/:y/ |-/-+/,$F[$?]=$_,$?+=($a-=2*$a*/\//)*($|- =/\/|\\/).1until($_=$F[$?])!~/[^# ]/;print@F 128, terje -n0 @;=split//}{$a++;$|?y/ |-/|+/:y/ |-/-+/,$;[$x]=$_,$x+=($a-=2*$a*/\//)*($|- =/\/|\\/).1until($_=$;[$x])!~/[^# ]/|$x<0;print@ 128, dkr -n0 @;=/./sg}until($%<0){for($;[$%]){/^(#|\n|)$/?$%=-99:abs$.<2?$..=y@| -@+- @?"":1:y@- |@+|@||chop$.;$.*=-1if/\//}$%+=$.}{print@ 129, kcwu

Edition 2007-01-09 top secret / strictly confidential page 191 of 520 Perlgolf History

@a=map{split//}<>;until($_=$a[$p],$p<0|/^#?$/){$a[$p]=/ /?$d%3?'|':'-':'+'if/[ |-]/;$p+=(1,11,-11,-1)[$d^=1+index'\/',$_]}print@a 153, Dan Flyer aka KarieZ (alternative) for(@i){@x=@i;$e=$_;$r="";while($#x){$u=($f=shift@x)+($s=shift@x);if($f==$e){$r =0 .$r;$e=$u}if($s==$e){$r=1 .$r;$e=$u}@x=sort{$a<=>$b}(@x,$u)}@o=(@o,$r)}

5.3. Rotating sentences http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=3&season=0 The game started 2002-08-26 12:00:00 and ended 2002-08-28 23:00:00.

5.3.1. Rules In "Rotating Sentences" you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them from top to bottom and right to left. Output should be padded with spaces so that the length of the output lines is the number of input lines. Input is /^([ -~]{0,100}\n){0,100}\z/ from STDIN. Sample Input Rene Decartes once said, "I think, therefore I am." Sample Output "R Ie n te h iD ne kc ,a r tt he es r eo fn oc re e s Ia i ad m, . "

5.3.2. Solutions 49, tybalt89 (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 192 of 520 Perlgolf History

-ln0 s/^$/ /gm,print(reverse/^./mg),s///gwhile/./ 51, ton -ln0 s##s/^$/ /gm^s/^./$@=$&.$@;""/gem&&print$@#gee 52, ton (alternative) -ln0 $}=!print$}while s/^$/ /gm^s/^./$}=$&.$};""/emg 52, ton (alternative) -ln0 s/^$/ /gm,print(reverse/^./mg),s/^.//mgwhile/./ 53, ton (alternative) -ln0 s/^.?/$;=(~$&||~$").$;/eemg,print~$;until$;=!/./ 53, tybalt89 -ln0 print(map/./?$_:$",reverse/^.?/mg),s///gwhile/./ 54, mtve -ln0 s/^.?/$,=pack(A,$&).$,;''/emg,$,=!print$,while/./ 54, mtve (alternative) -ln0 print reverse map/./?$_:$",/^.?/mgwhile s///g,/./ 54, kcwu (post-mortem) -ln0 s/^$/ /gm,print(reverse/^(.)/mg),s/^.//mgwhile/./ 55, beowulf -l @[=reverse<>;print map s/.//?$&:$",@[while map/./,@[ 55, terje -ln0 s/^.?/$;=(~$&?$&:$").$;;""/meg,print$;until$;=!/./ 55, m.thelen (alternative) -ln0 s/^.?/!($;=(~$&||~$").$;)/emg,print~$;until$;=!/./ 55, m.thelen -ln0 s/^.?/$;=(~$&?$&:$").$;,''/emg,print$;until$;=!/./ 55, suo -ln $k|=$_;@y=($_,@y)}{$k=~s#.#print map//?$&:$",@y#cge 55, suo (alternative) -ln $k|=$_;@@=($_,@@)}{print map//?$&:$",@@for$k=~/./cg 56, mtve (alternative) -ln0 s/^.?/!unshift@,,o&$&?$&:$"/gem,@,=!print@,while/./ 57, p.kailasa -nl @@=($_,@@);$@|=$_}{print map{s///?$&:$"}@@for$@=~/./g 58, suo (alternative) -p $k|=$_;@y=($_,@y)}{$k=~s#.#$\.=//?$&:$"for@y;$\.=$/#cge 60, kcwu

Edition 2007-01-09 top secret / strictly confidential page 193 of 520 Perlgolf History

-n0 while(/./){s/^$/ /gm;print reverse" ",/^(.)/mg;s/^.//mg} 65, g.allen -pl $_.=$;x99;s/./$;[pos]=$&.$;[pos]/eg}for(grep/[^\x1C]/,@;){y/\x1C// 66, g.allen (alternative) -pl $_.=$;x100;s/./$;[pos]=$&.$;[pos]/eg}for(grep/[^\x1C]/,@;){y/\x1C// 74, s7l -nl $--=s/./$;[$-++][99-$.]=$&/ge}{print map/^$/?' ':$_,@$_[99-$...98]for@ 74, m.wrenn (@_,$")=reverse<>;print$/while"@_"=~/./&&map{s/(.)//,print$+eq''?" ":$+}@_ 76, dkr -naF| $n=0;$;[$n++]=$_.$;[$n]for@F,(" ")x(@;-@F)}{printf"%-".$.."s ",$_ for@

5.4. Eggtimer http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=4&season=0 The game started 2002-09-10 22:30:00 and ended 2002-09-12 23:00:00.

5.4.1. Rules Given the input N, print an eggtimer of size N. The height and max width of the timer will be X = N * 2 - 1. Input will be an commandline argument (@ARGV), and 0 < N < 40 Output will match /^([ *-]{N,X}\n){X}\z/ The timer must be left padded with spaces, and no trailing spaces. Sample Input 3 Sample Output *-*-* *-* * *-* *-*-*

5.4.2. Solutions 48, topmach s/^/ /gm,$_="*-$'$_*-$'"for($_='* ')x~-pop;print 48, ton s/^/ /mg,$_="*-$'$_*-$'"for($_="* ")x~-pop;print 50, david seed aka gimbo

Edition 2007-01-09 top secret / strictly confidential page 194 of 520 Perlgolf History

print$"x($i-abs),"*-"x abs,"* "for-($i=-1+pop)..$i 50, terje print$"x($a-abs),"*-"x abs,"* "for-($a=-1+pop)..$a 50, terje (alternative) print$"x-($a+abs),"*-"x abs,"* "for($a=1-pop)..-$a 50, tybalt89 print$"x-($n+abs),'*-'x abs,'* 'for($n=1-pop)..-$n 52, david seed aka gimbo (alternative) for$i(1..pop){s/^/ /mg;$_=$'?"*-$'$_*-$'":"* "}print 52, david seed aka gimbo (alternative) $_=@_?"*-$& @_*-$&":"* ",@_=/.* /gfor 1..pop;print@_ 56, dkr for($n=pop;$n--;$m++){s/^|\z/$"x$n."*-"x$m."* "/eg}print 57, dkr (alternative) $n=pop;$s=$"x--$n."*-"x$m++."* ",s/^|\z/$s/gwhile$n;print 57, kcwu print map{$_=abs;$"x($n-$_)."*-"x$_."* "}-($n=-1+pop)..$n 66, banshee -l $y=$_=$"x((pop)-1).'*';s/ \*/*-*/,$y="$_ $y $_"while/ /;print$y 69, id5 $a=1-pop@ARGV;for$i($a..-$a){print" "x(-$a-abs$i),"*-"x(abs$i),"* "};

5.5. Forth http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=5&season=0 The game started 2002-09-17 12:00:00 and ended 2002-09-24 12:00:00.

5.5.1. Rules In this problem, you will write an interpreter for a small subset of the FORTH language. Forth is a stack based language, with a very simple syntax.

Edition 2007-01-09 top secret / strictly confidential page 195 of 520 Perlgolf History

A Forth program consists of a sequence of WORDS. A WORD is a sequence of non-blank characters (case sensitive). WORDS are separated by an arbitrary number of blank characters (space, tab, newline). Each word has some effect on the stack. You are to handle the following Forth WORDS: 1. An integer (matching /^0$|^-?[1-9]d{0,3}$/) this this integer is pushed onto the stack. 2. +: the top two numbers on the stack are popped off the stack, and their sum is pushed onto the stack. 3. -: the top two numbers on the stack are popped off the stack, and their difference is pushed onto the stack (that is, the second to top minus the top, not the other way around). 4. *: the top two numbers on the stack are popped off the stack, and their product is pushed onto the stack. 5. /: the top two numbers on the stack are popped off the stack, and their integer quotient is pushed onto the stack (that is, the second to top divided by the top, not the other way around). 6. dup: the top number is pushed onto the stack (i.e. duplicated). 7. swap: the top two numbers of the stack are swapped. 8. . (a period): pops a number off the stack and displays it, followed by a newline character. In addition to these basic words, you will allow the definition of new Forth WORDS. This is done in the following way: First, the WORD : (a colon) indicates the start of a definition. Second, the new WORD. Third, an arbitrary number of existing WORDS, which make up the definition. Last, the WORD ; (a semicolon). For example, we could define the WORD square (to find the square of a number) as follows: : square dup * ; You can make the following assumptions: 1. You will never be asked to pop a number from an empty stack. 2. The stack will never have more than 100 numbers on it. 3. You will never encounter a WORD that is not in the language. 4. A WORD will never be defined more than once, and the basic WORDS will never be redefined (unlike in the real Forth). 5. WORD is always defined before it gets used. 6. All input in tests will be valid and will cause no problems like overflows, divisions of integers with different signs, or divisions by zero. The input file will consist of a Forth program as described above. Output should consist of integers, one on each line (these integers are the effect of the . WORDS in the input program). Example of the input:

Edition 2007-01-09 top secret / strictly confidential page 196 of 520 Perlgolf History

68-. : square dup * ;

: x^2+1 square 1 + ;

3 x^2+1 . Your program should print: -2 10

5.5.2. Solutions 143, pom (rejected) -ln0 $r=$2,s/\s\Q$1\E(?=\s)/$r/gwhile s/:\s+(\S+)(.+?);//s;/\./?print pop@s:push@s,/\d/?$_:/d/?@s:int eval join"$_ ",splice@s,-2,2-/s/for split 144, eugene (post-mortem) -ln0 sub p{pop}s/\s/ /g;s/\Q $1 /$a/gwhile$a=$2x s/: +(\S+)(.*?);//;$==&p,/\./?print$=:push@_,/\w/?($=,/d/?$=:/s/?&p:$_):eval"&p$ _$="for/\S+ /g 145, eugene -ln0 s/\s/ /g;s/\Q $1 /$a/gwhile$a=$2x s/: +(\S+)(.*?);//;$==pop@_,/\./?print$=:push@_,/\w/?($=,/d/?$=:/s/?pop@_:$_):ev al pop(_).$_.$=for/\S+ /g 145, tybalt89 -ln0 sub p{pop d}$a=$+,s/\s\Q$1\E(?=\s)/$a/gwhile s/:\s+(\S+)(\C+?);//;map{/\./?print p:push d,/\d/?$_:/d/?(p)x2:/s/?(p,p):eval"int&p$_ ".p}split 147, pom -ln0 $r=$2,s/\s\Q$1\E(?=\s)/$r/gwhile s/:\s+(\S+)(.+?);//s;/\./?print pop@t:push@t,/\d/?$_:/d/?$t[-1]:int eval join"$_ ",splice@t,-2,2-/s/for split 152, mtve (rejected) -lan0 /^:$/../^;$/ or" @F"=~/ : \Q$_\E( .*?) ; /?map do$0,$1:/w/?@1[1,0]=@1:/\w/?@1=(/d/*"@1"+$_,@1):eval"\$1[0]$_="."!print "x/\./.int shift@1for split 195, g.allen -aln0 $_=" @F ";0while$:='(-?\d+) ',s/ :( \S+ )((\S+ )*?); /$k{$1}=$2;$;.="|\Q$1";$"/e|s/$;/ $k{$&}/||s~$:dup~$1 $1~|s~$:$:swap~$2 $1~|s~$:$:([-+/*])(?= )~eval"int $1$3 $2"~e|s~$:\. ~print$1;''~e 200, k.c.ivey (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 197 of 520 Perlgolf History

-lna0 $t{$_=shift@F}?unshift@F,@{$t{$_}}:/\w/?push@_,/d/?$_[- 1]:/s/?(pop@_,pop@_):$_:/\./?print pop@_:/:/?do{$w=shift@F;push@{$t{$w}},$_ until$_=shift@F,/^;$/}:($_[-1]=$==eval"$_[-2]$_ ".pop@_)while@F 200, k.c.ivey -lna0 $t{$_=shift@F}?unshift@F,@{$t{$_}}:/\w/?push@_,/d/?$_[- 1]:/s/?(pop@_,pop@_):$_:/\./?print pop@_:/:/?do{$w=shift@F;push@{$t{$w}},$_ until$_=shift@F,/^;$/}:($_[-1]=$==eval"$_[-2]$_ ".pop@_)while@F 228, terje -lna0 sub z{push@s,@_}sub w{pop@s}sub f{shift@F}while(@F){unshift@F,@{$f{$_=f}};if(/^[-+*\/]$/){$x=w;z+int eval w."$& $x"}if(/^:$/){$f=f;push@{$f{$f}},$_=f until/^;$/}/^- ?\d+$/?z$_:/^dup$/?z+(w)x2:/^swap$/?z+w,w:/^\.$/&&print w}

5.6. Ordered fractions http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=6&season=0 The game started 2002-09-17 12:00:00 and ended 2002-09-19 12:00:00.

5.6.1. Rules Consider the set of all reduced rational numbers R (0 < R ≤ 1) with denominators less than or equal to N. Write a program that, given an integer 0 < N < 10, prints the fractions in order of increasing magnitude. If 2 or more fractions exist with the same value, the one with the smallest denominators should be used Input is command line argument with value 0 < N < 10 Output should match m|{\d/\d\n}+\z| Sample input 5 Sample output 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4/5 1/1

5.6.2. Solutions 50, ton print@{map$0[99*$_/$']="$_/$' ",/./..$'}for-pop..0 51, terje (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 198 of 520 Perlgolf History

map{$a[$_*99/$']||="$_/$' "for//..$_}1..pop;print@a 52, mtve map{map$a[$_*99/$']||="$_/$' ",//..$_}1..pop;print@a 52, g.allen map$f[$_/$;*99]||="$_/$; ",1..++$;for 1..pop;print@f 52, tybalt89 map$a[99*$_/$-]||="$_/$- ",1..++$-for 1..pop;print@a 52, Adam Antonik map$_[99*$_/$-]||="$_/$- ",1..++$-for 1..pop;print@_ 52, aqumsieh (post-mortem) map$x[99*$_/$&]||="$_/$& ",/./..$&for 1..pop;print@x 54, dkr for$i(1..pop){$a[$=*$_/$i]||="$_/$i "for 1..$i}print@a 55, g.allen (alternative) $f[$n--/$d*99]="$n/$d "while$n||=--($d||=1+pop);print@f 56, terje map{$a{$_/$'}||="$_/$' "for//..$_}1..pop;print@a{sort%a} 59, p.kailasa for$;(1..($n=pop)){$;[$=*$;/$_]||="$;/$_ "for$;..$n}print@; 59, Jasper map$f{$_/$d}||="$_/$d ",1..++$d for 1..pop;print@f{sort%f} 60, andys for$l(1..($p=pop)){$a[$l/$_*1e2]||="$l/$_ "for$l..$p}print@a 62, m.wrenn for(;$i|=pop;$i--){$s{$_/$i}="$_/$i "for 1..$i}print@s{sort%s} 65, p.kailasa (alternative) $"=",";@_=1..pop;$;[$=*eval]||="$_ "for<{@_}/{@_}>;print@;[1..$=] 65, aqumsieh (alternative)

Edition 2007-01-09 top secret / strictly confidential page 199 of 520 Perlgolf History

-l for$*(1..pop){map$x[1e3*$_/$*]||="$_/$*",1..$*}map$_&&print,@x 71, mtve (alternative) ord=~/^[1-@ARGV]/&&print"$'/$& "for'[QG=3\)H\x1FS4I^\xA7_J5U K+a6ALWb\x0B'=~/./g 73, pom -l map{$d=$_;map$f{$_/$d}||="$_/$d",1..$_}1..pop;print for@f{sort keys%f}

5.7. Power Crisis http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=7&season=0 The game started 2002-09-19 21:30:00 and ended 2002-09-25 22:00:00.

5.7.1. Rules During the power crisis in New Zealand this winter (caused by a shortage of rain and hence low levels in the hydro dams), a contingency scheme was developed to turn off the power to areas of the country in a systematic, totally fair, manner. The country was divided up into N regions. A number, m, would be picked 'at random', and the power would first be turned off in region 1 and then in every m'th region after that, wrapping around to 1 after N, and ignoring regions already turned off. For example, if N = 17 and m = 5, power would be turned off to the regions in the order: 1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7. Input and Output Input will be 2 lines from STDIN. first 1 < N < 100, second 0 < m < N. Output will be the regions in the right order, newline separated, matching (/^(\d+\n){N}\z/) Sample input 7 3 Sample output 1 4 7 5 3 6 2

5.7.2. Solutions 44, ton -ln0 @;=/ /..$`;$z++%$'?push@;,$_:print for@ 44, mtve (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 200 of 520 Perlgolf History

-ln0 $#$_&&=$c++%$'||!print for(/ /..$_)x999 45, ton (post-mortem) -ln0 1while@;=grep$i++%$'||!print,1..? ?*$`,@ 46, pom -l 1while@d=grep$i++%($m+=<>)||!print,@d,1..<> 47, Jasper -ln0 do$0if@;=grep$i++%$'||!print,/ /..$`-$i,@; 48, Adam Antonik -l $_=2x<>;$m=<>;1while s/2/$c++%$m?2:print@+/eg 49, wuuru -l @N=1..<>;$m=<>;1while@N=grep$i++%$m||!print,@N 50, mtve -ln0 map{$x+=$'-print splice a,$x%=@a,1}@a=/ /..$` 50, m.wrenn -l map$s{$_}||=!($c++%($n|=<>))&&print,(1..<>)x999 50, ton (alternative) -ln0 map@a=@a[-$#a..-1/$_],print..$' for@a=/ /..$` 50, tybalt89 -ln0 map$p+=$'-print(splice a,$p%=@a,1),@a=/ /..$_ 52, pom (alternative) -l map{$;+=($,|=<>)-print splice@*,$;%=@*,1}@*=1..<> 52, `/anick -l @a=1..<>;$x=<>;1 while@a=grep{$i++%$x or!print}@a 54, ton (alternative) -ln0 @;=/ /..$`;$z++%$'?push@;,$_:print while$_=shift@ 56, topmach -l print(splice@a,$o%=@a,1),$o+=($n|=<>)-1for@b=@a=1..<> 57, terje -l map{($x+=($y+=<>)-print splice@a,$x,1)%=@a||1}@a=1..<> 57, topmach (alternative) -l @,=1..<>;$%++%($n|=<>)?push@,,$_:print while$_=shift@, 57, david seed aka gimbo

Edition 2007-01-09 top secret / strictly confidential page 201 of 520 Perlgolf History

-l @a=1..<>;$b=<>;$i++%$b?push@a,$_:print while$_=shift@a 58, Peter Haworth -lp @n=1..$_;$m=<>}while(@n){$_=splice@n,$x%=@n,1;$x+=$m-1 59, k.c.ivey -l @@=1..<>;$==<>-1;map{print splice@@,($i%=@@),1;$i+=$=}@@ 60, Wesley Darlington -nl $m=<>;map{print+splice@a,$i,1;($i+=$m-1)%=@a||1}@a=1..$_ 62, m.wrenn (alternative) -l map{print shift@_;@_=(1,(@_)x99)[($m|=<>)..$m+$#_]}@_=1..<> 63, p.kailasa -l @_=1..<>;$i=1-($m=<>);print splice@_,($i+=$m-1)%=@_,1while@_ 64, brohm -l sub{$m=<>;map{print shift;map{push@_,shift}2..$m}@_}->(1..<>) 66, dkr -l @@=(1..<>);eval((';print shift@@;push@@,shift@@for$...'.<>)x@@) 69, dkr (alternative) -l @@=(1..<>);$m=<>-1;$i++,print,eval'push@@,splice@@,$i,1;'x$m for@@ 75, ktotam -l $n=<>-1;$m=<>;map{$i=0;map{$i=($i+$m)%$_||$_}$n-$_+1..$n;print$i+1}0..$n 80, dkr (alternative) -ln0 /.+/;eval"map$'!=1&&\$_&&++\$c%$'-1?1:do{\$_&&print;\$_=0},1..$&for 1..1e3" 89, dkr (alternative) -l sub f{$m!=1&&++$i%$m-1?push@_,$_:$n--&&print for@_[$i..$#_];$n&&&f}($n,$m)=<>;f(1..$n) 98, andys -p s|.*|join$/,1..$_|e;$m=<>;$?=$??$m%y/ //||y/ //:1while s#(\d+ ){$?}.*#$\.=$+;/\b$+/;$'.$`#es,$_ 109, Jerom $n=<>;$p='\d+,'x(<>-1);$s.="$_,"for(1..$n);$_=$s x9999;for$i(1..$n){s/(\d+),//;print"$1\n";s/,$1,/,/g;s/$p//}

5.8. Starmap http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=8&season=0 The game started 2002-09-27 19:00:00 and ended 2002-09-30 20:00:00.

Edition 2007-01-09 top secret / strictly confidential page 202 of 520 Perlgolf History

5.8.1. Rules Your task is to draw a map of stars given a set of coordinates for each star. Rectangular coordinates are a pair of numbers (X,Y). You must draw stars as char "*" on ascii map in the column X and row Y (counted from zero). (0,0) is upper left corner. Both coordinates are integers in range 0..99 inclusive. Stars will not be duplicated. Input has no particular order, i.e. star (5,7) can occur before (1,2). You will get the sequence of lines on STDIN, 0 ≤ lines < 100, with the two numbers X and Y separated by space on each line. You should print the starmap. Your output must not contain any chars except of space " ", star "*" and newline "\n". Each line must be properly newline terminated. You should not output unnecessary spaces before newline or unnecessary newlines at the end of output. So input will match /^(\d+ \d+\n)*\z/ or more strictly /^([1-9]?\d [1-9]?\d)\n){0,99}\z/ and your output must match /^[ *\n]\z/ or more strictly /^(([ *]{0,98}\*)?\n){0,98}\z(?

* *

5.8.2. Solutions 34, mtve -lp / /;$a[$']|=$"x$`.'*'}for(@a){ 34, ton -lp / /;$a[$']|=$"x$`."*"}for(@a){ 34, ton (alternative) -lap $a[pop@F]|=$"x$_."*"}for(@a){ 34, banshee -alp $;[pop@F]|=$"x$_.v42}for(@;){ 34, tybalt89 -lp / /,$a[$']|=$&x$_.'*'}for(@a){ 37, p.kailasa

Edition 2007-01-09 top secret / strictly confidential page 203 of 520 Perlgolf History

-ln / /;$;[$']|=$"x$`.'*'}{print for@ 37, pom -nl / /;$;[$']|=$"x$`."*"}{print for@ 38, topmach -ln / /;$;[$']|=' 'x$`.'*'}{print for@ 38, m.wrenn -nl / /,$s[$']|=$"x$`."*"}{print for@s 41, brohm (post-mortem) -lp vec($S[$'],$`,8)=/ /}for(@S){y/\0\1/*/ 45, andys -p $;[$'][$`]=/ /}for(@;){$_="@$_ ";s/1.?/*/g 45, terje -p $a[$'][$`]=/ /}for(@a){$_="@$_ ";s/1 ?/*/g 47, banshee (alternative) -ln $;[$'][$`]='*'x/ /}{print+map$_|$",@$_ for@ 47, p.kailasa (alternative) -ln / /;$;[$'][$`]='*'}{print map$_|$",@$_ for@ 53, sh -nl END{y/\0/ /,print for@;}/ /,vec($;[$'],$`,8)=42

5.9. Cantor's revenge http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=9&season=0 The game started 2002-10-01 18:00:00 and ended 2002-10-04 22:00:00.

5.9.1. Rules output this to STDOUT:

Edition 2007-01-09 top secret / strictly confidential page 204 of 520 Perlgolf History

*************************** ****************** *************************** *** ****** ****** *** ** **** **** ** *** ****** ****** *** *************************** ****************** *************************** ********* ********* ****** ****** ********* ********* *** *** *** *** ** ** ** ** *** *** *** *** ********* ********* ****** ****** ********* ********* *************************** ****************** *************************** *** ****** ****** *** ** **** **** ** *** ****** ****** *** *************************** ****************** ***************************

5.9.2. Solutions 28, mtve (rejected) -p INIT{@ARGV=<*>}$_ x=/^\*/ 50, dkr (rejected) -l for$f(glob"*"){open f;/^\*.*/&&print$&while} 51, mtve -l //,print map$_!~~$'.j&~Q,@;for@;=glob"{\321,.,\321}"x3 53, ton -l print//g,map$_&$`|0?$":"*",@;for@;=glob"{0,1,0}"x3 61, suo $_=QYQ;s/./$&x9|QSQUWUQS/ge;s//$&x99&$_.P/ge;y/P-a/ * /;print 70, topmach for$i(s//* /,3,9){my$r;s/.+/$r.=$&.$"x$i."$& ";$&x3/ge;$_.=$r.$_}print 70, Sec (post-mortem) s!.+!$..=$&.($&&$"x$=).$&.$/;$&x3!ge,$.x=$_.=$..$\for($\="* ")x3;print 70, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 205 of 520 Perlgolf History

$;='',s/.+/$;.=$&.$"."$& ";$&x3/ge,$_.=$;.$_,$"x=3for($\="* ")x3;print 72, Sec $q="",s!.+!$q.=$&.($&&$"x$=).$&.$/;$&x3!ge,s/^/$_$q/for($_="* ")x3;print 73, terje $_=("*"x27 .$/)x27;for$x(1,3,9){s!.!$i/$x/27%3&$i++/$x%3^1?$&:$"!eg}print 78, p.kailasa -l map@_=(@x=map($_ x3,@_),@_?map($_.$"x y///c.$_,@_):'*',@x),0..3;print for@_ 82, m.wrenn -l map{s/(..{$#_}){3}/$1.$"x@_.$1/ge}@s=@_=(@_,@s,@_)for(@s='*'x27)..4;print for@_ 98, wuuru -l for$i(("\0\111\0\34\135\34\0\111\0"x3)=~/./g){($_=0 .unpack"b*",$i).=(++$j=~/1[0-8]/?1x9:$_).$_;y/1 0/ */;print} 106, mtve (alternative) ($_=unpack'b*',"\0\0\0\220\$I\022\0\0\0p\340\300\241K\227.\0348p\0\0\0\@\222\$I \0\0\0\0\360\37\200\244\377\222\0\374\7\200\343?\16]").=1x9 .reverse;y/10/ */;s/.{27}/$& /g;print 116, beowulf print map{++$?;for$f(1,3,9){$c=$?%(3*$f);$r="(.{$f})"x3;s/$r/$1.($"x$f).$3/eg if$c>$f&&$c<=$f*2}$_.$/}@a=('*'x27)x27 116, beowulf -l for$i(1..27){$s='*'x27;map{$c=$i%(3*$_);$r="(.{$_})"x3;$s=~s/$r/$1.($"x$_).$ 3/eg if$c>$_&&$c<=$_*2}1,3,9;print$s} 116, Hirogen2 (rejected) print+(`wget -O- 'terje.dev.webon.net/wsp/pgas/score.pl?func=rules&hole=9' 2>/dev/null`=~m!.*

(.*)
.*!s)[0] 147, Hirogen2 (post-mortem) ($_=unpack"B*",'\xFF\xFF\xFF\xF6\xDBm\xB7\xFF\xFF\xFF\xF1\xF8\xFCz- \x16\x8B\xC7\xE3\xF1\xFF\xFF\xFF\xFD\xB6\xDBm\xFF\xFF\xFF\xFF\xF0\x07\xFE\xD A\x00\xB6\xFF\xC0\x1F\xFE8\x03\x8FE\x00Qx\xE0\x0E?\xFC\x01\xFF\xB6\x80- \xBF\xF0\x07\xFF\xFF\xFF\xFF\xDBm\xB6\xDF\xFF\xFF\xFF\xC7\xE3\xF1\xE8\xB4Z/\ x1F\x8F\xC7\xFF\xFF\xFF\xF6\xDBm\xB7\xFF\xFF\xFF\x80')=~y/01/ */;print$1." "while/(.{27})/g 152, dkr -l @a=("*"x27)x27;sub f{my($n,$x,$y)=@_;substr$a[$x+$n+$_],$y+$n,$n,$"x$n for 0..$n-1;$n>1&&f($n/3,$x+$n*int($_/3),$y+$n*($_%3))for 0..8}f 9;print for@a 175, banshee

Edition 2007-01-09 top secret / strictly confidential page 206 of 520 Perlgolf History

-l ($a,$b)=map{unpack b243,$_}"\xFF\xFF\xFFo\xDB\xB6\xED\xFF\xFF\xFF\x8F\x1F?^\\xB4h\xD1\xE3\xC7\x 8F\xFF\xFF\xFF\xBFm\xDB\xB6\xFF\xFF\xFF\7","\xFF\1\xFCo\xb\xa0\xED\x7F\0\xFF \x8F\38^\x14\@\xD1\xE3\0\x8E\xFF\7\xF0\xBF- \x80\xB6\xFF\1\xFC\7";$_=$a.$b.$a;y/10/* /;print for/.{27}/g 188, dkr (alternative) $s=$"x9;$a="*"x9;$b="* *"x3;$c="*** ***";$d="* * * *";$h=$a x3;$i=$b x3;$l="$a$s$a ";$x="$h $i $h $c$c$c $d$d$d $c$c$c $h $i $h ";print"$x$l$b$s$b $l$c$s$c $d$s$d $c$s$c $l$b$s$b $l$x" 192, Jean-Pierre Vidal push@t,$c=f(0).f(1).f(0),$a=f(3),f(1,$a),$a,$c,$b=f(9),f(1,$b),$b,$d=f(3,$b);pr int@t,f(1,$d),reverse@t;sub f{($z,$_)=@_;$m='\*'x$z;$s=' 'x$z;$_=$_?$_:'*'x27;s/($m)$m$m/$1$s$1/g;$_[1]?$_:"$_ "} 208, Jerom -l$_='*';$i=1;&x;$i=3;&x;$i=9;$_?print:$_ for(split /(.{27})/, &x);sub x{$j=$s='';for(split//) {if('*'eq$_){$s|=' 'x(int($j/$i)*$i*3*3).' 'x($j%$i*3).'***'.' 'x($i*3-3).'* *'.' 'x($i*3-3).'***';}$j++;}$_=$s;} 231, Hirogen2 (post-mortem) print join(" ",@o=($c=($a="*"x3)x9,$g=($b="* *")x9,$c,$e=($a.($d=" "x3).$a)x3,$_=($f="$b$d$b")x3,$e,$c,$g,$c,$h=$a x3 .($k=$d x3).$a x3,$i=$b x3 .$k.$b x3,$h,($j="$a$d$a").$k.$j))," ",($n=$b.$d.$b).$k.$n," ",join(" ",reverse@o)," " 246, Hirogen2 (post-mortem) ($_=unpack"B*",pack"H*",fffffff6db6db7fffffff1f8fc7a2d168bc7e3f1fffffffdb6db6df ffffffff007feda00b6ffc01ffe38038f45005178e00e3ffc01ffb6802dbff007ffffffffdb6 db6dfffffffc7e3f1e8b45a2f1f8fc7fffffff6db6db7ffffff80)=~y/01/ */;print$1." "while/(.{27})/g 2281, p.kailasa (alternative)

Edition 2007-01-09 top secret / strictly confidential page 207 of 520 Perlgolf History

eval eval '"'.

'#'.'!'.('['^'+').('`'|'%') .+(((((((((((((((( '[')))))))))))))))^(')')).( '`' |','). ("\!"^ '+' ). (((( (((( (( ((( '\\')) )))))) ))) )).'@'.'_'.'='.('['^"\-").( (((((((((((((((((( '^'))))))))))))))))))^('`'| ('*'))).( '^'^('`'| (((((( (((((( ',')))))) )))))))). ';' .+( '`' |(( (( (( (( (( '-' ))) ))) ))) )).("\`"| '!').('[' ^((((( (((((( '+')))))) )))))).(( '\\')).'@'.'_'.'='.'('.'\\' .((((((((((((((((( '@'))))))))))))))))).("\["^ '#' ).'='. ("\`"| '-' ). (((( (((( (( '`' )))))) )))|(( '!' ))).('['^'+').'('.'\\'.'$'. (((((((((((((((((( '_')))))))))))))))))).('{'^ '[').('['^'#').('^'^(('`')| (((((((((((((((((( '-')))))))))))))))))))).',' .(( '\\')) ."\@". '_' .( (((( (((( (( ')' )))))) ))))). ',' .('`'|'-').('`'|'!').("\["^ (((((((((((((((((( '+'))))))))))))))))))).'('. '\\'.'$'. '_'."\.". (((((( (((((( '\\'))))) ))))))).+ '$' .(( ((( ((( (( (( (( (( ((( ((( ((( ((( '\\'))))) ))))))))) )))))) )))))) ))."\"".( '['^'#'). ('{'^'[').('['^'"').'/'.'/' .((((((((((((((((( '/'))))))))))))))))).("\`"| '#' ).'.'. '\\'.+ '$' .( (((( (((( (( '_' )))))) ))))). ',' .'\\'.'@'.'_'.')'.','.'\\'. (((((((((((((((((( '@')))))))))))))))))).('['^ '#').')'.','.('^'^('`'|'/') ).+((((((((((((((( '.'))))))))))))))).'.'.('^' ^+( ('`')| '-')). ';' .( (((( (((( (( '[' )))))) ))))^+ '+' ).('['^')').('`'|')').('`'| (((((((((((((((((( '.'))))))))))))))))))).('[' ^'/').''. '\\'.'"'. (((((( (((((( '\\'))))) ))))))).+ '$' .(( '_' )). (( (( (( (( '!' ))) ))) )^+ '+').'\\' .'"'.('`' |((((( (((((( '&')))))) )))))).+( '`'|'/').('['^')').'\\'.'@' .((((((((((((((((( '_'))))))))))))))))).("\!"^ '+' ).'"'; $:='.' ^(( (( (((( (((( (( '~' )))))) )))))) )); $~='@'|'(';$^=')'^('[');$/= (((((((((((((((((( '`'))))))))))))))))))|"\.";

5.10. Add 11 http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=10&season=0 The game started 2002-10-14 18:00:00 and ended 2002-10-17 18:00:00.

Edition 2007-01-09 top secret / strictly confidential page 208 of 520 Perlgolf History

5.10.1. Rules You task is to add two digits in base 11. You'll get two digits in base 11 as command line arguments. 10 (decimal) is represented by the uppercased letter "A" (base 11). Print to STDOUT the base 11 sum (one or two digits) and the newline "\n". So the program ./add11.pl A 3 Should print 12 Both command line arguments will match /^[0-9A]\z/ and your output should match /^1?[0- 9A]\n\z/.

5.10.2. Solutions 38, mtve (post-mortem) printf'%X ',eval'$~+=$~>10|hex pop;'x7 39, Sec -l print+(hex pop..9,A,10..19)[hex pop] 40, ton printf'%X ',$~+5x($~>8+map$~+=hex,@ARGV) 40, david seed aka gimbo $~+=$~<11?hex:5for@ARGV,z;printf'%X ',$~ 40, david seed aka gimbo (rejected) printf'%3$X ',map$~+=$~<11?hex:5,@ARGV,z 40, g.allen $~+=$~<11?hex:5for@ARGV,z;printf'%X ',$~ 40, mtve (post-mortem) printf'%X ',eval'$~+=$~<11?hex pop:5;'x3 41, m.wrenn $~+=hex,for@ARGV;printf'%X ',$~+($~>10)*5 41, Peter Haworth $~+=hex,for@ARGV;printf'%X ',$~+5*($~>10) 41, g.allen $~+=hex,for@ARGV;printf'%X ',$~+5x($~>10) 41, g.allen (alternative)

Edition 2007-01-09 top secret / strictly confidential page 209 of 520 Perlgolf History

$~+=hex,for@ARGV;printf'%X ',$~+5x($~>10) 41, m.thelen -l map$~+=hex,@ARGV;print$~^10?$~-=$~>9:A 41, m.thelen map$~+=hex,@ARGV;printf"%X ",$~+5x($~>10) 41, Stephen Turner map$~+=hex,@ARGV;printf'%X ',$~+5x($~>10) 41, Geoff Hubbard $~+=hex,for@ARGV;printf'%X ',$~+5x($~>10) 41, Ross Younger $~+=hex,for@ARGV;printf'%X ',$~+5x($~>10) 41, brohm $~+=hex,for@ARGV;printf'%X ',$~+($~>10)*5 41, Bass map$~+=hex,@ARGV;printf'%X ',$~+5x($~>10) 42, ton (alternative) -l print+(0..9,A,10..19)[hex(pop)+hex pop] 42, ton (alternative) -l print/10/?A:$_-/../for hex(pop)+hex pop 42, p.kailasa -l $_=hex(pop)+hex pop;print?10??A:$_-?..? 42, p.kailasa (alternative) -l $a+=hex for@ARGV;print$a-10?$a-($a>9):A 42, Jasper -l $_=hex(pop)+hex pop;print?10??A:$_-?..? 42, Jasper -l map$a+=hex,@ARGV;print$a-10?$a-($a>9):A 42, Jasper -l print+(0..9,A,10..19)[hex(pop)+hex pop] 42, dkr map$~+=hex,@ARGV;printf"%X ",$~+5*int$~/11 42, dkr (alternative)

Edition 2007-01-09 top secret / strictly confidential page 210 of 520 Perlgolf History

map$~+=hex,@ARGV;printf"%X ",$~>10?$~+5:$~ 42, mtve -l $_=hex(pop)+hex pop;print/10/?A:$_-/../ 42, m.thelen -l print+(0..9,A,10..99)[hex(pop)+hex pop] 42, terje -l s~~'+hex(pop)'x2~ee;print?10??A:$_-?..? 42, Stephen Turner (alternative) -l print+(z..9,A,10..99)[hex(pop)+hex pop] 42, banshee -l print/10/?A:$_-/../for+hex(pop)+hex pop 42, banshee (alternative) -l s~~'+hex(pop)'x9~ee;print/10/?A:$_-/../ 46, jp vidal -l ($_=hex(pop)+hex pop)>10?$_--:s/10/A/;print 47, andys -l s~~'+hex(pop)'x2~ee|s~..~--$_^9?$_:A~e|print 47, m.wrenn (alternative) -l $~+=$_+10*/A/for@ARGV;print$~-10?$~-($~>9):A 49, dkr (alternative) -l $_=map{(1)x hex}@ARGV;print/10/?A:/../?$_-1:$_ 54, dkr (alternative) $"="+0x";$_=eval"0x@ARGV";$_+=$_>10?5:0;printf"%X ",$_

5.11. Go golf http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=11&season=0 The game started 2002-10-21 20:30:00 and ended 2002-10-27 19:00:00.

5.11.1. Rules You have a board of the game Go1 just after last move by the black. Remove any white stones taken. According to the real Go rules2 capturing takes place when group of adjacent whites has no liberties where adjacent is either horizontal or vertical neighboring and liberties are the adjacent empty spots themselves.

1 http://senseis.xmp.net/?BasicRulesOfGo 2 http://gobase.org/rules/?id=3&ln=uk

Edition 2007-01-09 top secret / strictly confidential page 211 of 520 Perlgolf History

From STDIN you get a drawing of a 9 by 9 go board before white stone removal, and you should output on STDOUT the corresponding board drawing after white stone removal. All lines are properly newline terminated. Empty spots are represented as ".", black stones as "#" and white stones as "O". Example input ...... ##...... #OO#... ..#O#...... #...... Output ...... ##...... #..#... ..#.#...... #...... So both input and output should match /^(([.#O]){9}\n){9}\z/

5.11.2. Solutions 54, ton -p0 $_=reverse,s/O(|.{9})[o.]/\l$&/swhile$^H--;y/oO/O./ 55, mtve -p0 $_=reverse,s/O(.{9})?[.o]/\l$&/sfor($_)x98;y/oO/O./ 57, andys -p0 s/O((.{9}|)[.+])|([.+](.{9}|))O/$3+$1/s?redo:y/+O/O./ 57, terje -p0 s/([.a](.{9})?)O|O(?=(.{9})?[.a])/$1a/s?redo:y/Oa/.O/ 57, tybalt89 -p0 s/([.o](.{9})?)O|O((.{9})?[.o])/$1o$3/s?redo:y/oO/O./ 57, Bass -p0 s/([G.](.{9})?|(?=.(.{9})?[G.]))O/$1G/s?redo:y!GO!O.! 57, Honza Pazdziora -p0 s/([.,](.{9})?)O|O((.{9})?[.,])/$1,$3/s?redo:y/O,/.O/ 58, ton (alternative) -p0 s!O(|.{9})[o.]|[o.](|.{9})O!$&|" $+ "!se?redo:y/oO/O./ 59, m.wrenn

Edition 2007-01-09 top secret / strictly confidential page 212 of 520 Perlgolf History

-p0 1while s/([.X](.{9})?)O|O(?=(.{9})?[.X])/$1X/s;y/OX/.O/ 59, tinita -p0 1while s/O(?=(.{9})?[.X])|([.X](.{9})?)O/$2X/s;y/XO/O./ 61, Wladimir Palant -p0 a while s/([.a](.{9})?)O|O(?=(.{9})?[.a])/$1a/s;tr/Oa/.O/ 64, ton (rejected) -p0i([o.](|.{8}.))O $I=reverse$^I;s!$^I|$I!$1o$3!s?redo:y/Oo/.O/ 65, Jasper -p0 s/([O.])(.{9})?(?!\1)[.O]/.$2./sfor($;=$_)x99;$_|=$;;y/oO/O./

5.12. Modular Fibonacci http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=12&season=0 The game started 2002-10-21 21:30:00 and ended 2002-10-27 19:00:00.

5.12.1. Rules The Fibonacci numbers (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defined by the recurrence: F1 = 1 F2 = 1 Fi = Fi-1 + Fi-2 for i > 2 Write a program which calculates Mn = Fn mod 2m for given pair of n and m. 0 < n < 10000 and 0 < m < 20 . Note that a mod b gives the remainder when a is divided by b. Input consists of one newline-terminated line specifying a pair of n and m separated by a space. Output should be corresponding Mn, and a newline. Sample Input 11 7 Sample Output 89

5.12.2. Solutions 38, mtve (rejected) -p $\=$.%2**$'%[$.+=$\].$/for/ /..$`}{ 39, mtve (rejected) -pl $_=$.%2**$'%[$.+=$_]for($_=!/ /)x$` 39, ton (post-mortem) -p $\=$.%2**$'+!($.+=$\).$/for/ /..$`}{ 40, mtve (post-mortem) -pl $_=$.%2**$'+!($.+=$_)for($_=!/ /)x$` 40, ton (rejected)

Edition 2007-01-09 top secret / strictly confidential page 213 of 520 Perlgolf History

-lp $_=$b%2**$'%[$b+=$_]for(/ /+0)x$`,$_ 41, ton -lp $a=$_+0+($_=$a%2**$')for(/ /+0)x$_,$_ 42, mtve -pl $_=$b%2**$'+!($b+=$_)for($_=/ /)x$`,$_ 42, tybalt89 -lp $_="$."+($.=$_)&2**$'-1for($_=!/ /)x$` 43, andys -pl eval'$_=(/ /||~~$~+($~=$_))%2**$\';'x$_ 43, p.kailasa -lp ($_)=($}%2**$',$}+=$_)for($_=/ /)x$`,$_ 45, Peter Haworth -lp ($.,$;)=($.+$;&2**$'-1,$.)for/ /..$_;$_=$ 46, m.wrenn -lp $_=/ /;$_=(($i+=$_)-$_)%2**$' until$k++>$` 46, terje -pl ($_,$b)=(($_+$b)%2**$',$_)for($_=/ /)x~-$` 46, Petri Mikkelä -pl ($i,$.)=($.,($i+$.)%2**$')for/ /..$`;$_=$i 46, terje (alternative) -pl ($_,$b)=($b%2**$',$_+$b)for($_=/ /)x($`+1) 46, Wesley Darlington -apl $.=(($,+=$.)%=1<<$F[1])-$.while$_--;$_=$, 46, Wesley Darlington (alternative) -apl map$.=(($,+=$.)%=1<<$F[1])-$.,1..$_;$_=$, 46, Jasper -lp $;=(0+$b+($b=$;)||1)%2**$' for/ /..$`;$_=$ 47, Honza Pazdziora -alp $_=1;$_=(($.+=$_)-$_)%2**$F[1]while--$F[0] 48, sorrow -lp / /;map$;=(0+$b+($b=$;)||1)%2**$',1..$`;$_=$ 48, brohm -lp $;=$k%2**$',$k+=$m,$m=$;for($k=/ /)..$`;$_=$ 48, Wladimir Palant -pal $_=1;$_=(-$a-($a=-$_))%2**$F[1]while--$F[0] 49, tinita

Edition 2007-01-09 top secret / strictly confidential page 214 of 520 Perlgolf History

-lnap $_=1;$_=($y/1+($y=$_))%2**$F[1]while--$F[0] 49, banshee -lp $b=1;($a,$b)=($b%2**$',$a+$b)for/ /..$`;$_=$a 50, zxc -lp $a=/ /;($a,$b)=($b%2**$',$a+$b)for 0..$`;$_=$a 51, m.thelen -lpa $_=1;($_,$^F)=($^F%2**$F[1],$_+$^F)while--$F[0]>1 52, FatPhil -pl $r=/ /;($l,$r)=($r%(1<<$'),$l+$r)for 1..$`;$_=$l 68, tinita (alternative) -lnap $s=1;$s=~s/.*/(($x=$y)+($y=$&))%2**$F[1]/efor 0..$F[0]-2;$_=$s

5.13. Self numbers http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=13&season=0 The game started 2002-11-03 22:00:00 and ended 2002-11-06 22:00:00.

5.13.1. Rules In 1949 the Indian mathematician D.R. Kaprekar discovered a class of numbers called self-numbers. For any positive integer n, define d(n) to be n plus the sum of the digits of n. (The d stands for digitadition, a term coined by Kaprekar.) For example, d(75) = 75 + 7 + 5 = 87. Given any positive integer n as a starting point, you can construct the infinite increasing sequence of integers n, d(n), d(d(n)), d(d(d(n))), .... For example, if you start with 33, the next number is 33 + 3 + 3 = 39, the next is 39 + 3 + 9 = 51, the next is 51 + 5 + 1 = 57, and so you generate the sequence 33, 39, 51, 57, 69, 84, 96, 111, 114, 120, 123, 129, 141, ... The number n is called a generator of d(n). In the sequence above, 33 is a generator of 39, 39 is a generator of 51, 51 is a generator of 57, and so on. Some numbers have more than one generator: for example, 101 has two generators, 91 and 100. A number with no generators is a self-number. There are thirteen self-numbers less than 100: 1, 3, 5, 7, 9, 20, 31, 42, 53, 64, 75, 86, and 97. Write a program to output all positive self-numbers less than or equal 1000 in increasing order, one per line.

5.13.2. Solutions 32, ton -l print$#a+=/-|0/?2:11for-4..97 32, ton (alternative) print$#a+=11-9x/0/,$/for-104..-3 32, tybalt89 -l print$#n+=/-|0/?2:11for-4..97 32, terje

Edition 2007-01-09 top secret / strictly confidential page 215 of 520 Perlgolf History

-l print$#a+=2+!/-|0/*9for-4..97 32, david seed aka gimbo -l print$#i+=/-|0/?2:11for-4..97 32, mtve -l print$#$-=9*/-|0/-11for-4..97 32, Bass -l print$#x+=11^9x/0/for-104..-3 33, Bass (alternative) -l print$#x-=7-9*y/0//cfor 6..107 33, Bass (alternative) -l print$#x+=2+9x!/9|^1/for-93..8 35, andys -l print$a+=2-??+9*!/-|9$/for-5..96 35, banshee -l print$t-=9*/-|0/-11for--$t-3..97 35, terje (alternative) -l print~-($a+=2+!/-|0/*9)for-4..97 36, Sec -li-1 print$^I+=11-9*/-|9$/for-5..96 36, Amir Karger -l print$%+=/-|0$/?2:11for--$%-3..97 37, andys (alternative) -l print$a+=$a%101<9?2-??:11for-2..99 37, Jasper -l print$n+=2+9*/.[^0]/for$n--.6..107 39, m.wrenn (alternative) -l print$a+=$_>4&!/4$/?11:2for$a--..101 41, ton (post-mortem) -l print$_*11+9-9*int$_*(/-/+.1)for-4..97 42, m.wrenn -l print$a+=$_>4&$_%10!=4?11:2for$a--..101 42, ton (alternative) print$_*(/-/?2:12.5)+9-1.5*hex,$/for-4..97 42, tybalt89 (alternative) -l print$_*11+9-9*int$_/10+$_*/-/for-4..97 43, Stephen Turner

Edition 2007-01-09 top secret / strictly confidential page 216 of 520 Perlgolf History

print map$_*2+9*($_*!/-/+/.$/-$`).$/,-4..97 43, mtve (post-mortem) -l map@{s//+0x/g,$`+eval}=@$_||print,1..1e3 43, Wladimir Palant -l $a--;print$a+=2+($_%10&&$a>8)*9for-4..97 44, p.kailasa -l print,$_+=$_>7&&++$i%10?11:2for(++$_)x102 45, ton (alternative) print"1 3 5 ",map$_*10.1+9+$_%10*.9.$/,-1..97 45, mtve (alternative) -l map@{$_+map+(1)x$_,/./g}=@$_||print,1..1e3 48, banshee (alternative) -l $t=7;print for 1,3,5,7,map$t+=2+9*!/1$/,1..98 48, tybalt89 (post-mortem) -l map${-$_+!s//+0x/g-eval}=${-$_}||print,1..1e3 49, tybalt89 (alternative) -l ${-$_+!s//+0x/g-eval}=${-$_}||print for 1..1e3 49, beowulf -l $_=-1;print$_+=$_%101==7||$_<9?2:11while$_<995 52, m.wrenn (alternative) -l map$s{$_+$1+$2+$'}=/(.)(.)?/&$s{$_}||print,1..1e3 53, zxc -l map{$x[$d=$_]?1:print;$x[$d]=s/\d/$d+=$&/ge}1..999 55, banshee (alternative) -l ++$s{eval(join"+",/./g,$_)},$s{$_}||print for 1..999 56, Sec (alternative) -l map$z[$_]||print,map{s||+|g;$z[eval$_.++$a]=$a}1..1e3 56, Jacco -l for(1..999){$_[$_]||print;$d=$_;$_[$d]=s/./$d+=$&/eg} 60, Giovans map{$_[$_]||print$_.$/;$_[$_+eval join'+',/\d/g]++}(1..1000) 62, tinita -l map$s[$_]||print,map{$d=$_;map$d+=$_,m/./g;$s[$d]=$_}1..999 66, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 217 of 520 Perlgolf History

-l grep(($m=$_,s//+/g,eval$_.$m==$n),1..($n=$_))||print for 1..999 72, Jasper (alternative) -l (1x$_)!~/^(1{100}1){0,9}(1{10}1){0,9}(1{1}1){0,9}$/&&print for 1..999 79, tinita (alternative) @o=1..999;$"=" ";$s="@o "; for(@o){$d=$_;map$d+=$_,m/./g;$s=~s/\b$d\n//}print$s 92, NumberCruncher for($i=0;$i<999;$i++){$j=$i;map($j+=$_,split(//,$i));$d{$j}=1;print"$i\n"if!exi sts($d{$i});} 96, jp vidal -l $t.="$_ "for 1..999;for$s(1..999){$s+=$_ for split'',$s;$t=~s/\b$s\b//};$_=$t;print for split

5.14. Spinning wheels http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=14&season=0 The game started 2002-11-20 19:00:00 and ended 2002-11-23 22:00:00.

5.14.1. Rules How long will it take a set of randomly spinning wheels to all be identically oriented on a given moment, or if it is ever possible. All wheels have an initial position represented in degrees 0 ≤ p < 360 and their spinning direction and speed -1000 ≤ s ≤ 1000 represented in number of degrees per seconds. Each wheel info is given as "position[+-]speed", with a single space separating the different wheels. The input line (@ARGV) will have a minimum of 2 and a maximum of 5 wheels. Input matching: /{\d+[+-]\d+ }{1,4}\d+[+-]\d+\n\z/. Output will be the orientation at which they align and the elapsed time in seconds. Output matching: /(\d+ \d+|-1)\n/. Sample input 0+45 180-90 Sample output 180 4 because they align at 180 degree in 4 seconds. at 0 second wheel 1 is at 0 degree and wheel 2 is at 180 degree. at 1 second wheel 1 is at 45 degree and wheel 2 is at 90 degree. at 2 second wheel 1 is at 90 degree and wheel 2 is at 0 degree. at 3 second wheel 1 is at 135 degree and wheel 2 is at 270 degree. at 4 second wheel 1 is at 180 degree and wheel 2 is at 180 degree. If after 360 seconds no alignment have been found then the output should be -1.

Edition 2007-01-09 top secret / strictly confidential page 218 of 520 Perlgolf History

5.14.2. Solutions 70, mtve -l {%z=map{eval"($_*$?)%360",$".$?}@ARGV;print++$??(%z)[3]?redo:%z:-1} 71, tybalt89 {print 2<(@a=%{{map{eval"($_*$?)%360",$?}@ARGV}})?++$??redo:-1:"@a",$/} 73, ton (post-mortem) -l {print/\d*/-grep($&.1ne$&.s//eval()%360/e,@ARGV)?++$??redo:-1:"$& $?"} 74, ton (post-mortem) print+(/\d*/-grep$&.1ne$&.s//eval()%360/e,@ARGV)?++$??!do$0:"-1 ":"$& $? " 76, ton -l $a=""while++$?&&grep$&*s/\d+/eval()%360/e-($a||="$& "),@ARGV;print$a,--$? 84, ton (post-mortem) $x=-/\d*/;$x+=$&.1ne$&.s//eval()%360/efor@ARGV;print$x?$%++<360?!do$0:"-1 ":"$& $% " 86, p.kailasa -l map{%a=map{$a=$_%360,s/-?\d+/$_/ee}@ARGV;$b||="$a $_"if 2>keys%a}0..360;print$b||-1 87, terje $x=-1;$;=$&,s/\d+/eval()%360/e,$x+=$;ne$&for@ARGV;print$x?$%++<360?!do$0:"-1 ":"$; $% " 91, m.wrenn -l $_=-1until(join'',map$m=(eval"$_*$%")%360,@ARGV)=~/^($m)+$/&&s/.*/$m $%/||$%++>360;print 95, topmach -l for$,(0..360){@a=map{/\d+/;($,*$'+$&)%360}@ARGV;$a||=$1.$,if"@a "=~/^(\d+ )\1+$/}print$a||-1 99, andys -l /\d+/,/^( ($&)\D\S+)*$/?$a="$2 $?":$?+++s/ \d+/$".($&+$')%360/egfor($_=" @ARGV")x360;print$a||-1 101, banshee -l @X=@ARGV;map{$s=($;=0)+"@X";$;+=$s!=$_,s/\d+/(eval)%360/efor@X;$;or$x||="$s $_"}0..360;print$x||-1

5.15. Columns squeezer http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=15&season=0 The game started 2002-11-29 20:00:00 and ended 2002-12-03 22:00:00.

Edition 2007-01-09 top secret / strictly confidential page 219 of 520 Perlgolf History

5.15.1. Rules And finally something useful from golf. Squeeze empty columns in text, where empty means space or place beyond end of line. For example in following text wide empty columns are marked by blue background: smmsp -- 2 0 0 - 2 uucp -- 892 0 0 - 4700 asd www -- 18 0 - 6 mysql -- 1089 0 0 - 57 201 -- 511 0 0 - And such columns should be narrowed to only one space: smmsp -- 200- 2 uucp -- 89200-4700 asd www -- 18 0 - 6 mysql -- 108900-57 201 --51100- Other examples of input you can get from `df -k` on Solaris or `repquota -a` on BSD. STDIN will consist of no more than 99 lines, no more than 99 chars on each line, only printable chars [ -~], no tabs.

5.15.2. Solutions 42, mtve -p0 1while/^$a?\S/m?$a.='.':s/^($a)./$1/mg 42, ton -p0 s- -/.*\G/;$&=~/$/;$"x/^.{@+}.?\S/m-eg 42, tybalt89 -p0 1while/^$m?\S/m?$m.='.':s/^($m) /$1/gm 45, ton (alternative) -p0 /^.{$^H}.?\S/m||s/^(.{$^H}) /$1/mgwhile$^H-- 48, tybalt89 (alternative) -p0 $a|=$_,y/ /_/for/.+/g,$a;s//$&&$a/ge;y/\x00//s 49, ton (alternative) -p0 y/ -~/\x00\xFF/,$a|=$_ for/.*/g;s!!$&&$a!eg;y/\x00//s 51, banshee -p0 map$x|=$_,/.*/gm;$x=~y/ /S/;s//$&&$x/ge;y/\x00//s 70, topmach $a|=$_ for@a=<>;for(@a){$b=$a;s/(.{@-}) /$1/while$b=~s/[* ] / /;print} 85, Colm Dougan @x=<>;$i=0;($y==grep s/^(.{$i} ) /$1/,@t=@x)?@x=@t:$i++while$y=map/.{$i}./,@x;print@x 89, m.wrenn

Edition 2007-01-09 top secret / strictly confidential page 220 of 520 Perlgolf History

-nl $s[@s]=$_;s/\S| (?! )/1/g;y/ /0/;$x|=$_}{$s=print map$_ x($x=~/./g)[++$s- 2],/./gfor@s

5.16. DNA sorting http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=16&season=0 The game started 2002-12-06 19:30:00 and ended 2002-12-11 21:00:00.

5.16.1. Rules One measure of "unsortedness" in a sequence is the number of pairs of entries that are out of order with respect to each other. For instance, in the letter sequence "DAABEC", this measure is 5, since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence "AACEDGG" has only one inversion (E and D)-- it is nearly sorted--while the sequence "ZWQM" has 6 inversions (it is as unsorted as can be-- exactly the reverse of sorted). You are responsible for cataloguing a sequence of DNA strings (sequences containing only the four letters A, C, G, and T). However, you want to catalog them, not in alphabetical order, but rather in order of "sortedness", from "most sorted" to "least sorted". All the strings are of the same length. Input Input will consist of 0 < x < 100 lines with the length 0 < l < 100 matching /^([ACGT]{1,99}\n){1,99}\z/ Output Output the list of input strings, arranged from "most sorted" to "least sorted". If two or more strings are equally sorted, list them in their original order. Sample Input AACATGAAGG TTTTGGCCAA TTTGGCCAAA GATCAGATTT CCCGGGGGGA ATCGATGCAT Sample Output CCCGGGGGGA AACATGAAGG GATCAGATTT ATCGATGCAT TTTTGGCCAA TTTGGCCAAA

5.16.2. Solutions 45, ton (rejected) -n s#.#@a[/[^$&-Z]/g]#g;$;[y///c].=$`}{print@ 46, mtve -n s#.#@{[/[^$&-Z]/g]}#g;$;[y/ //].=$`}{print@ 46, ton

Edition 2007-01-09 top secret / strictly confidential page 221 of 520 Perlgolf History

-naF(.).*(?{$_+=$1gt$'})^ $;[$_].="@F"}{print@ 46, david seed aka gimbo -n s|.|@{[/[^$&-Z]/g]}|g;$;[y///c].=$`}{print@ 47, ton (alternative) -n /(.|).*(?{$_+=$1gt$'})\z/;$;[$_].=$`}{print@ 47, ton (alternative) -na /(.).*(?{$#F+=$1gt$'})^/;$;[@F].=$_}{print@ 47, david seed aka gimbo (alternative) -na s|.|push@F,/[^$&-Z]/g|ge;$;[@F].=$`}{print@ 47, tybalt89 -n @;[/(.).*(?{$_+=$+gt$'})^|/g,$_].=$`}{print@ 49, terje -n $;[map{/./,/[^$&-T]/g}/(?=(.*))/g].=$_}{print@ 50, mtve (alternative) -na $;[/(.).*(.)(?{$#F+=$1gt$2})^/+@F].=$_}{print@ 50, david seed aka gimbo (rejected) -na /(.).*(.)(??{$#F+=$1gt$2})/;$;[@F].=$_}{print@ 52, terje (alternative) -n $x=$_;s#.#@{[/[^$&-T]/g]}#g;$;[y/ //].=$x}{print@ 52, Colm Dougan (post-mortem) -p $;[map{s/.//;map/[^$&-Z]/,@_}@_=/./g].=$_}{print@ 53, Daniel and John (post-mortem) -paF// $a[map{$@=pop@F;grep$@lt$_,@F}@F].=$_}for(@a){ 54, Jasper -n $;[map{s/.//;/[^$&-T]/g}($c=$_)x y///c].=$_}{print@ 54, Daniel and John -p $a[map{$@=pop@b;grep$@lt$_,@b}@b=/./g].=$_}for(@a){ 55, topmach -n $a=$_;s|.|1x(()=/[^$&-Z]/g)|ge;$;[y/1//].=$a}{print@ 56, Colm Dougan -p $o[map{$c=pop@l;map/[^A-$c]/,@l}@l=/./g].=$_}for(@o){ 61, m.thelen -n $;[$t=0,s!.!map$t+=$>$_,split'',$';$&!eg,$t].=$_}{print@ 62, srushe -p $c=$s=$_;$c+=s/[^$&-Z]/$&/g while s/.//;$z[$c].=$s}for(@z){ 66, Karsten Sperling

Edition 2007-01-09 top secret / strictly confidential page 222 of 520 Perlgolf History

sub f{$_=pop;/.+(?{$_+=ord$&>ord$'})^/;$_}print+sort{f($a)- f$b}<> 67, m.wrenn -n $c=$t=$_;map{$c+=length$`while$t=~s/$_//}A..G;$;[$c].=$_}{print@ 72, tinita -n END{print@h}$c=@\xA7=/./g;map{$c+=$\xA7lt$_}@\xA7while$\xA7=pop@\xA7;$h[$c*9 9+$.]=$_ 72, Paul van Eldijk -naF// $t=0;while($@=shift@F){$t+=grep{$@gt$_}@F}@@[$t].=$_;END{print@@} 77, Chris Dolan sub f{($x=$n=pop)=~s,.,$n+=eval"$'=~y/$&-Z//c",eg;$n}print sort{f($a)- f$b}<> 94, yogi sub x{$n=0;$_=$_[0];$n++while(s/(T[ACG]|GA|GC|CA)/reverse$+/e);$n};print+sort{x( $a)<=>x($b)}<> 156, Matthias Schoder sub mp{$x=0;while($_[0]=~/./g){$q=$&;$_=$';while(/./g){ $x++if$q gt$&}}$x}print map$_->[0],sort{mp($a->[0])<=>mp($b->[0])||$a->[1]<=>$b->[1]}map[$_,$i++],<> 178, NumberCruncher @l=<>;push@m,map{&o($_)}@l; map{print$l[$_]}(sort{$m[$a]<=>$m[$b]}(0..$#m)); sub o{@f=split//,shift;@g=@h=@f;pop@g;$s=0;map{$q=$_;shift@h;{map{$s++if($q gt$_);}@h;}}@g;return$s;}

5.17. Clock patience http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=17&season=0 The game started 2002-12-17 11:00:00 and ended 2002-12-23 22:00:00.

5.17.1. Rules Card sharp Albert (Foxy) Smith is writing a book on patience games. To double check the examples in the book, he is writing programs to find the optimal play of a given deal. The description of Clock Patience reads as follows: "The cards are dealt out (face down) in a circle, representing a clock, with a pile in each hour position and an extra pile in the centre of . The first card goes face down on one o'clock, the next on two, and so on clockwise from there, with each thirteenth card going to the center of the clock. This results in thirteen piles, with four cards face down in each pile."

Edition 2007-01-09 top secret / strictly confidential page 223 of 520 Perlgolf History

The game then starts. The top card of the 'king' pile (the last card dealt) is exposed to become the current card. Each move thereafter consists of placing the current card face up beneath the pile corresponding to its value and exposing the top card of that pile as the new current card. Thus if the current card is an Ace it is placed under the 'one' pile and the top card of that pile becomes the current card. The game ends when the pile indicated by the current card has no face down cards in it. You win if the entire deck is played out, i.e. exposed Write a program that will read in a shuffled deck, and play the game. Input and Output The input will consist of a standard deck of cards arranged in four lines of 13 cards, cards separated by a single blank. Each card is represented by two characters, the first is the rank (A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K) followed by the suit (H, D, C, S). The deck is listed from bottom to top, so the first card dealt is the last card listed. The output will consist of the number of cards exposed during the game, and the last card exposed (in the format used in the input), separated by a single space. Sample Input TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC 9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D 6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C Sample output 44 KD To help debugging, here is the correct order of the cards in the example above TS 8D 2D KS 9D QH QC JH 8S QS 4S 2H 4D 5H 9H 2S 6S KH 6D 2C 6C 3D TH JD 7H 3H AD KC AS 5D 4H 3S 4C TC 5S 8C JS 9S 7S TD 6H AC 9C KD

5.17.2. Solutions 62, ton (post-mortem) -pa0 }{$\=++$n." $_ "while$_=$F[y/TJQA-Z/A-C1,/&&13*++$$_-hex] 68, ton (post-mortem) -pa0 }{$_=KS;$\=++$n." $_ "while$_=$F[y/TJQKA-Z/A-D1,/,13*++$$_-hex] 70, ton -p0 $\=s/\G(.).//+$\." $& "while KQJT98765432A=~$1,/^(\S* ){@-}\b/mg}{ 70, ton (alternative) -p0 $\=s/(.)\G.//+$\." $& "while KQJT98765432A=~$1,/^(\S* ){@-}\w/mg}{ 70, ton (alternative) -p0 $\=s/(.)\G.//+$\." $& ",KQJT98765432A=~$1while/^(\S* ){0@-}\S/mg}{ 70, ton (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 224 of 520 Perlgolf History

-pa0 }{$_=K;$\=++$n." $_ "while$_=$F[y/TJQKA-Z/A-D1/d,13*++${~$_}-hex] 71, mtve -p0 $\=1+$\." $& "while KQJT98765432A=~$2,s/(?<=^(.. ){@-})(\S)./ /m}{ 71, ton (alternative) -p0 $\="$n K$& "while$n+=KQJT98765432A=~$2,s/(?<=^(.. ){@-}(.))\D/0/m}{ 71, tybalt89 -p0 $\=1+$\." $& "while KQJT98765432A=~$+,s/(?<=^(...){@-})(\w)./../m}{ 71, ton (post-mortem) -pa0 }{$_=K;$\=++$n." $_ "while$_=$F[y/TJQKA-D/A-D1,/,13*++$i[hex]-hex] 72, ton (post-mortem) -pa0 }{$\=++$n." $_ ",y/QJT987654B-H32A/1-C/while$_=@F[13*$i[hex]+++hex] 75, m.wrenn -pal map$k{$_}.=pop@F,A,2..9,T,J,Q,K}{$_=++$c." $&"while$k{$1||K}=~s/(.).// 75, david seed aka gimbo (post-mortem) -pa $_.=pop@F for@_{A,2..9,T,J,Q,K}}{$_=++$c." $& "while$_{$1||K}=~s/(.).// 76, topmach -lpa $h{$_}.=pop@F for A,2..9,T,J,Q,K}{$_=++$_.$".$&while$h{$1||K}=~s/(.).// 76, terje -lp0 s/\s/k.(A,2..9,T,J,Q,K)[--$i%13]/eg;$_=s/((.).)k$2//&&++$a?do$0:"$a $1" 76, terje (post-mortem) -lp0 $_=s/(?<=^.{@{[3*$-[KQJT98765432A!~$1]]}})(\w)./##/m&&++$a?do$0:"$a $&" 77, terje (alternative) -lp0 $_=s/^(.{@{[3*$-[KQJT98765432A!~$3]]}})((\w).)/$1##/m&&++$a?do$0:"$a $2" 77, banshee -lap map$$_[4-$.]=pop@F,A,2..9,T,J,Q,$s=K}{$_++,$\=" $s "while$s=pop@{$s&~v0} 78, pom -pa0 }{$;=++$k." $_ ",y/KQJT987654B-H32A/0-C/while$_=$F[13*$i[hex]+++hex];$_=$ 79, Jasper -lna map$a{$_}.=pop@F,A,2..9,T,J,Q,K}{$n++while$a{$1||K}=~s/(.).//;print"$n $&" 80, Petri Mikkelä

Edition 2007-01-09 top secret / strictly confidential page 225 of 520 Perlgolf History

-pa0 $_{$_}.=pop@F for(A,2..9,T,J,Q,K)x4;$_=++$c." $& "while$_{$1||K}=~s/(.).$// 80, Colm Dougan -lap0 $p=$F[$p]=~s#(.).#@{$_=++$c." $&"}#?index KQJT98765432A,$+:$p+13while$p<52 81, srushe -pal map$p[$i++%13].=$_,@F}{$_=++$t.$".$&while$p[index KQJT98765432,$1]=~s/(.).// 82, david seed aka gimbo -p s|\S+|$_[pos].=$&|ge}{$_=++$c." $& "while$_[3*index KQJT98765432A,$1]=~s/(.).// 84, Peter Haworth -alp push@$_,pop@F for A,2..9,T,J,Q,$c=K}$_=$c,chop$c,++$;while$c=shift@$c;s//$; /;{ 92, Peter Haworth (alternative) -ap $d.=" $_".pop@F for A,2..9,T,J,Q,$c=K}{$c=$2,++$;+$1while$d=~s/ $c((.).)//;$_="$; $1 " 110, _-Ani-_ (post-mortem) -lp0 y/TJQKA/:-=1/;$y=0;$x++while s/^((\S* ){$y})(\S+)/$y=61- ord($c=$3);$1/me}{$_=$x.$".($c=~y/:-=1/TJQKA/,$c) 122, wersh -an END{while($_=shift@{$c[$p]}){$l=$_;chop;$p=index'KQJT98765432A',$_;$x++}prin t"$x $l\n"}$i=0;push@{$c[$i++]},$_ for(@F) 140, Hirogen2 (post-mortem) $_{$_}=++$/for A,2..9,T,J,Q,K;push@{$a[$x++%13]},$_ for reverse split/ /,<>;*_=$a[12];*_=$a[$y++,$_{pack A,$z=pop@_}-1]while@_;print"$y $z " 141, Hirogen2 $_{$_}=++$/for A,2..9,T,J,Q,K;push@{$a[$x++%13]},$_ for reverse split/\s/,<>;*_=$a[12];*_=$a[$y++,$_{pack A,$z=pop@_}-1]while@_;print"$y $z "

5.18. Ideal golf http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=18&season=0 The game started 2002-12-28 13:30:00 and ended 2003-01-01 21:00:00.

5.18.1. Rules Given two positive integers a and b, consider all numbers generated by z=a*x+b*y

Edition 2007-01-09 top secret / strictly confidential page 226 of 520 Perlgolf History where x and y are integers. This set will of course consist of positive numbers, negative numbers and zero. And in fact, there will be some number d=a*X+b*Y which is the smallest of all positive numbers so generated (d > 0). It can easily be proven that d will be the greatest common divisor of a and b, d = gcd(a,b), and that all elements z are in fact multiples of d (It's in fact a commutative subring of the integers, a so called "ideal"1) The challenge: Given a and b on the commandline (in that order), print X, a space, Y and a newline to STDOUT. Since there are multiple solutions, print the one with the smallest abs(X) + abs(Y). And if even that is equal for multiple cases, choose the one with smallest X. The integers a and b will both be in the range 1..99 (they match /^[1-9]\d?\z/), and will be different: a ≠ b. So if the input is: 820 The output should be: -2 1 Since 4 = 8*(-2) + 20*1 is a better solution than 4 = 8*3 + 20*(-1). Some Algorithm hints 1. Brute Force It's easy to prove that abs(X) ≤ b and abs(Y) ≤ a, so in fact the search space is limited. Try them all and select the best one. 2. The reverse Euclidian algorithm The standard gcd algorithm is based on: gcd(a, b) = a if b == 0 gcd(b, a%b) if b != 0 For example, if a=37 and b=30, then gcd(37,30)= gcd(30,37%30)=gcd(30,7)= gcd(7,30%7)=gcd(7,2)= gcd(2,7%2)=gcd(2,1)= gcd(1,2%1)=gcd(1,0)=1 Or written in another way:

1 http://www.math.niu.edu/~beachy/aaol/rings.html#ideals

Edition 2007-01-09 top secret / strictly confidential page 227 of 520 Perlgolf History

37=1*30+ 7 // // // 30=4* 7+ 2 // // // 7=3*2+ 1 // // // 2=2*1+ 0 | V d=gcd(37,30) You can then start from d=d and work upward (see the right column): 37=1*30+ 7 d=-3*30+13*(37-1*30)=13*37-16*30 / / \ \______\__ / / \______\ // \ \ \ 30=4* 7+ 2 d= 1* 7- 3*(30-4* 7)=-3*30+13* 7 / / \ \______\__ / / \______\ // \ \ \ 7=3*2+ 1 d= 0* 2+ 1*( 7-3* 2)= 1* 7- 3* 2 / / \ \______\__ / / \______\ // \ \ \ 2=2*1+ 0 d= 1* 1+ 0*( 2-2* 1)= 0* 2+ 1* 1 | V d=gcd(37,30)=1 That gives you one solution (X=13 and Y=-16). You can find the others by starting from other values than x=0 in d= 1* 1+ x*( 2-2* 1) Or you can make the observation that the difference between two solutions must give: X*a+Y*b=0 which has at least one obvious solution X=-b and Y=a, and since d divides both a and b X=-b/d and Y=a/d, which will be the smallest possible difference. So if you have any solution (X, Y), all other solutions can be generated using: (X, Y)+z*(-b/d, a/d) where z is any integer.

5.18.2. Solutions 71, ton -l print`$^X $0 $. @{[($a=pop)%$.]}`=~$"*$',$",//+$`-$'*int$a/$.if$.=pop 86, ton (rejected) //,map$b[(-$'*"@ARGV"-$ARGV[1]*$_)%1e4*3e3+$_*$']="$' $_ ",@;for@;=-49..49;print pop@b 88, ton (alternative)

Edition 2007-01-09 top secret / strictly confidential page 228 of 520 Perlgolf History

//,map$b[(-$'*"@ARGV"-$ARGV[1]*$_)%1e4*@;-abs$_-$']="$' $_ ",@;for@;=-50..50;print pop@b 92, mtve for$i(@z=-49..49){$w[(-"@ARGV"*$i-$ARGV[1]*$_)%1e4*99-abs($i)-abs]="$i $_ "for@z}print$w[-1] 92, mtve (alternative) print$w[-!!map{//;$w[(-"@ARGV"*$'-$ARGV[1]*$_)%1e4*99-abs($')-abs]="$' $_ "for@z}@z=-49..49] 101, Step'n'Jas ($a,$b)=@ARGV;($a,$b,@d)=($b,$r,$a/$b,@d)while$r=$a%$b;$y=1;($r,$y)=($y,$r- $y*int)for@d;print"$r $y " 101, topmach for$@(@n=-50..50){${$ARGV[0]*$@+$ARGV[1]*$_}[$@**2+abs]="$@ $_ "for@n}$i++until"@$i"=~/\S.* /;print$& 109, Jasper (rejected) for$x(@b=-99..99){map{eval'$a[$x*$ARGV[0]+$_*$ARGV[1]-1][abs +abs$x]="$x $_ "'}@b}print+(grep$_,map@$_,@a)[0] 112, Jasper for$x(@b=-99..99){map{$a[$s][abs +abs$x]="$x $_ "if($s=$x*$ARGV[0]+$_*$ARGV[1])>0}@b}print+(grep$_,map@$_,@a)[0] 112, Petri Mikkelä for$x(@a=-49..49){map{$g=$f,$\="$x $_ "if($f=($ARGV[0]*$x+$ARGV[1]*$_)*(1e5+abs($x)+abs))>0&$f<($g||[])}@a}print 129, david seed aka gimbo $S=$^T;($a,$b)=@ARGV;for$x(- $b..$b){map{($S,$^T,@R)=($s,$r,$x,$_)if$^T>=($r=$x*$a+$_*$b)&$r>0&$S>($s=abs ($x)+abs)}-$a..$a}print"@R " 134, topmach (alternative) -l for$t(@n=1..99){for$i(@n){for(0,1){for(@n){@a=($_,$_- $i);$ARGV[0]*$a[$|]+$ARGV[1]*$a[--$|]==$t&&print("$a[--$|] $a[-- $|]")+exit}}}} 169, Dave Giancaspro -l $b=pop;$a=pop;$d=99;$m=99;@x=(-$b..$b);@y=(- $a..$a);foreach$x(@x){map{$z=$a*$x+$b*$_;$z<=$d&&$z>0?eval{$d=$z;abs$x<=abs$ m?eval{$m=$x;$n=$_}:$a;}:$a;}@y}print "$m $n"; 302, NumberCruncher (post-mortem) use POSIX qw(fmod abs);$z=100000; ($m,$n)=@ARGV;$d=&gcd(($m,$n));@U=(-$n..$n); foreach $u(@U){$h=($d-$m*$u)/$n;next if($h!=int($h));$t=abs($u)+abs($h);if($t<$z){$z=$t;$x=$u;$y=$h;}} printf "%i %i\n",$x,$y;sub gcd {($x,$y)=@_;for($i=$x;$i>=1;$i--){last if((fmod($x,$i)==0)&&(fmod($y,$i)==0));}return$i;}

Edition 2007-01-09 top secret / strictly confidential page 229 of 520 Perlgolf History

5.19. Scrabble http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=19&season=0 The game started 2003-01-05 22:00:00 and ended 2003-01-12 21:00:00.

5.19.1. Rules Given a string representing a bag of letters (matching /^[a-z]{1,30}\z/) as argument, output upto 10 words from the given wordslist (not necessarily sorted) provided via the standard input (matching /^([a-z]{1,30}\n){1,9999}\z/) that can be made from those letters. The output (STDOUT) should match /^([a-z]{1,30}\n){0,10}\z/ and consist of the words that can be made from the given letters. Words should be sorted first by the most letters per words and then alphabetically. Each letters from the bag may be used only once. Not all letters from the bag have to be used. If less then 10 words can be formed then simply return the short sorted list. If no words can be formed from the given letters then you should not return anything. So if the input is: reverse The output should be: reserve resever reverse severer revere revers server severe verser esere

5.19.2. Solutions 71, ton (rejected) print/\D/gfor(sort grep$_*s//"$a.'&z'e"/ee,<>)[($a=pop)!~s!!''.s'!g..9] 72, mtve print/\D/gfor(sort map{$b=$';(~s#.#$b!~s/$&//#eg.$`)x!//}<>)[pop!~//..9] 72, ton print/\D/gfor(sort grep$_*s//"$a.'&$''e"/ee,<>)[($a=pop)!~s!!''.s'!g..9] 72, ton (alternative) print/\D/gfor(sort map{$q=$';(~s#.#$q!~s/$&//#eg.$`)x!//}<>)[pop!~//..9] 73, ton (rejected) print/\D/gfor(sort grep$_&s/()/"$a\\b''g"/ee,<>)[($a=pop)!~s!!''.s'!g..9] 74, ton (alternative) $a=pop;print@F{A..J}=map/\D+$/g,sort map~s#.#s/$&//g>map//g,$a#eg.$`.//,<> 74, ton (alternative) print+(map/\D+$/g,sort grep s/()/"$a.'1'"/gee,<>)[($a=pop)!~s!!''.s'!g..9] 75, mtve (alternative)

Edition 2007-01-09 top secret / strictly confidential page 230 of 520 Perlgolf History

print+(sort{@$b-@$a}grep{$d=$';!grep$d!~s/$_//,@$_=/./g}sort<>)[pop!~//..9] 80, tybalt89 print+(map/\D+/g,sort map{//;{($t=$m)=~s/./s#$&##/ge}/./||$t.$'}<>)[$m=pop,1..9] 80, Daniel (post-mortem) split//,pop;map$j++>9||s/ +//&&print,sort map{//;for$c(@_){s/$c/ /}/./||$_.$'}<> 83, terje $a=pop;print/1(\D+)/for(sort map{$x=$_;$a=~s|.|s/$&/1/,$&|eg;$&x/^1+$/.$x}<>)[0..9] 83, Daniel split//,pop;map$j++>9||s/ +//&&print,sort map{$s=$_;for$c(@_){s/$c/ /}/./||$_.$s}<> 83, andys $x=pop;print+(grep{$y=$x;!grep$y!~s/$_//,/./g}sort{$b=~y///c- length$a}sort<>)[0..9] 83, Jasper $l=pop;print+(map/(\D+)/,sort map{$c=$l;(grep$c!~s/$_//,@a=/./g)||1x@a.$_}<>)[0..9] 83, Peter Haworth $W=pop;print+(grep!($w=$W,s/..//,grep$w!~s/$_//,/./g),sort map$=- y///c.$_,<>)[0..9] 86, Michael Rybakin $a=pop;print/(\D+)/for(sort grep{$c=$t=$a;s|^|63^s/./$c+=$t!~s@$&@@/ge|e;!$c}<>)[0..9] 88, david seed aka gimbo (rejected) $w=pop;print/\D/gfor(sort map{$:=$t=$w;$:x=$t=~s/$_//for/./g;$:?30- y///c.$_:()}<>)[0..9] 90, david seed aka gimbo $w=pop;print+(grep{$:=$t=$w;$:x=$t=~s/$_//for/./g;$:}sort{$b=~y///c- length$a}sort<>)[0..9] 90, pom @;=pop=~/./g;print+(sort{$b=~y///c-length$a}grep{$;=$_;$;=~s/$_ ?//for@;;!$;}sort<>)[0..9] 91, Petri Mikkelä map{s/\d+//;$e=$_;$e=~s/$_ ?//for"@ARGV"=~/./g;$e||$g++<10&&print}sort map~y///c.$_, 93, topmach @l=pop=~/./g;print+(grep{$w=$_;$w=~s/$_//for@l;$w!~/./}sort{length$b<=>length$a }sort<>)[0..9] 93, m.wrenn

Edition 2007-01-09 top secret / strictly confidential page 231 of 520 Perlgolf History

$p=pop,print((map/(\D+)/,sort map{for$q($p=~/./g){s/$q/uc$q/e}/[a-z]/||9x y///c.lc}<>)[0..9]) 97, giovans (post-mortem) split??,pop;print@b[0..9]=sort{$$b-$$a||$a cmp$b}map{$c=$g=$_;$$c+=$g=~s/$_//for@_,$/;!$g&&$_}<>; 99, m.thelen $a=pop;map{$;=$_;$;=~s/$_//for$a=~/./g;$z[30- y///c].=$;!~/./&&$_}sort<>;print+("@z"=~/\S+ /g)[0..9] 100, tinita @s=sort pop=~/./g;print+(sort{length$b<=>length$a}grep{$f=join'.*',sort/./g;"@s"=~/$ f/}sort<>)[0..9] 117, giovans @_=split??,pop;@b=map{$c=$g=$_;$$c+=$g=~s/$_//for@_,$/;(!length$g)&&$_}<>;@b=so rt{$$b-$$a||$a cmp$b}@b;print@b[0..9]; 150, Hirogen2 $P{$_}++for$/,split//,pop;N:while(<>){%_=%P;for(split//){next N if-- $_{$_}<0}push@Q,$_}print+(sort{length$b<=>length$a||$a cmp$b}@Q)[0..($#Q>9?9:$#Q)] 153, Frantisek Darena $t=shift;while(<>){@p=/./g;$s=$t;shift@p while$s=~s/$p[0]//and@p;push@{$v{length($_)}},$_ if!@p}push@w,sort@{$v{$_}}for sort{$b<=>$a}keys%v;print@w[0..9] 176, me ELOISE p(split(//,pop),'','');print((sort{length$b<=>length$a||$a cmp$b}grep{$h{$_}}<>)[0..9]);sub p{my$s=pop;my@a=@_;pop@a;$h{"$s "}=1;for(1..@a){p(@a,$s.$a[-1]);push(@a,shift(@a))}} 261, JLO -l @a=split'',pop;while(<>){$u=$_;for $b(0..@a){$u=~s/$a[$b]//;}push(@u,(length($_)+10).$_)if $u eq "\n";}for($i=($#a+12);$i>10;$i--){for(reverse sort @u){($x,$y)=/($i)(.*)/;push(@x,$y)if $y;if($x!=$i){push(@k,sort @x);@x=();}}}for(0..9){print $k[$_]if $k[$_];}

5.20. "LED" Display http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=20&season=0 The game started 2003-01-13 16:30:00 and ended 2003-01-17 21:00:00.

5.20.1. Rules Given a number composed of 1 to 20 digits (matching /^\d{1,20}\z/) as argument, output on STDOUT the same number in a "LED" format where each digit is 3 cells wide and 5 cells high (matching /^([# ]{3}( [# ]{3}){0,19}\n){5}\z/).

Edition 2007-01-09 top secret / strictly confidential page 232 of 520 Perlgolf History

Digits should be single space separated and no trailing spaces should be present after the last digit, except the ones filling the blank cells within the digit itself. If no argument is given you are to print nothing. So if the input is: 01234567892 The output should be: ### # ### ### # # ### ### ### ### ### ### ## # # #### # ##### # # # # ### ### ### ### ### # ### ### ### ## ## # # ### ### ## ### # ### ### # ### ### # ### ### ### If the first digit is 1 you are to print the 2 leading spaces that compose the "LED" digit.

5.20.2. Solutions 83, mtve (post-mortem) $r+=print"@{[glob'{#,#,\ }'x3]}[map{8*vec'\x0C\x02\xE0o\xAD\x0E\xC0\xE0\xFD\xEE\x0C\xC3',$r.$_,2}/./g ] "for(@ARGV)x5 85, mtve (post-mortem) $r+=print"@{[glob'{#,\ }'x3]}[map{3*vec('\x08\x03\xB0z\xF9\x0B\x80\xB0\xA9\xBB\x08\x82',$r.$_,2)%7} /./g] "for(@ARGV)x5 86, ton (post-mortem) y/01/ #/&&print"@{[/.../g]}[@_] "for unpack'b30'x5,'\xE7\xDF\xFF?%\xD9\x84-\xE5\xFF\x9F?eH\x96%\xE7\xCF\x9F?'x split//,pop 87, mtve (post-mortem) map{y/01/ #/,print"@{[/.../g]}[@_] "}unpack'B30'x5,'\xE7\xFB\xFF\xFC\xA4\x9B!\xB4\xA7\xFF\xF9\xFC\xA6\x12i\xA4\xE7 \xF3\xF9\xFC'if split//,pop 87, mtve (post-mortem) $r+=print"@{[glob'{#,\ }'x3]}[map{vec('\x08\x03\xB0z\xF9\x0B\x80\xB0\xA9\xBB\x08\x82 \xC2',$r.$_,2)*3%7}/./g] "for(@ARGV)x5 88, ton y/01/ #/,@F=/.../g,print"@F[@_] "for unpack'(b30)*','\xE7\xDF\xFF?%\xD9\x84- \xE5\xFF\x9F?eH\x96%\xE7\xCF\x9F?'x!!split//,pop 88, mtve map{y/01/ #/,@q=/.../g,print"@q[@_] "}unpack'B30'x5,'\xE7\xFB\xFF\xFC\xA4\x9B!\xB4\xA7\xFF\xF9\xFC\xA6\x12i\xA4\xE7 \xF3\xF9\xFC'if split//,pop 88, Daniel (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 233 of 520 Perlgolf History

@a=map{substr'### # #',2*vec('\x0C\x01\xD0\x9F^\x0D\xC0\xD0\xFE\xDD\x0C\xC3',$i.$_,2),3}/./gand$ i+=print"@a "for(pop)x5 88, tybalt89 @m='### ## # #'=~/.../g;$r+=print"@m[map{vec'\x04\x03p\xB5\xF6\x07@pVw\x04A',$r.$_,2}/./g ] "for(@ARGV)x5 90, Daniel @a=map{substr'### # #',2*vec('\x0C\x01\xD0\x9F^\x0D\xC0\xD0\xFE\xDD\x0C\xC3',$i+$_,2),3}/./gand$ i+=9+print"@a "for(pop)x5 92, Benoît Chauvet (post-mortem) -l $x+=print"@{[map{('# # # ####'=~/.../g)[vec'\xFB\xFD\x9F\x1AX\xF9\xBF\x9F\xA8\x99\xFB\xBE\x0F',$x.$_, 2]}/./g]}"for(@ARGV)x5 93, ton (alternative) $_=unpack'b*','\xE7\xDF\xFF\x7FI6a[\xFE\xFF\xF9\x97!Y\x96\xE7\xCF\x9F?';s!.{30} !@F=/.../g;print"@F[@_] "!eg if split!y/01/ #/,pop 94, Alma Media Golf Team s//\x08\x03 \xAB\x97\x0F \x0B\x80 \x9B\xBA\x0B \x08\x82 /;s!.+!@{[glob'{#,\ }'x3]}[map vec($&,$_,2)*3%7,@d]!g,print if@d=pop=~/./g 97, banshee @a=pop=~/./g;y/01/ #/,@b=/.../g,@a&&print"@b[@a] "for(unpack"b*",'\xE7\xDF\xFF\x7FI6a[\xFE\xFF\xF9\x97!Y\x96\xE7\xCF\x9F?')=~/.{ 30}/g 97, Michael Rybakin $_=pop;for$d(2..6*/./){print"@{[map{substr'### # #',2*vec('@\xC5\xFF\x8C0S<2H\xF0O\x041',5*$_+$d,2),3}//g]} "} 100, Benoît Chauvet -l map{$x+=print"@y"if@y=map{("# # # ####"=~/.../g)[vec'\xFB\xFD\x9F\x1AX\xF9\xBF\x9F\xA8\x99\xFB\xBE\x0F',$x.$_, 2]}"@ARGV"=~/./g}0..4 100, andys $a+++print"@{[map{y/01/ #/;/(...){$a}/}(unpack'B15'x10,'\xF6\xDE$\x92\xE7\xCE\xE7\x9E\xB7\x92\xF3\x9 E\xF3\xDE\xE4\x92\xF7\xDE\xF7\x9E')[/./g]]} "for(@ARGV)x5 101, terje

Edition 2007-01-09 top secret / strictly confidential page 234 of 520 Perlgolf History

s!.!(unpack("B*",'\xE7\xFB\xFF\xFE\x92l\x86\xDA\x7F\xFF\x9F\xE9\x84\x9Ai\xE7\xF 3\xF9\xFC')=~/.../g)[$i.$&].0!eg,$i+=s/0$/ /,y/01/ #/&print for@a=(pop)x5 102, p.kailasa -l s!.!((unpack"B*","\xE7\xFB\xFF\xFE\x92l\x86\xDA\x7F\xFF\x9F\xE9\x84\x9Ai\xE7 \xF3\xF9\xFC")=~/.../g)[$?.$&].0!eg+y/01/ #/,$?+=chop&&print for@_=(pop)x5 102, Petri Mikkelä split('',pop)&&map{//;print"@{[('# ','# #','###',' #')[map{vec'V\xFE\xEF\xA2\xBB\xE5\x8B+\xA6\xFFf\x9A\x0B',$_*5+$',2}@_]]} "}0..4 103, Juho Snellman @a=/^.../gm,s///g,print"@a "for($_=pop)x(s^.^$/.unpack"(x$&)2B*",'\xF6\xDF$\x93\xE7\xCF\xE7\x9F\xB7\x93\xF 3\x9F\xF3\xDF\xE4\x93\xF7\xDF\xF7\x9F'^ge*y/01/ #/&&5) 104, Krzysztof Koczyjan split//,pop;($~="@_ ")=~s:\d:(bbb,aab,bab,baa)[3&hex>>$&*2]^AAA:ge&&print$~for+204,A7E56,4006,66576 ,4104 104, anfi -l y/01/ #/,@X=/.../g,print"@{[map{$X[$_]}@_]}"for(@_=pop=~/./g)?unpack"B30"x5,"\xE7\ xFB\xFF\xFC\xA4\x9B!\xB4\xA7\xFF\xF9\xFC\xA6\x12i\xA4\xE7\xF3\xF9\xFC":() 104, Chris Dolan $_=unpack"b*","\xE7\xDF\xFF\x7FI6a[\xFE\xFF\xF9\x97!Y\x96\xE7\xCF\x9F?";y/10/# /;@h=/.../g;$_=pop;print"@h[//g] ",!splice@h,0,10while/./&&@h 105, Szeryf map{$h=hex;print"@h "if@h=map{substr'### # #',2*$h/4**$_&6,3}"@ARGV"=~/./g}'10C',A5E9FD,C00D,DDFED,C30C 105, Karsten Sperling -l s,.,$&x4,eg,chop,y,0-9,;(5i.cs){k,for$;=pop;$_=$;&"$_ "x20,y, ,#,c&&print for'#!-" ,vdl0 hppx'=~/.../g 106, Honza Pazdziora -l for$c(qw!\xE7\xDF\xFF?%\xD9\x84- \xE5\xFF\x9F?eH\x96% \xE7\xCF\x9F?!){@x=unpack('b*',$c)=~/.../g;$_="@x[$ARGV[0]=~/./g]";y!01! #!&&print} 109, topmach $_=unpack"b*","o{\x92\xE4\xF9\xFC<\xDF\x9E|\xCE?\xEFO\x92\xEF\xFB\xF7<";y/10/# /;@f=/.../g;$_=pop;for$r(0..4){print"@t "if@t=map$f[$_*5+$r],/./g} 111, Jasper print map"@{['### ## # #'=~/.../g]}[(/./g)[@_]] ",-1003e5,3111322133,31e8|100,3121113131,-10x4 if split'',pop 113, vRm

Edition 2007-01-09 top secret / strictly confidential page 235 of 520 Perlgolf History

for$r(0..4){$_="@ARGV";s/\d/@{[unpack b4,chr vec'WUGDDG\x17wttUGtqt\x17WwDDWWwut',$&*5+$r,4]}/g;s/0$/ /;y/01/ #/;print} 113, vRm (alternative) for$r(0..4){$_="@ARGV";s/\d/@{[sprintf'%04b',vec'\xAE\xAA."".\x8E\xEE\xE2\xE2\x AA.\xE2\xE8\xE2\x8E\xAE\xEE""\xAE\xAE\xEE\xEA\xE2',$&*5+$r,4]}/g;s/0$/ /;y/01/ #/;print} 114, g.allen for$l(0..4){$_="@d "if@d=map{substr(unpack("B*","\xF6\xDEI'\x9F?<\xFBy>s\xFC\xF7\xF2I\xF7\xDF\xEF< "),$_*15+$l*3,3)}"@ARGV"=~/./g;y/01/ #/;print} 114, Michael Robinson -l @!=map{$_*=3,$_+1,$_+2,-1}pop=~/./g;$_=pop@!&&'\xE7\xDF\xFF?%\xD9\x84- \xE5\xFF\x9F?eH\x96%\xE7\xCF\x9F?';s/..../print map vec($&,$_,1)?'#':$",@!/eg 116, michalj -l $_=unpack"B*","\xF6\xDEI'\x9F?<\xFBy>s\xFC\xF7\xF2I\xF7\xDF\xEF<";y/10/# /;@t=/.../g;$,=$";split'',pop;for$r(0..4){@_&&print map$t[$r+5*$_],@_} 116, david seed aka gimbo -l y/01/ #/,map$R[$i++%5].="$_ ",/.../gfor(unpack("B*","\xF6\xDEI'\x9F?<\xFBy>s\xFC\xF7\xF2I\xF7\xDF\xEF<") =~/.{15}/g)[pop=~/./g];chop,print for@R 117, gibbering -l for$l(0..4){$_=join$",map{substr unpack(b150,'o{\x92\xE4\xF9\xFC<\xDF\x9E|\xCE?\xEFO\x92\xEF\xFB\xF7<'),$_*15 +3*$l,3}split'',$ARGV[0];y/01/ #/&&print} 117, RobTM -l for$i(57,515145145,7157,1154551,117){$_="@ARGV";eval"y/470268359/$i/";s/./($ `&$").(glob'{\ ,#}'x3)[$&]/ge&& print} 119, Magus $_=pop;s/./substr("_Q_ _]UWUU_GD_WU]_U]AA__U_WU_",3*$&,3).$"/eg;for$i(0..4){s/./print$'?1<<$i&ord$& ?"#":$":"\n";$&/eg} 120, aqumsieh $_=pop;for$i(0..4){push@$i,join'',map(vec('\xE7\xDF\xFF\x7FI6a[\xFE\xFF\xF9\x97 !Y\x96\xE7\xCF\x9F?',30*$i+$&*3+$_,1)?'#':$",0..2)while/./g;@$i&&print"@$i "} 135, m.wrenn $_=pop;(@k=map{substr'### ## ## ',(X06660333330309003030660330903009060033330606006030=~/./g)[5*$_+$n],3}/./ g)&&print"@k "while$n++<5 163, JLO

Edition 2007-01-09 top secret / strictly confidential page 236 of 520 Perlgolf History

-l @a=split//,pop;@b=split//,"3033233333200021102220333330332010002020303303303 3";@c=" ## # ####"=~/.../g;for$x(0..4){$_=join" ",map{$c[$b[$x.$_]]}@a;print if$_} 166, m.wrenn (alternative) $_=pop;@s=('###',('# #','###')x2)x10;@s[2,20,5..9,11,16,18,23,24,28,36..39,48,13,26,31]=(('# #')x2,(' #')x16,('# ')x3);print"@s[map$_*5+$n-1,/./g] "while/./&&$n++<5 167, Hirogen2 (post-mortem) @M=qw(\xF6\xDE $\x92 \xE7\xCE \xE7\x9E \xB7\x92 \xF3\x9E \xF3\xDE \xE4\x92 \xF7\xDE \xF7\x9E);if(@A=split//,pop){for(0..4){for(@_=@A;@_;){($S=substr unpack("B*",$M[shift@_]),$_*3,3)=~y/01/ #/;print$S;print" "if@_}printf" "}} 183, Frantisek Darena @d=qw(01110 22222 02030 02020 11022 03020 03010 02222 01010 01020);@z=('###','# #',' #','# ');@c=shift=~/./g;@c||exit;for$r(0..4){print join(' ',map{$z[($d[$_]=~/./g)[$r]]}@c),"\n"} 186, m.wrenn (alternative) $p=pop;$e=1x15-1e4-1e10;@s=(1e7,- 9e13+($a=100110)x2,1e3+1e11,1e5+1e11,1e13+$a,1e5+1e9,1e9,$a x2,0,1e5);for$n(0..4){$_=$p;s/./substr$e-$s[$&],3*$n,3/ge;y/012/ # /;(@k=/.../g)&&print"@k "} 198, Hirogen2 @M=qw(F6DE 2492 E7CE E79E B792 F39E F3DE E492 F7DE F79E);if(@A=split//,pop){for(0..4){for(@_=@A;@_;){($S=substr unpack("B*",pack"H*",$M[shift@_]),$_*3,3)=~y/01/ #/;print$S;print" "if@_}printf" "}} 222, Frantisek Darena push@s,[(' ')x$i]for 1..($i=pop);while($r<@s/2){$s[$r][$_-1]='#'for$c..@s- $c;$s[$_][@s-$c-1]='#'for$r..@s-$r-1;last if$r>=@s/2-1;$s[@s-$r -1][$_]='#'for$c..@s-$c-1;$s[$_][$c]='#'for$r+2..@s-$r- 1;$r=$c+=2}print@$_,"\n"for@s 227, IainT @x=(' #','# ','# #','###');@n=(32223,00000,30313,30303,22300,31303,31323,30000,32323,32303);e xit if($s=shift)eq'';for$l(0..4){@d=split//,$s; while(@d){$d=shift@d;$k=substr($n[$d],$l,1); $o.=$x[$k].(@d?' ':'')}$o.="\n"}print$o 250, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 237 of 520 Perlgolf History

-l $N='#### ## ## ############ ##### ###### #### ##### ## #### # ##### ### ######## #### ############### ### ## ######## #### ####'; $n=pop; for$l(0..4){ $_="@{[map substr($N,$_*15+$l*3,3),split//,$n]}"or last; print } 259, Chris Angell $t="###";$f="$t#";@a=split//,"@ARGV";map{$s="."x(3*$_);map{print+(split/:/,"$f ####$f:#####:$t $f# $t:$t $f $f:# ## $f # #:$f $t $f:$f $f $f:$t####:$f $f# $f:$f $f $f")[$_]=~/$s(...)/;@a==++$c||print" "}@a;@a&&print$/;$c=0}0..4 512, NumberCruncher @s=qw(0000 0010 0001 2001 0210 0201 2201 0410); @c=qw(765321 36 76421 76431 5463 75431 754321 763 7654321 765431 ); $l=shift;$h=0;$p=""; foreach $t(split//,$l) {foreach$i(0..2){foreach$j(0..4){$d[$j][$i]=" ";}}; foreach$e(split//,$c[$t]) {($x,$y,$i,$j)=split//,$s[$e];foreach$o(0..2){$d[$y+$o*$j][$x+$o*$i]="#";};} foreach$r(0..4){undef $u[$r];foreach$v(0..2){$u[$r].=$d[$r][$v];}} if($h){$p=" ";}else{$h=1;} for($j=4;$j>=0;$j--){$r=join("",$f[$j],$p,$u[$j]);$f[$j]=$r;}} for($j=4;$j>=0;$j--){print $f[$j],"\n";}

5.21. Spiral http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=21&season=0 The game started 2003-01-21 19:30:00 and ended 2003-01-27 21:00:00.

5.21.1. Rules Given input n draw a spiral using the "#" char, in a square of size n x n. The spiral starts in the upper left corner of the square and runs clockwise to the center. The program gets one argument, a number 0 < n < 100 matching /^[1-9]\d?\z/ Output on STDOUT should match /^([ #]{n}\n){n}\z/. So if the argument is: 8 The output should be:

Edition 2007-01-09 top secret / strictly confidential page 238 of 520 Perlgolf History

######## # ###### # ### ## ## # #### # ## ########

5.21.2. Solutions 80, tybalt89 (post-mortem) -l map$a[$i&1?$^F:$x+=($i&2)-1,$x]|=$"x-$^F."#",$_..$i++%-2for-pop..-1;print for@a 81, mtve (post-mortem) -l map$a[$y-=$Y]|=$"x-($^F-=$').'#',$_..!($Y=-$'*$Y=~//)for++$Y-pop..0;print for@a 81, ton (post-mortem) -l $i++,map$a[$|?$^F:$x+=($i&2)-1,$x]|=$"x-$^F."#",$_..-$|--for-pop..-1;print for@a 82, mtve -l //,print map$#:&($z=($_&~1)+$'>@:)^1&($_+!$z<$'^$z?$_:$')?'#':$",@:for@:=1..pop 83, tybalt89 -l map$a[$y-=$Y]|=$"x-($^F-=$t=$X).'#',$_..!($X=$Y,$Y=-$t)for++$Y-pop..0;print for@a 83, terje (post-mortem) -l map{$#{$|}-=($i&2)-1,$a[@0]|=$"x(@1-2)."#"for$|--..-$_;$i++}-pop..-1;print for@a 85, ton $_=($n=pop)%2>0;($z=$n%4x s/ |^/$:/g)&&s/-/#/while$_="$z$_$z ",$n*$n>y/# -4/ #/;print 91, mtve (alternative) map{($#{$'&1}+=$_>2)-=$'- 1&2,$a[@0][@1]=1for$_|//..@w}@w=0..pop;print+($",'#')[@$_],$/for@a 91, ton (alternative) $n=pop;$_=($z=$n%2?$"x s/.*?$/reverse$&/se:"#")x s/ /$z /g."$z $_",s/# $/##/while$n--;print 91, Daniel (post-mortem) @_=(('#')x($z=@:=1..pop),$/)x@:;map$_[$z+=(-@:,2,@:+2)[$d%4]- 1]=$",++$d|1..$#:for@:;print@_ 93, michalj (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 239 of 520 Perlgolf History

@t=(("#")x($p=$z=pop),$/)x$z;map$t[$p+=(-$z,2,$z+2)[$o%4]-1]=$",$_..++$o%2for 3-$z..3;print@t 93, ton (alternative) $n=pop;$_.=$;x s/ / $;/g.$/,s!^!$;?"#":$"!ewhile$;=$n%2?"#":$"x s/\C*./reverse$&/e,$n--;print 93, ton (alternative) $_=($n=pop)&1?"# ":"

";s/^/z# /mg,s/ /#/,s#.#s/^.//mg;(reverse$/,//g)x/./#segwhile--$n;print 94, Daniel @_=(('#')x($z=$n=pop),$/)x$n;for$c(1..$n){$_[$z+=(-$n,2,$n+2)[$c%4]- 1]=$"for$c|1..$n-1}print@_ 94, michalj @t=(("#")x($p=$z=pop),$/)x$z;map$t[$p+=(-$z,1,$z,-1)[$o%4]]=$",$_..++$o%2for 3- $z++..3;print@t 94, terje (rejected) -l map{$#{$|}-=($i&2)-1,$a[@0][abs@1-2]="#"for$|--..-$_;$i++}-pop..-1;print map$_|$",@$_ for@a 94, Michael Rybakin @s=(('#')x($p=$n=pop),$/)x$n++;map$s[$p+=(-$n,1,$n,- 1)[$i&3]]=$",$_+3..++$i%2for-$p..0;print@s 96, ton (alternative) -l print!//,map$_==($#b=$'-1)&$_<@;/2+@;%4/8^!!\@b[$_-1,@;-$',@;-$_]&@;- @b?$":"#",@;for@;=1..pop 97, terje -l map{$#{$|}-=($i&2)-1,$a[@0][@1-1]="#"for$|--..-$_;$i++}-pop..-1;print map$_|$",@$_[1..$i]for@a 98, ton (alternative) $_=($"x($z=$n=pop).$/)x$n;eval'pos=$#p+=(-$n,2,$n+2)[$i%4]- 1,s/.\G/#/;'x(++$i%2+$z--)while$z;print 100, tybalt89 (alternative) -lX use Math'Complex;$p=-2;$d*=i*!!map$a[Im$p+=$d]|=$"x(Re$p).'#',$_..-- $|for++$d-pop..0;print for@a 101, Karsten Sperling $.=$n=pop;$_|=$"x($p+=(-$n,1,$n,-1)[$%%4]-??).'#'while$---or$-=$.-??-$%++%2,$.- -;$,=$/;print/.{$n}|/g 101, Juho Snellman -l map{@{$l[$_]}[@%]=((@%<3?' ':$")x/^$s$/,($"^v3)x@%)for@%=$s++..-- $_;$"^=v3}(pop)x99;print@$_ for@l 107, Benoît Chauvet

Edition 2007-01-09 top secret / strictly confidential page 240 of 520 Perlgolf History

sub p{my$x="#"x$l.$/;--$l?--$l?do{$x.=$"x$l;$_=reverse&p;s/ /# /g;"$x$_## "}:"$x # ":"# "}$l=shift;print&p 115, g.allen sub g{($a-=2)<2?'# 'x$a:(($_=reverse&g),s/.+/$& #/g,s/(#*) #\Z/$1##/,"##$1 @{[$1&' 'x99]} #$_ ")[3]}print+g$a=2+pop 124, gibbering -l map{$z=$_%4;map{$z&1and$y-=$z-2or$x-=$z-1;$a[$y][$x-1]='#'}1..$w;$w- =$_?$z%2?0:2:1}0..($w=pop)-1;print map$_|$",@$_ for@a 127, RobTM @a=$"if$j=-- ($i=pop)%2;$"='#'if!($i&2);@a=($"x($j+=2),map($".$_.$"^'\x03',@a),($"^='\x03 ')x1x$j)for 1..$i>>1;print"$_#\n"for'#'x$i,@a 128, m.wrenn -l print map$_|$",splice@s,0,@~for map{$s[!$s[$m+$a]|$m%@~<1&$m>@~&&($m+=$a)- $a]='#'for@~;$m-=$a;$a*=$a%@~?@~:-1/@~}@~=++$a..pop 132, Magus -l $_="#"x($x=$t=$.=pop).$"x$.x--$x;{for$d(0..($t-=2*--$|)){vec($_,$x+=[$.,-1,- $.,1]->[$i&3],8)=35}$i++;$t>0&&redo}print for/.{$.}/g 133, topmach $_=("00 00",1,"11 01",0)[($s=pop)%4];s/.$/$& /;$|=!$&;$t=s/.+/$|$&$|/g,$r=$|--x(2+$t),s/.(.*)/$r $|$1$r /suntil/.{$s}/;y/10/# /;print 134, david seed aka gimbo -l ($i,@p)=($n=pop)&1?(0,'#'):(1,'##',' #');@p=('#'x$i,$"x-- $i.'#',map{reverse(pop@p).(@p?' #':'##')}2..$i)until($i+=3)>$n;print for@p 139, topmach (alternative) -l @{$a[$q++]}=@d for@d=("#")x pop;$#d-=$x=1;$y--;while(@d){$i=--$|*2- 1;$a[$x][$y+=$i]=$"for@d;$#d-=2;$a[$x+=$i][$y]=$"for@d}print@$_ for@a 179, Chris Dolan -l sub b{$a[$m=$x+2*$u][$n=$y+2*$v]eq"#"&&$m*$n>=0}$l=pop;$y-- ;$v=++$x;map$a[$_]=[("#")x$l],0..$l-1;b||(($u,$v)=($v,-$u))while b&&$a[$x+=$u][$y+=$v]=~y/#/ /;$l-->0&&print@$_ for@a 222, Frantisek Darena push@s,[(' ')x$i]for 1..($i=pop);while($r<@s/2){$s[$r][$_-1]='#'for$c..@s- $c;$s[$_][@s-$c-1]='#'for$r..@s-$r-1;last if$r>=@s/2-1;$s[@s-$r -1][$_]='#'for$c..@s-$c-1;$s[$_][$c]='#'for$r+2..@s-$r- 1;$r=$c+=2}print@$_,"\n"for@s 260, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 241 of 520 Perlgolf History

$n=$l=pop;$_=($"x$l.e)x$l;s/./>/;1while s/> ([ e])/#>$1/||s/v(.{$l}) (.{$l}[ e]|.{0,$l}$)/#$1v$2/||s/([ e]) (.{$l})( .{$l}[ e]|.{0,$l}$)/v$1$2/||s/ v/ /)&&--$n;y/e>

5.22. Card trick http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=22&season=0 The game started 2003-01-30 22:00:00 and ended 2003-02-03 21:00:00.

5.22.1. Rules Write a program to perform this simple card trick: 1. Give a pack of cards to a member of the audience. 2. Have them cut the cards into two approximately equal piles and recombine the piles into one pack by shuffling them together. By shuffling we mean interleaving the cards with one or more cards from each pile at the time. 3. Repeat step 2 a few more times to ensure the cards are thoroughly shuffled. 4. Without showing you, have them take the top card, remember which card it is, and replace it somewhere in the middle of the pack. 5. Take back the pack and find which card was replaced in the middle of the pack. Show it to the audience to demonstrate your conjuring prowess! To see how this amazing feat is performed, consider the pack ABCDEFGHIJKLMNOPQRST with 20 cards. Cutting and shuffling twice, then hiding the top card in the middle of the pack gives: Cut: ABCDEFGHI JKLMNOPQRST Shuffle: JKALBCMDNEOPFGQRHSTI Cut: JKALBCMDNE OPFGQRHSTI Shuffle: OJPFKALGBQCMRHDSNTEI Hide top card in middle: JPFKALGBOQCMRHDSNTEI If the initial pack is ordered (1 sequence), cutting and shuffling k times produces 2 to the power of k interleaved sequences. Hiding the top card produces 2**k+1 (a power of 2 plus one) sequences, one of which contains only one card. So taking out the JKLMN sequence leaves PFAGBQOCRHDSTEI. Taking out PQRST leaves FAGBOCHDEI. Taking out FGHI leaves ABOCDE and taking out ABCDE leave O. We know this is the hidden card because there are 5 (2**2+1) sequences, and only one contains exactly one card (this one). Here is a decomposition of what takes place in the above example. JPFKALGBOQCMRHDSNTEI # original input string J K L M N # Notice that these are consecutive letters P QRST FG H I ABCDE O # after ABCDE is removed, only O remains Input The input on STDIN is the order of cards in the pack after step 4 of the trick. The pack will contain between 5 and 52 cards matching (/^([A-Za-z]){5,52}\n\z/) and have been cut and shuffled between one and four times.

Edition 2007-01-09 top secret / strictly confidential page 242 of 520 Perlgolf History

The packs are all prepared so the trick will always succeed. The point to remember is that the only time you get a sequence with just one card, is when you have found the hidden card, even if there are still cards left in the pack Each card is represented by a single letter and the initial order of a full 52 card pack is ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. Packs with n < 52 cards contain the first n of these beginning with A. Output The output on STDOUT is one letter followed by a newline, (matching /^[A-Za-z]\n\z/) Sample input JPFKALGBOQCMRHDSNTEI Sample output O

5.22.2. Solutions 45, Daniel -p s#.#j^($a=$&)++or$a=a;s/$&//>s/$a//&&$&#ge 47, mtve -p s#.#$&x($d.=++($_=$&).y/A/a/s)!~$&x$'!~$_#eg 48, ton -alpF| y/a?-z/Z>-y/while@+>/A/g|/(B)/g;$_=@F[@-] 48, ton (alternative) -alpF| y/a\x01-z/Z\x00-y/until/^.*(\x0B)/g>/\x0C/g;$_=@F[@-] 48, ton (alternative) -alpF| y/a\x01-z/Z\x00-y/until/^.*(\x0B[^\x0C]*$)/;$_=@F[@-] 50, Juho Snellman -p for$i(sort/./g){s/$^%?(.*$i)/$1%/;$^=$i}s/.%//g 51, tybalt89 -p s![@{[map$`=~/($^).*(@{[$^=$_]})/,sort/./g]}]!!g 52, Michael Rybakin -p for$c(A..Z,a..aa){s/$"+((.*($c))|$")/$2$3/;$"=$c} 55, mtve (alternative) -p s/[$1-$+]//gwhile/(.)(.*((??{($+..z,a)[$+ne z]})))+/ 56, ton (alternative) -ap s^(.)^y/\x00/\xFF/c;$_&="@F";${s#$1#y/aB-{/ZA-z/;v0#eg}^eg 56, tybalt89 (alternative) -p s#[@{["@{[sort/./g]}$_"=~/(.)(?= (.).*\1.*\2)/g]}]##g 58, andys

Edition 2007-01-09 top secret / strictly confidential page 243 of 520 Perlgolf History

-p for$a(@F=sort/./g){s/$a.*(?=[$F[++$i]+])/#$&#/}s/#+.//g 58, m.wrenn -pl s/1*(.)//,Z eq($k=$+)++?$k=a:a,$_=s/$k/1$&/|$&?redo:$+ 60, gibbering -p for$x(@a=(A..Z,a..z,1)){s/$x(.*)($a[++$i])/$1$2/||s/$2//} 62, Jasper (post-mortem) -pl for$f(1,A..Z,a..aa){$_=$;if/$;/&$`!~$d&$'!~$f;$d=$;;$;=$f} 64, Jasper -nl for$f(1,A..Z,a..aa){/$e/&$`!~$d&$'!~$f&&print$e;$d=$e;$e=$f} 65, terje -p s#.#$&x($`!~($&eq a?Z:chr~-ord$&)&$'!~($&eq Z?a:++($x=$&)))#eg 66, michalj -pl for($a=A;$i-1;$i++,($b=$a++)ne Z or$a=a while/$a/g){$i=0}$_=$b 68, Colm Dougan -lp $i=0;s/.//;$i+=s/$&//while$'=~($&eq Z?a:++($t=$&));$_=$i?redo:$& 70, Roy Johnson -pl for$L(A..Z,a..z){/\G.*$L/g?++$S:($S>1||last,$S=0,redo);$p=$L}$_=$p 76, aqumsieh -pl @_=(1,A..Z,a..z,1);/$_[0].*$_[1]|$i.*$_[0]/||s/..+/$_[0]/while$i=shift@_ 77, tinita -p @h{@b=(A..Z,a..z,0)}=0..52;s#.#!/$b[$h{$&}-1].*$&|$&.*$b[$h{$&}+1]/&&$&#eg 77, dkr -lpaF| $n=$#F,$_=$s=$F[0],@F=map/$s/?do{/Z/?$s="a":$s++;()}:$_,@F while@F!=$n 80, Chris Dolan -lp @;=sort/./g,1,'{';/$;[0].*$;[1]|$;[1].*$;[2]/||(print$;[1]),shift@;while@;>2 82, srushe -lp while(s/.//){$f=s/$n//while$n=Z eq$&?a:++($n=$&)and/.{@-}$n/;$f-- or$_=$&,last} 85, JLO -pl s#.#$i=ord$&;$q=$i==97?Z:chr$i-1;$w=$i==90?a:chr$i+1;$& if($`!~/$q/&&$'!~/$w/)#eg 95, aj -nl @p{@a}=(0,@a=(A..Z,a..z));@f{@a}=(@a[1..51],0);/$p{$&}.*$&/||/$&.*$f{$&}/||p rint$&while/./g 98, thepoet

Edition 2007-01-09 top secret / strictly confidential page 244 of 520 Perlgolf History

-p @m=(A..Z,a..z);while(/../){for$c(0..50){/($m[$c]).*($m[$c+1])/&&push@d,$1,$2 }for$c(@d){s/$c//}} 123, gibbering (alternative) -l for(;;@l<2&&exit print@l){@l=();$_ =$x||=<>;for(($t)=/./g;/$t/||last;$t=Z eq$t?a:++$t){push @l,$t;$_=$'}$x=~s/$_//for@l} 165, Frantisek Darena @p=<>=~/./g;while(1){$c=$p[0];my@n;$d=$c;'Z'eq$d?$d='a':$d++;print("$c"),exit if!grep/$d/,@p[1..55];while(@p){($w=shift@p)eq$c?'Z'eq$c?$c='a':$c++:push@n, $w}@p=@n}

5.23. Ascii http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=23&season=0 The game started 2003-02-03 22:00:00 and ended 2003-02-05 21:00:00.

5.23.1. Rules Output this to STDOUT : !"#$%&'()*+,-./ 0123456789:;<=>? @ABCDEFGHIJKLMNO PQRSTUVWXYZ[\]^_ `abcdefghijklmno pqrstuvwxyz{|}~ It's the printable characters of an ASCII table

5.23.2. Solutions 36, mtve print chr,$_%16>14&&$/for 32..126,10 36, Szeryf print$_%17?chr$a+++32:$/for 1..100,0 36, terje print chr,$/x!(~$_&15)for 32..126,10 36, m.wrenn print chr,$_%16>14&&$/for 32..126,10 36, tybalt89 print chr,$_%16>14&&$/for 32..126,10 36, ton print chr,$/x!(~$_%16)for 32..126,10 36, Daniel print chr,$_%16>14&&$/for 32..126,10 36, p.kailasa

Edition 2007-01-09 top secret / strictly confidential page 245 of 520 Perlgolf History

print chr,$/x!(~$_&15)for 32..126,10 36, murky print chr,$_%16>14&&$/for 32..126,10 36, Michael Rybakin print chr,$/x!(~$_&15)for 32..126,10 37, Juho Snellman print$",map$/x!($_&15).chr,33..126,10 37, mtve (alternative) $_=pack'C16x'x6,32..126;y/\x00/ /s;print 37, anfi -l print map{chr,~$_&15?'':$\}32..126 37, banshee print$_=chr,$/x/[\/?o~_]/ifor 32..126 37, thepoet -l print map{chr,$/x!(~$_%16)}32..126 37, castrox (post-mortem) print$_=chr,$/x y!/?O_o~!!for+32..126 37, Petri Mikkelä -l print$",map$/x!($_%16).chr,33..126 37, mtve (alternative) $_=pack'U15v'x6,32..$^H;y/\x00\x7F/ /d;print 37, Magus print$_=chr,$/x/[\/?O_o~]/for 32..126 37, aj print chr,($/)[$_+1&15]for+32..126,10 37, terje (alternative) print chr,$/x($_%16/15)for 32..126,10 37, Jasper print map{chr,$/x!(~$_&15)}32..126,10 38, michalj -l print map{chr,++$_%16?'':$/}32..126 38, gibbering -l print map{chr,++$i%16?'':$/}32..126 38, andys -l print map{chr,$/x!(++$_%16)}32..126 38, topmach

Edition 2007-01-09 top secret / strictly confidential page 246 of 520 Perlgolf History

-l print map{chr,1+$_&15?"":$/}32..126 38, david seed aka gimbo -l print map{chr,++$_%16?'':$/}32..126 38, castrox print$_=chr," "x y!/?O_o~!!for+32..126 38, mtve (alternative) printf join($/,('%c'x16)x6),32..126,10 38, Jon Honeycutt -l print map{chr,$\x!(++$_%16)}32..126 38, ton (alternative) $_=pack"(C16x)*X",32..126;y/\x00/ /;print 38, Chris Dolan -l print map{chr,++$i%16?():$/}32..126 38, k.c.ivey -l print map{chr,$/x!(++$_&15)}32..126 38, JLO -l print map{chr,$/x!($_+1&15)}32..126 38, Michael Robinson -l print map{chr,++$n%16?@!:$/}32..126 38, tinita -l print map{chr,$/x!(++$c%16)}32..126 40, dkr $_=chr,s@[/?O_o~]@$& @,print for 32..126 40, dkr (alternative) print$_=chr,/[\/?O_o~]/?$/:""for 32..126 40, Spoon print chr,$_&15^15?"":"\n"for 32..126,10 40, VesaK print map{chr,~$_%16?"":"\n"}32..126,10 41, Frantisek Darena map{$_=chr;s#[/?O_o~]#$&\n#,print}32..126 42, Vava $,=$/;print+(pack"C*",32..126)=~/.{0,16}/g 43, slawek-

Edition 2007-01-09 top secret / strictly confidential page 247 of 520 Perlgolf History

print chr,++$_%16?'':$/for(32..126);print$/ 43, pandi print chr,++$_%16?'':$/for(32..126);print$/ 50, Robert Garwacki -l for$i(32..126){$_.=chr$i}s/(.{16})/$1\n/g;print 67, tomekM for($i=31;++$i<127;){print chr$i;print"\n"if($i-31)%16==0}print"\n"

5.24. Soundex http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=24&season=0 The game started 2003-02-10 15:00:00 and ended 2003-02-13 21:00:00.

5.24.1. Rules The Soundex Index System was developed so that similar sounding names or names with similar spelling could be encoded for easy retrieval. It has been used by the U.S. Bureau of the Census, and some States use it to help encode your drivers’ license number. Your task is to read a sequence of names, one at a time and one per line, compute and print the corresponding soundex code (one line of output per name). Names will consist of 1 to 20 uppercase letters (matching /^[A-Z]{1,20}\n\z/). A Soundex Code always consists of a letter followed by three digits. Here are the rules for soundex encoding: 1. The first letter of a name appears as the first and only letter in the soundex code. 2. The letters A, E, I, O, U, Y, W and H are never encoded, but do break successive code sequences (see next rule). 3. All other letters are encoded EXCEPT when they immediately follow a letter (including the first letter) that would be encoded with the same code digit. 4. Since the first letter is in the code, the first letter and all immediately following letters with the same code digit shall not be encoded. 5. The soundex code guide is: Code Key Letters and Equivalents 1 B,P,F,V 2 C,S,K,G,J,Q,X,Z 3D,T 4L 5M,N 6R 6. Trailing zeros are appended to short codes so all names are encoded with a letter followed by three digits. 7. Longer codes are truncated after the third digit. Example: SCHAEFER. First letter is S so the code will start with S. SC is not coded (rule 4), HAE is not coded (rule 2), F => 1, E is not coded (rule 2), R = 6. This leaves S16, and with zero padding this gives the soundex code of S160.

Edition 2007-01-09 top secret / strictly confidential page 248 of 520 Perlgolf History

Important notice concerning rules: The "Generic perl golf rules" states that you may use any of the 5.8.0 standard modules. This is not the case in this golf. No modules allowed. Input The input on STDIN a list of names (matching /^([A-Z]{1,20}\n){1,99}\z/). Output The output should be a list the soundex code (matching /^([A-Z]\d{3}\n){1,99}\z/). Sample Input LEE KUHNE EBELL EBELSON SCHAEFER SCHAAK Sample Output L000 K500 E140 E142 S160 S200

5.24.2. Solutions 64, tybalt89 (post-mortem) -lp $_=_&$_|H777&$_.!y!!/-spqrpprrtuupqrvrspqprpr!cs*s/\Bp//g x3 64, ton (post-mortem) -lp $_=_&$_|H777&$_.!y!!/-spqrpprrtuupqrvrspqprpr!cs*s/\Bp//g x3 65, mtve (post-mortem) -lp $_=a000^pack ac3,uc^a.y/FB-DL-VXZKGJ/11-55x12623x12/s,/\B\d/g 65, Daniel (post-mortem) -lp $_=_&$_|Hwww&$_.!y/FB-DL-VXZKGJ/11-55O12623U12/s*s/\B\D//g x3 66, mtve -lp $_=a000^pack ac3,uc^a.y/B-VXZ/123A12AA22455A12623A12/s,/\B\d/g 66, Daniel -lpa y/FB-DL-VXZKGJ/11-55x12623x12/s;$_=pack'a'x4,@F,/\B\d/g,(0)x3 66, tybalt89 -lp $_=_&$_|Hwww&$_.!y/A-Z/0-30120022455012623010202/s*s/\B0//g x3 66, Daniel (alternative) -lpa y/FB-DL-VXZKGJ/11-55x12623x12/s;$_=pack aaaa,@F,/\B\d/g,0,0,0 66, Daniel (alternative) -lpa y/FVB-DL-TXZKGJ/111-55x126232/s;$_=pack aaaa,@F,/\B\d/g,0,0,0 66, ton

Edition 2007-01-09 top secret / strictly confidential page 249 of 520 Perlgolf History

-lpaF| $_=$F[y!!/-spqrpprrtuupqrvrspqprpr!cs

22455 12623 1 2 2/s;printf$&.'%01s'x3 .$/,//g 73, terje -lpaF| y/A-Z/0- 30120022455012623010202/s;s/./$F[0]$'\xB0\xB0\xB0/;s/0//g;$_&='\x7F'x4 73, Juho Snellman -nl /./;y/B-TVXZ/123 12 22455 1262312/s;print"$&",(/^.|\d/g,(0)x3)[1..3] 73, Krzysztof Koczyjan -lp $f=_&$_;y/BDFL- TVXZCGJK/131455O1262312/s;s/^.|\D//g;$_=_www&"$f$_\xB0\xB0\xB0" 74, banshee -lpaF| y/YA-Z/7712371277224557126237172/s;s/./$F[0]$'000/;s/7//g;$_&='\xFF'x4 74, m.wrenn -plaF| $_=$F[y/B-Z/123A12AA22455A12623A1A2A2/s

Edition 2007-01-09 top secret / strictly confidential page 250 of 520 Perlgolf History

-anlF| y/BPFVDTLMNRCSKGJQXZ/11113345562/s;print$F[0],(/^.|\d/g,(0)x3)[1..3] 76, pom -pl /./;y/A-Z/0-30120022455012623010202/s;{s/^.|0//g}$_=$&.substr$_.$|x3,0,3 77, Chris Dolan -plaF| y/A-Z/0-30120022455012623010202/s;s/^.|0//g;s/$/000/;/.../;$_=$F[0].$& 77, anfi -plaF'' y/A-Z/0-30120022455012623010202/s;s/^.|0//g;$_=pack'a4',$F[0].$_.$[x3 79, michalj -pl @a=/^./g;y/A-Z/x123x12xx22455x12623x1x2x2/s;s//@a$'000/;y/x//d;/.{4}/;$_=$& 80, slawek- -plaF| y/A-Z/0- 30120022455012623010202/s;s/./$F[0]/;y/0//d;$_=substr$_.'000',0,4 80, Sami Silvennoinen -lpaF// y,A- Z,01230120022455012623010202,s,s,^.|0,,g,$_=substr$F[0].$_.'000',0,4 80, Benoît Chauvet -lp $i=_&$_;y/B- Z/123A12AA22455A12623A1A2A2/s;s/^.|A//g;$_.='000';/.../;$_=$i.$& 81, JLO -pl ($a)=/./g;y/A-Z/ 123 12 22455 12623 1 2 2/s;s#.#$a$'000#;y/ //d;($_)=/..../g 83, dkr -n /./;$p=$&;y/RMNLDTBPFVCSKGJQXZ/65543311112/s;s/^.|\D//g;printf"$p%.3s ",$_."000" 83, VesaK -lp ($a)=/(.)/;y/A- Z/01230120022455012623010202/s;s/^.|0//g;$_=pack"A4",$a.$_."000" 84, Michael Robinson -p @L=/(.)/;y/A- Z/01230120022455012623010202/s;s//@L/;y/0//d;s/$/000/;s/(....).+/$1/ 85, Frantisek Darena -p /./;$p=$&;y/BPFVDTLMNRCSKGJQXZ/11113345562/s;s/^.|\D//g;s/$/000/;s/(...).*/$ p$1\n/ 85, david seed aka gimbo -nl print/(.)/,(y/A-Z/0- 30120022455012623010202/,s/(.)\1*//,/([^0])\1*/g,0,0,0)[2..4] 86, thepoet -lp /./;$s=$&;y/BPFVDTLMNRCSKGJQXZ/11113345562/s;s/.//;s/\D//g;s/$/000/;/.../;$_ =$s.$& 88, Hirogen2

Edition 2007-01-09 top secret / strictly confidential page 251 of 520 Perlgolf History

-lp $z=ord;y/A-Z/01230120022455012623010202/;y///cs;s/.//;s/0//g;$_=pack CA3,$z,$_."000" 89, Jasper -ln for$c(BPFV1,CSKGJQXZ2,DT3,L4,MN5,R6){s/[$c]+/$`?$c:$&/eg;$_.=0}print+(/^.|\d /g)[0..3] 90, Paul van Eldijk -lp ($@)=/(.)/;y;A- Z;.123.12..22455.12623.1.2.2;s;s;(^.|\.)\1*;;g;$_=substr$@.$_.'000',0,4 92, Spoon -n /./;y/BPFVDTLMNRCSKGJQXZ/111133455622222222/s;{s/.//}y/A- Z\n//d;printf"$&%.3s\n",$_."000" 102, Sec -nl /./;$b=$&;y.BZTLNRMDPFVCSKGJQX.1-6531112.;//;$d=$&;s/$/000/;print $b,/$d*\D*(.)\1*\D*(.)\2*\D*(.)/ 119, kcwu -lp sub f{vec'\x102\x10\x02 BU\x10b2\x10 ',- 65+ord$_[0],4}($r)=/./g;$b=f$r;for(//g){$r.=$,if$b- ($,=f$_)and$b=$,}$_=substr$r."000",0,4 152, IainT -pl $l=0;for$m(split//){$i=6;$o=$l?$o:$m;for(qw(R MN L DT CSKGJQXZ BPFV)){if(/$m/){$o.=$i if$i!=$l&&$l;$l=$i;last}$l=--$i?$l:7}}($_)="${o}000"=~/(.{4})/ 160, Vava -lp $z="1bpfv2cskgjqxz3dt4l5mn6r";$_=(@l=/./g)[0];$q=(map{$z=~/(\d)[a- z]*$_/i;$_=$1}@l)[0];$_.=substr join("",((grep{!/0/}map{$_=$_!=$q?$q=$_:""}@l),0,0,0)),0,3 160, Vava (alternative) -lp $z="1bpfv2cskgjqxz3dt4l5mn6r";$_=(@l=/./g)[0];$q=(map{$z=~/(\d)[a- z]*$_/i;$_=$1}@l)[0];$"=!map{$_=$_!=$q?$q=$_:""}@l;$_.="@l";s/0//g;s/$/000/; s/(.{4}).*/$1/ 180, tomekM -lp $r="";$i=4;foreach(split//){$c=/[BPFV]/&&1||/[CSKGJQXZ]/&&2||/[DT]/&&3||/L/& &4||/[MN]/&&5||/R/&&6;$_=($c!=$p?$c:"")if$r;$r.=$_;$p=$c;$i--if$_;last if!$i}$r.="0"while$i--;$_=$r

5.25. Isometric boxes http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=25&season=0 The game started 2003-02-14 16:00:00 and ended 2003-02-17 21:00:00.

5.25.1. Rules Given as a commandline argument (ARGV) is a positive integer 1 < n < 20 (matching /^([2- 9]|1\d)\n\z/), your task is to draw a quadratic box. The length of each side of the box is n. Chars

Edition 2007-01-09 top secret / strictly confidential page 252 of 520 Perlgolf History

used for the drawing are "+" for the corner points, "-" for X axis, "|" for the Y axis, "/" for the Z axis and " " for the empty areas. The "+" corner chars counts as half the length of the other chars, so square of size 4 will have 5 chars painting the horizontal lines. 2 times "+" and 3 times "-" No leading or trailing lines or whitespaces are allowed. Lines in Z direction are to be painted as one step right and one step up Input The input (ARGV) consists of a positive integer (matching /^([2-9]|1\d)\n\z/). Output The output should be a the isometric drawing (matching /^([|/ -+]*\n){3,42}\z/). Sample Input 4 Sample Output +---+ //| //| //| +---+ + ||/ ||/ ||/ +---+

5.25.2. Solutions 88, ton s# #$/.=" $'/$_/$`| ";$b.="|$_|$'/ ";"-"#eg,print" $`+$_+$/+$_+ $`+ $b+$_+ "for$"x~-pop 91, mtve $d='-'x($v=$_=$"x~-pop)=~s# #|$_|$'/ #g;s## $'/$_/$`| #g;print" $`+$d+ $_+$d+ $`+ $v+$d+ " 95, Jasper $_=$"x map$b.='-',2..pop;$t=$t?"$`/$_/$'| $t |$_|$'/":"+$b+$_+"while//g;print" $_+$b+ $t +$b+ " 95, dkr

Edition 2007-01-09 top secret / strictly confidential page 253 of 520 Perlgolf History

$_=$"x~-pop;$t.="$' /$_/$`| ",$b.="|$_|$'/ "while/\G /g;y/ /-/;print"$` +$_+ $t+$_+$`+ $b+$_+ " 98, anfi $_=$b='-'x(-1+pop);y/-/ /;$A="+$b+$_+ ";$A=" $`/$_/$'| $A|$_|$'/ "while/./g;print" $_+$b+ $A+$b+ " 99, michalj $_=$"x--($l=pop);$f="-"x$l;$s=" +$f+$_+ ";$s=" $` /$_/$'|$s|$_|$'/ "while/./g;print"$_ +$f+$s+$f+ " 99, tybalt89 -lX print$"x-$_,pack"(A$n)2X".abs.A,$_%$n?split'','//'x/-/.'||/':'+'.'- 'x$n,'+','+'for-($n=pop)..$n 99, kcwu $s=$_=$"x~-pop;y/ /-/;$o="+$_+$s+ ";$s=~s! !$o=" $`/$s/$'| $o|$s|$'/ ";$&!ge;print"$s +$_+ $o+$_+ " 100, dkr (alternative) $h=$_=$"x~-pop;$h=~y/ /-/;$m="+$h+$_+";$m="$` /$_/$'| $m |$_|$'/"while/\G /g;print"$_ +$h+ $m +$h+ " 101, Sami Silvennoinen $_=$"x((pop)-1);$a.="$' /$_/$1| ",$b.="|$_|$'/ ",$x.='-'while/($&) /;print"$_ +$x+ $a+$x+$_+ $b+$x+ " 102, mtve (alternative) print$"x-$_,$~=/$;|^0/?'+':$_<0?'/':'|',(//?'-':$")x~-$;,$~|$"x($;-abs).($~^S x!//),$/for-($;=pop)..$; 103, Daniel (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 254 of 520 Perlgolf History

print$"x-$_,('+| -/'=~/./g)[$j=($k=$m-abs)*$_<=>0,(2+!$j)x~-$m,$j,(2)x~- $k,7*!$k-$j],$/for-($m=pop)..$m 106, andys $_=$"x-$_.a.'-'x~-$n.a.$"x($n-1-abs)."| ",$a++%$n?/^ /?y#a-#/ #:y#|a-#/| #:y#a|#+#s,print for-($n=pop)..$n 107, Daniel print$"x-$_,('+| -/'=~/./g)[$j=($k=$m-abs)*$_<=>0,(2+!$j)x($m-1),$j,(2)x($k- 1),7*!$k-$j],$/for-($m=pop)..$m 112, k.c.ivey $t='-'x--($n=$m=pop);s//$m+$t+ a+$t+ /;s:a:$m/$n/$%| a|$n|$%/ :,$%++while--$m;s/a/+$t+$n+ /;s/\d+/$"x$&/ge;print 112, m.wrenn s~~ +-+ 1/ /| +-+ + ||/ +-+ ~;for$k(3..pop){s~( |-)+~$1$&~g,s~(.*)\|~1$& $1 |~,s~(.*\|)/~$1 / $&~}y/1/ /,print 120, Chris Dolan $b=$"x--($s=pop);$c="-"x$s;$m.=$"x$s--."/$b/".$"x$i++."| ",$n.="|$b|".$"x$s."/ "while$s;print" $b+$c+ $m+$c+$b+ $n+$c+ " 122, andys (alternative) -l $a=!!($_%$n),print+("+/- |"=~/./g)[(3)x-$_,$b=2*$a*/-/-$a,($a+2)x~- $n,($b)x($a^!$_),(3)x($n-1-abs),-$b]for-($n=pop)..$n 133, slawek- -l $a=pop;for$i(0..$a*2){$u=$a-$i;$_=' 'x$u.'+'.'-'x--$a.'+'.' 'x($a++- abs$u).'|';$i%$a?y!-+! /!:$u?chop:y/|/+/;$u<0&&y!/|!|/!;print} 134, andys (alternative) s#([- ])\1*#$1$&#g,s#^ ( /.*).#$&\n$1 |#m,s# \|$# |#gm,s#(.*\|)/#$1 /\n$&#for($_=" +-+ //| +-+ + ||/ +-+ ")x~-~-pop;s/\n//;print 135, gibbering

Edition 2007-01-09 top secret / strictly confidential page 255 of 520 Perlgolf History

$,=$/;$S=$"x--($s=pop);$a='+'.'-'x$s.'+';print" $S$a",(map$"x$s-- ."/$S/".$"x$c++.'|',1..$s),"$a$S+",(map"|$S|".$"x--$c.'/',1..$c),$a,'' 140, IainT -l $i=pop,$a=$"x--$i,$b="+"."-"x$i."+";print for" $a$b",(map$"x($i-$_)."/$a/".$"x$_."|",0..$i-1),"$b$a+",(map"|$a|".$"x($i- $_)."/",1..$i),$b 152, Przemek Jam Swiderski -l $b=$"x--($a=pop);print$"x$a," +",$c='-'x$a.'+';print$"x($a- $_)."/$b/".$"x$_.'|'for 0..$a-1;print$_?"|$b|".$"x($a-$_).'/':"+$c$b+"for 0..$a;print"+$c" 156, Vava -l $a=pop;$b='-'x--$a;$c=" "x$a;print"$c +$b+";print" "x($a-$_),"/$c/"," "x$_,"|"for 0..$a-1;print"+$b+$c+";print"|$c|"," "x($a-$_),"/"for 1..$a;print"+$b+" 161, beowulf -l $b.=$b=$"x($l=-1+pop).'/';print$"x($l+1),$_='+'. '- 'x$l.'+';map{print"$b|";($b.=$")=~s/.//}1..$l;print$_,$"x$l,'+';$b=~y#/#|#;c hop$b,print"$b/"for 1..$l;print 162, Frantisek Darena $l=pop;$s=' 'x--$l;$x='-'x$l--;$o=" $s+$x+$/";$o.=' 'x($l-$_+1)."/$s/".' 'x$_."|$/"for 0..$l;$o.="+$x+$s+$/";$o.="|$s|".' 'x($l-$_)."/$/"for 0..$l;print"$o+$x+$/" 163, Frantisek Darena $l=pop;$s=' 'x--$l;$x='-'x$l--;$o=" $s+$x+$/";$o.=' 'x($l-$_+1)."/$s/".' 'x$_."|$/"for 0..$l;$o.="+$x+$s+$/";$o.="|$s|".' 'x($l-$_)."/$/" for 0..$l;print"$o+$x+$/" 170, tomekM $n=$ARGV[0]-1;$a="-"x$n;$b=" "x$n;$o="$b +$a+\n";$o.=" "x($n-$_)."/$b/"." "x$_."|\n"for 0..$n-1;$o.="+$a+$b+\n";$o.="|$b|"." "x($n-$_)."/\n"for 1..$n;$o.="+$a+\n";print$o 181, thepoet $d=$ARGV[0];$b=$d-1;$c=" $d+-$b+\n";map$c.=" ".($d-$_)."/ $b/ ".-- $_."|\n",1..$b;$c.="+-$b+ $b+\n";map$c.="| $b| ".($b-$_)."/\n",1..$b;$c.="+- $b+\n";$c=~s/(\D)(\d+)/$1x$2/eg;print$c 192, Hirogen2 sub f{printf@_}$*=($;=shift)-1;f"%$;s+%s+ ","","-"x$*;f"%s/%s/%s| "," "x($;-$_)," "x$*," "x($_-1)for 1..$;-1;f"+%s+%s+ ","-"x--$;," "x$;++;f"|%$*s|%s/ ",""," "x($;-$_)for 2..$;;f"+%s+ ","-"x$* 213, Paul van Eldijk -nl $,="\n";print((' ')x$_.'+'.('-')x--$_.'+');$@=$_;print((map{(' ')x($@- $_+1).'/'.(' ')x$@.'/'.(' ')x--$_.'|'}1..$@),'+'.('-')x$@.'+'.(' ')x$@.'+',(map{'|'.(' ')x$@.'|'.(' ')x($@-$_).'/'}1..$@),'+'.('-')x$@.'+') 244, thorsten schau

Edition 2007-01-09 top secret / strictly confidential page 256 of 520 Perlgolf History

-l ($x,$y,$z,$c,$w,$l)=('-','|','/','+',' ',"$ARGV[0]"-1);p($w x($l+1).$c.$x x$l.$c);for(0..$l-1){p($w x($l-$_).$z.$w x$l.$z.$w x$_.$y);}p($c.$x x$l.$c.$w x$l.$c);for(0..$l-1){p($y.$w x$l.$y.$w x($l-1-$_).$z);}p($c.$x x$l.$c);sub p{print$_[0];}

5.26. All roads leads where ? http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=26&season=0 The game started 2003-02-23 19:30:00 and ended 2003-02-27 21:00:00.

5.26.1. Rules There is an ancient saying that "All Roads Lead to Rome". If this were true, then there is a simple algorithm for finding a path between any two cities. To go from city A to city B, a traveller could take a road from A to Rome, then from Rome to B. Of course, a shorter route may exist. The network of roads in the Roman Empire had a simple structure: beginning at Rome, a number of roads extended to the nearby cities. From these cities, more roads extended to the next further cities, and so on. Thus, the cities could be thought of as existing in levels around Rome, with cities in the ith level only connected to cities in the i-1th and i+1th levels (Rome was considered to be at level 0). No loops existed in the road network. Any city in level i was connected to a single city in level i-1, but was connected to up to nine cities in level i+1. Thus, to get to Rome from a given city in level i, a traveler could simply walk along the single road leading to the connected i-1 level city, and repeat this process, with each step getting closer to Rome. Given a network of roads and cities, your task is to find the shortest route between any two given cities, where distance is measured in the number of intervening cities. Input The road structure is given on STDIN. The lines in the input each contain the names of a pair of cities separated by a single space. A city name consists of one or more letters, the first of which is in uppercase. The name Roma (not Rome) always appears at least once in this section of input; this city is considered to be at level 0, the lowest-numbered level. The pairs of names indicate that a road connects the two named cities. The first city named on a line exists in a lower level than the second named city. No two lines of input in this section are repeated. A city name matches /^[A-Z][A-Za-z_-]+\z/. Input matching /^([A-Z][A-Za-z_-]+ [A-Z][A-Za-z_-]+\n){1,999}\n\z/ The query pair is given as two arguments. (ARGV) Output Output a space-separated sequence of city names which make up the shortest route between the two query pair cities, including the query pair cities themselves. A city will never be paired with itself in a query. Sample input Query pair as arguments: Milan Florence Road structure on STDIN:

Edition 2007-01-09 top secret / strictly confidential page 257 of 520 Perlgolf History

Roma Turin Turin Venice Turin Genoa Roma Pisa Pisa Florence Venice Athens Turin Milan Sample output Milan Turin Roma Pisa Florence

5.26.2. Solutions 79, ton $$a=$a=pop;$b=pop;s/(.+) (.+)/$2 $1/,$$2||=$$1&&"$2 $$1"for(<>)x2e3;print"$$b " 93, tybalt89 (post-mortem) -l map$_=pop|$$_,$b,$a;/ (.*)/,$$1=$`for<>;s/,|$/ $a,$b /;s/( .+ ).+\1/$1/?print/ (.*) /:do$0 94, ton (alternative) $$a=$a=pop;$b=pop;/(.+) (.+)/,$$2||=$$1&&"$2 $$1",$$1||=$$2&&"$1 $$2"for(@F=<>)x@F;print"$$b " 95, mtve (would be rejected after 2.5 years, due to $ARGV problem) -lp INIT{$0=pop;$x=pop}/ /,${$'}=$`}{s/.+/${$&}/guntil$_="$x $_ $0",s/^(.+) \C* \1$/$1/m;y/ // 97, anfi -lap0 INIT{$l=pop;$c=pop}%r=%R=reverse@F;0while$R{$c}=$p,$c=$r{$p=$c};$_=$l;s//$l /while$l=$R{$l} 98, Krzysztof Koczyjan (post-mortem) -lp / /;${$'}=$`}INIT{$l=pop;$f=pop}{do{@$f=@t=(@t,$f)}while$f=$$f;s// $l/,$l=$$l until@$l;s//@$l/ 99, terje (rejected) -l $_=pop|$$_ for$b,$a;/ (.*)/,$$1=$`for<>;s/0|^$/$a 0 $b/;$a|$b?do$0:s/( .+ |\bRo).+\b\1/$1/+print 99, Krzysztof Koczyjan -lp / /;${$'}=$`}BEGIN{$l=pop;$f=pop}{do{@$f=@t=(@t,$f)}while$f=$$f;s// $l/,$l=$$l until@$l;s//@$l/ 99, g.allen (rejected) -l $_=pop|$$_ for$b,$a;/ (.*)/,$$1=$`for<>;s/0|^$/$a 0 $b/;$a|$b?do$0:s/( .+ |\bRo).+\b\1/$1/+print 99, g.allen (rejected)

Edition 2007-01-09 top secret / strictly confidential page 258 of 520 Perlgolf History

-l $_=pop|$$_ for$b,$a;/ (.*)/,$$1=$`for<>;s/0|^$/$a 0 $b/;$a|$b?do$0:s/( .+ |\bRo).+\b\1/$1/+print 99, Magus $/+=$a=pop;$b=pop;$x=<>;sub k{print"@_\n"x/^$b/;s/ *$_[0] *//^/^$_[1]$/&&k($_,@_)for$x=~/.+$/mg}k$a 100, terje -l map$_=pop|$$_,$b,$a;/ (.*)/,$$1=$`for<>;s/,|^$/ $a,$b /,$a|$b?do$0:s/( .+ ).+\1/\1/+print/ (.*) / 105, tybalt89 $"=/ (.+)/,$$1=$`for;s//@ARGV /;s/1/ @{[map$_=$$_,@ARGV]} /until s/((?;$_=" @{[reverse(f shift),f pop]} ";s/( .+ ).*\1/$1/;s/^ | $//g;print 112, Jasper -p0 BEGIN{$o=pop;$i=pop}sub f{"@_",/(.+) @_$/m&&f($1)}$_=" @{[f($i),reverse f$o]} ";s/( .* ).*\1/$1/;s/^ | $//g 113, Daniel sub f{@_&&f("@c"=~/(\S+) @_ /),@_}@c=;s// @{[reverse(f shift),f pop]} /;s/( .+ ).*\1/$1/;s/^ | $//g;print 114, Krzysztof Koczyjan (alternative) -lp / /;$b{$'}=$`}BEGIN{$l=pop;$f=pop}{{s/ ?$/ $f/;$$f=$_;redo if$f=$b{$f}}$_='';s// $l/,$l=$b{$l}until$$l;s//$$l/ 114, JLO (rejected) -l $t=pop;$f=pop;/ (.*)/,$$1=$`for<>;s##$f\xA3$t#;while(($t=$$t)|($f=$$f)){s#\xA3#$f\xA3$t #}s#( .+ |\bRo).+\b\1#$1#;print 116, p.kailasa -lp0 INIT{@a=pop;@b=pop}for$x(\@a,\@b){push@$x,$1while/(.+) $$x[- 1]$/m}pop@a;$_="@{[@b,reverse@a]}";s/( .+ ).*\1/$1/ 116, Michael Robinson -lp0 BEGIN{$R=$r=pop;$L=$l=pop}$L.=$".($l=$1)while s/(.+) $l$//m;$R=($r=$1)." $R"while/(.+) $r$/m;$_=$L;s/\b$r.*/$R/ 120, k.c.ivey -p0 INIT{$;=pop;@$=$:=pop}splice@$,++$%,0,$:while$%-=$|,$:=/(.+) $: /?$1:$;x--$|;$_="@$ ";s/(?)x1e3;$f="@f"=~/(.*( |^)$_)( |$)/?$1:"$f $_"for@g;print$f 125, pom

Edition 2007-01-09 top secret / strictly confidential page 259 of 520 Perlgolf History

-pl INIT{$;=pop;$f=pop}/ /;$;{$'}=$`}{$_=$f.$;while$f=~s/\S+$/$& $;{$&}/+$;=~s/^\S+/$;{$&} $&/;s/(^| )(.+) .* \2($| )/$1$2$3/ 129, Chris Dolan -lnaF BEGIN{$d=pop;$s=pop}push@{$r{$_}},@F for@F}{sub d{print"@_"if($_=@_[- 1])eq$d;local$v{$_}=1;$v{$_}||d(@_,$_)for@{$r{$_}}}d$s 132, topmach @c=;for(t,f){@$_=$$_=pop;push@$_,$$_=$1while"@c"=~/(\S+) $$_ /;$a{$_}++for@$_}@a=grep{$a{$_}<2or!$i++}@f,reverse@t;print"@a " 136, Frantisek Darena -l $e=pop;@c=pop;chop(@h=<>);for$c(@c){$c=~/\S+$/;$p=$&;map{push@c,"$c $m",$_=''if/ /,$m=$`eq$p?$':$' eq$p&&$`}@h}print+(grep/$e/,@c)[0] 221, IainT -l /(.*) (.*)/,$t{$2}=$1for;$r='Roma';sub k{@x=($x=pop);push@x,$x=$t{$x}while$x ne$r;@x}@j=(k(shift),reverse k pop);for$l(@j){@_=@j[$p+1..@j];if(grep/^$l$/,@_){do{splice@j,$p,1}until$j[$p ]eq$l}++$p}print join' ',@j

5.27. Crossing (s)words http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=27&season=0 The game started 2003-03-04 11:30:00 and ended 2003-03-07 21:00:00.

5.27.1. Rules Input consists of two lines on STDIN, each contain an odd length word completely in uppercase (so STDIN matches /^([A-Z]{L}\n){2}\z/ with L an odd number). These words have no letters in common except for the letter exactly in the middle. The lengths of the two words are identical, 3 ≤ L ≤ 19 (and L % 2 == 1). You must output these two words to STDOUT, the first word vertical and the second horizontal so that they intersect on the common middle letter. You should use leading spaces to position the vertical word, but there should be no trailing spaces. So STDOUT will match /^( {H}[A-Z]\n){H}[A-Z]{L}\n( {H}[A-Z]\n){H}\z/ where H=(L-1)/2. Sample input AWAKENING PROCESSOR Sample output

Edition 2007-01-09 top secret / strictly confidential page 260 of 520 Perlgolf History

A W A K PROCESSOR N I N G

5.27.2. Solutions 38, Magus -paF.. s!.!++$q%@F?$"x$#F.$&.$/:<>!egs 38, andys -apF.. s/\D/++$F%@F?$"x$#F."$& ":<>/eg 38, terje -paF.. s|.|"@+"%@F?$"x$#F.$&.$/:<>|seg 38, Daniel -paF.. s!.!++$i%@F?$"x$#F.$&.$/:<>!sge 38, mtve -paF.. s!.!"@+"%@F?$"x$#F.$&.$/:<>!seg 40, ton -paF.. s!(.) ?!@F[@-]?<>:$"x$#F.$1.$/!eg 41, Juho Snellman -paF.. s|\C|++$F%@F?$"x(@F-1)."$& ":<>|ge 42, Szeryf -paF.. s|.|$#F-pos&&$'?$"x$#F.$&.$/:<>|egs 44, g.allen -lp $"x=$x=s/\B/ /g/2;s%. ?%$x--?$".$&:<>%ge 44, Florian Häglsperger -paF'' s|.|2*++$i%@F?$"x($#F/2).$&.$/:<>|sge 45, m.wrenn -naF| print$i++-$#F/2?$"x(@F/2).$_.$/:<>for@F 45, p.kailasa -p $l=@l=/../g;s~(.) ?~$l--?$"x@l."$1 ":<>~eg 46, k.c.ivey

Edition 2007-01-09 top secret / strictly confidential page 261 of 520 Perlgolf History

-p chop;s|.|pos^($h=y///c/2)?$"x$h.$&.$/:<>|ge 47, Jasper print$i++^@a/2?$"x(@a/2)."$_ ":<>for@a=<>=~/./g 47, anfi -lapF| $F[$l=@F/2]=<>}for(@F){chomp||s//$"x$l/e 47, michalj -naF| $"x=$n=--$#F/2;print$n--?$".$_.$/:<>for@F 47, Bass -n print$f++*2^$#y?$"x(@y/2).$_.$/:<>for@y=/./g 48, m.wrenn (alternative) -naF| @F[.5*map$_=$"x(@F/2).$_.$/,@F]=<>;print@F 48, Michael Robinson -p s,.,pos^($w=y///c/2-1)?$"x$w.$&.$/:<>,eg;chop 48, aqumsieh -n print$x++-$#_/2?$"x($#_/2).$_.$/:<>for@_=/./g 48, Chris Dolan -lpaF| s|.|$#F-$n++*2?$"x(@F/2)."$& ":<>|ge;chop 48, aj -p chop;s;.;pos^($n=.5*length)?$"x$n.$&.$/:<>;eg 49, Paul van Eldijk -alpF| s#.#@F[$F=@F/2]eq$&?<>:$"x$F.$&.$/#ge;chop 49, Paul van Eldijk (alternative) -apF| s#.#++$i==@F/2?<>:$"x(@F/2-1).$&.$/#ge;chop 50, banshee -lpaF| $t=<>;s!.!$t=~$&?$t:$"x(@F/2).$&.$/!ge;chop 50, IainT -p chop;$i++for/../g;s,.,pos==$i?<>:$"x$i.$&.$/,eg 51, beowulf -paF// chop;s#.#pos==@F/2-1?<>:$"x(@F/2-1).$&.$/#ge 51, JLO -apF| s!.!$&ne$F[$#F/2]?$"x($#F/2).$&.$/:<>!eg;chop 51, Vava -p $n=y///c/2-1;chop;s#.#pos==$n?<>:" "x$n.$&.$/#ge 58, gibbering -lnaF| @l or@l=@F}{print$i++==($x=$#l/2)?@F:$"x$x.$_ for@l 61, Shlomi Fish

Edition 2007-01-09 top secret / strictly confidential page 262 of 520 Perlgolf History

split//,<>;pop@_;print map$_[$h=@_/2]eq$_?<>:' 'x$h."$_\n",@_ 72, Frantisek Darena -lp ($x?$y:$x)=$_}@x=map{$"x($#x/2).$_}@x=$x=~/./g;$x[$#x/2]=$y;for(@x){ 84, Gerb -l chop(($v,$h)=<>);$_=$h;/[$v]/g;$c=pos;for$x(split//,$v){print/$x/?$_:' 'x~- $c.$x} 127, Hirogen2 $\=$/;chop(($_,$*)=<>);print" "x$.,substr$_,~-$-,1while$- ++<($.=int.5*length);print$*;print" "x$.,substr$_,$-++,1while$-;chomp(@a);$n=length($a[1]);$l=1+int($n/2);@v=split(/ */,$a[0]);foreach$s(1..$n){if($s==$l){printf"%s\n",$a[1];}else{print" "x($l- 1),$v[$s-1],"\n";}}

5.28. Rough Flying http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=28&season=0 The game started 2003-03-10 21:30:00 and ended 2003-03-14 21:00:00.

5.28.1. Rules While flying on Kiwi Air (motto "we soar like the Kiwi bird") I have noticed that every time the plane is jolted downwards I lose 20% of my drink and every time the plane is jolted upwards I lose 10% of my drink. Read as a command line argument the proportion of drink remaining, and print out the number of upjolts and downjolts. Input will be a one 6-place decimal number (matching /^0\.\d{6}\z/) as a command line argument, representing the proportion of drink left. The number of jolts will always be such that the proportion left can be exactly represented in 6 places of decimals. Output (STDOUT) will be the number of downjolts followed by the number of upjolts, separated by a single space (matching /^\d \d\n\z/). Example Input 0.414720 Example Output 32

5.28.2. Solutions 36, mtve $_=2725*log pop;print$_%7,$",$_%8,$/ 45, ton print$%-=s///g+9*log,$","@+"-3-$%,$/for.6*pop 48, tybalt89

Edition 2007-01-09 top secret / strictly confidential page 263 of 520 Perlgolf History

$_+=pop;print$n-($-=($n=y///c-2)*2+9*log)," $- " 49, ton (alternative) $%++until($_=$_/9+4e6*pop)%9;/.0*$/;print"@- $% " 52, Daniel $_=1e6*pop;$?++,$_/=9until$_%9;/1?0*$/;print"@- $? " 52, mtve (alternative) $=-=!$^C--until"@ARGV"=~(.8**$^C*.9**$=);print"$^C $= " 52, m.wrenn /./eq.8**$&*.9**$'/"@ARGV"&&print"$& $' "for'00'..AA 52, m.wrenn (rejected) /./eq.8**$&*.9**$'/"@ARGV"&&print"$& $' "for'00'..99 52, terje s/.$/ $& /*"@ARGV"eq.8**$`*.9**$&&&print for"01"..AA 52, g.allen s/.$/ $& /ne"@ARGV"/.8**$`/.9**$&||print for'01'..aa 53, Juho Snellman $_=0+pop;s/..//;print s^.^$_/=8;$%+=/\./^ge-$%," $% " 53, k.c.ivey $_+=/.$/until.9**$&*.8**$`eq($;+=pop);print$`|"0 $& " 53, Jasper $_++until/\B.\B/*"@ARGV"eq.8**$&*.9**$';print"$& $' " 54, banshee /.$/ne"@ARGV"/.8**$`/.9**$&||print$`+0," $& "for 0..99 54, andys /./eq"@ARGV"/.8**$&/.9**$'&&print"$& $' "for"00".."60" 56, anfi /./,${.8**$&*.9**$'}="$& $' "for"01".."60";print${0+pop} 56, michalj

Edition 2007-01-09 top secret / strictly confidential page 264 of 520 Perlgolf History

$_++until/.$/,$ARGV[0]==".".8**$`*9**$&;print$`+0," $& " 56, Frantisek Darena /./*.8**$&*.9**$'.0-$ARGV[0]||print"$& $' "for'00'..'99' 58, Chris Dolan s/.$/ $& /+$ARGV[0]eq"1.".8**$`*9**$&&&print for"00".."66" 58, VesaK print+{map{/./;.8**$&*.9**$',"$& $' "}'00'..'99'}->{0+pop} 58, JLO /.(.)/,($a+=pop)eq.9**$1*.8**$'&&print"$' $1$/"for 99..166 59, p.kailasa -l s/\B/ //~1abs$x-.9**$&*.8**$`&&print$`+0," $& "for($x=pop)..99 62, aqumsieh map{abs"@ARGV"-.8**$_*.9**$=<1e-6&&print"$_ $= "}0..9while$=-- 63, Mykola Zubach for$i(0..9){map{$a{.8**$i*.9**$_}="$i $_\n"}0..9}print$a{0+pop} 64, Jacob Cohen $x=pop;map{$i=$_;map{".".8**$i*9**$_-$x||print"$i $_ "}0..6}0..6 65, Mercutio for$u(0..9){@ARGV[0]/(.9**$u*.8**$_)eq 1&&print"$_ $u\n"for 0..9} 66, aqumsieh (alternative)

Edition 2007-01-09 top secret / strictly confidential page 265 of 520 Perlgolf History

map{"@ARGV"=~/^@{[.8**$_*.9**$=]}0*$/&&print"$_ $= "}0..9while$=-- 68, Honza Pazdziora map{for$j(0..9){print"$_ $j "if$ARGV[0]*1e9eq.8**$_*.9**$j*1e9}}0..9 73, NumberCruncher map{$n=$_;map{abs($ARGV[0]-.8**$n*.9**$_)<.001?print"$n $_\n":0}0..9}0..9 75, Paul van Eldijk $L=pop;for$i(0..9){for(0..9){8**$i*9**$_/10**($i+$_)-$L||print$i,$",$_,$/}} 78, Hirogen2 $d++while($_=sprintf"%f",log($ARGV[0]/.8**$d)/log.9)!=int;printf"%d %d ",$d,$_ 78, IainT -l $r=pop;for$d(0..6){(sprintf'%.6f',.9**$_*.8**$d)==$r&&print"$d $_"for 0..6} 111, Gerb (alternative) sub F{my($d,$u)=@_;$x==($t='.'.9**$d*8**$u)and$_="$u $d ";$t>$x&&F($d,$u+1)+F($d+1,$u)}$x=pop;F 1,0;F 0,1;print 134, Vava $i=1;$b=pop;$a=$$;{$b==sprintf("%.6f",$i)?(print("$- $%\n"),close$~,kill 9,$a):$i>$b?fork?($i-=$i*.2,$-++):($i-=$i*.1,$%++):exit;redo}

5.29. Digit sums http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=29&season=0 The game started 2003-03-18 23:00:00 and ended 2003-03-22 23:00:00.

5.29.1. Rules Given 3 positive integers A, B and C, find how many positive integers less than or equal to A, when expressed in base B, have digits which sum is C. Input will be 3 positive integers A, B and C (each matching /^[1-9]\d*\z/) as commandline arguments where 1 ≤ A ≤ 9999, 2 ≤ B ≤ 36, 1 ≤ C ≤ 100. Output (STDOUT) will be the number of matching numbers. (matching /^(0|[1-9]\d*)\n\z/) Example 1: A=50, B=10, C=9. the numbers 9, 18, 27, 36, 45 are the only (base 10) numbers ≤ 50 where the sum of it's digits are 9. Example 2: A=20, B=2, C=3. the numbers 111, 1110, 1101, 1011, 10011 are the only (base 2) numbers ≤ 20 where the sum of it's digits are 3. Example 3: A=9999, B=36, C=75. the numbers 5ZZ, 6YZ, 6ZY are the only (base 36) numbers ≤ 9999 where the sum of it's digits are 75. Example Input

Edition 2007-01-09 top secret / strictly confidential page 266 of 520 Perlgolf History

50 10 9 Example Output 5

5.29.2. Solutions 61, andys (post-mortem) -l print~~grep$'==eval'+$_%$&%[$_/=$&]'x14,"@ARGV"=~/ ../..$` 62, mtve -l print~~grep$'==eval'+$_%$&%[$_/=$&]'x14,"@ARGV"=~/ .* /..$` 62, andys -l print~~grep!eval$'.'-$_%$&-!($_/=$&)'x14,"@ARGV"=~/ ../..$` 62, ton -l print~~grep$'==eval'+$_%$b%[$_/=$b]'x14,pop!~!($b=pop)..pop 62, ton (alternative) -l print~~grep$'==eval$_.'%$b+($_/=$b)'x99,pop=~!($b=pop)..pop 64, tybalt89 -l sub f{$_?$_%$&+f($_/=$&):-$'}print~~grep!f,"@ARGV"=~/ ../..$` 64, terje (post-mortem) -l print~~grep{($b,$c)=@ARGV;1while$c-=$_%$b,$_/=$b;!$c}0..shift 66, Shlomi Fish (post-mortem) -l print~~grep{for(($b,$c)=@ARGV;$_;$_/=$b){$c-=$_%$b}!$c}0..shift 67, Jasper -l $c=pop;print~~grep{$i=$c;1while$i-=$_%$',$_/=$';!$i}pop=~//..pop 67, terje -l print~~grep{$x=$';1while$x-=$_%$&,$_/=$&;!$x}"@ARGV"=~/ .+ /..$` 67, m.wrenn -l print$`-grep{$i=$';1while$i-=$_%$&,$_/=$&;$i}"@ARGV"=~/ .* /..$` 67, Shlomi Fish -l print 0+grep{for(($b,$c)=@ARGV;$_;$_/=$b){$c-=$_%$b}!$c}0..shift 67, Shlomi Fish (alternative) -l print 0+grep{($b,$c)=@ARGV;{$c-=$_%$b;redo if$_/=$b}!$c}0..shift 67, Shlomi Fish (alternative) -l print 0+grep{($b,$c)=@ARGV;do{$c-=$_%$b}while$_/=$b;!$c}0..shift 67, Alma Media Golf Team -l print~~map{($;,$x)=@ARGV;$x-=$_%$;,$_/=$;while$_;$x&&()}1..shift 68, banshee -l $c=pop;$b=pop;print~~grep{$;=$c;1while$;-=$_%$b,$_/=$b;!$;}0..pop 68, p.kailasa

Edition 2007-01-09 top secret / strictly confidential page 267 of 520 Perlgolf History

-l $c=pop,$?=pop;print~~grep{$s=$c;1while$s-=$_%$?,$_/=$?;!$s}1..pop 69, michalj -l $s=pop;$;=pop;print~~grep{$x=$s;$x-=$_%$;,$_/=$;while$_;!$x}1..pop 69, Michael Robinson -l $C=pop;$B=pop;print$_=grep{$s=$C;1while$s-=$_%$B,$_/=$B;!$s}1..pop 69, Daniel -l $s=pop;$@=pop;print~~map{$_/=$@,$s+=~-$@until$_%$@;--$s&&()}1..pop 70, Florian Häglsperger -l $c=pop;$,=pop;print 0+grep{$s=$c;$s-=$_%$,,$_/=$,while$_;!$s}1..pop 72, Gerb -l ($a,$b,$c)=@ARGV;print$a-grep{for($d=$c;$_;$_/=$b){$d-=$_%$b}$d}1..$a 75, Mykola Zubach ($n,$b,$s)=@ARGV;map{$t=$s;1while$t-=$_%$b,$_/=$b;$n--if$t}1..$n;print$n.$/ 75, gibbering -l $S=pop;$b=pop;map{for($s=$S;int;$_/=$b){$s-=$_%$b}$%+=!$s}1..pop;print$% 76, Arkady -l ($n,$M,$c)=@ARGV;print- -grep{my$s;do{$s+=$_%$M}while$_/=$M;$s==$c}1..$n; 79, Chris Dolan ($a,$b,$c)=@ARGV;sub c{$_&&$_%$b+c($_=int$_/$b)}$c-&c||$%++for 1..$a;print$%,$/ 79, Frantisek Darena "@ARGV"=~/ \d+/;map{my$p;$p+=$_%$&,$_/=$&while$_;$'-$p||$*++}0..$`;print$*|0,$/ 80, ErikB ($a,$b,$c)=@ARGV;map{for($y=$c;int;$_/=$b){$y-=$_%$b}$a-- if$y}0..$a;print++$a,$/ 85, Mercutio ($",$.,$;)=@ARGV;sub o{$_=pop;$_?$_%$.+o(int$_/$.):0}$-+=$;==o$_ for 0..$";print$-,$/ 108, JLO -l ($t,$b,$s)=@ARGV;for(0..$t){$n=0;$a=14;while($_>0){$b**$a<=$_?($n++,$_- =$b**$a):$a--}$?++if$n==$s}print$?

5.30. Minesweeper http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=30&season=0 The game started 2003-03-28 16:00:00 and ended 2003-04-01 21:00:00.

5.30.1. Rules Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating System which name we can't really remember. Well, the goal of the game is to find where are all the mines within an MxN field. To help you, the game shows a number in a square which tells you how

Edition 2007-01-09 top secret / strictly confidential page 268 of 520 Perlgolf History

many mines there are adjacent to that square. For instance, suppose the following 4x4 field with 2 mines (which are represented by an * character): *...... *...... If we would represent the same field placing the hint numbers described above, we would end up with: *100 2210 1*10 1110 As you may have already noticed, each square may have at most 8 adjacent squares. In this task we will use a 8x8 field so the Input (STDIN) will be 8 lines containing exactly 8 characters + a newline (matching /^([.*]{8}\n){8}\z/). Each safe square is represented by an "." character (without the quotes) and each mine square is represented by an "*" character (also without the quotes). You should output on STDOUT the playing field with the hint numbers placed (matching /^([0- 8*]{8}\n){8}\z/). Sample Input ...... ***. ...**.*. ..**...... ***** ...*.*.* ...*.*** Sample output 00000000 00012321 0013***2 013**5*2 01**6543 014***** 003*7*8* 002*4***

5.30.2. Solutions 36, mtve -p0 s#\.#map/"/g,$`.666e6x3&$^.$_#eg 36, tybalt89 -p0 s!\.!map/\x1B/g,$^.$_^$`.111e6x3!ge 36, Daniel -0p s#\.#map/\x1C/g,$^.$_^$`.666e6x3#ge 36, ton -p0 s!\.!map/"/g,$`.666e6x3&$^.$_!eg 39, k.c.ivey

Edition 2007-01-09 top secret / strictly confidential page 269 of 520 Perlgolf History

-p0 s/\./($`."^^^$~"x3^$^.$_)=~y^t^^/ge 40, RobTM -p0 s#\.#($^.$_^$`."aaa$~"x3)=~y/K//#ge; 47, Daniel (alternative) -0p s#\.#map/\xD5(?=.{7,9}$|$)/g,~$`,~reverse$'#ge 53, terje -pa0 s#\.#grep"$^@F"=~/^.{@-}.{$_}\*/&$_%9<3,0..20#eg 54, Jasper -p0 s#\.#map/\*/,map{(/./sg)[0,7..9]}$',~~reverse$`#eg 57, andys -p0aF| s#\.#grep$F[127&$_+"@+"]eq'*',-11..-9,-2,0,7..9#eg 59, Chris Dolan -p0aF| $#F=99;s#\.#grep$_%9<3&&$F[$+[0]-$_]=~/\*/,-9..11#ge 63, aj -p0 s#\.#$c=0,/(\G.(.{7,9}|)\*|\*(.{7,9}|)\G)(??{$c++})/s,$c#ge 65, Michael Robinson -p0aF// s!\.!grep$F[$x=$-[0]+$_]eq'*'&$x>-1,-10..-8,-1,1,8..10!ge 66, m.wrenn -0p for$i((!y/./0/,0,7..9)x2){s/\d(?=.{$i}\*)/$&+1/esg;$_=reverse} 66, Paul van Eldijk -0paF| s!\.!grep{$F[$p=$-[0]+$_]eq'*'&&$p>=0}-1,-10..-8,1,8..10!ge 66, Shlomi Fish -0paF'' s%\.%grep$F[/-/?8:$_]eq"*",map$+[0]-$_,-9..-7,2,0,9..11%ge 67, Awie -0paF// s#\.#grep/\*/,@F[grep!/-/,map{$-[0]+$_,$-[0]-$_}1,8..10]#eg 69, Gerb -p0 y/./0/;eval'for$x(0,7..9){s/\d(?=.{$x}\*)/1+$&/sge}$_=reverse;'x2 69, p.kailasa -p0 y/./0/;eval'for$a(0,7..9){s/\d(?=.{$a}\*)/$&+1/seg}$_=reverse;'x2 134, Thomas Insel -n $v{$.,pos}=1while/\*/g;END{for$i(1..8){for$j(1..8){my$a;for$x(- 1..1){$a+=$v{$x+$i,$_+$j}for(-1..1)}print$v{$i,$j}?"*":$a}print" "}} 194, Hirogen2 -n sub c{$f[$y+pop][$x+pop]eq"*"&&++$q}y/./0/;push@f,[split//]}for$y(0..7){for$x(0. .7){if(!${*q=\$f[$y][$x]}){for(-1..1){c$_,-1if$y}c-1,0;c 1,0;for(- 1..1){c$_,1if$y<8}}}}print join"",@$_ for@f;{

Edition 2007-01-09 top secret / strictly confidential page 270 of 520 Perlgolf History

5.31. Linear Cellular Automata http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=31&season=0 The game started 2003-04-03 13:00:00 and ended 2003-04-08 20:00:00. Rules by terje. Tests by mtve.

5.31.1. Rules A biologist is experimenting with DNA modification of bacterial colonies being grown in a linear array of culture dishes. By changing the DNA, he is able to "program" the bacteria to respond to the population density of the neighboring dishes. Population is measured on a four point scale (from 0 to 3). The DNA information is represented as an array DNA, indexed from 0 to 9, of population density values and is interpreted as follows: • In any given culture dish, let K be the sum of that culture dish's density and the densities of the dish immediately to the left and the dish immediately to the right. Then, by the next day, that dish will have a population density of DNA[K]. • The dish at the far left of the line is considered to have a left neighbor with population density 0. • The dish at the far right of the line is considered to have a right neighbor with population density 0. Now, clearly, some DNA programs cause all the bacteria to die off (e.g., [0,0,0,0,0,0,0,0,0,0]). Others result in immediate population explosions (e.g., [3,3,3,3,3,3,3,3,3,3]). The biologist is interested in how some of the less obvious intermediate DNA programs might behave. Write a program to simulate the culture growth in a line of 39 dishes, assuming that dish 20 starts with a population density of 1 and all other dishes start with a population density of 0. The input (ARGV) will be 10 integer values 0 ≤ N ≤ 3, each matching /^[0-3]\z/) Your program should print the densities of the 39 dishes for each of the next 50 days. Each day's printout should occupy one line of 39 characters. Each dish is represented by a single character on that line. Zero population densities are to be printed as the character " ". Population density 1 will be printed as the character ".". Population density 2 will be printed as the character "x". Population density 3 will be printed as the character "W". So the output (STDOUT) should match /^([ .xW]{39}\n){50}\z/ Sample Input 0120133230 Sample Output . ... .x x...... x x. .x x. ...xxx xxx... .x .WW.x x.WW. x. . .xxW . Wxx. . Note: We show only the first ten lines of output (the total number of lines must be 50)

Edition 2007-01-09 top secret / strictly confidential page 271 of 520 Perlgolf History

5.31.2. Solutions 74, mtve $#:=19;s#.#$ARGV[(y/0-3/ .xW/?!print:$z)+(w&$')+($z=$&)]#gfor("@:1@: ")x50 74, Daniel -l $#:=19;s/^|./$ARGV[~$'?$&+(ww&$')%9:y!0-3! .xW!.print]/gfor("@:1@:")x50 75, ton (alternative) -l s!^|.!~$'?$ARGV[$&+(ww&$')%9]:y/0-3/ .xW/

Edition 2007-01-09 top secret / strictly confidential page 272 of 520 Perlgolf History

-l $p=print((' .xW'=~//g)[/./g])/s##$ARGV[$p+('?'&$')+($p=$&)]#gfor($_=0 x19 .1 .0 x19)x50 92, banshee -l $_='0 'x19;s//$'1 /;for$s(0..49){print+($",v46,x,W)[split];s!\d!$ARGV[$'+$&+reverse$`]!g} 92, k.c.ivey $;x=19;s//$;1$;/;s@.@$ARGV[$&+(w&$')+$~]*print$/^qw(* $ r ])[$~=$&]@ge,print$~=$/while--$=^9 93, Benoît Chauvet -l (my$r,@a)=map$ARGV[($z=$t)+($t=$r)+($r=$_)],@a,!print+($",'.',x,W)[@a]for(@a [19,38]=1)..50 94, Michael Robinson $x=$|x19;$x.="1$x ";$_=$x,y/0-9/ .xW/,$p=$x!~s!.!$ARGV[$p+($'&"\xFF")+($p=$&)]!g,print for 1..50 94, Shlomi Fish -l split//," .xW";$#s+=print@_[@s=map@s?$ARGV[$s[$_- 1]+$s[$_]+$s[$_+1]]:$_==19,0..38]for 0..49 99, aqumsieh $_=$"x19;s|$|1$_|;s/(?<=(.))?.(?=(.))?/print+($",'.',x,W)[$&];$ARGV[$1+$2+$&]/e g,print$/while--$=>9 104, Arkady -l ++$=[20];print(map{$@[$_]=$ARGV[$=[$_]+$=[$_-1]+$=[$_+1]];substr' .xW',$=[$_],1}1..39),@==@@for 1..50 109, Paul van Eldijk -l $_=$"x19;$_.='.'.$_;print,s!.!$ARGV[map{/\x18/g,(/N/g)x2,(/a/g)x3}$".$_^$`.6 66]!ge,y/0-3/ .xW/until$i++>49 116, Mercutio -l @_=map/19/&&1,0..38;map{print map{(split//," .xW")[$_]}@_;@_=map$ARGV[($_&&$_[$_-1])+$_[$_]+$_[$_+1]],0..38}1..50 116, Nicolas Mendoza split//," .xW";$p[20]=1;for(0..49){for(1..39){$q[$_]=$ARGV[$p[$_]+$p[$_- 1]+$p[$_+1]];print$_[$p[$_]]}print" ";@p=@q} 117, Nicolas Mendoza split//," .xW";$p[20]=1;for(0..49){for(1..39){$q[$_]=$ARGV[$p[$_]+$p[$_- 1]+$p[$_+1]];print$_[$p[$_]]}print"\n";@p=@q} 118, Nicolas Mendoza split//," .xW";$p[20]=1;for(0..49){for(1..39){$q[$_]=$ARGV[$p[$_]+$p[$_- 1]+$p[$_+1]];print$_[$p[$_]]}print"\n";@p=@q} 119, JLO

Edition 2007-01-09 top secret / strictly confidential page 273 of 520 Perlgolf History

-l $a=$%x19;$a.='1'.$a;for$i(1..50){$s=$%.($_=$a);$a=~s!.!$s=~s/(.)(.)(.?)/$2$3 /;$ARGV[$1+$2+$3]!eg;y/0123/ .xW/;print} 125, IainT -l $s=$"x19;$_="$s.$s";print,y/ .xW/0123/,@l=split(//," $_"),$i=1,s/./$ARGV[$l[$i-1]+$&+$l[++$i]]/eg,y/0123/ .xW/while$q++<50 129, Jurgen Pletinckx -l $i[19]=1;map{$#i=38;print map{substr' .xW',$_,1}@i;unshift@i,0;push@i,0;map{$i[$_]=$ARGV[$i[$_]+$i[$_+1]+$i[$_+2]] }0..38}1..50 147, NumberCruncher @i=1..39;$q=' .xW';@s=0 x41;$s[20]=1;map{$u='';map{$u.=substr$q,$s[$_],1}@i;print$u,"\n";map{$k[$_]= $ARGV[$s[$_-1]+$s[$_+1]+$s[$_]]}@i;@s=@k}1..50;

5.32. Motley boxes http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=32&season=0 The game started 2003-04-10 19:30:00 and ended 2003-04-14 20:00:00. Rules by ton. Tests by terje.

5.32.1. Rules Consider piles of boxes, at most 9 piles. Each pile has at least 1 box, at most 9 boxes. The boxes are in 3 different colors, red, green and blue. The bottom box in the leftmost pile is red. The next box both vertically and horizontally is green and the next one is blue, then repeat (red green blue etc). This gives a set of piles where the same colors are found on the top left to bottom right diagonal. The input (ARGV) is a list of the number of boxes in each pile (each matching /^[1-9]\z/). The total number of boxes are 4 ≤ boxes ≤ 81 The output (STDOUT) will be the number of red, green and blue boxes, separated with a single space and newline terminated (matching /^([1-9]\d?)( [1-9]\d?){2}\n\z/) Visualization of the boxes

Edition 2007-01-09 top secret / strictly confidential page 274 of 520 Perlgolf History

+-+ |R| +-+ +-+ +-+ |R| |B| +-+ +-+ +-+ +-+ +-+ |B| |G| |B| +-+ +-+ +-+ +-+ +-+ +-+ +-+ |G| |B| |R| |G| +-+ +-+ +-+ +-+ +-+ +-+ +-+ +-+ |R| |G| |B| |R| +-+ +-+ +-+ +-+ Sample Input 4253 Sample Output 545

5.32.2. Solutions 44, mtve map$a[$_%3]++,$^F..$_+$^F++for@ARGV;print"@a " 44, Juho Snellman map$F[$_%3]++,$^F..$_+$^F++for@ARGV;print"@F " 44, ton map$a[$_%3]++,$^F..$_+$^F++for@ARGV;print"@a " 44, m.wrenn map$c[$_%3]++,$^F..$_+$^F++for@ARGV;print"@c " 44, k.c.ivey $c[$_%3]+=$_<$ARGV[chop]for 0..89;print"@c " 44, Daniel map$a[$_%3]++,$^F..$_+$^F++for@ARGV;print"@a " 44, tybalt89 map++$a[$_%3],$^F..$_+$^F++for@ARGV;print"@a " 44, kcwu map$a[$_%3]++,$^F..$_+$^F++for@ARGV;print"@a " 44, Filip Gralinski

Edition 2007-01-09 top secret / strictly confidential page 275 of 520 Perlgolf History

$t[$_%3]+=@ARGV[/./g]>$`for 0..90;print"@t " 45, terje map{$r[$_++%3]++for($i++)x$_}@ARGV;print"@r " 45, Andreas map$c[$_++%3]++,($s++)x$_ for@ARGV;print"@c " 45, Daniel (alternative) map$a[~$_%3]++,$@-$_..--$@for@ARGV;print"@a " 45, m.wrenn (alternative) map$c[$_%3]++,@_..$_+$#_++for@ARGV;print"@c " 45, Jasper map{$o[$_++%3]++for($a++)x$_}@ARGV;print"@o " 45, andys map$a[$_++%3]++,($a++)x$_ for@ARGV;print"@a " 45, kcwu (alternative) map$a[~$_%3]++,$,---$_..$,for@ARGV;print"@a " 45, RobTM map$a[$_%3]++,$^F..$_+$^F++for@ARGV;print"@a\n" 46, Peter Makholm map++$_[--$_%3],$i..$_+$i++for@ARGV;print"@_ " 46, dkr map$a[$_%3]++,$;++..$_-2+$;for@ARGV;print"@a " 46, michalj map$x[$_%3]++,$i++..$i+$_-2for@ARGV;print"@x " 46, ton (alternative) eval'$a[$_++%3]++;'x shift for 0..9;print"@a " 46, michalj (alternative) $x[$_%3]+=$ARGV[$_%10]-->0for 0..89;print"@x " 46, Nicolas Mendoza

Edition 2007-01-09 top secret / strictly confidential page 276 of 520 Perlgolf History

map$_[--$_%3]++,$...$_+$.++for@ARGV;print"@_ " 46, p.kailasa map{eval'$_[$_++%3]++;'x shift}0..8;print"@_ " 46, Michael Rybakin map$n[--$_%3]++,$r..$_+$r++for@ARGV;print"@n " 47, Andreas (alternative) map$c[$i++%3]+=/-/,-$_..$_*2for@ARGV;print"@c " 47, okrach map$c[--$_%3]++,$l..$_+$l++for@ARGV;print"@c\n" 47, Chris Dolan map($c[($#ARGV+$_)%3]++,1..pop)?do$0:print"@c " 47, Mercutio map$_[$_%3]++,$-++..$_-2+$-for@ARGV;print"@_$/" 47, Arkady map++$a[$_%3],$b++..$_+$b-2for@ARGV;print"@a\n" 49, gibbering $c=$i++,map$a[$c++%3]++,1..$_ for@ARGV;print"@a " 50, JLO -l $ARGV[$_%10]-->0&&$a[$_%3]++for 0..99;print"@a" 50, aqumsieh map$_[($#ARGV+$_)%3]++,1..$=while$==pop;print"@_ " 50, Honza Pazdziora map{$z[($j+$_)%3]++while$_--;$j++}@ARGV;print"@z " 51, id5 for(@ARGV){$_[($i+$_)%3]++while$_--;$i++}print"@_ " 53, jas eval'$c[--$_%3]++for'.'$i..$i+++shift,'x9;print"@c\n" 53, Paul van Eldijk map{map$_[($_+$i)%3]++,0..$_-1;$i++}@ARGV;print"@_$/" 54, shr for(@ARGV){$a[($k+$_-1)%3]++for 1..$_;$k++}print"@a$/" 56, Vanish

Edition 2007-01-09 top secret / strictly confidential page 277 of 520 Perlgolf History

for$j(0..8){$c[($_+$j)%3]++for(0..(shift)-1)}print"@c\n" 57, Jurgen Pletinckx -l map{$c++;map{$o[($_+$c-2)%3]++;}1..$_}@ARGV;print"@o"; 68, vgod $s.=substr"012"x4,$c++%3,$_ for@ARGV;$h[$_]++for$s=~/./g;print"@h$/" 70, ErikB @x=split"",'012'x6;map{$h[$x[--$_]]++while$_;shift@x}@ARGV;print"@h$/" 70, greg map{$_%3>1?$a++:$_%3?$c++:$b++for($o..$_+$o++)}@ARGV;print"$c $a $b\n" 111, NumberCruncher @k=0..2;map{$n=int$_/3;$r=$_%3;map{$_+=$n+($r>0);$r-- }@a[@k];$i++;push@k,shift@k}@ARGV;print join(" ",@a),"\n"; 118, IainT -l $_=(123)x3; for$i(@ARGV){ ($q)=/(.{$i})/;/./;$_=$'.$&; for(1..3){ $r{$_}++while$q=~/$_/g; } } print join$",@r{1..3}

5.33. Hamming sequence http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=33&season=0 The game started 2003-04-15 19:30:00 and ended 2003-04-18 20:00:00. Rules and tests by ton.

5.33.1. Rules The Hamming sequence is the ascending sequence of numbers whose prime factors are only 2, 3 and 5. The first few numbers are 1 2=2 3=3 4 = 2*2 5=5 6 = 2*3 8 = 2*2*2 9 = 3*3 10 = 2*5 12 = 2*2*3 There is no input, on STDOUT you should write the first 4096 hamming numbers, each followed by a newline. So the output matches /^(\d+\n){4096}\z/ and will actually look like this:

Edition 2007-01-09 top secret / strictly confidential page 278 of 520 Perlgolf History

1 2 3 4 5 6 8 9 10 12 . . . 5932617187500 5944066965504 5950778711040 5971968000000 5978711250000 6000000000000 6025163444928 Some hints If you look at the last value, 6025163444928, it should be pretty obvious that the naive method (checking each number and looking if you can build it from only the factors 2, 3 and 5) is pretty hopeless. You have to use the fact that each number (except 1) is a previous entry in the sequence times 2, 3 or 5. A functional method to generate the hamming sequence is demonstrated in one of Jason Dominus' articles1.

5.33.2. Solutions 59, Peter Makholm (rejected) -l @1=1;@{$_}and@{$_*2}=@{$_*3}=@{$_*5}=print for 1..602e10 63, Daniel (post-mortem) $#:=7x5,map$:[2643*log]=$_.$/,map$^C%6*$_||1,@:while--$^C;print@: 64, mtve $#:=7x5,map{$:[2643*log]=$_.$/for$^C%6*$_||//}@:while--$^C;print@: 66, Daniel -l ($n,@s)=sort{$a>$b}grep$_>$n,@s,map$_*$n,print..5for($n=1)x4096 66, Daniel (post-mortem) -l ($n,@s)=sort{$a>$b}grep$_>$n,@s,map$_*$n,print..5for($n=1)x4096 67, Peter Makholm (post-mortem) -l print+($n)=@h=sort{$a>$b}grep$n<$_,1,@h,map$n*$_,2..5for 2..4097 68, Juho Snellman

1 http://perl.plover.com/Stream/stream.html

Edition 2007-01-09 top secret / strictly confidential page 279 of 520 Perlgolf History

-l map$a{$a*$_}=9e12,2..6-print$a=(1,sort{$a<=>$b}%a)[$_]for 0..4095 68, ton @b=sort{$a{$_*$a.$/}=$a<=>$b}1,keys%a,0for(1..5)x27;print@b[2..4097] 69, Andreas -l print+($n)=@h=sort{$a<=>$b}grep$_>$n,1,@h,map$_*$n,2..5for 1..4096 69, Peter Makholm -l print(($n)=@h=sort{$a>$b}grep$n<$_,1,@h,$n*2,$n*3,$n*5)for 2..4097 69, banshee (post-mortem) -l map\$s{$s*$_},2..4+print$s=(sort{$a<=>$b}keys%s)[$_]||1for-1..4094 70, banshee -l map\$s{$s*$_},2,3,4+print$s=(sort{$a<=>$b}keys%s)[$_]||1for-1..4094 70, terje printf"%s "x4096,sort{$a<=>$b}map/(..)(..)/*2**$1*3**$2*5**$',$^Cx6..$~ 70, ErikB map{print$x=(1,sort{$a<=>$b}keys%h)[$_],$/;map$h{$x*$_}++,2..5}0..4095 71, m.wrenn map$a{@a%6*$_.$/}=1e14,@a=(sort{$a<=>$b}%a)[1..$_],1for 1..4096;print@a 72, m.wrenn (alternative) map$a{$k%6*$_.$/}=1e14,@a=(sort{$a<=>$b}%a)[1..++$k],1for A..FAN;print@a 72, m.wrenn (rejected) map$@{$k%6*$_.$/}=1e14,1,@a=sort{$a<=>$b}%@while++$k<4097;print@a[1..$k] 72, Juho Snellman (alternative) -l map$a{sprintf"%32s",$a*$_}=a,2..6-print$a=(1,sort%a)[$_]+0for!1..4095 74, shr (post-mortem) -l map{print$;=delete$_{sort{$a<=>$b}%_}||1;$_{$_*$;}=$_*$;for2..5}1..4096 74, tybalt89 \@a{map!/e/*$^H%6*$_.$/,%a,1}while--$^H;print+(sort{$a<=>$b}%a)[7356..11451] 75, Jasper -l @h{1,map$'%6*$_,%h}=//for 1..153;print for(sort{$a<=>$b}keys%h)[1..4096] 76, okrach (post-mortem) -l print@#[$_]=sort{$a<=>$b}grep$_>$#[-1],1,map{2*$_,3*$_,5*$_}@#for 0..4095 77, okrach -l print@x[$_]=sort{$a<=>$b}grep$_>$x[-1],1,map{2*$_,3*$_,5*$_}@x for 0..4095 78, Jacob Cohen

Edition 2007-01-09 top secret / strictly confidential page 280 of 520 Perlgolf History

print+(sort{$a<=>$b}map{5**($_%19)*3**($_%27)*2**($_%43).$/}0..22058)[0..4095] 78, k.c.ivey -l print+($@[@@])=sort{$a<=>$b}grep$_>$@[-1],1,map{2*$_,3*$_,5*$_}@@for a..fan 78, eugene -l {$b{$_=pop(a)||1}++or@a=sort{$b<=>$a}$_*2,@a,$_*3,$_*5*print;$_>6e12||redo} 81, kcwu -l @a{1,map{$_*2,$_*3,$_*5}%a}=0for 0..43;print for(sort{$a<=>$b}keys%a)[1..4096] 81, Peter Haworth -l map@4{$_*2,$_*3,$_*5}=1,%4for%4=(1)x43;print for(sort{$a<=>$b}keys%4)[1..4096] 81, Peter Haworth (alternative) -l map@4{$_*2,$_*3,$_*5}=1,@h=sort{$a<=>$b}1,keys%4for 1..44;print for@h[0..4095] 84, Jason Parker-Burlingham -l %h=1;@h{map{$_*2,$_*3,$_*5}%h}=1for 0..41;print for(sort{$a<=>$b}keys%h)[1..4096] 86, shr map{@_=sort{$b<=>$a}%_;delete$_{$;=pop@_||1};print"$; ";map$_{$_*$;}=1e19,2..5}1..4096 86, VesaK -l %a=1;map{print$i=(sort{$a<=>$b}keys%a)[0];delete$a{$i};map$a{$_*$i}++,2,3,5} 1..4096 88, Jurgen Pletinckx (rejected) -l for(@a=1;@a<4096;$k++){push@a,$k if grep{$_*2==$k||$_*3==$k||$_*5==$k}@a}map print,@a 88, Frantisek Darena -l %1=1;map{@1{2*$_,3*$_,5*$_}++}keys%1for 1..43;print for(sort{$a<=>$b}keys%1)[0..4095] 89, Mercutio $h{1}=1;map{delete$h{$n=(sort{$a<=>$b}keys%h)[0]};map$h{$n*$_}=1,2,3,5;print$n. $/}1..4096 90, gibbering -l map{for$k(%a){map$a{$k*$_}=1,2,3,5}}$a{1}++..44;map$i++<4**6&&print,sort{$a< =>$b}keys%a 92, id5 $a{1}=1;map@a{$_*2,$_*3,$_*5}=1,keys%a for 1..45;print"$_ "for(sort{$a<=>$b}keys%a)[0..4095] 93, p.kailasa

Edition 2007-01-09 top secret / strictly confidential page 281 of 520 Perlgolf History

-l $"=",",@_=0..42;print for(sort{$a<=>$b}map{y/./*/;eval}<5..{@_}.3..{@_}.2..{@_}>)[0..4095] 95, Nicolas Mendoza -l map{/.(..)(..)/;push@,,$;if($;=2**$'*3**$2*5**$1)<603E10}1E6..12E5;map print,sort{$a<=>$b}@, 95, Chris Dolan -l @h=1;for$i(0..5){for$n(2,3,5){push@h,map$_*$n**2**$i,@h}}print for(sort{$a<=>$b}@h)[0..4095] 98, Jurgen Pletinckx -l $a{1}++;for(1..42){for$m(2..5){map$a{$_*$m}++,keys%a}}map print,(sort{$a<=>$b}keys%a)[0..4095]; 106, dkr -l use bignum;@@=(1);@@>1e5||$h{$_}++||push@@,$_*2,$_*3,5*$_ for@@;print for(sort{$a<=>$b}keys%h)[0..4095] 112, Jurgen Pletinckx (alternative) -l $a{1}++;for(1..42){for$m(2..5){map{$a{$_*$m}++if$_*$m<2**43}keys%a}}map print,(sort{$a<=>$b}keys%a)[0..4095];

5.34. Vigenere Cipher http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=34&season=0 The game started 2003-04-22 10:00:00 and ended 2003-04-25 20:00:00. Rules by Mercutio. Tests by terje.

5.34.1. Rules The Vigenere Cipher, proposed by Blaise de Vigenere from the court of Henry III of France in the sixteenth century, is a polyalphabetic substitution based on the following tableau:

Edition 2007-01-09 top secret / strictly confidential page 282 of 520 Perlgolf History

ABCDEFGHIJKLMNOPQRSTUVWXYZ

A ABCDEFGHIJKLMNOPQRSTUVWXYZ B BCDEFGHIJKLMNOPQRSTUVWXYZA C CDEFGHIJKLMNOPQRSTUVWXYZAB D DEFGHIJKLMNOPQRSTUVWXYZABC E EFGHIJKLMNOPQRSTUVWXYZABCD F FGHIJKLMNOPQRSTUVWXYZABCDE G GHIJKLMNOPQRSTUVWXYZABCDEF H HIJKLMNOPQRSTUVWXYZABCDEFG I IJKLMNOPQRSTUVWXYZABCDEFGH J JKLMNOPQRSTUVWXYZABCDEFGHI K KLMNOPQRSTUVWXYZABCDEFGHIJ L LMNOPQRSTUVWXYZABCDEFGHIJK M MNOPQRSTUVWXYZABCDEFGHIJKL N NOPQRSTUVWXYZABCDEFGHIJKLM O OPQRSTUVWXYZABCDEFGHIJKLMN P PQRSTUVWXYZABCDEFGHIJKLMNO Q QRSTUVWXYZABCDEFGHIJKLMNOP R RSTUVWXYZABCDEFGHIJKLMNOPQ S STUVWXYZABCDEFGHIJKLMNOPQR T TUVWXYZABCDEFGHIJKLMNOPQRS U UVWXYZABCDEFGHIJKLMNOPQRST V VWXYZABCDEFGHIJKLMNOPQRSTU W WXYZABCDEFGHIJKLMNOPQRSTUV X XYZABCDEFGHIJKLMNOPQRSTUVW Y YZABCDEFGHIJKLMNOPQRSTUVWX Z ZABCDEFGHIJKLMNOPQRSTUVWXY Note that each row of the table corresponds to a Caesar Cipher. The first row is a shift of 0; the second is a shift of 1; and the last is a shift of 25. The Vigenere cipher uses this table together with a keyword to encipher a message. For example, suppose we wish to encipher the plaintext message: TO BE OR NOT TO BE THAT IS THE QUESTION using the keyword RELATIONS. We begin by writing the keyword, repeated as many times as necessary, above the plaintext message. To derive the ciphertext using the tableau, for each letter in the plaintext, one finds the intersection of the row given by the corresponding keyword letter and the column given by the plaintext letter itself to pick out the ciphertext letter. Keyword: RELATIONSRELATIONSRELATIONSREL Plaintext: TOBEORNOTTOBETHATISTHEQUESTION Ciphertext: KSMEHZBBLKSMEMPOGAJXSEJCSFLZSY You will get a plaintext message on STDIN and a keyword as a commandline argument. Your task is to encipher the message using the keyword. The only characters that are to be encoded are the lower and uppercase letters, all other characters are to be ignored. The lowercase letters will have to be converted to uppercase in order to find them in the tableau. Input on the command line will be the key in uppercase, matching /^[A-Z]{1,20}\z/ Input on standard input will be the plaintext to be enciphered, matching /^[ -~]{1,99}\n\z/ Output should match /^[A-Z]{0,99}\n\z/ Sample input on commandline CHOCOLATE Sample input on STDIN

Edition 2007-01-09 top secret / strictly confidential page 283 of 520 Perlgolf History

The way to a man's heart is through the left ventricle. Sample output VOSYOJTHEOHBUVPAKXKZHJFZUZLVOSNSQTOIPAFKQWE

5.34.2. Solutions 62, mtve (post-mortem) -l $k=pop;print map+("$'$k"=~//,$&..Z,A..Z)[31&ord],<>=~/\pL/g 62, ton (post-mortem) -l $k=pop;print map+("$'$k"=~//,$&..Z,A..Z)[31&ord],<>=~/\pL/g 63, mtve $a=pop;$_=uc<>;"$'$a"=~//,eval"y/A-Z/$&-ZA-Z/;print"for/\pL| /g 64, k.c.ivey -l $k=(pop)x$^H;print map+($k!~//g,$&..Z,A..Z)[31&ord],<>=~/\pL/g 64, andys $a=(pop)x111;$a=~s//"y!A-Z!$&-ZA-Z!,print"/eefor(uc<>)=~/\pL| /g 64, tybalt89 -l $^=pop;print map{(uc..Z,A..Z)[-65+vec$^x99,$i++,8]}<>=~/\pL/g 64, Jasper (rejected) -l $k=(pop)x99;print+map{$k=~//;(uc..Z,@a=A..$&)[$#a]}<>=~/\pL/g 65, Juho Snellman $n=(pop)x99;$_=uc<>;$n=~//g,eval"y/A-Z/$&-ZA-Z/;print"for/\pL| /g 65, Jasper (rejected) -l @k=pop=~/\pL/g;print+map{(uc..Z,@a=A..$k[$i++%@k])[$#a]}<>=~// 66, eugene -l $a=pop()x99;print map{(A..Z,A..uc)[$a!~//g-92+ord$&]}<>=~/\pL/g 66, k.c.ivey (alternative) -pl INIT{$k=(pop)x$^H}s@\PL*(.)?@($k!~/./g,$&..Z,A..Z)[31&ord$1]@ge 66, Daniel -l $a=(pop)x99;print map{$a=~//g;(A,$&..Z,A..Z)[31&ord]}<>=~/\pL/g 66, Jasper -l $k=(pop)x99;print+map{$k=~s///;(uc..Z,@a=A..$&)[$#a]}<>=~/\pL/g 66, Michael Rybakin $~=pop;print+((A..Z)x7)[map{ord(uc)+vec$~x99,$i++,8}<>=~/\pL/g],$/ 66, Alma Media Golf Team

Edition 2007-01-09 top secret / strictly confidential page 284 of 520 Perlgolf History

$;=pop()x99;$;=~//g,eval"y/A-Z/$&-ZA-Z/;print"for(uc<>)=~/[A-Z ]/g 68, p.kailasa -l split'',pop;print+map{(uc..Z,A..Z)[-65+ord$_[$?++%@_]]}<>=~/\pL/g 70, Szeryf -l split//,pop;print map{chr 65+(ord(uc)+ord$_[$i++%@_])%26}<>=~/\pL/g 70, terje -l split//,pop;print map{((A..Z)x9)[ord(uc)+ord$_[$i++%@_]]}<>=~/\pL/g 72, eugene (alternative) -l $a=pop;print map{(uc..Z,A..Z)[($a=~//g||$a=~//g)-66+ord$&]}<>=~/\pL/g 72, terje (alternative) -l split//,pop;print map{for$z(B..A.$_[$i++%@_]){++$_}uc chop}<>=~/\pL/g 72, Peter Haworth -l split//,pop;print map+($_[$i++%@_]..Z,A..Z)[ord(uc)-65],<>=~/[A-Z]/gi 74, ErikB -l split//,pop;print map{(A..Z)[ord($_[$:++%@_])-156+ord]}(uc<>)=~/[A-Z]/g 74, kcwu -l $k=(pop)x99;print map chr$k=~/\G./g+64+(ord(uc)+ord$&)%26,<>=~/[A-Z]/ig 74, Chris Dolan -l split//,pop;print map{((A..Z)x9)[ord($_[$i++%@_])+ord uc]}<>=~/[A-Z]/ig 74, clkao -l @a=pop=~/./g;print map[$_..Z,$a[$!++%@a]..Z,A..Z]->[26],<>=~/[^\W\d_]/g 74, Michael Robinson -pl INIT{@k=pop=~/./g}s/\PL//g;s/./(A..Z)[ord(uc$&)-156+ord$k[$i++%@k]]/eg 77, m.wrenn -lp INIT{$~=pop}s#.#$_=uc$&;((A..Z)x9)[ord(substr$~x99,$i++)+ord]if/[A-Z]/#ge 77, dkr -l $;=pop()x99;$_=uc<>;print@{[(A..Z)x7]}[map{$;=~s/.//;ord($&)+ord}/[A-Z]/g] 78, Andreas -p INIT{$:=(pop)x99}s/([a-z])|./chr((ord(uc$1)+ord$:)%26+65*$:=~s\.\\)if$1/egi 79, Frantisek Darena -lp INIT{@p=pop=~/./g}$_=uc;y/A-Z//cd;s/./((A..Z)x7)[ord($p[$i++%@p])+ord$&]/eg 79, srushe -lp INIT{@k=pop=~/./g}s/[^A-Z]//ig;s/./chr 65+(ord($k[$c++%@k])+ord uc$&)%26/ge 81, id5 $b=(pop)x99;print chr(((95&ord)+ord$b)%26+64+$b=~s/.//)for<>=~/[A-Za- z]/g;print$/ 82, Mercutio

Edition 2007-01-09 top secret / strictly confidential page 285 of 520 Perlgolf History

-lp INIT{$:=reverse(pop)x99}s|[^a-z]||ig;s|(.)|chr 65+(ord(uc$1)+ord chop$:)%26|eg 82, shr -l split//,(pop)x99;print map{chr((ord()+ord$_[$i++])%26+65)if/[A- Z]/}split//,uc<> 83, IainT -lp INIT{@k=split//,(pop)x99}y/A-Za-z//dc,s/./chr(65+(ord(uc$&)+ord shift@k)%26)/eg 83, Honza Pazdziora -pl BEGIN{$*=pop}y!A-Za-z!!dc;s!.!((A..Z)x2)[ord(uc$&)-130+ord substr$*x99,$i++]!ge 84, jinx (alternative) -lp INIT{@a=unpack"C*",pop}s/([a-z])/chr 65+(ord(uc$1)+$a[$c++%@a])%26/ieg;y/A- Z//cd 85, jinx -l @}=unpack"C*",pop;print map{chr 65+(ord()+$}[$@++%@}])%26}grep/[A- Z]/,split//,uc<> 87, Hirogen2 -lp INIT{@@=pop=~/(.)/g}y/A-Za-z//cd;s/(.)/chr 65+(ord(uc$1)- 130+ord$@[pos()%@@])%26/eg 87, Hirogen2 (alternative) -lp INIT{@@=split//,pop}s/[^A-Z]//gi;s/(.)/chr 65+(ord(uc$1)- 130+ord$@[pos()%@@])%26/eg 87, Jonathan Stimmel -l @k=(unpack("c*",pop),$_=uc<>);y/A- Z//cd;s/./chr(65+($k[$c++%$#k]+ord$&)%26)/eg;print 97, BlueBoar -l @a=unpack"C*",(pop)x99;$_=uc(<>);y/A-Z//cd;print map chr(($_- 130+shift@a)%26+65),unpack"C*",$_ 97, beowulf -pl INIT{@a=map{ord}pop=~/./g,1}s/[^a-z]//ig;s/[a- z]/chr((ord(uc$&)+$a[pos()%$#a]-130)%26+65)/egi 106, Jurgen Pletinckx -l split//,$ARGV[0]x99;$_=uc;y/A-Z//cd;print map{$_=ord()+ord(shift@_)- 65;$_-=26if$_>90;chr}split//

5.35. Musical Notes http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=35&season=0 The game started 2003-04-28 20:00:00 and ended 2003-05-02 20:00:00. Rules by terje. Tests by mtve. Idea by Luke Palmer.

Edition 2007-01-09 top secret / strictly confidential page 286 of 520 Perlgolf History

5.35.1. Rules First some background on musical notation: Musical notes are given characters as names: C, D, E, F, G, A, B for all the "white" notes. The black notes came later in history and their names are denoted as half a note up "#" or half a note down "b". Notice, between E-F and B-C are no half notes. C# is called C-sharp, Bb is called B-flat and so on.

The above piano roll introduces the concept of octaves. Each set of notes C through B is called an octave and is indicated by appending its number to the note. One complete octave: 1 2 3 4 56 7 8 9 10 11 12 C C# or Db D D# or Eb EFF# or Gb G G# or Ab A A# or Bb B The distance between two adjacent notes is called a half step. Your task is given two notes n1 and n2 as commandline arguments, output the number of half steps between the notes. The first note will always be lower than the second (i.e. you'll never get F3 D3, or D#5 D#4) Your input (ARGV) is two notes (each matching /^[A-G][b#]?[1-8]\z/) Output (STDOUT) should be a the number (1 ≤ s ≤ 95) of half steps (matching /^[1-9]\d?\n\z/) Sample Input F3 Bb3 Sample Output 5

5.35.2. Solutions 53, mtve $\=(/./+ord)*1.6%12-$\+/#/-/b/+12*$'.$/for@ARGV;print 53, ton $\=1.6*(/./+ord)%12+/#/-/b/+12*$'-$\.$/for@ARGV;print 54, terje $\=/#/-$\+ord()/.511%13-/b/+12*chop().$/for@ARGV;print 54, g.allen (post-mortem) $\=ord()*13/8%12-(s/\B//g-12*chop)-$\.$/for@ARGV;print 54, tybalt89 $\=(12*chop)+(13/8*ord)%12+/#/-/b/-$\.$/for@ARGV;print 54, tybalt89 (alternative) $\=/#/-/b/-$\-7170/ord()%12+12*chop().$/for@ARGV;print 55, eugene

Edition 2007-01-09 top secret / strictly confidential page 287 of 520 Perlgolf History

-l map$a=/#/-/b/-$a+ord()*13/8%12+12*chop,@ARGV;print$a 55, Jasper -l $a=ord()/.615%12-$a+/#/-/b/+12*chop for@ARGV;print$a 56, Daniel $\=/#/-y/B-b/D9;=>@/+12*(chop)-$\+(ord).$/for@ARGV;print 56, Daniel (alternative) $\=/#/-y/FGABb/F-I/+2*(6*(chop)+ord)-$\.$/for@ARGV;print 57, g.allen (post-mortem) $\=/#/-y/A-b/JLACEFH/+ord()+12*chop()-$\.$/for@ARGV;print 57, Jeff Moore -l map$b=/#/-y/B-b/D9;=>@/+(ord)-$b+12*chop,@ARGV;print$b 57, Alma Media Golf Team -l map$a=/#/-y/B-b/D9;=>@/-$a+(12*chop)+ord,@ARGV;print$a 58, kcwu -l $a=(3+ord)%7*2+y/CDE#//-$a-/b/+12*chop for@ARGV;print$a 58, Andreas $d=/#/-$d-y/FGABb/F-I/+(2*ord)+12*chop for@ARGV;print$d,$/ 58, id5 $a=y/A-F#/HJ?ACD/-$a-/b/+12*(chop)+ord for@ARGV;print$a.$/ 58, k.c.ivey -l $t=y/#CDE//-$t-/b/+(3+ord)%7*2+12*chop for@ARGV;print$t 58, g.allen $\=(/#/-y/A-b/JLACEFH/+12*/\d/*$&-$\+ord).$/for@ARGV;print 58, shr map$i=(3+ord)%7*2+y/CDE#//-/b/-$i+12*chop,@ARGV;print$i,$/ 59, p.kailasa (post-mortem) $\=2*(y/B#//+6*chop)-y/C-Gb#/86431/d-$_-$\.$/for@ARGV;print 59, p.kailasa (rejected) $\=2*/B|#/-y/C-Gb#/86431/d+12*chop()-$_-$\.$/for@ARGV;print 60, p.kailasa $\=y/AC-G#/902457/d-/b/+12*(/B/+chop)+$_-$\.$/for@ARGV;print 60, michalj -l $x=/\d/*12*$&-$x+(3+ord)%7*2+y/CDE#//-/b/for@ARGV;print$x 62, m.wrenn -l $~=/#/+13*/A|B/-$~-(y/bFG//-12*chop)+2*ord for@ARGV;print$~ 63, Peter Haworth

Edition 2007-01-09 top secret / strictly confidential page 288 of 520 Perlgolf History

-l y/AB/HI/,$x=chop()*12+/#/-y/bF-I//-$x+2*ord for@ARGV;print$x 63, k.c.ivey (alternative) -l y/B-Gb/C13568!/,$t=(12*chop)-$t-/!/+/#/+hex for@ARGV;print$t 63, Chris Dolan -l y/B-Gb/C13568z/,$x=chop()*12-$x-/z/+/#/+hex for@ARGV;print$x 63, Shlomi Fish -l map{y/AB/HI/;$t=(12*chop)-$t+/#/-y/F-b//+2*ord}@ARGV;print$t 65, ypcat $a=/\d/+$&*12-$a+/#/-/b/+index+CCDDEFFGGAAB,$`for@ARGV;print$a,$/ 66, srushe -l $z=/\d/+$&*12-(2,4,5,7,9,-2)[71-ord]-$z+/#/-/b/for@ARGV;print$z 68, m.wrenn (alternative) -l sub k{$_=pop@ARGV;/#/+13*/A|B/-(y/bFG//-12*chop)+2*ord}print&k-&k 71, Michael Robinson -l $@+=/ /?-$@*2:$_*12||index"C#D EF G A B",$_ for"@ARGV"=~/./g;print$@ 73, manzo ($a,$b)=map{y/AB/HI/;2*ord()-(ord>69)+/#/-/b/+12*chop}@ARGV;print$b-$a.$/ 76, mhsin -l $a=-$a- y/b#A-G1-8/\0\2JLACEFH%1=IUamy/,s/./$a+=ord$&/eg for@ARGV;print$a 82, Honza Pazdziora -l s!\d!+12*$&!,y!D-GA!24579!,s!B!11!,s!#!+1!,s!b!-1!,$x=-$x+eval for@ARGV;print$x 82, gugod -l s/\d/+12*$&/,s/#/+1/,s/b/-1/,y/AD-G/92457/,s/B/11/,$t=-$t+eval for@ARGV;print$t 94, IainT -l $_="$ARGV[1]-($ARGV[0])";s/\d/+12*$&/g,y/A-G/9X02457/,s/#/+1/g,s/b/- 1/g,s/X/11/g;print eval 99, Hirogen2 /(.)(\D?)/,$_=$'*12+${{B,11,split//,D2E4F5G7A9}}{$1}+($2?$2eq"b"?- 1:1:0)for@ARGV;print pop()-pop,$/ 100, m.thelen -l $t+=(-1)**$;++*(s/b//- s/#//)for($_,$~)=@ARGV;$t+=y/A-G/B-GA/+!/F/- (/C/&&!!$_++)until/$~/;print$t 141, Mercutio -l $b={b,1,"#",$c=-1};map$b{$_}=$c+=2- (/F/),C..G,A,B;$_="@ARGV";s/(.)(b|#)?(.).(.)(b|#)?(.)/print$b{$4}- $b{$1}+12*($6-$3)+$b->{$2}-$b->{$5}/e

Edition 2007-01-09 top secret / strictly confidential page 289 of 520 Perlgolf History

5.36. Strange Numbers http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=36&season=0 The game started 2003-05-08 20:00:00 and ended 2003-05-09 20:00:00. Rules and tests by terje. Idea by nicomen.

5.36.1. Rules While searching for yet another old forgotten civilization the archaeologists have found some old writings. After a while they realized that the writings are actually numbers. The ancient civilization used only sequences of zeroes and ones (bits) to represent the numbers, but it was not the ordinary binary system we use today. The ancient number system works as follows: Zero is encoded as "0". To write the number (N+1) take the sequence for the number N and change the least significant bit (1 to 0 and vice versa) such that the sequence produced does not represent any number less than N. In case no such bit exists prepend "1" to the sequence. N+1 will only differ from N by one bit. The representation of some numbers: 0: 0 1: 1 2: 11 3: 10 4: 110 5: 111 6: 101 15: 1000 16: 11000 Your task is to help the archaeologists to convert decimal numbers to this ancient system Input The input is an integer (0 ≤ N ≤ 9999) as a commandline argument (matching /^(?:0|[1- 9]\d{0,3})\z/). Output Your output (STDOUT) should be the strange number version of your input value (matching /^(?:0|1[01]{0,13})\n\z/). Sample Input 6 Sample Output 101

5.36.2. Solutions 25, michalj printf"%b ","@ARGV"/2^pop 25, Jeff Moore

Edition 2007-01-09 top secret / strictly confidential page 290 of 520 Perlgolf History

printf"%b ",($a=pop)^$a/2 25, tybalt89 printf'%b ',"@ARGV"/2^pop 25, Daniel printf"%b ",($a=pop)^$a/2 25, andys printf"%b ",($_=pop)^$_/2 25, ton printf"%b ",($_=pop)^$_/2 25, Michael Rybakin printf"%b ",($a=pop)^$a/2 25, anfi printf'%b ',($_=pop)^$_/2 25, Wesley Darlington printf"%b ",($n=pop)^$n/2 25, id5 printf"%b ",($_=pop)^$_/2 25, shr printf"%b ",($_=pop)^$_/2 25, Juho Snellman printf"%b ",($_=pop)^$_/2 25, kcwu printf"%b ",($n=pop)^$n/2 25, Shlomi Fish printf"%b ",($_=pop)^$_/2 25, terje printf"%b ",($w=pop)^$w/2 25, VesaK

Edition 2007-01-09 top secret / strictly confidential page 291 of 520 Perlgolf History

printf"%b ",($_=pop)^$_/2 25, RobTM printf"%b ",($i=pop)/2^$i 25, Jasper printf"%b ",($_=pop)^$_/2 25, Andreas printf"%b ","@ARGV"/2^pop 25, Peter Haworth printf'%b ',$x^($x=pop)/2 28, Jacob Cohen -l $_=pop;printf"%b",$_^$_/2

Edition 2007-01-09 top secret / strictly confidential page 292 of 520 Perlgolf History

6. Games - Terje’s PGAS season 1 6.1. Candy bags http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=37&season=1 The game started 2003-05-20 18:30:00 and ended 2003-05-24 19:00:00. Rules and tests by terje.

6.1.1. Rules Little Michael loves candies. Most of all, he likes chocolate, strawberry and banana flavored ones. No wonder that he has candy bags everywhere - there are at least four bags on his table, one or two in the pockets of his jeans, and one under his bed (just in case). Each bag contains some candies of all three flavors. Whenever he wants to eat a candy, he finds the nearest bag (which is usually is not very far because he has really A LOT of them) and eats the candy he wants. Yesterday, he wanted a strawberry one, so he opened one of his bags and... It is almost impossible to describe how great his disappointment was when he found out that there were no strawberry candies left in that bag. To make the matters worse, there were also none in the second bag he found. He was sure that he had lots of strawberry candies left, but he didn't know in which bags they were. Therefore, he decided to reorganize his candies, and keep the candies of the three different flavors in three distinct bags. He brought all his bags into the center of his room and realized, that there are really an awful lot of them. Michael has N bags full of candies. He knows the number of candies of each flavor in each bag. He wants to put all chocolate ones into one bag, all strawberry ones into another bag and all banana ones into yet another bag. He has to move the candies one-by-one, because he always has to look at it to determine its flavor. Moving one candy from one bag into another takes 1 second. Your task is to select the bag for each flavor, so that the total time required for Michael to move all the candies into their bags would be minimal. Input The input (STDIN) consists of 3 ≤ N ≤ 99 lines with 3 space separated numbers on each line (matching /^(([1-9]\d? ){2}[1-9]\d?\n){3,99}\z/) The numbers C, S, B are the numbers of chocolate, strawberry and banana candies in that bag. The bags are numbered from 0 to N-1 in the order in which they appear in the input. Output Output (STDOUT) should be 3 space separated numbers (matching /^([1-9]\d? ){2}[1- 9]\d?\n\z/), that are the "bag number" of the C, S and B bag. C ≠ S, S ≠ B, B ≠ C. The numbers C, S, B have to be such that the total number of the required moves is minimal. If there are more than one solution, use the one with the smallest C. if the C's are the same then use the one with the smallest S. if the S's are the same then use the one with the smallest B. Sample Input

Edition 2007-01-09 top secret / strictly confidential page 293 of 520 Perlgolf History

10 10 10 40 39 40 10 20 30 30 20 10 1227 Sample Output 312

6.1.2. Solutions 83, ton (post-mortem) -p0a @c=$;[map 1..!$c[$_--]++*$F[3*$_+$b++%3],@a=/\B../g]||="@a "for 1..2e6;$_=pop@ 83, ton (post-mortem) -p0a %c=$;[map$c{$_+=0}++*$^T..$F[3*$_+$b++%3],@a=/\B../g]||="@a "for 1..2e6;$_=pop@ 85, ton -p0a @c=$;[map{($c[$_--]++&&())x$F[3*$_+$b++%3]}@a=/\B../g]||="@a "for 1..2e6;$_=pop@ 87, mtve -ap0 <>,$;[map 1..$F[($_*=1)*3+$.++],@c=/(..)(?!..\1|\1)/g]||="@c "for$|x6..9x6;$_=pop@ 90, ton (alternative) -p0a $a='((?!\1|\2)..)'x3,$;[map{($_+=0)x$F[3*$_+$a++]}@a=/1$a/]||="@a "for 1..2e6;$_=pop@ 99, Jasper -lap0 $s[map{(1)x$F[3*$_+$i++%3]}/1$m/]||=join$",map int,//for($m='(..)(?!\2|\1)'x3)..2e6;$_=$s[-1] 110, michalj -lpa0 @;=/../g,$y=0,grep$;[$_]-($;[$_-1]+=0)&&($y+=$F[3*$;[$_]+$_])>$Y,0..2 and$Y=$y,@t=@;for$|x6..9x6;$_="@t" 113, tybalt89 -pa0 for$c(@r=0..98){map$a[$'-$c&&$_-$c&&$_- $'&&$F[$c*3]+$F[$'*3+1]+$F[$_*3+2]]||="$c $' $_ ",@r,//for@r}$_=pop@a 114, Jeff Moore -pla0 for$b(@d=0..98){for$c(@d){$e[/^($b|$c)$/||$b- $c&&$F[3*$b]+$F[3*$c+1]+$F[3*$_+2]]||="$b $c $_"for@d}}$_=pop@e 115, andys -lp0a s#^(..)(?!(..)?\1)(..)(?!\3)#$b[$F[3*$1]+$F[3*$3+1]+$F[3*$'+2]]||="$1 $3 $'"#efor$?x6..9x6;$_=$b[-1];s/0\B//g 117, kcwu

Edition 2007-01-09 top secret / strictly confidential page 294 of 520 Perlgolf History

-lap0 for$i(@r=0..99){for$j(@r){map{$x[$F[$i*3]+$F[$j*3+1]+$F[$_*3+2]]||="$i $j $_"if$i-$j&&$i-$_&&$j-$_}@r}}$_=pop@x 119, k.c.ivey -pa0 $m<($==/1(..)(?!\1)(..)(?!\1|\2)(..)/&&$F[3*$1]+$F[3*$2+1]+$F[3*$3+2])and$m= $=,@s=map$$_+0,1..3for 1..2e6;$_="@s " 120, Colm Dougan -ap0 @c=0..@F/3;for$i(@c){for$j(@c){$;[(!/^($i|$j)$/&$i!=$j)*$F[$i*3]+$F[1+$j*3]+ $F[2+$_*3]]||="$i $j $_ "for@c}}$_=pop@ 122, Skeeve (post-mortem) sub p{my$b=pop;@p<3?map{push@p,shift;p(@_,(<$b[$_]>)[$#p]+$b);push@_,pop@p}@_:$b >$s?($s=$b,$\="@p\n"):0}p 0..(@b=<>);print 123, Peter Haworth -pa @{$.-1}=@F}for$c(@i=0..$.- 1){for$s(@i){/^($c|$s)$/||$c^$s&&($n=$$c[0]+$$s[1]+$$_[2])>$"&&($"=$n,$\="$c $s $_ ")for@i}}{ 124, Skeeve sub p{my$b=pop;@p<3?map{push@p,shift;p(@_,$b+(<$b[$_]>)[$#p]);push@_,pop@p}@_:$b >$s?($s,$\)=($b,"@p\n"):0}p 0..(@b=<>);print 124, Paul van Eldijk -alp0F for$c(@R=0..@F/3- 1){for$s(@R){for(@R){$;[$F[$c*3]+$F[$s*3+1]+$F[$_*3+2]]||="$c $s $_"if$c!=$s&$c!=$_&$s!=$_}}}$_=pop@ 128, Shlomi Fish -pa0 for$e(@i=0..99){for$f(@i){$_!=$f&$f!=$e&$e!=$_&($a=$F[$e*3]+$F[$f*3+1]+$F[$_ *3+2])>@d&&(@d=("$e $f $_ ")x$a)for@i}}$_=$d[0] 131, Benoît Chauvet @B=<>;map{$s=@Z=/\B../g;map{$s+=$s&&($B[$d=$Z[$_]|=0]=~/\d+/g)[$_];$s*=$d!=$Z[$ _-1]}0..2;($m,@b)=($s,@Z)if$s>$m}9x6..2x7;print"@b " 131, Chris Dolan -pa push@B,@F}{for$c(@R=0..98){for$s(@R){map{$x=$z,$\="$c $s $_ "if($z=$c-$s&&$s-$_&&$_-$c&&$B[$c*3]+$B[$s*3+1]+$B[$_*3+2])>$x}@R}} 140, Honza Pazdziora @c=map/\d+/g,<>;for$i(0..$.){for$j(0..$.){map{$\="$i $j $_ ",$y=$,if($,=$c[3*$i]+$c[3*$j+1]+$c[3*$_+2])>$y&&$i-$j&&$j-$_&&$i- $_}0..$.}}print 141, Mathieu Longtin

Edition 2007-01-09 top secret / strictly confidential page 295 of 520 Perlgolf History

@D=map{split}<>;for$c(@S=0..$.){for$/(@S){$T<($;=$D[$c*3]+$D[$/*3+1]+$D[$_*3+2] )&&$_-$c&&$_-$/&&$c-$/and$z="$c $/ $_\n"and$T=$;for@S}}print$z 142, Peter Haworth (alternative) -pa @{$.-1}=@F}(($c,$s,$b)=map$_<$.?$_+0:(),/../g)>2&&$c-$s&&$c-$b&&$s- $b&&($n=$$c[0]+$$s[1]+$$b[2])>$m&&($m=$n,$\="$c $s $b ")for 0 x6..9x6;{ 144, srushe -pal push@n,@F}{for$x(0..@n){for$y(0..@n){for$z(0..@n){($f=$z==$x|$z==$y|$y==$x|| $n[$x*3]+$n[$y*3+1]+$n[$z*3+2])>$v&&($v=$f)&($_="$x $y $z")}}} 153, Jeremy Leader @x=map{[split]}<>;for$c(0..99){for$s(0..99){for$b(0..99){$s!=$c&$b!=$s&$b!=$c&( $y=$x[$c][0]+$x[$s][1]+$x[$b][2])>$z?($z=$y,@r=($c,$s,$b)):0}}}print"@r\n" 204, yktang push@l,[split]for<>;for$i(0..$#l){for$j(0..$#l){next if$i==$j;for$k(0..$#l){next if$j==$k||$i==$k;push@s,[$l[$i]->[0]+$l[$j]- >[1]+$l[$k]->[2],"$i $j $k"]}}}@s=sort{$b->[0]<=>$a->[0]}@s;print"$s[0]- >[1]\n"

6.1.3. Explanation by Ton Hospel Newsgroups: perl.golf Subject: Michael and the candy, my solution Date: Tue, 27 May 2003 14:17:18 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) The basic problem is given a set of bags (3 to 99) with in each 1 to 99 objects of 3 possible colors, move them all to 3 bags so that in each bag is only one color. Do this in as few as possible moves. If multiple solutions exist, order all possibilities lexical and report the first one. Each bag is represented as a line with 3 numbers (one for each color). Moving all colors to one bag involves removing it from all of them and subtracting from that the number there already where in the target bag, since these don't have to be moved. The first part is a constant for all solutions, so we can ignore that and the problem becomes: For each color, select a bag and see how many of that color there are Maximize the sum. (no repetitions of bags, lexical first if there are multiple solutions). The plan is to basically try all combinations and see which one is best. Since the value to be optimised is a relatively small number, you can do that by assigning to an array and then popping the highest value, basically like: $array[$value] = $solution for all_combinations; print pop @array; To get the lexical first, you must work through combinations in reverse lexical order. That also means that the $solution part is evaluated before the $value part, which turns out to be awkward. So instead I went for: $array[$value] ||= $solution for all_combinations; print pop @array; $value is now evaluated before $solution (if $solution is evaluated at all) and only the first time $value is seen is it put in the @array, so here you must run through the combinations in lexical order.

Edition 2007-01-09 top secret / strictly confidential page 296 of 520 Perlgolf History

The next step is generating all combinations without repeats. All ways of generating a complete set and 3 times removing one element from that turned out long, so instead I go for generating all combinations with repeats and then filtering out the repeats. There are two basic ways to get all combinations with repeats quickly: map...,0 x6..$~ generates all strings from "000000" to "999999". Still needs to be chopped in groups of 2 characters and ...for 1..2e6 generates all numbers up to 2e6. Still needs the first char removed and chopping in groups of 2 chars, and elimination of 2000000 and the 1..999999 range since they correspond to selecting less than 3 bags. In most solutions you don't have to do anything for that, since if you select less than 3 bags, there will be a solution with selecting one more bag which gives a higher sum (there is at least one of every color in each bag). The 2000000 also gives no problem since it's a repeat of 00 00 00 which will already have been seen as 1000000, so it's already in the @array, and the ||= will not trigger. Next is splitting up in groups of 2 and filtering. If you do them together, for the map case that can be done with : /(..)(?!..\1|\1)/g and for the for case with: /(\B..)(?!..\1|\1)/g so combined they work out to exactly the same length. Or you can do the filtering separate from the chopping, and using a hash you get: %c=();check $c{$_}++ for each /../g in the map case %c=();check $c{$_}++ for each /\B../g in the for case Again the lengths will be the same. The chopping up process gives us strings like "00" where in the output we must have 0. So we need to numify the results, which will involve something like $_+=0 or $_*=1 at some point. The last remaining step is taking the sum. For small positive numbers in a loop that's easiest done with map in scalar context, since it needs no initialization of a counter and directly returns the sum: map{(1)x$_}@array In fact, you can do better with map 1..$_,@array something I missed and why my solution is not optimal. In the case of the hash filtering this becomes: map{($c{$_--}++&&())x$_}@array which basically removes the contribution of repeated entries, so it basically selects less than 3 bags in these cases. And since then there is a bigger sum by indeed selecting an extra different bag, it will never become the result of pop@array, so repeated solutions are indeed effectively eliminated. Next we need to get all input in an array so we can repeatedly select from it. We could put each bag line in an element, but we later need to select the specific colors, which gets awkward. It's easier to have each value as element, and then use $array[3*$line+$color] to select line and color. That works out perfectly for the -a option of perl which makes the @F array exactly like we want it.

Edition 2007-01-09 top secret / strictly confidential page 297 of 520 Perlgolf History

For $color, we want to select the next color each time, so something like $b++ seems natural, but after each combination we want it to start at 0 again, so it either needs a reset or a %3 if the selection is always per 3 in the 3-string region. Working through these possible combination, and using the fact that -p gives a free ; at the end, we get: 86 -p0a map%c=$;[map{($c{$_+=0}++&&())x$F[3*$_+$b++%3]}@a=/../g]||="@a\n",$^Cx6..$~; $_=pop@ 86 -p0a %c=$;[map{($c{$_+=0}++&&())x$F[3*$_+$b++%3]}@a=/\B../g]||="@a\n"for 1..2e6;$_=pop@ %c here is either empty the very first time, or initialized with something like "0 1 2\n" => undef, which doesn't screw up the relevant entries $c{a number}, so it's effectively a reset of %c. $b happens to be a multiple of 3 by the time we get to $_ = "1000000", so the candy counting starts at the first color. That $_+=0 bugged me however. I'd love to make that into $_--, but if $_ would be 0, that would become -1, which will select from the last bag in @F and lead to false solutions. It also means the result will never have bag 99, but that's ok, the challenge happens to be such that bags only go from 0 to 98. The $_-- would work if somehow we could pre-sabotage %c so that it starts with e.g. %c=(0=>1), but that's pretty expensive. But... for an array it's easier to put something on index 0, so I started considering the following: 85 -p0a map@c=$;[map{($c[$_-- ]++&&())x$F[3*$_+$b++%3]}@a=/../g]||="@a\n",$^Cx6..$~;$_=pop@ The very first time @c will be (), but the rest of the time it will start out as "xyz\n". So it looks like we have something that's true on index 0 always! But no! What if x is 0? That one is no problem actually. if $_ is 0, the $c[$_--]++ will be "0yz\n", which is actually true, only after that is $_ numified and $c[0] becomes 1. The problem is actually if x is -1 and the selected combination has two zeros. In that case the first zero gives "-1yz\n", which causes it to be ignored for the sum, and $c[0] is set to 0. The second zero now picks up that $c[0]=0 and is counted in the sum as -1, so selecting the last bag. The non-zero number now also gets counted. It's no problem if that refers to any but the last bag, since it then still corresponds to selecting 2 bags, so there will be some better 3 bag solution. If however the last number also refers to the last bag, we're in trouble if the counts are high enough that it gives a solution. We will effectively have chosen the same bag twice. And this does happen: 121 112 99 99 99 gives -1 -1 2 Bummer!

Edition 2007-01-09 top secret / strictly confidential page 298 of 520 Perlgolf History

But interesting enough, this works: 85 -p0a @c=$;[map{($c[$_--]++&&())x$F[3*$_+$b++%3]}@a=/\B../g]||="@a\n"for 1..2e6;$_=pop@ Why? What's different? The reason lies in the failure mode of the previous example. The -1 -1 2 solution succeeded in getting into the system because @c was "-1yz\n", which was the kind of solution we didn't really want anyways. and the -1's got into @; at the very first "000000". In the last variant however @; will never contain -1, which we can prove by induction (skipped). Notice this all this works only because 3 is relative prime to 100 and small enough so that with 9 tries $b%3 cycles through all possible combinations. Which makes 3 (and 0 or 1) actually the only number of bags for which this method works. It also needs the fact that there can be only 99 instead of 100 bags, and that no bag has none of any color. So it actually uses every random detail of the challenge. Going back to using 1..$_ instead of (1)x$_, in the post-mortem this was improved to: 83 -p0a @c=$;[map 1..!$c[$_--]++*$F[3*$_+$b++%3],@a=/\B../g]||="@a\n"for 1..2e6;$_=pop@ and it turns out we don't even need the tricky proof above by going back to a hash: 83 -p0a %c=$;[map$c{$_+=0}++*$^T..$F[3*$_+$b++%3],@a=/\B../g]||="@a\n"for 1..2e6;$_=pop@ A pity, since I really liked my twisted solution. -- In modern mathematics, algebra has become so important that numbers will soon only have symbolic meaning.

6.2. Boggle http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=38&season=1 The game started 2003-06-03 21:00:00 and ended 2003-06-07 19:00:00. Rules and tests by jasper.

6.2.1. Rules Boggle is a word game played with dice. The dice have letters of the alphabet on each face, and are thrown into a four by four grid. Players make words out of the grid by going left, right, up, down or diagonally to an adjacent letter. Each instance of a letter may be used only once. thir jaqs puet neyl This grid can form the words thirst, queen, this, steep etc. It cannot make punnet, steal, japan. You get the idea.

Edition 2007-01-09 top secret / strictly confidential page 299 of 520 Perlgolf History

Our boggle program will be a filter on a list of words on STDIN, with the dice being rolled as a list of arguments on the command line. The first row of the boggle grid will be filled, left to right, from the first four letters, the second row filled left to right from the second four, and so on. The real game has funny rules for "q", but we won't bother with that. Each letter in the grid will be a single letter in the alphabet. Input The command line input consists of 16 space separated letters. The input (STDIN) consists of a list of words (matching /^([a-z]{1,16}\n){1,999}\z/) in no particular order, and not guaranteed to be unique. A word is defined by not containing more than 5 equal letters. Output Output should be those words which can be made from the boggle grid of sixteen letters (matching /^([a-z]{1,16}\n){1,999}\z/), in the same order as they appear on STDIN. Duplicates may also appear here. Your program should run in a reasonable time for the cases in the testprogram, and run in finite (but possibly impractical) time even for specially constructed pathological cases. Sample Input on commandline amphcrbivaoiansu Sample Input (STDIN) amphibious caravans dinosaurs Sample Output amphibious caravans

6.2.2. Solutions 114, ton -p BEGIN{$^H<<=map$~.=$_%5&&pop,0..76}s/./.{1,3}(.{5}){6,8}$&/g;$_="$`"x($~x17) =~/$_.*(??{grep$c{$_%38}++,%c=@+})/x 115, ton (alternative) -p BEGIN{$^H=1< 121, ton (post-mortem) -p INIT{\$$_{--$=*5>>2}while$_=pop}sub b{local$p=- $_.$p;!@_!=grep$p!~$_&&b(@_)&($_+$p)=~/$_|\b[1456]$/,%{+pop}}$_ x=b/./g 122, tybalt89

Edition 2007-01-09 top secret / strictly confidential page 300 of 520 Perlgolf History

print grep{@a=0;@a=map$&eq$ARGV[$n=$_]?map$_&&/ $n /|1 124, ton (post-mortem) -p INIT{push@$_,--$=*5>>2while$_=pop}sub b{local$p=- $_.$p;!($n=pop)!=grep$p!~$_&($_+$p)=~/$_|\b[1456]$/&b(@_),@$n}$_ x=b/./g 133, Jasper -p INIT{push@$_,32|$;++/4+$;while$_=pop}sub b{my($p,$n,@L)=@_;!$n|!!grep$p!~$_&b("$_ $p",@L)&($_- $p)=~/$_|\b[1456]$/,@$n}$_ x=b/^|./g 141, terje sub r{my$i;map{$_=$l++,r($i-1),$_=$b[--$l]if(abs$i-"@_"<6&abs$i++%4- "@_"%4<2|!$l)&$b[$l]eq$_}@ARGV;$f|=$l==@b}@b=/./g,r&&print,$f=0for 143, kcwu sub f{my($l,$x,@s)=($_,@_);grep{local@u=@u;!@u|abs($l%4-$_%4)<2&abs($l- $_)<6&&$ARGV[$_]eq$x&!$u[$_]++&&!@s|f(@s)}0..15}print grep{f/./g} 148, Shlomi Fish sub c{@_<3||grep$_[1]eq$ARGV[$_]&abs$_%4-$_[0]%4<2&abs$_- $_[0]<6&&c(local$ARGV[$_]=$_,@_[2..$#_]),0..15}print grep{split//;grep{c$_,@_}0..15} 149, Jeff Moore (rejected) push@{$z{pop||$/}},int$_/.8for-19..0;sub r{local$_=$_;for$d(@{$z{$f&&=chop}}){r(local$c=$d,$d- =25),$d+=25if!$c|1<<$c+6-$d&7335}$f}$f=1,r||print for<> 152, shr sub k{my($a,$b,$i)=@_;ord==ord$a&(!$#_|2>abs$i%4-$b%4&6>abs$i- $b)&&($_=uc,k(substr($a,1),$i),$_=lc),$i++for@ARGV;$s|=$a!~/./}print grep{$s=0,k$_} 167, lf -naF// INIT{@a=splice@ARGV}sub g{my$n=$_;if((E^$F[$i++])eq($a[$n]^=E)){$.*=$#F!=$i;(abs($_- $n)>5|abs(($n&3)-($_&3))>>1or&g)for@I}$a[$n]^=E;$i--}g for@I=0..42;$.||print 169, Peter Haworth push@L,shift,++$x%4&&()for%::;for$w(<>){map(f($_,$w),0..18)&&print$w}sub f{my($p,$w)=@_;$w!~s/.//||$p>=0&&$L[$p]eq$&&&!local$L[$p]&&map f($p+$_,$w),- 6..-4,-1,1,4..6or()} 170, Bass sub r{my($c,$R)=@_;$ARGV[$c]ne chop$R?():local$ARGV[$c]|$R?map{r($c+$_,$R)}(- 5,-1,3)x($c%4),-4,4,(-3,1,5)x($c%4!=3):1}$#ARGV=42;map{print if map{r$_,$`}(!/$/..15)} 179, eugene -p sub n{local$b[$s=pop];local@f=map{$_+$s,$s- $_}1,4,5,6;!($l=shift)||&p}INIT{@b=((1)x5,map{$_%4&&(),pop}0..15)}($l,@_)=/. /g;@f=0..@b;$_ x=!!&p;sub p{map{n@_,$_}grep$b[$_]eq$l,@f} 181, Skeeve

Edition 2007-01-09 top secret / strictly confidential page 301 of 520 Perlgolf History

-n BEGIN{1while($a[$i++/4*5]=pop)}sub R{my($i,@a)=@_;ord($a[$i]^=$s[$j++])?$j<@s?0:print pop@x:map{R($i+$_,@a)}(- 6..-4,-1,1,4..6);--$j}@x=$_;@s=split//;$#a=$i=30;R($i,@a)while($i--) 190, topmach sub d{my($p,$w,@l)=@_;if($w=~s/^$l[$p]//){$l[$p]=0;print($o),$o=''if$/eq$w;d($p+ $_,$w,@l)for-6..-4,- 1,1,4..6}}while($o=){d$_,$o,(0,@ARGV)[1..4,0,5..8,0,9..12,0,13..16,(0 )x6]for 0..18} 206, Jeff Moore -ln BEGIN{map$b.=pop,1..16}sub r{local($_,$c,$d)=($_,$d);for$l(chop or$f=0){until(($d=index$b,$l,$d)<0){(0,$w=4&(~$c^$d),0,!$w,1,!$w)[$c+1?abs$c -$d:4]&&r(substr(local$b=$b,$d)^=A),$d++}}$f}$d=$f=-1,r||print 216, m.thelen I:for(){for$y(0..3){for$x(0..3){t($y,$x,$_,@ARGV)&&print&&next I}}}sub t{my($y,$x,$w,@g)=@_;${for$Y(-1..1){for$X(- 1..1){t($y+$Y,$x+$X,$w,@g)|!$w&&return 1}}}if($;=chop$w)eq$/|!(($x|$y)&4)&$g[$y*4+$x]=~s/$;/_/} 216, Ingo Saitz ($i="@ARGV")=~s/(.{5} .)/ $1/g;sub i{my($l,$r,$j,$i)=($_[0]=~/(.)(.*)/)or print,next i;$_[2]&&($i-$_[2])!~/^- ?(2|7|9|11)$/||(substr($j=$_[1],$i,1)=0,i($r,$j,$i))while($i=index$_[1],$l,+ +$i)>0}i:while(){i$_,$i} 220, Michael Robinson -paF// INIT{(@g,@ARGV)=@ARGV}$i=!pop@F;for$@(@F){@;=$i++?map{/\d+/;map$g[$;=$&+$_]e q$@&$;>-1&!(1+index$'," $; ")?"$; $& $'":(),$&%4>2?(-5,-4,-1,3,4):$&%4?(- 5..-3,-1,1,3..5):(-4,-3,1,4,5)}@;:grep$g[$_]eq$@,0..@g}$_=""if!@ 251, Chris Dolan -n INIT{@a=@ARGV;@ARGV=()}sub f{if($_[0]-(@w=/./g)){for my$i(0..$#a){if($a[$i]eq$w[$_[0]]&&!$f{$i}){local$f{$i}=1;if($_[1]==- 1||(($b=abs$i- $_[1])!=2&&$b<6&&!(($i%4==0&&$_[1]%4==3)||($i%4==3&&$_[1]%4==0)))){f($_[0]+1 ,$i)}}}}else{$m++||print}}f($m=0,-1) 380, Jurgen Pletinckx -l for(0..15){$r=$_%4;my@a;if($_>3){push@a,$_-4;push@a,$_-5if$r;push@a,$_- 3if$r!=3}push@a,$_- 1if$r;push@a,$_+1if$r!=3;if($_<12){push@a,$_+4;push@a,$_+3if$r;push@a,$_+5if $r!=3}$v[$_]=\@a}W:for(){chomp;@n=map{[$_]}0..15;for$l(split//,$_){my @e;for$r(@c=grep{$ARGV[$_->[-1]]eq$l}@n){@a=@{$r};for$c(@{$v[$a[- 1]]}){push@e,[@a,$c]unless grep/^$c$/,@a}}@n=@e;next W unless@c}print}

6.2.3. Explanation Newsgroups: perl.golf From: per… @ton.iguana.be (Ton Hospel) Date: Tue, 10 Jun 2003 15:48:40 +0000 (UTC) Message-ID: Pff, they kept pushing me to write an explanation. Ok. Here you go.

Edition 2007-01-09 top secret / strictly confidential page 302 of 520 Perlgolf History

This challenge basically asked for backtracking, and perl already has a backtracking system: the regex engine. So my idea was to take the boggle board as a string to match on, and rewrite the target word as a regex and then see if it matches. The first problem is that on the board you sometimes have to go backward, and regexes only go forward (I really wish perl would get variable length lookbehind). So instead I'll take repeated copies of the board as string to match on, and jump from board to board during the match. The second problem is the edges. If you write a board like abcd efgh ijkl mnop as the string "abcdefghijklmnop" (x repeater), you can see that e.g. you can move one right from c to get to d as wanted, but you also can move one right from d to e, which is not a valid boggle move. So I need to introduce extra invalid characters in between the edges. Since I'm going to repeat the board string, it also needs an edge at the bottom or top, otherwise you can still wrap vertically. E.g. putting the extra protection at the front the minimum string I can use is: XXXXXabcdXefghXijklXmnop where the X's must be characters that can't appear in a target word. For the front string I decided to use $~ (STDOUT) which is a bit too long, but that's no problem, we'll just skip a bit extra when moving from board to board. So building the string becomes: map$~.=$_%5&&pop,0..19 which gives: STDOUT0ponm0lkji0hgfe0dcba notice the string is backward, but that doesn't matter, since the boggle rules are symmetric in all directions. The extra 0 after STDOUT is again no problem, just a bit of extra shifting. Also notice we can play with that 19 to make it bigger. It will just cause extra 0's at the end, which we can again compensate for when skipping from board to board. If we make it big enough, there will even be enough extra 0's at the end that we don't need to use $~, since these extra end 0's already protect against edge skips. (Unfortunately I see no way to use that fact). Next comes building the regex. Basically we want to make a sequence AB into: A (skip to the next boards left up position relative to A) (choose to go 0, 1 or 2 steps forward) (choose to go 0, 1 or 2 steps downward) B Where the () pieces can be in any order. For the given board string that would be: A.{19}.{0,2}(.{5}){0,2}B So the first (naive) version of constructing the regex if the target string (without \n) is in $_ would be: s/\B/.{19}.{0,2}(.{5}){0,2}/g after which we can check if it can be made from the board is: ($~ x 16) =~ $_ We need at least as many copies of the board as there are letters in the target string, which can have a size up to 16. I tried to use the previous regex construction s/// as the multiplier in my final solution, but it always turned out to be one too short, and adding 1 looses more strokes than just using a

Edition 2007-01-09 top secret / strictly confidential page 303 of 520 Perlgolf History constant like 16. It would be faster in the failure case though, since now the failing case tries all possible starting positions). The main problem left now is that the current method is wrong. It will happily reuse positions already visited before, even staying put if it likes to. Bummer. But wait! We can use @+ or @- to collect the positions where we matched a letter. If we take these modulo boardstring length, we have absolute positions on the board. So we are going to demand no repeating there. We can use the (??{}) regex construct to conditionally construct a regex piece that allows regex to progress beyond it or not. The shortest way would likely be to after each matched letter in the target word to check the current pos versus the old positions in @+ or @-. Unfortunately I never got that working properly since there's a bug in backtracking over (??{}) in that you get spurious undef entries which take too much work too ignore them. So instead I decided to only check at the total end, using this construct: .*(??{grep$c{$_%26}++,%c=@+} For the moment assuming %c is empty, this will count how many times a certain spot is used, and the grep will match if any spot is ever used more than once. So you get 0 if every spot is used only once, 1 or more otherwise. If we make sure there is a 0 somewhere after the last match position that will mean further match is possible and the whole regex will match. And since 1-9 don't appear in the string, if a spot is double used, it will not match, and the backtracking will resume. We can get that 0 by adding an extra board or by increasing the 19 in the map that constructs the board string. However, %c is not empty. It's initialized with @+, so it actually has all kinds of values already. We don't actually care about these unless some keys are smaller than 26 however, since otherwise they don't cause fake counts in $c{$_%26}++. If some positions are below 26, this can however cause a spurious backtrack. But again this is no problem if we attach an extra board. If there is a solution, then there will now also be a solution starting at board 2, and in that case all values in @+ (or @-) will be bigger than 26. So everything works out. The next problem is that now we have a runtime constructed regex containing (??{}), which is actually not allowed unless you do use re "eval"; which is pretty long. Checking in the source of the re pragma, we see that what it really does is effectively: BEGIN { $^H |= 0x00200000 } That's good! We wanted a BEGIN{} or INIT{} block anyways so that we can use the perl -p/-n option to loop over STDIN, which needs us to empty @ARGV first. So we want that board construction map inside a BEGIN/INIT anyways. INIT comes too late for $^H, so BEGIN it is. And we need to set $^H to 221. mmm. Hey, that map returns at least 20, so we can use things like: BEGIN{$^H=2<

Edition 2007-01-09 top secret / strictly confidential page 304 of 520 Perlgolf History

know if it's always so (the main missing CPU in my survey is the M68000 family. Anyone has such a perl?) Since $^H actually is initialized with 256 (2**8), if we shift left by 77, we get $^H = 2**21 as it should be (the loss of the 2**8 bit seems to cause no problems). That gives: BEGIN{$^H<<=map$~.=$_%5&&pop,0..76} The board string is now a lot longer, but that's ok, just properly increase all later constants. All that's left now is some minor tricks: • We need to parenthesis so that positions are actually filled in in @+/@-. We already need a (.{5}){0,2} construct though. We can in fact use these parenthesis, but we will only get the end of the last match in the repeat, so we actually should use @+ and not @- • s/\B//g only works properly if we have a -l option. But that means we can't handle the failing strings by printing "", we must then do a conditional print. Too long. Instead let's set $_ to either the original string or "". But that means that /\B/ would also match between the \n and end of string, so we get an extra spurious () at the end. And if we just spiraled on the boggle board to the center of a 3x3 block, no position of that tail () is actually valid, so this is unacceptable. So instead go to s/./ $& /g style constructor. It means we get an extra \n in the result though. We can ignore that by using the x modifier to the regex. It also means we get some extra match stuff in front of the first letter. But that's no problem. The position of that start doesn't get into @+, and we had an extra board in front anyways which provides enough characters for the match. • At the end we need to print the original string in case of a match. But we destroyed $_ ! Fortunately after the regex constructor, it's in $` (that's actually a perl bug). We need to be careful though since the final match will destroy it again. That's why you will see it quoted. • things like .{19} can be written as (.{5}){3}.{4}, and the multiples of 5 and one can be absorbed in the (.{5}){0,2}.{0,2} we already have. So in the end this gives this 114: -p BEGIN{$^H<<=map$~.=$_%5&&pop,0..76}s/./.{1,3}(.{5}){6,8}$&/g;$_="$`"x($~x17) =~/$_.*(??{grep$c{$_%38}++,%c=@+})/x

6.3. Palindrome http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=39&season=1 The game started 2003-06-16 19:00:00 and ended 2003-06-20 19:00:00. Rules and tests by terje.

6.3.1. Rules By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome. It is an easy job to test whether a given string is a palindrome or not. But it may not be so easy to generate a palindrome. Here we will make a palindrome generator which will take an input string and return a palindrome. You can easily verify that for a string of length "n", no more than (n-1) characters are required to make it a palindrome. Consider "abcd" and its palindrome "abcdcba" or "abc" and its palindrome "abcba".

Edition 2007-01-09 top secret / strictly confidential page 305 of 520 Perlgolf History

But life is not so easy for programmers!! We always want optimal cost. And you have to find the shortest possible palindrome if you are only allowed to add characters at the start and the end of the string. Input The input as a commandline argument (ARGV) is a string of lower case letters (matching /^[a- z]{3,25}\z/). The input string will not be a palindrome. Output The output (STDOUT) should be the palindrome string (matching /^[a-z]{4,49}\n\z/). In theory there can be 2 equally short palindromes for each input line, but the problemset will consist of cases where there will be just one solution that is shortest. Sample Input abcc Sample Output abccba

6.3.2. Solutions 44, mtve (rejected) -l $_=a;$_++until/@ARGV/&$_=~reverse$&;print 54, mtve $_=($a=reverse$;=$a.pop)|$"x$$a++.$;.$/until/$;/;print 56, Jasper (post-mortem) $i+=$|--,print/(.{$i})/,$_=reverse,/^$'/?$/:redo for pop 57, Jasper pos=$i++/2,//g,print"$`",$_=reverse,/^$'/?$/:redo for pop 57, Jasper (alternative) $i+=$|^=1,print/(.{$i})/,$_=reverse,/^$'/?$/:redo for pop 57, RobTM -l $i+=.5while($"x$i.$_|($_=reverse|pop))!~/$_.+/;print$& 60, ton ($_=" @ARGV ").=reverse.$_;s//print?(.*)(.*)

\2(.{@-} )?/eg 64, Szeryf -l $i+=.5while($_=($a&"\x7F"x$i).($a=reverse$a.pop))!~reverse;print 67, tybalt89 ($_._.($_=reverse))=~/(.+)_\1/,@a[@+]="$`$_ "for(pop)x2;print pop@a 68, yktang

Edition 2007-01-09 top secret / strictly confidential page 306 of 520 Perlgolf History

$_=pop;until($a&&/^$'/){/${$_}./;${$_}=$a=$&;$_=reverse}print"$a$_ " 70, andys ("$_ ".($_=reverse))=~/(.*) \1/,$a["@+"]="$`$_ "for(pop)x2;print pop@a 71, Amir Karger -l sub v{$`.reverse$_}$_=pop;1until grep{/./g;v=~/$_.*/&&print$&}$_,~~v 74, Peter Haworth -l $_=pop;1until($s,$_)=($_,~~reverse),$d.='.'x$|--,$s=~$d,s/^$'/$s/;print 75, Michael Rybakin $b=reverse$_=pop;print s/$/-$b =$b-$_ /*s/(.+)-\1/$1/g*/=/*"@-"$e}"$o $r ","$r $o ";print 81, Jeff Moore sub r{~~reverse$_}/(.*).?(??{reverse$1})/g,$c[pos]=r."$' "for$_=pop,r;print$c[-1] 81, ErikB (post-mortem) -l while($_=reverse|pop){$z+=$c++%2;/.{$z}/;$b=$&.reverse;last if$b=~/$_/}print$b 87, Nicolas Mendoza -l map{/^(.+).?(??{reverse$1})/&&push@b,reverse.$'}$_=pop,reverse."";($_,)=sort @b;print 87, Skeeve $x=pop;map{$\=$z.$/if reverse($z=$x.substr+($y=reverse$x),$_/2)eq$z;$x=$y}(0..50);print 90, Chris Dolan -l $r=reverse$a=pop;0while($_=$x++%2?$a.substr$r,-$c:substr($r,0,++$c).$a)ne reverse;print 90, Arkady (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 307 of 520 Perlgolf History

-l r=reverse$s=pop;@r=grep{reverse=~$_}substr($r,0,++$-).$s,$s.substr$r,-$- until@r;print@r 91, topmach $b=reverse($a=pop);($a,$b,$c,$d)=($b,$a,$d,$c=(chop$a).$c)until"$a$c"=~/$b$/;pr int"$a$c$d " 92, Peter Haworth (rejected) -l $r=reverse$s=pop;map$_ eq reverse&&exit print,$s.substr($r,- $_),$r.substr$s,-$_ for 1..24 92, Arkady -l $r=reverse$s=pop;@r=grep{reverse eq$_}substr($r,0,++$-).$s,$s.substr$r,-$- until@r;print@r 102, ErikB -l for($a=reverse$b=pop;++$z;){$b=~/.{$z}/;$_=$&.$a;last if/$b/;$a=~/.{$z}/;$_=$&.$b;last if/$a/}print 105, Paul van Eldijk $_=pop;$r=reverse;($e="$_ $r ")=~s/(.+) \1/$1/;($t="$r $_ ")=~s/(.+) \1/$1/;print length$e

6.4. Mathematical forest http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=40&season=1 The game started 2003-07-05 13:00:00 and ended 2003-07-10 19:00:00. Rules by Carsten. Tests by terje.

6.4.1. Rules Imagine you are in a mathematical forest where you have lots of beautiful one-dimensional trees (very, very thin), one at each gridcrossing (so you get a tree whenever both coordinates are integers). However, once you are in this forest, some trees cannot be seen anymore since they are blocked from your view by trees which are in front of them. Given the size of the forest (first two arguments on the command line) and your position (third and fourth argument on the command line), the task is to plot your position "@" and each tree you can see "*" (not visible trees should be marked by a blank " "). Input is 4 integers on the commandline (ARGV). The first two numbers (matching /^([2-9]|[1- 9]\d)\z/) give the width and height of the forest, and the last two numbers (matching /^(0|[1-

Edition 2007-01-09 top secret / strictly confidential page 308 of 520 Perlgolf History

9]\d?)\z/) give the x and y coordinates of the viewer. The x-coordinate runs from left to right, the y- coordinate runs from top to bottom, and the upper left is (0, 0). The observer will be inside the forest. Output (STDOUT) should be the forest, matching /^([ *@]{x}\n){y}\z/. Sample Input 50 20 4 19 Sample Output **** ****************** ****************** ******* ** ** ** ** ** ** ** ** **** **************** **************** *********** ************************* *************************** ***** ****** ****** ***** **** ************ ************ ************ ****** ** ** ** ** ** ** ** ** **** ********** ********** ********** ********** * **** **** **** **** **** ********************************* ************************* **** ****** ****** ****** ****** ****** ****** *** ** ** ** ** ** ** ** ** **** **** **** **** **** **** **** **** **** **** ************************* ********************************* ************************* ************************************************** *@*

6.4.2. Solutions 90, tybalt89 -l $a-=print map$"^('`',$/)[bgcd($a,$_-$b)**2],0..$d- do'bigint.pl'for(!map$$_=pop,a..d)x$c 91, ton (rejected) -l $a+=print map$"^($/,"`")[//<

Edition 2007-01-09 top secret / strictly confidential page 309 of 520 Perlgolf History

-l $a+=print map"`"x!($_=grep$a%$_|$'%$_,//..98)^$"^$/x/7/,$b..$b+~$d for$c..3-map$$_=-pop,a..d 98, Juho Snellman -l $a-=print map$a|--$X?$"|'*'x!grep!($a%$_|$X%$_),2..99:"@",($X=$b+1)x$d for(!map$$_=pop,a..d)x$c 100, terje (post-mortem) -l map$$_=pop,a..d;$a-=print map$a|$_?(grep!($a%$_|$'%$_),1+//..99)?$":"*":"@",-$b..$d-$b-1while$c-- 101, Amir Karger ($w,$h,$x,$y)=@ARGV;print/$w/?$/.$y--x0:$y|($a=$_- $x)?$"|$/x!grep$a%$_+$y%$_<1,2..99:"@"for(0..$w)x$h 102, Andreas -l ($@,$Y,$#x,$y)=@ARGV;$y-=print map-- $e|$y?grep(!($e%$_|$y%$_),2..97)?$":"*":"@",($e=@x)x$@while$Y-- 103, Jeff Moore -l ($;,$q,$x,$a)=@ARGV;$a-=print map{$b=$_-1-$x;qw/@ */[(- grep$a%$_|$b%$_,2..99)%99]||$"}1..$;for 1..$q 104, Shlomi Fish -l ($},$h,$x,$s)=@ARGV;$s-=print map$s|($t=$_-$x- 1)?(grep!($s%$_|$t%$_),2..99)?$":"*":"@",1..$}for 1..$h 105, Peter Haworth -l ($W,$H,$#X,$y)=@ARGV;$x=@X,print(map-- $x|$y?grep(!($x%$_+$y%$_),2..99)?$":'*':'@',1..$W),$y--while$H-- 109, michalj -l ($X,$Y,$a,$b)=@ARGV;$y=$_-$b,print map$y|($x=$_- $a)?$"^$\x!grep!($x%$_|$y%$_),2..99:'@',0..$X-1for 0..$Y-1 111, id5 -l ($w,$h,$x,$y)=@ARGV;print(map{$^=$y;($^,$_)=($_%$^,$^)while$^;(qw(@ *))[abs]||$"}-$x..$w-1-$x),$y--while$h-- 113, Skeeve -l ($W,$H,$X,$Y)=@ARGV;for$y(0..$H-1){print map{$z=$y- $Y;($_,$z)=($z,$_%$z)while$z;qw(@ *)[abs]or$"}-$X..$W-$X-1} 115, qmole -l ($w,$h,$b,$a)=@ARGV;$r=$a-$_,print map$r|($q=$b- $_)?(grep!($q%$_|$r%$_),2..$w+$h)?$":'*':'@',0..$w-1 for 0..$h-1 117, Chris Dolan @x=@ARGV;$b=$x[3]-$_,print map(($a=$x[2]- $_)||$b?grep({!($a%$_||$b%$_)}2..99)?$":"*":"@",0..$x[0]-1),$/for 0..$x[1]-1 120, Jasper

Edition 2007-01-09 top secret / strictly confidential page 310 of 520 Perlgolf History

-l ($x,$y,$e,$f)=@ARGV;print map{qw(@ *)[$_?~~grep+($_=$_*$'/$d)==int,1..($d=abs):$']||$"}-$e..$x-$e-/-?/for-$f..- -$y-$f 122, shr -l sub k{($m,$n)=@_;$n?k($n,$m%$n):('@','*')[abs$m]||$"}for$i(0..(@a=@ARGV)[1]- 1){print map{k$a[2]-$_,$a[3]-$i}0..$a[0]-1} 137, chhsiao ($w,$h,$x,$y)=@ARGV;for$i(-$y..$h-$y-1){print$_|$i?g($_,$i)>1?' ':'*':'@'for- $x..$w-$x-1;print"\n"}sub g{($a,$b)=@_;$b?g($b,$a%$b):abs$a} 142, Ingo Saitz ($x,$y,$p,$q)=@ARGV;for$D(-$q..$y-$q-1){for$U(-$p..$x-$p-1){$_=$~;s/D|U/6x abs${$&}/eg;print/TOT/?"@":/T((66+)\2*O\2*|O66+)T/?" ":"*"}print$/} 163, Peter Haworth (rejected) -l ($W,$H,$X,$Y)=@ARGV; for$x(-$W..$W){ for$y(-$H..$H){ $t{$x*$_,$y*$_}=$x|$y?$":'@'for 2..99 } } for$y(0..$H-1){ print map$t{$_-$X,$y-$Y}||'*',0..$W-1 }

6.5. Goldbach's Conjecture http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=41&season=1 The game started 2003-08-18 18:00:00 and ended 2003-08-22 19:00:00. Rules by http://acm.uva.es/p/v5/543.html . Idea by tybalt89.

6.5.1. Rules In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers. For example: • 8 = 3 + 5. Both 3 and 5 are odd prime numbers. • 20 = 3 + 17 = 7 + 13. • 42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23. Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.) Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a ten thousand. For each even number n you should print a confirmation for the conjecture in form a + b. If there is more than one pair of odd primes adding up to n, choose any of possible pairs.

Edition 2007-01-09 top secret / strictly confidential page 311 of 520 Perlgolf History

Input The input in @ARGV will contain one even number n which is between and including 6 ≤ n ≤ 9998. Example: 42 Output Print to STDOUT two odd prime numbers separated by '+' (plus) sign and a newline (so your output should match /^([1-9]\d*)\+([1-9]\d*)\n\z/). Sum of your numbers must be equal to n. Example output for input 42: 11+31

6.5.2. Solutions 50, mtve (rejected) grep(2**$_%$_-2,$a-=1-pop,++$b)?do$0:print"$a+$b " 57, tybalt89 $^F++while~-grep$^F*$#a%$_<1,2..--($#a+=pop);print"$#a+$^F " 58, mtve $a+=pop while map/^(11+|)\1+$/,1x--$a,1x++$b;print"$a+$b " 59, Bass map(/^(..+)\1+$/,1x++$^F,1x--$_)?redo:print"$^F+$_ "for-2+pop 61, Juho Snellman (1x++$^F.$/.1x--$_)=~/^(..+)\1+$/m?redo:print"$_+$^F "for-2+pop 62, Jasper (alternative) 1while map{(1x$_)=~/^(..+)\1+$/}++$,$b=$ARGV[0]-$;print"$+$b " 63, Amir Karger $_=z.1x($y=pop);$y-=s/1/;/while/z.1|\b(..+)\1+\b/;print"$y+@- " 63, Jasper $b=-2+pop;1while map{(1x$_)=~/^(..+)\1+$/}++$,--$b;print"$+$b " 63, Jasper (alternative) 1while map{(1x$_)=~/^(..+)\1+$/}++$,$b-=3-(pop||2);print"$+$b " 64, m.thelen $;-=2-pop;1until(1x++$^F.$/.1x--$;)!~/^(..+)\1+$/m&&print"$^F+$; " 64, Jeff Moore

Edition 2007-01-09 top secret / strictly confidential page 312 of 520 Perlgolf History

$b=pop;1while??|map/^(..+)\1{1,98}$/,7x++$x,7x--$b;print"$x+$b " 65, Jasper $b=-2+pop;1while map{(1x$_)=~/^(..+)\1+$/}++$^F,--$b;print"$^F+$b " 65, Jasper (alternative) 1while map{(1x$_)=~/^(..+)\1+$/}++$^F,$b=$ARGV[0]-$^F;print"$^F+$b " 65, Jasper (alternative) 1while map{(1x$_)=~/^(..+)\1+$/}++$^F,$b-=3-(pop||2);print"$^F+$b " 77, m.wrenn until($j++){for$k(++$^F,$p=($i|=pop)-$^F){$j*=$k%$_++for 2..$k/2}}print"$^F+$p " 78, Shlomi Fish map{do{print"$_+$a\n";exit}if(1x$_.$/.1x($a=$n-$_))!~/^(11+)\1+$/m}3..($n=pop) 79, Michael Robinson //,grep$'%$_==0,@@or map$N-$_-$'||exit(print"$_+$' "),@@=(@@,$')for 2..($N=pop) 83, Peter Haworth sub p{!grep!($o%$_),2..($o=pop)-1}p($_)*p($n-$_)&&exit print"$_+$o "for 3..($n=pop) 87, ccn (rejected) -l sub _{3>grep!($_[0]%$_),1..$_[0]}map{print$n++-$_,"+$_"if _($_)&_$n- $_}3..($n=pop)/2 88, antir for$/(2..9x4){@a=grep{$/+$_==$ARGV[0]&&print("$/+$_\n")+exit;1}@a,$/if!grep{!($ /%$_)}@a} 91, ccn -l sub _{3>grep!($_[0]%$_),1..$_[0]}map{_($_)&_($n-$_)&&(print"$_+",$n- $_)&exit}3..($n=pop)

6.6. Automatic Editing http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=42&season=1 The game started 2003-08-25 20:00:00 and ended 2003-08-30 19:00:00. Rules by http://acm.uva.es/p/v101/10115.html . Idea by tybalt89.

6.6.1. Rules Text-processing tools like awk and sed allow you to automatically perform a sequence of editing operations based on a script. For this problem we consider the specific case in which we want to perform a series of string replacements, within a single line of text, based on a fixed set of rules. Each rule specifies the string to find, and the string to replace it with, as shown below.

Edition 2007-01-09 top secret / strictly confidential page 313 of 520 Perlgolf History

Rule Find Replace-by 1. ban bab 2. baba be 3. ana any 4. ba b hind the g To perform the edits for a given line of text, start with the first rule. Replace the first occurrence of the find string within the text by the replace-by string, and then try to perform the same replacement again on the new text. Continue until the find string no longer occurs within the text, and then move on to the next rule. Continue until all the rules have been considered. Note that 1. when searching for a find string, you always start searching at the beginning of the text, 2. once you have finished using a rule (because the find string no longer occurs) you never use that rule again, and 3. case is significant. For example, suppose we start with the line banana boat and apply these rules. The sequence of transformations is shown below, where occurrences of a find string are underlined and replacements are boldfaced. Note that rule 1 was used twice, and then rule 2 was used once, then rule 3 was used zero times, and then rule 4 was used once. Before After banana boat babana boat babana boat bababa boat bababa boat beba boat beba boat behind the goat The input on STDIN contains one test case. Each test case consists of rules, which number will be between 1 and 10 and the text. Each rule is specified by a pair of lines, where the first line is the find string and the second line is the replace-by string. Following all the rules is a line containing the text to edit. Output to STDOUT a line containing the final edited text. Both find and replace-by strings will be at most 80 characters long, where character is a letter or a space. Find strings will contain at least one character, but replace-by strings may be empty (indicated in the input file by an empty line). During the edit process the text may grow as large as 255 characters, but the final output text will be less than 80 characters long. So strictly speaking, input will match /^([A-Za-z ]{1,80}\n[A-Za-z ]{0,80}\n){1,10}[A-Za-z ]{1,80}\n\z/, and output should match /^[A-Za-z ]{0,80}\n\z/. There will be no input that leads to endless loops, such as transformation 'a'->'a' for example. The test case in the sample input below corresponds to the example shown above. Example input:

Edition 2007-01-09 top secret / strictly confidential page 314 of 520 Perlgolf History

ban bab baba be ana any ba b hind the g banana boat Example output: behind the goat

6.6.2. Solutions 43, Bass (rejected) -ln <>=~$/?$a.="s/$_/$`/;"x255:eval$a|print 43, Bass -ln <>=~$/?$a.="s/$_/$`/;"x2e4:eval$a|print 44, mtve -p0 s/$`(?=.*$)/@a/ or$_=$' while@a=/ (.*) / 44, ton (rejected) -ln <>=~$/?$,.="s|$_|$`|;"x2e4:eval"$,print" 45, ton (alternative) -ln eval($~.=<>=~$/?" while s|$_|$`|;p":rint) 46, Bass -ln <>=~$/?$a.="{s/$_/$`/&&redo}":eval$a|print 47, Juho Snellman -p0 s/(.*) (.*) /$a.="s|$1|$2|;"x2e4/gee;eval$a 47, m.thelen -p0 s/(.*) (.*) /$,.="s~$1~$2~;"x4e5/eeg;eval$, 48, Juho Snellman (alternative) -p0 s/(.*) (.*) /${$a.="s|$1|$2|;"x2e4}/g;eval$a 49, m.thelen (alternative) -p0 s/(.*) (.*) /$,.="s!$1!$2!;"x4e4;''/eg;eval$, 49, aqumsieh (rejected)

Edition 2007-01-09 top secret / strictly confidential page 315 of 520 Perlgolf History

-0p s|(.*) (.*) |$s=$2;s/($1)(?=.*$)/$s/&&redo|eg 49, tybalt89 -p0 s/(.+) (.*) / s~.*#~~swhile s~$1~$2~;#/g;eval 49, mtve (alternative) -alp0F\n $_=pop@F;1while s/$;/$b/ or($;,$b,@F)=@F 49, tybalt89 (alternative) -lp0aF\n $_=pop@F;0while s/$;/$a/ or($;,$a,@F)=@F 50, Juho Snellman (alternative) -p0 s/(.*) (.*) /$a.="{s|$1|$2|&&redo}"/gee;eval$a 50, m.thelen (alternative) -p0 s/(.*) (.*) /$,.="1while s!$1!$2!;"/eeg;eval$, 51, Daniel -lp0aF\n $i+=2*!s/$F[$i]/$F[$i+1]/for($_=pop@F)x3e4 51, Jasper -lp0aF\n $i+=2*!s/$F[$i]/$F[$i+1]/for($_=pop@F)x999 51, alf -0p s/(.*) (.*) /1while s'$1'$2';/g,s,.+;,,s,eval$& 51, Amir Karger -nl $y.="s/$z/$_/;"x$^Hx$|--;$z=$_;eval$y;eof&&print 52, Michael Robinson -p0 s/(.*) (.*) /!($x.="{s|$1|$2|&&redo}")/eg;eval$x 52, Peter Haworth -lp $x=$x?!($z.="{s/$x/$_/&&redo}"):$_}{$_=$x;eval$z 53, Shlomi Fish -lap0F\n $_=pop@F;splice@F,0,!s!$F[0]!$F[1]!*2while@F 53, pom -lp0aF\n $_=pop@F;$.+=2*!s/$F[$.-1]/$F[$.]/while$.<@F 53, Jeff Moore

Edition 2007-01-09 top secret / strictly confidential page 316 of 520 Perlgolf History

-lp0aF\n $_=pop@F;$x+=2*!s/$F[$x]/$F[$x+1]/while$x<@F 54, aqumsieh -0p s|(.*) (.*) |$s=$2;s/($1)(?=.*$)/$s/&&redo|e&&redo 54, Jasper (alternative) -lp0aF\n @F=@F[2*!s/$F[0]/$F[1]/..99]for($_=pop@F)x9e4 54, Jasper (alternative) -lp0aF\n $_=pop@F;@F=@F[2*!s/$F[0]/$F[1]/..$#F]while@F 54, Colm Dougan -p0 eval"1while s/$1(.*)\$/$2\$1/"while s/(.*) (.*) // 57, dantie -lp @_=($_,@_)}($_)=@_;0while s/$_[-1]/$_[-2]/ or$#_-=2;{ 57, Arkady -0pl12aF $_=pop@F;for$c(@F){$k=$k?do{0while s/$k/$c/}:$c} 59, terje -lap0F\n $_=pop@F;eval"+s@@s@"x255while@s=splice@F,$"="@",2 59, m.wrenn -lp push@_,$_}{$_=pop@_;1while$a&&s/$a/$b/||(($a,$b,@_)=@_) 60, Ryan Zachry -lpa0F\n $_=pop@F;for$m(@F){++$x%2&&do{1while+s/$m/$F[$x]/}} 67, Team Creutz -l chop(@a=<>);for($_=pop@a;s/$a[0]/$a[1]/ or@a=@a[2..$#a];){}print 67, gibbering -lp push@l,$_}for($_=pop@l;($x,$y)=splice@l,0,2;1while s/$x/$y/){}{ 70, Chris Dolan @a=<>;$_=pop@a;s/$a[0]/$a[1]/||(@a=@a[2..$#a])while map chomp,@a;print 75, Korum -lp0 $r="(.*)\n";($a)=/$r$/;s/$r$r/$u=$1;$x=$2;0while$a=~s~$u~$x~/eg;$_=$a;

6.7. Align 2 http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=43&season=1 The game started 2003-09-02 21:00:00 and ended 2003-09-05 21:00:00. Idea by ton.

Edition 2007-01-09 top secret / strictly confidential page 317 of 520 Perlgolf History

6.7.1. Rules There are two columns of words. Left-justify the left column, and right-justify the right column, then squeeze as many spaces as possible out from between them while keeping at least one space on every line and keeping the justifications. So for input: waf zrsea abdef sedrgf a warfhjik You should output: waf zrsea abdef sedrgf a warfhjik Input will be on STDIN, no more than 10 lines, with two words separated by one space. Maximum word length is 10. Input matches /^([a-z]{1,10} [a-z]{1,10}\n){1,10}\z/, output should be the same but with "(space)+" instead of "(space)".

6.7.2. Solutions 38, ton -p0 s/$a|( )+/$&$1/gwhile$a.=".+",/$a/ 38, tybalt89 (post-mortem) -p0 s/$p+|( )+/$&$1/gwhile$p.='.',/$p/ 39, ton (alternative) -p0 s/$a.*|( )*/$&$1/g,$a.="."while/$a/ 40, Juho Snellman -p0 s| .*(?

Edition 2007-01-09 top secret / strictly confidential page 318 of 520 Perlgolf History

-p0 s/^(?!$G).* /$& /gmwhile$G.='.',/$G/ 41, argggh -p0 s/^(?!$i).* /$& /gm,$i.='.'while/$i/ 42, Daniel @l>(@l=/./g)&&s/ / /for(@a=<>)x30;print@a 45, tybalt89 (alternative) /.{$-}$/?$-="@+":s/ / /for(@F=<>)x22;print@F 45, Amir Karger -p0 1while/.{$^F}./?$^F++:s/^(?!.{$^F}).* /$& /m 46, Jasper (post-mortem) map{s/ /@a[y###c..@_]/;print}grep\$_[y///c],<> 47, ton (alternative) -p0 $a++;s! !$"x(/.*\G.*/+$a-length$&)||redo!eg 48, Jasper map{s/ /$&x(@_-length)/e;print}grep\$_[y///c],<> 49, Peter Haworth -p push@F,$l[y///c]=$_}for(@F){s/ /@s[y###c..@l]/ 50, Bass map{s/ / /while$b=y///c,map/.{$b}/,@a;print}@a=<> 52, p.kailasa map{s/ / /while($_^$l)=~/ $/;print}map{$l|=$_;$_}<> 53, ccn map{s} } }while"@:"=~/\S.{@{[y]]]c-1]}}/;print}@:=<> 53, pom -p0 s/.*/$&^$_^$_/ge;$a=$"x/\w /while s/( .+)\x00/$a$1/g 54, aqumsieh map{$y=y|||c;map{s/ / /while$y>y|||c}@_}@_=<>;print@_ 59, gibbering -naF| \@@[@F+U,$K[$.]=$_]}{s/ /$&x(@@-length)/e,print for@K 60, m.thelen -p0 $,|=$"x y///cfor/.*/g;s/.+/$&|$,/eg;s/(\S+)( *) /$2$1 /g 61, Jean-Pierre Vidal (post-mortem) $,=s///g>$,?s///g:$,for@t=<>;s/ /$&x($,-length)/e&print for@t 61, Jean-Pierre Vidal

Edition 2007-01-09 top secret / strictly confidential page 319 of 520 Perlgolf History

$,=s///g>$,?s///g:$,for@t=<>;s/ /$&x($,-length)/e&print for@t 63, Ryan Zachry -lna0F\n $l["@+"]=/.*/for@F;/ .*/,print$`.$"x($#l-"@+").$&for@F 63, Team Creutz -p0 for(;/\w$/m;s/^($d)$/$1 /gm,$d.='.'){}s/ (\w+)( +)$/$2$1/gm 66, Frantisek Darena map{$m=length if$m;s/ /$"x(1+$m-length)/e,print for@w 82, Jurgen Pletinckx $m;for(@a=<>){$l=length;$m=$l if$m<$l}for(@a){$n=' 'x($m+1-length);s/ /$n/;print}

6.8. Perl Bowling http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=44&season=1 The game started 2003-09-03 17:00:00 and ended 2003-09-08 10:02:00. Rules by kernelpanic. Idea by tybalt89.

6.8.1. Rules This golf runs in parallel with PCLP#20 (see section 8.17), perlgolf running on polish site kernelpanic1. We've stole their idea and testsuit. Well, you should know standard bowling scoring. Example input: 12341234123412341234 Output: 50 Another example input: 10 10 10 10 10 10 10 10 10 10 10 10 Output: 300 Input will be in @ARGV, from 11 to 21 numbers each between 0 and 10. Print to STDOUT resulting score, that should match /^\d+\n\z/.

6.8.2. Solutions 54, mtve (rejected) $"='+';print/10.1.*1/*360/("@-"+2&6)+eval,$/for"@ARGV" 64, mtve (rejected)

1 http://www.kernelpanic.pl/index.mx

Edition 2007-01-09 top secret / strictly confidential page 320 of 520 Perlgolf History

-l print~~map{map$?+=$?>9?$ARGV[$_]:$_&&shift,!``,1,0;1..$?}a..j 64, mtve (post-mortem) -l print~~map{map$!+=$!>9?$ARGV[$_]:$_&&shift,!``,1,0;1..$!}a..j 65, Daniel (post-mortem) -l for$s(a..j){map$s+=$s>9?$ARGV[$_]:$_&&shift,2,1,0;$_+=$s}print 65, mtve (post-mortem) -l print~~map{map$@+=$@>9?$ARGV[$_]:$_&&shift,eval,1,0;1..$@}a..j 66, tybalt89 -l print eval'+($a=$a>9?$r:shift)+($r=shift)+"@ARGV"*($a+$r>9)'x10 68, Daniel -l $r+=$s,$s=0,map$s+=$s>9?$ARGV[$_]:$_&&shift,2,1,0for-1..9;print$r 68, Jeff Moore -l $s+=(($_=shift)+=//?$ARGV[1]:shift)+//*"@ARGV"for/\B/..10;print$s 73, Andreas ($f,$s,$t)=@ARGV,shift>9||shift,$o+=($f+=$s)+$t*($f>9)for a..j;print$o,$/ 75, michalj -l for$w(a..j){$w>9?($t+=$ARGV[-$_]):($w+=$_&&shift)for-2..0;$t+=$w}print$t 76, Kevin Scaldeferri -l map{($s+=$p=$ARGV[1]+($n=shift))+=$p>9&&$ARGV[1];$n>9||shift}0..9;print$s 89, Daniel Cutter $s+=($a=shift)+($b=$a<10&&shift)+($a+$b>9&&$ARGV[0])+($a>9&&$ARGV[1])for- 9..0;print"$s\n" 93, Chris Dolan -l $_+=($b=shift)+($b-10?($b+$ARGV[0]- 10?0:$ARGV[1])+shift:$ARGV[0]+$ARGV[1])for($_)x10;print 128, Matthias Schoder -l for(0..9){($a,$b,$c)=@ARGV[$r..$r+2];if($a==10){$s+=10+$b+$c}elsif($a+$b==10 ){$s+=10+$c;$r++}else{$s+=$a+$b;$r++}$r++}print$s 147, Team Creutz -l for(@ARGV){if($b){$t+=$_ if$a>1;$b=0;$a=$_+$p>9}else{$t+=$_ if++$c<11&&$a;$t+=$_ if$c<12&&$a>3;$a=0if$a==1;$_<10?$b=1:$a+=2;$p=$_}$t+=$_}print$t

6.9. Huffman codes http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=45&season=1 The game started 2003-09-11 15:00:00 and ended 2003-09-16 19:00:00. Idea by gibbering.

Edition 2007-01-09 top secret / strictly confidential page 321 of 520 Perlgolf History

6.9.1. Rules Following theory text was taken from http://people.cs.und.edu/~mschroed/jpeg.html#APPENDIX_A . You may skip it. The Huffman encoding scheme was developed by David A. Huffman1 in 1952. The algorithm outlined by Huffman achieves data compression by encoding data based on its frequency. The data structure used to actually encode the data is a weighted binary tree, or Huffman tree. A Huffman tree has several unique properties: 1. A Huffman tree must be a binary tree. 2. A Huffman tree is weighted; elements appearing often in the data stream are towards the top of the tree while rarer occurring elements sink to the bottom of the tree. 3. Each left branch of a Huffman tree is assigned a value of zero, and each right branch of a tree is assigned a value of 1 (or vice versa). In order to construct a Huffman tree, two passes must be made through the data. On the first pass, a list of unique data elements and their frequencies is constructed. This is sorted in ascending order, thereby putting the most frequently occurring data elements at the end of the list. Next, the actual Huffman tree is constructed. The tree is built by taking the two elements with the lowest frequencies and making them the leaves of a tree. The parent of the two leaves is the sum of the leaf's frequencies. The tree is then inserted into the list (the parent node's value is used to determine where to insert the tree), and the two leaves used to make the tree are removed from the list. This process continues until there is only one element left in the list, which is the parent node of the final Huffman tree. Before the Huffman tree can be used to encode the data, a way to uniquely identify each value in the tree must be established. This is done by assigning each left branch in the tree a value of zero and each right branch in the tree a value of one. Now it is possible to uniquely identify each element in the tree by using the 0's and 1's assigned to the tree's branches. A table containing the unique code for each leaf in the Huffman tree is generated by traversing the tree and outputting a zero each time a left branch is taken or outputting a one (1) each time a right branch is taken. Normally the Huffman tree is traversed backwards, starting at the desired leaf. This is because the resulting code's first bit MUST start from the top of the tree. The only step that remains is to pass through the original data again and output to file each data element's associated Huffman code. Since the Huffman code representation of most (if not all) data elements is smaller than the data element itself, data compression is achieved. Since the output file contains Huffman codes, the original encoding information (like the Huffman tree or the data table generated from the Huffman tree) must also be stored in the output file in order for decompression to be possible. Let's look at an example of how the Huffman tree data structure is constructed and used to compress data. Suppose we have the following list of characters and their respective frequencies of occurrence:

1 http://www.soe.ucsc.edu/people/faculty/huffman.html

Edition 2007-01-09 top secret / strictly confidential page 322 of 520 Perlgolf History

Character Frequency b7 d13 a17 c22 g45 e77 f90 Notice that the above table is sorted by frequency in ascending order. This is how the list MUST be sorted in order to utilize the Huffman algorithm. Now, let's re-write the table in a linear list, being careful to maintain the list's ascending order : Step 1:

Now, we construct a tree from the two values with the lowest frequencies. Each value becomes a leaf and the parent of the two leaves is the sum of the leaf's frequencies. The list is now re-constructed, again making sure that it is sorted by frequency: Step 2:

Continue constructing new trees from the two lowest frequencies in the list. The remaining steps to building a Huffman tree in this example are given below: Step 3:

Step 4:

Step 5:

Edition 2007-01-09 top secret / strictly confidential page 323 of 520 Perlgolf History

Step 6:

Step 7:

There is one final modification to the Huffman tree that must be made before the newly constructed tree can be used to encode data. In order to produce unique codes for each character, a zero is assigned to each left branch in the tree and a one (1) is assigned to each right branch in the tree. The final Huffman tree looks like this:

Edition 2007-01-09 top secret / strictly confidential page 324 of 520 Perlgolf History

The character codes for the above tree are: Character Code b 01110 d 01111 a 0110 c 010 g00 e10 f11 Now you can use the derived Huffman codes for your original values. Notice that the Huffman codes for these characters are all shorter than the standard 8-bit ASCII representation of a character. Thus, when these values are written to file, data compression will occur. The task In this golf you should calculate canonical Huffman code for given frequencies determined by the algorithm above, so for example input 7131722457790 Output will be 01110 01111 0110 010 00 10 11 The input is chosen so that at no step any of the top weights are equal. And since the lowest weight becomes the left subtree, this makes the output unique. Input is on STDIN, consisting of 2 to 9 natural numbers arranged in ascending order, all separated by spaces with a final newline. The numbers can range from 1 to 99. Output should be on STDOUT, binary codes for corresponding input numbers, again separated by spaces with a final newline. Strictly speaking, input will match /^([1-9]\d? ){0,8}[1-9]\d?\n\z/, and output should match /^([01]+ ){0,8}[01]+\n\z/.

6.9.2. Solutions 72, mtve (post-mortem) -p sub b{$b++;s/\b$b\b/b-$#_/g?$b:&b}$s=b(s/b/$s/g)+b while/ \d/;y/-b//d 73, mtve (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 325 of 520 Perlgolf History

-p sub b{$b++;s/\b$b\b/b;$#_/g?$b:&b}$s=b(s/b/$s/g)+b while/ \d/;y/b;-//d 74, mtve (post-mortem) -p sub b{$b++;s/\b$b\b/b;@_/g?$b:&b}s/b/$s/g,$s=b(0)+b 1while/ \d/;y/b;//d 76, stalker -pa sub b{$b++;s/\b$b\b/b;@_/g?$b:&b}s/b/$s/g,$s=b(0)+b 1while$#F--;y/b;//d; 82, ton (rejected) -ap @;[@F]=@F}{$\="@r[@F] ",$;[eval]=$_.="+$`"x$|x!!map$_=--$|.$_,@r[/.*?\b/g]for@ 83, ton -ap @;[@F]=@F}{$\="@r[@F] ",$;[eval]=$_.=".+$`"x(s#\b#$r[$']!~s/^/$|/#eg&&$|--)for@ 85, mtve -pa ($~,$;,@F)=sort{$a-$b}@F,($c=$~+$;)x!!s/\b$~\b|\b($;)\b/$c,$#- /gwhile$;;s/$c|,//g 86, Juho Snellman -pa ($a,$b,@F)=sort{$a-$b}@F,$^T;$^T=$a+$b;s/\b$b\b/$^T- /g?s/\b$a\b/$^T,/g+do$0:y/,-9/01/d 87, tybalt89 -lpa @1[@F]=@F;$_?@{s//$./for@r[@_];split;$.^=1}[eval$t]=$t="$_ +@_":0for@1;$_="@r[@F]" 88, Daniel -pa s/\b(?:$x|($y))#?\b/$z#$#-/gwhile(($x,$y,@F)=sort{$a- $b}@F)^push@F,$z=$x+$y;s/$x#//g 90, RobTM -p s/\b($m(a|\b)|(a))/$|?$m+$n.a.!$3:a0/ge,$|--while$n=$m,($m)=sort{$a- $b}/\b\d+/g;s/a.//g 98, Andreas -pa @p[@G]=(($F[1]+=shift@F).O,$F[0].l)while(@G=@F=sort{$a-$b}@F)>1;1while s/\d+/$p[$&]/e;y/Ol/01/ 99, Szeryf -pal sub r{my($u,$v,@L)=@_;r(sort{$a-$b}@L,$u+$v)if@L;$X[$_]=$X[$u+$v].$|-- for$u,$v}r@F;$_="@X[@F]" 104, Jasper -lpa $_="@_",s/ /+/while//&&map{s/^/$|/for@h{/\d+/g};--$|}(@_=sort{eval"$a- ($b)"}split)[0,1];$_="@h{@F}" 120, Karsten Sperling -pal for(2..(@f=@F)){for$x(0,1){s/^/$x/for@c[$f[$x]=~/\d+/g]}@f=sort{$a- $b}$f[0]+$f[1]." @f[0,1]",@f[2..$#f]}$_="@c[@F]" 138, Jeff Moore

Edition 2007-01-09 top secret / strictly confidential page 326 of 520 Perlgolf History

-lpa {for$f(0,reset nz){$n+=$_=shift@F;s/^.* ?| / $f/g;$z.=$_}(@F=sort{$a-$b}@F,$n.$z)>1&&redo}$_=join$",sort{$b=~y///c- length$a}$z=~/.+/g 145, Chris Dolan -alp $a{shift@F}=$a{shift@F}=$.=$F[0]+$F[1],@F=sort{$a- $b}@F,$.while$#F;$_="@{[map{my$z;do{$z=int($a{$_}<$_*2).$z}while$a{$_=$a{$_} };$z}/\d+/g]}" 154, Dan Flyer aka KarieZ for(@i){@x=@i;$e=$_;$r="";while($#x){$u=($f=shift@x)+($s=shift@x);if($f==$e){$r =0 .$r;$e=$u}if($s==$e){$r=1 .$r;$e=$u}@x=sort{$a<=>$b}(@x,$u)}push(@o,$r)} 154, Skeeve -l split' ',<>;@a=map{@a=@_;$i=$r='';$j=$_;while($i<$#a){$s=$a[$i]+$a[$i+1];map{($j,$r )=($s,$_.$r)if$a[$i++]==$j}0,1;@a=sort{$a<=>$b}@a,$s}$r}@_;print"@a"

6.10. PERT/Gantt chart conversion http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=46&season=1 The game started 2003-10-25 23:00:00 and ended 2003-10-28 19:00:00. Idea by tybalt89.

6.10.1. Rules Your task is to convert some schedule from one format to another. Fortunately it's not from Micro$oft Project to Cry$tal Reports nor back. PERT (Program Evaluation and Review Technique) and Gantt (named after Henry Gantt) are two simple formats. Pert is defined here as a list of tasks with each task on one line, where task defined by ID (increased number beginning from 1), length (in some conventional units) and prerequisites (ID's of previous tasks on which this task is depended). A Gantt diagram is just a graphical chart that visually shows when each task can begin and when it ends. For example, given this PERT data as input: 14 251 362 43 544 655 72123456 The resulting Gantt chart should be:

Edition 2007-01-09 top secret / strictly confidential page 327 of 520 Perlgolf History

1 ---- 2 ----- 3 ------4 --- 5 ---- 6 ----- 7-- On STDIN there will be at least one but no more than 9 lines, with a few numbers separated by one space and terminated by a newline: task ID (which is consecutive and equal to line number), task length (number from 1 to 8), and prerequisites in ascending order (so no more than 8 prerequisites). The tasks are already sorted for you, so all prerequisites have a value lower than the current ID. Regex for input is /^([1-9] [1-8]( [1-8]){0,8}\n){1,9}\z/ The output for each task should be: task ID, space, some spaces to pad to the end of longest prerequisite, some minus signs to show task length and a newline. Regex for output is /^([1- 9] {1,65}-{1,8}\n){1,9}\z/

6.10.2. Solutions 57, ton -paF^...| $a[$`]=@;[@a[@F]]-=@;=$&+s/ .*/$"x@;."-"x$&/e*@ 57, ton (rejected) -pa $a[$`]=@;[@a[@F[2..9]]]-=@;=$&*s/ .*/$"x@;."-"x$&/e+@ 57, terje (rejected) -pa \@F[@a[@F[2..9]]];$a[$_]=$&- s/ .*/$"x$#F."-"x$&/e+@F 57, terje (post-mortem) -lpa \@;[@e[@F[2..9]]];@;=$e[$_=$..$"x@;."-"x$']=$'-/ /+@ 58, ton (alternative) -pa \@;[@a[@F[2..9]]];@;=$a[$`]=$&- s/ .*/$"x@;."-"x$&/e+@ 58, terje (post-mortem) -lpa \@q[@e[@F[2..9]]];@q=$e[$_=$..$"x@q."-"x$']=@q-/ /+$' 59, terje (rejected) -lpa \@F[@e[@F[2..9]]];$e[$.]=@F-/ /+$';$_=$..$"x$#F."-"x$' 60, mtve -lpa @s=++$a;\$s[@$_]for/^...|./g;$_="@s ".'-'x$F[1];@$a=//g 60, Jasper -ap @a=!s! .*!\@a[@p{@F[2..9]}];$p{$`}=$#a+$&;" @a".'-'x$&!e 61, Juho Snellman -pa s^ .*^(sort@L[@F[2..9]],b)[8].a x$&^e;$L[$.]=b x y/ab/- / 62, Bass -pl $a[$.]|=$"x$a[chop]=~y///cwhile/ . /;s/.$/$a[$.].="-"x$&/e 62, terje

Edition 2007-01-09 top secret / strictly confidential page 328 of 520 Perlgolf History

-lpa @q=/ /;\@q[@e[@F[2..9]]];$e[$_]=$#q+$';$_=$..$"x@q."-"x$' 63, Daniel -pla ($m,$n,@f)=@F;$m|=$_&$"x70for@l[@f],pp;$_=$l[$.]=$m.'-'x$n 63, Shlomi Fish -pla $e[$_="$. $n"]=($n=(sort@e[@F[2..9]])[-1]."-"x$F[1])&$"x80 64, Jasper (alternative) -ap s# .*#$p{$`}|=$"x y///cfor@p{@F[2..9]};$".($p{$`}.='-'x$&)#e 64, RobTM -apl $_=(sort map"$. @$_",@F[2..9])[-1].'-'x$F[1];$#{$.}=y///c-2 65, jas -pal $h[$_="$. $x"]=$"x99&($x=(sort@h[@F[2..$#F]])[-1].'-'x$F[1]) 68, Qtax -lp $,=s/ .//;$_>$,?$,=$_:0for@a[split];$a[$_=$`.$"x$,.'-'x$&]=$&+$, 72, aqumsieh (post-mortem) -lpa / ./;$_="$` ".$"x(sort{$b-$a}@l[@F[2..9]])[0].'-'x$&;$l[$`]=y|||c-2 76, o0lit3 (post-mortem) -lpa $s=(sort{$b-$a}@e[@F[2..9]])[0];$e[$_=$F[0].$"x++$s."-"x$F[1]]=$F[1]+$s 77, pom -pla $_=(sort map{$"x$g[$_-1]}@F[2..$#F])[-1]."-"x$F[1];push@g,y///c;s/^/$. / 80, Grizzley (post-mortem) -lna $s=(sort{$a-$b}@e[@F[2..9]])[-1];print$.,$",$"x$s,'- 'x$F[1];$e[$.]=$s+$F[1] 81, o0lit3 (post-mortem) -lpa $s=1;map{$s=$e[$_]if$e[$_]>$s}@F[2..9];$e[$_=$F[0].$"x$s."- "x$F[1]]=$F[1]+$s 86, Grizzley (post-mortem) -lna $s=0;($i,$l,@d)=@F;map{$s=$_ if$s<$_}@e[@d];print"$i ",' 'x$s,'- 'x$l;$e[$i]=$s+$l 90, Jurgen Pletinckx -anl ($n,$l,@F)=@F;$m=0;map{$m=$t[$_]if$t[$_]>$m}@F;$t[$n]=$m+$l;print$n,' 'x($m+1),'-'x$l 90, Grizzley -lna ($i,$l,@d)=@F;map{$e[$i]=$_}sort{$a-$b}@e[@d];print"$i ".' 'x$e[$i].'- 'x$l;$e[$i]+=$l 92, o0lit3 (post-mortem) -lna my$s;map{$s=$e[$_]if$e[$_]>$s}@F[2..9];$e[$F[0]]=$s+$F[1];print$F[0]." "x++$s."-"x$F[1] 121, o0lit3

Edition 2007-01-09 top secret / strictly confidential page 329 of 520 Perlgolf History

-n split;$i=shift@_;$l=shift@_;my$s;map{$s=$e[$_]if($e[$_]>$s)}@_;$e[$i]=$l+$s; print$i,(map" ",0..$s),(map"-",1..$l),"\n"

6.11. LED reader http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=47&season=1 The game started 2003-11-03 18:20:00 and ended 2003-11-08 21:00:00. Rules by jasper.

6.11.1. Rules Apologies to whoever gave us “LED Display” (see section 5.20). Given a number composed of 1 to 20 digits in "LED" (each digit is 3 cells wide and 5 deep) format (matching /^([# ]{3}( [# ]{3}){0,19}\n){5}\z/) on STDIN, output on STDOUT the corresponding number (matching /^\d{1,20}\n\z/). The 5 lines on STDIN will (of course) be of equal length. Input digit will be single space separated, while output will contain no spaces. So if the input is: ### # ### ### # # ### ### ### ### ### ### ## # # #### # ##### # # # # ### ### ### ### ### # ### ### ### ## ## # # ### ### ## ### # ### ### # ### ### # ### ### ### The output should be: 01234567892

6.11.2. Solutions 54, Eirik Berg Hanssen (post-mortem) -lp s\#\++vec$a,$./2^pos,2\ge}{$_=$a;y/\xFF\x92\xFB\xE8\x98\xAC\xBC\x97\xFC\xEC/ 0-9/ 56, Juho Snellman -lp s\#\++vec$a,$./2^2*pos,1\ge}{$_=$a;y/\x14\x10^\x1A\x198<\x15\x1C\x18/0-9/ 57, ton -p s/....?/(1e2.$.|$&)%9/eg;$\^=$_}{$\=~y/=<694:38>7/0-9/ 61, ton (alternative) -p s/....?/o&chr($..22|$&)/eg;$a^=$_}{$_=$a;y/CK@%a(LmM)/0-9/ 63, Eirik Berg Hanssen -p y; #;02;;s;(...).?;chr$1/$.;ge;$\^=$_}{$\=~y;\xE6\x03\x8B\xB9\xE5\xDC\xEE\xDF\x EF\xDD;0-9; 64, mtve

Edition 2007-01-09 top secret / strictly confidential page 330 of 520 Perlgolf History

-p s#....?#_&chr$.*($&^"\x10"x3)#eg;$a^=$_}{$_=$a;y/\x03\x0F\x1D\x01\x15_OAIY/0 -9/ 66, tybalt89 -p s/#/$./g;s/... ?/vec'\x01Er6IX',($&|'0')%106%11,4/gefor$\=$p^=$_}{ 72, Michael Rybakin -ln s/#/$./g;$s^=$_}{print map$- [y/7$%/2/d,"\x0B\x01\x00\xDD\x1F\x02\x0Coy\x15"!~chr],$s=~/\S+/g 77, Samy Kamkar -nl s|.|$x[$_/4]+=$&=~/#/*$.**($_++%4)|eg}{print+map{index'B74C=@A9ED',chr}@x 82, Krzysztof Koczyjan -nl y/# /10/;@a=map.7*shift(@a)+oct,/(...).?/g}{print map{index"\xBE\x02\xAB\x7FK\x94\xC1\x14\xC2\x95",chr}@a 82, Karsten Sperling -p s/./$x[.25*pos].=$&/seg}{s/###//g,$\.=index'U"\x12\x10\xAA@B\x11RP',pack B8,$_ for@x;$\.=$/ 83, andys -lp0 y/# /12/;$a.=(join"",/^.../mg)%651%10;s/^....//mg&&redo;$_=$a;y/386392517/1-9/ 90, Szeryf -pl s/ /$./g;$s^=$_}{$s=~s/$_.?/$?/g,$?++for'#5#11#2%4%%#"!#4%2#%2####%#4%#'=~/.../ g;$_=$s 94, Jeff Moore -l $y=0,map$;[$y++].=$_,/(...)./sgfor<>;print map{index'\xEE$\xBA\xB6t\xD6\xDE\xA4\xFE\xF6',pack"B*",join'',/.(.)/g}@; 100, o0lit3 (post-mortem) -ln y/ #/01/;@;=map{shift(@;).$_}/(...).?/g}{print map{index('\xF6\xDE$\x92\xE7\xCE\xE7\x9E\xB7\x92\xF3\x9E\xF3\xDE\xE4\x92\xF7 \xDE\xF7\x9E',pack B16,$_)/2}@ 100, Jasper -lp0 y/# /10/;$a.=(index"o{\$I\xE7s\xE7y\xEDI\xCFy\xCF{'I\xEF{\xEFy",pack"b15",join'' ,/^(...).?/mg)/2,s///gwhile/./;$_=$a 104, david seed aka gimbo -nl y/# /10/;@a[$i++]+=$_*$.for/(...).?/g;$i=0}{$k{+ord}=$i++for"'\x0Fy\xED\x85\xB3C }E\xB5"=~/./g;print@k{map$_%256,@a} 105, o0lit3 (rejected) map{$i=0;y/ # /01/;map{$x[$i++].=$_}/(...)./g}<>;print map{index('\xF6\xDE$\x92\xE7\xCE\xE7\x9E\xB7\x92\xF3\x9E\xF3\xDE\xE4\x92\xF7 \xDE\xF7\x9E',pack B16,$_)/2}@x 108, o0lit3

Edition 2007-01-09 top secret / strictly confidential page 331 of 520 Perlgolf History

-l map{$i=0;y/ # /01/;map{$x[$i++].=$_}/(...)./g}<>;print map{index('\xF6\xDE$\x92\xE7\xCE\xE7\x9E\xB7\x92\xF3\x9E\xF3\xDE\xE4\x92\xF7 \xDE\xF7\x9E',pack B16,$_)/2}@x 109, pom -lp $k=0;map$;[$k++]+=(/ #/+2*/# #/+3*/# /)<<2*$.,/....?/g}{$_=join"",map{index"\xA8U\xC4DJL\x8CT\x88H",chr($_/4&255) }@ 112, o0lit3 (rejected) map{$i=0;y/ # /010/;map{$x[$i++].=$_}/..../g}<>;print map{('0432689715'=~/./g)[index'\xEA\xAA\xE2\xE2\xE8\xEA\xEA\xE2""',pack B16,$_]}@x 114, o0lit3 (rejected) map{$i=0;y/ # /010/;map{$x[$i++].=$_}/..../g}<>;print map{index('19814232939003242209',substr(oct"0b$_",3,2))/2}@x 116, J.P. (rejected) map{y/# /100/;$u=0;map{chop;$p[$u++].=$_}/...0/g}<>;map{$_=oct"0b$_";print index'w&%^c:G_\O',chr((chop.chop)+20)}@p 121, J.P. -l map{y/# /100/;$u=0;map{chop;$p[$u++].=$_}/...0/g}<>;print map{$_=oct"0b$_";index'w&%^c:G_\O',chr((chop().chop)+20)}@p 170, Frantisek Darena -l while(<>){$i=0;while($x=substr$_,0,4,''){$j=0;$j++,$x[$i]+=/#/&&$j**$.for$x= ~/./g;$i++}}print map{402,0,363,1,328,2,408,3,374,4,400,5,401,6,366,7,410,8,409,9}->{$_},@x 171, Frantisek Darena -l while(<>){$i=0;while($x=substr$_,0,4,''){$j=0;$j++,$x[$i]+=/#/&&$j**$.for$x= ~/./g;$i++}}print map{402,0,363,1,328,2,408,3,374,4,400,5,401 ,6,366,7,410,8,409,9}->{$_},@x 208, Jurgen Pletinckx @a=<>;map{y/ /0/;push@b,split//,$_}@a;$m=@b/5;while($p<$m){$a=$b[$p+2+$m];$b=$b[$p+3*$m]; $_=$b[$p]?$b[$p+1]?$b[$p+4*$m]?$b[$p+1+2*$m]?$b[$p+2+3*$m]?$b[$p+$m]?$a?$b?8 :9:$b?6:5:3:2:0:7:4:1;print;$p+=4}print"\n"

6.11.3. Explanation by Juho Snellman Newsgroups: perl.golf Date: Mon, 10 Nov 2003 13:02:01 +0200 Subject: LED reader solutions Message-ID: <[email protected]> From: [email protected] (Juho Snellman)

Edition 2007-01-09 top secret / strictly confidential page 332 of 520 Perlgolf History

I'm suprised at how different all the solutions for the LED reader minigolf were. Most solutions of course had the same basic approach of somehow hashing the led characters into a single byte, and then transforming the bytes into the correct ascii characters. (The main exception being tybalt who somehow managed to hash directly to the correct bytes.) Anyway, here's an explanation of my solution. There's a cute trick with vec() that I haven't seen used before (found with the usual approach of "pure luck"). The solution: -lp s\#\++vec$a,$./2^2*pos,1\ge}{$_=$a;y/\x14\x10^\x1a\x198<\x15\x1c\x18/0-9/ [The contents of the y/// are of course actually raw bytes, but they probably wouldn't fare too well in email transit... ] The hashing is done by finding all "#":s on a line, and modifying a corresponding bit in the output string with a vec in lvalue context. The bit to modify is calculated from pos and $. using the formula ($./2)^(2*pos). The results from this operation can be visualized with the following table: 024 0 024 1 135 1 135 2 206 2 206 As is apparent from the table, multiple "#":s can map to the same bit. The cute trick I mentioned earlier is using ++ on vec, which effectively flips the value of the bit between 0 and 1 on each invocation (thanks to vec truncating the value). For example '0': ### ## # # => 0, 1, 1, 2, 2, 2, 0, 4, 5, 5, 6, 6 => 0010100 ## ### This turns out to be unique for each led character. I originally used addition instead of xor for combining $. and pos, but that had the unfortunate side-effect of hashing one of the characters to "-", which required escaping when embedded in the y///. -- Juho Snellman

6.12. Reversi - Yet Another 2D Perl Golf http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=48&season=1 The game started 2003-11-17 17:00:00 and ended 2003-11-21 20:00:00. Rules by Juho Snellman.

6.12.1. Rules Two players (o and x) are playing a game of Reversi on an 8 by 8 board. On a player's turn, he places a piece into an empty space on the board. For the placement to be valid, at least one of the opponent's pieces must be outflanked. A row of pieces is outflanked when it is surrounded on both ends by the other player's pieces, and one of those pieces is the newly played one. The outflanked row can only

Edition 2007-01-09 top secret / strictly confidential page 333 of 520 Perlgolf History

contain one player's pieces, and can't contain any empty spaces. The row may run either vertically, horizontally or diagonally. For example: playing an "o" into the space marked by a "*" would result in the three "x" pieces being outflanked: ...... *xxxo...... Playing an "o" into the space marked by a "*" wouldn't outflank any pieces (the row between the "*" and the rightmost "o" contains an "o" piece in addition to the two "x" pieces), and wouldn't therefore be a valid placement: ...... *oxxo...... The program receives on STDIN an 8 by 8 board, where empty spaces are marked with ".", your pieces by "o" and the opponent's pieces by "x". The rows of the board are separated by newlines. The input will therefore match the regular expression /^([ox.]{8}\n){8}\z/. The task is to print to STDOUT the same board, with one additional piece of information: for any empty spaces that you could validly play an "o" piece on, you should print a "*" instead of a ".". The output will therefore match /^([ox.*]{8}\n){8}\z/. For example, given the following input: ...... ox... ..oox...... x...... The program should output: ...... *.. ...ox*.. ..oox*...... x*...... *......

6.12.2. Solutions 61, tybalt89 -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/swhile$^C+=9870=~/./g 61, mtve -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/swhile$^C-=7890=~/./g 61, ton -p0 s/\.(?=.{$&}(x.{$&})+o)/*/swhile$_=reverse,$=-=7890!~/./g 61, ton (rejected)

Edition 2007-01-09 top secret / strictly confidential page 334 of 520 Perlgolf History

-p0 s/\.(?=.{$&}(x.{$&})+o)/*/swhile$_=reverse,--$^D=~/[0789]/ 62, ton (alternative) -p0 s/\.(?=.{$1}(x.{$1})+o)/*/sgwhile$_=reverse,9870=~/(.)??/g 62, ton (alternative) -p0 s/\.(?=.{$&}(x.{$&})+o)/*/sgwhile$_=reverse,998877e3=~/./g 62, ton (rejected) -p0 s/\.(?=.{$&}(x.{$&})+o)/*/sgwhile$_=reverse,(73/813)=~/./g 62, Eirik Berg Hanssen -p0 s/\.(?=.{$&}(x.{$&})+o)/*/sgwhile$_=reverse,789789e3=~/./g 63, Andreas (rejected) -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/gswhile(643/813)=~/./g 63, o0lit3 (post-mortem) -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/gswhile 99887700=~/./g 63, Andreas -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/gswhile 98700789=~/./g 63, Bass -p0 $_=reverse,s/\.(?=(.{$&}x)+.{$&}o)/*/gswhile+98700789=~/./g 64, ton (alternative) -p0 $n=$^H/-64%10,$_=reverse,s/\.(?=.{$n}(x.{$n})+o)/*/swhile$^H-- 64, Jeff Moore -p0 for$n(0,0,(7..9)x2){$_=reverse;s/\.(?=.{$n}(x.{$n})+o)/*/sg} 64, RobTM -p0 for$i(0,0,(7..9)x2){s/\.(?=(.{$i}x)+.{$i}o)/*/gs;$_=reverse} 64, terje -p0 for$i((0,0,7..9)x98){$_=reverse;s/(o.{$i}(x.{$i})+)\./$1*/s} 64, Jasper -p0 for$m((0,0,7..9)x2){$_=reverse;s/\.(?=(.{$m}x)+.{$m}o)/*/sg} 64, Jasper (alternative) -p0 for$m((7..9)x24){$_=reverse;s/\.(x+|(.{$m}x)+.{$m})o/*$1o/s} 64, Grizzley -0p for$w((0,0,7..9)x44){s/(o.{$w}(x.{$w})+)\./\1*/s;$_=reverse} 66, Krzysztof Koczyjan -p0 eval'for$a(0,7..9){s/\.(?=(.{$a}x)+.{$a}o)/*/gs}$_=reverse;'x2 66, Krzysztof Koczyjan (alternative) -p0 eval'$_=reverse;for$a(0,7..9){s/\.((.{$a}x)+.{$a}o)/*$1/s}'x98 66, wmeriic

Edition 2007-01-09 top secret / strictly confidential page 335 of 520 Perlgolf History

-0p eval'$_=reverse;for$i(0,7..9){s/\.(?=(.{$i}x)+.{$i}o)/*/gs}'x2 76, m.thelen -p0 for$~(map"((.{$_}x)+.{$_})",0,7..9){s/o$~\./o$1*/s|s/\.$~o/*$1o/s&&redo} 79, o0lit3 -p0 s|\.|(map{$x=$_;map$x=~/^(.{$_}x)+.{$_}o/s,0,7..9}$',~~reverse$`)?'*':$&|ge 89, mascara -p0 for$l(($.=split,$.++,$.- 2,0)x15){$"="((.{$l}x)+.{$l})";s/o$"\./o$1*/s;s/\.$"o/*$1o/s} 102, o0lit3 (post-mortem) -p0aF| s|\.|(map{$i="@-";$x=$_;"@F[map{($i+=$x)<0?8:$i}1..7]"=~/^(x )+o/}-10..- 8,-1,1,8..10)?'*':$&|eg

6.13. Entropy compress http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=49&season=1 The game started 2003-12-03 19:52:00 and ended 2003-12-06 20:00:00. Rules by http://acm.uva.es/p/v2/245.html . Idea by tybalt89.

6.13.1. Rules A simple scheme for creating a compressed version of a text file can be used for files which contain no digit characters. The compression scheme requires making a list of the words in the uncompressed file. When a non-alphabetic character is encountered in the uncompressed file, it is copied directly into the compressed file. When a word is encountered in the uncompressed file, it is copied directly into the compressed file only if this is the first occurrence of the word. In that case, the word is put at the front of the list. If it is not the first occurrence, the word is not copied to the compressed file. Instead, its position in the list is copied into the compressed file and the word is moved to the front of the list. The numbering of list positions begins at 1. For the purposes of this problem, a word is defined to be a maximal sequence of upper- and lower-case letters. Words are case-sensitive - the word abc is not the same as the word Abc. Word can not be split over two lines. In perl terms, word is \w+. Write a program that takes an uncompressed file as input and generates a compress of the original uncompressed file as output. You can assume that no word contains more than 50 characters, no line contains more than 80 characters, no more than 20 lines in the input and that the original uncompressed file contains no digit characters neither binary zeroes. Sample Input Dear Sally, Please, please do it--it would please Mary very, very much. And Mary would do everything in Mary's power to make it pay off for you.

-- Thank you very much-- Sample Output

Edition 2007-01-09 top secret / strictly confidential page 336 of 520 Perlgolf History

Dear Sally,

Please, please do it--1 would 4 Mary very, 1 much. And 4 6 8 everything in 5's power to make 14 pay off for you.

-- Thank 2 18 18-- Regex for input and for output is /^(.{0,80}\n){0,20}\z/.

6.13.2. Solutions 44, Magus (post-mortem) -p0 s!\w+!$_.=$=.$&;s/0$&6//?$'=~y/0//:$&!eg 44, Juho Snellman -p0 s^\w+^$_.=$=.$&;s/0$&6//?$'=~y/0//:$&^ge 45, Magus -p0 s!\w+!$_.=$=.$&;s/0$&6//?split 6,$':$&!eg 46, ton -p s/\w+/($a.=-$&)=~s!-$&-!-!?-$'=~y!-!!:$&/eg 46, ton (alternative) -p0 s/\w+/$_.="0$&";s!0$&0!0!?split 0,$':$&/eg 46, ton (alternative) -p0 s/\w+/$_.="\x00$&";s!\x00$&\x00!\x00!+$'=~y!\x00!!||$&/eg 46, pom (post-mortem) -p0 s!\w+!$_.="$& ";s/^$& ^//m?$'=~y/ //:$&!ge 46, Grizzley (post-mortem) -p s!\w+!($s.=-$&)=~s#\b$&-##?-$'=~y/-//:$&!eg 47, Daniel -p s#\w+#($a.=" 1$&")=~s!1$& !!?$'=~y/1//:$&#ge 48, pom -p s!\w+!($/.="$& ")=~s/^$& ^//m?$'=~y/ //:$&!ge 49, Jeff Moore -p s!\w+!($n.="$&,")=~s/\b$&,\b//?$'=~y/,//:$&!ge 49, topmach -p s!\w+!($w.=$&.$")=~s/\b$& \b//?$'=~y/ //:$&!eg 49, Bass

Edition 2007-01-09 top secret / strictly confidential page 337 of 520 Perlgolf History

-p s#\w+#($a.=" $&")=~s/\b$& //?$'=~y/ //+1:$&#ge 49, Michael Rybakin -p s^\w+^($s.=_.$&)=~s/_$&_/_/?1+$'=~y/_//:$&^ge 49, Michael Rybakin -p s^\w+^($s.=$".$&)=~s/\b$& //?1+$'=~y/ //:$&^ge 50, andys -p0 s#\w+#($l.=";$&")!~s/;$&;/;/?$&:1+$'=~y/;//#eg 51, Grizzley -p0 s!\w+!$s.=" $&";$s=~s#\b$& ##?1+$'=~y/ //:$&!eg 52, mtve -p0 s#\w+#s!\b($&)\b.*\G!$&^$1!se?map/\W+/g,$&:$&#eg 52, tybalt89 -p s/\w+/$_+=~$_>~($a=$w{$&})for%w;$w{$&}=1;$a|$&/ge 52, o0lit3 (post-mortem) s/\w+/map$_+=$_<($z=$x{$&})|!$z,%x;$x{$&}=1;$z|$&/eg 54, Roy Johnson (post-mortem) -p s/\w+/$_+=!$x|$_<($x=$M{$&})for%M;$M{$&}=1;$x|$&/ge 55, mtve (alternative) -p0 s#\w+#$`=~/.*\b$&\b/s?1+keys%{{$'=~/\b\w*/g}}:$&#eg 55, o0lit3 (post-mortem) -p0 s/\w+/$_+=!$z|$_<($z=$x{$&})for%x;$x{$&}=1;$z|$&/eg 55, aqumsieh -p s/\w+/$*=$h{$&};$_+=$_<$*|!$*for%h;$h{$&}=1;$*|$&/eg 56, Peter Haworth (post-mortem) -p s/\w+/$_+=!($,=$w{$&})||$_<$,for%w;$w{$&}=1;$,||$&/ge 56, Two-Bits (post-mortem) -p s/\w+/$H=$w{$&};map$_+=$_<$H|!$H,%w;$w{$&}=1;$H|$&/ge 58, Two-Bits -p s/\w+/$H=$w{$&};map$_+=$_<$H|!$H,%w;$w{$&}=1;$H or$&/ge 59, Roy Johnson (post-mortem) -p s/\w+/$_+=$_<($x=$M{$&})for%M;$M{$&}=++$w;$x?$w-$x:$&/ge 61, Roy Johnson (alternative) -p s#\w+#$x=keys%{$M{$&}};$M{$&}={};++$_->{$&}for%M;$x||$&#eg 62, Szeryf

Edition 2007-01-09 top secret / strictly confidential page 338 of 520 Perlgolf History

-p s%\w+%$i=$j=0;@a=($&,grep++$i*!s/^$&$/$j=$i/e,@a);$j||$&%eg 62, Jasper -p0 s#\w+#my%s;$`=~/.*\b$&\b/s?grep!$s{$_}++,$'=~/\w+|/g:$&#eg 64, wmeriic -p s'\w+'@a{@a=($&,@a)}=0..@a;splice@a,$i,1if$i=$a{$&};$i||$&'ge 67, o0lit3 -p0 s/\w+/map{$_++if!($z=$x{$&})||$_<$z}values%x;$x{$&}=1;$z||$&/eg 67, o0lit3 -p0 s/\w+/map{$_++if!($z=$x{$&})||$_<$z}values%x;$x{$&}=1;$z||$&/eg 71, Jasper -p0 s#(.*((\b(\pL|_)+)\b.*))\b\3\b#"$1".(@a=$2=~/[A-Za-z_]+/g)#es&&do$0 75, Roy Johnson (alternative) -p0 s#(\w+)(?=(.*?\b\1\b))?#$x=keys%$1||$1;%$1=map{$_,1}$2=~/(\w+)/g;$x#ges 76, thepoet -p s/\w+/(($a=(grep{$x[$_]eq$&}1..unshift@x,$&)[0])&&splice@x,$a,1)?$a:$&/eg 80, Bass (alternative) -p0 s#(.*)(\b[\pL_]+\b)(.+)\b\2\b#"$1$2$3".keys%{{split/([\W\d]+)/,$3}}#se&&redo

6.14. Matcher http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=50&season=1 The game started 2003-12-12 21:00:00 and ended 2003-12-17 20:00:00. Rules by Magus.

6.14.1. Rules On the standard input two pictures are placed. On the standard output the script should write "YES" if pictures are same, and "NO" otherwise. Pictures are the same if one fits another after any rotation of (0,90,180,270) degrees. Flipped pictures are not the same. Each picture is no more than 10x10 chars. Each picture is a polygon (each # is connected with other # by a side or corner) and match: /^([ #]{0,9}#\n){1,10}\z/. Each line can be with different length but at least one line will begin from # (the picture touches left border, and rotations are based on the actual dimensions of the picture). Pictures are separated by an empty line. The whole STDIN will match: /^([ #]{0,9}#\n){1,10}\n([ #]{0,9}#\n){1,10}\z/. Output shall match: /^(YES|NO)\n\z/. Example input (char "." is used instead of " " for presentation only, in the tests there will be " " of course):

Edition 2007-01-09 top secret / strictly confidential page 339 of 520 Perlgolf History

..## ######### .##.#### .######

.# .## .### .### .### ##.# #### .### .# Output: YES Another example: ### #

# ### Output: NO

6.14.2. Solutions 83, mtve (post-mortem) -lp00 $$_=eval's%.%s/$/ /mg;/#/&&reverse$\,/^./mg,!s///g%seg/!$$_;'x8}{$_=$@?YES:NO 88, ton -lp00 eval's%.%s/$/ /mg;/#/&&reverse$\,/^./mg,!s///g%seg/!/^$a$/;'x8;$a=$_}{$_=$@?YES:NO 104, mtve -lp0 $$1=s/(\C* ) //;s!\C!$@.="$& "while s/^.?/${$a=($&|$").$a}/mg,$a=~s/.*#//;${$_=$@}!eeg;$_=$_?YES:NO 110, Daniel -lp0aF\n\n $_=(map{$_=$"=!split$\;s#^#@{[map{s/.//?$&:' '}@_]} #,s/ +$//mwhile"@_";/^$F[1]$/}($F[0])x4)?YES:NO 110, Juho Snellman -lp00 $^=<>;$_=(grep{$_=join'',map{chop||$/}($,,map{pack A10,$_}/.+/g)x11;s/^ * | +$//gm;$^eq$_}($_)x4)?YES:NO 110, tybalt89

Edition 2007-01-09 top secret / strictly confidential page 340 of 520 Perlgolf History

-lp0aF\n\n $_=(map{map$a.=$_||$",reverse$\,/^.?/gmwhile s///g,/./;$_=$a;$a=!s/ *$//gm;/^@F$/}(pop@F)x4)?YES:NO 117, andys -lp0 /

/;$;=$';$_=(grep{(map$a.=$_||$",reverse$/,/^.?/mg),s///gwhile/./;$_=$a;$a=!s/ *$//mg;$;eq$_}("$` ")x4)?YES:NO 122, shr (post-mortem) -lp0 ($x,$c)=split/^$/m;$_=qw/NO YES/[grep{my$d;$_=/ *\d/,$d.="$` "while$c=~s/^.?/$_=$&|" $_";''/gme,/#/;($c=$d)eq$x}0..3] 123, pom -lp0 /

/;$;=$`;$:=$';$_=(grep{$_=$;;$;="";$;=join("",/^./gm," $;"),s/.(.*)/$1 /gmwhile$;=~s/ *$//m,/#/;$;eq$:}0..4)?YES:NO 124, Peter Haworth -lp0 /^ /m;$;=$`;$_=$';for$R(A..D){$l='',s/^.?/${$l.=$&|$"}/gm,$$R="$l $$R"while/#/;$_=$$R;s/ + / /g;$a+=$;eq$_}$_=$a?YES:NO 126, shr (post-mortem) -lp0 ($x,$c)=split/^$/m; $_=qw/NO YES/[grep{my$d; $_=/ *\d/,$d.="$` "while$c=~s/^.?/$_=$&|" $_";''/gme,/#/; ($c=$d)eq$x }0..3] 136, wmeriic -la00 ($a,$b)=<>;$_=NO;eval'($a=join"",map$_||" ",map{$a=~/^.{0,$_}(#?)/mg," "}reverse 0..9)=~s/^ *\n| +$//mg;$_=YES if$a eq$b;'x4;print 164, o0lit3 -pl $X[!/#/?++$B:$B].=$_|$"x10}{$Z=$X[0]|$"x100;$_=(grep{@Z=$"="";map{$i=10;map$ Z[$i--].=$_,/./g}$Z=~/.{10}/g;$_=$Z="@Z";s/^ +| +$//g;$X[1]=~/^ *$_ *$/}1..4)?YES:NO 168, o0lit3 -pl $X[!/#/?++$B:$B].=$_|$"x10}{$Z=$X[0]|$"x100;$_=(grep{@Z=$"="";map{$i=10;map$ Z[$i--].=$_,/./g}$Z=~/.{10}/g;$_=$Z="@Z";s/^ +| +$//g;$X[1]=~/^ *$_ *$/}1..4)?'YES':'NO'

6.15. Nim http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=51&season=1 The game started 2003-12-22 18:00:00 and ended 2003-12-25 20:00:00.

Edition 2007-01-09 top secret / strictly confidential page 341 of 520 Perlgolf History

Rules by ton.

6.15.1. Rules Nim is a game in which players take turns removing objects from heaps, but may only take from one heap at a time. A player must take at least one object. If he can't, he loses. A typical normal game starting with heaps of 3, 4 and 5 might run like: A B C (Heaps A, B, and C) 3 4 5 I take 2 from A 1 4 5 You take 3 from C 1 4 2 I take 1 from B 1 3 2 You take 1 from B 1 2 2 I take entire C heap 2 2 0 You take 1 from A 1 2 0 I take 1 from B 1 1 0 You take 1 from B 1 0 0 I take the last 1 and win. You can play a thinly disguised version of the game as the fruit game1 (Each line of one kind of fruit corresponds to a heap). The way to win this game may not seem obvious, but a rather elegant method exists: Write down the size of each heap in binary (right aligned, possibly add zeros at the left) one above the other, and count the number of ones in each column: 0 1 1 Heap A in binary (3) 1 0 0 Heap B in binary (4) 1 0 1 Heap C in binary (5) ----- 2 1 2 The "sum" (quotes because if there are more than 10 heaps, column sums can be bigger than 10) of heaps A, B, and C Since there is an odd number in the sum, we call this position "odd". If all columns had an even number of ones, the position would be "even". The basic observation is that every possible move in an even position will make it odd, and in every odd position there will be a move that makes the position even. And the final position (sum 0) is even. Therefore you win by giving your opponent an even position. Whatever he does, he'll have to make it odd, and you'll just make it even again, until finally no objects are left and you win. If however on the first move you are in an even position already, you will normally lose. Just make some random move and hope for a mistake by your opponent. In this golf you will be given an odd position as input, and you are to determine any one of the winning moves (making the position even). (For even positions your move doesn't matter, so your program doesn't have to do anything sensible in that essentially boring case). On STDIN you will get up to 9 lines, each containing a positive integer describing a heap size. Heap sizes can run from 1 to 9. So STDIN matches /^([1-9]\n){1,9}\z/. For the given example, you'd get:

1 http://king.2020tech.com/cgi-bin/nim/nim

Edition 2007-01-09 top secret / strictly confidential page 342 of 520 Perlgolf History

3 4 5 On STDOUT you should print the heap number (heaps are counted starting from 0), a space, the number of objects to remove from that heap and then a newline. So STDOUT matches /^[0-8] [1-9]\n\z/. The resulting position should be even. It's possible that more than one move will give an even position. In that case you can return any single one of them. In the given example the only valid move is to remove 2 objects from the first heap (the heap with number 0), so the output should be: 02 In case you don't directly see how to solve it, here is one way (definitely not the only one). Look for the leftmost odd digit in the sum. There must be some heap with a 1 in that column (otherwise that column would have sum 0 and be even). For that heap, flip (change 0 to 1, and 1 to 0) all digits where the column sum is odd. For the given example, the leftmost odd number in "2 1 2" is the second one. Only heap A has a 1 in that column, so our move must be in the first heap (remember that the size of heap A in binary was "011"). Now in the sum "2 1 2" only the second number is odd, so flipping the corresponding digits for heap A makes "011" (binary for 3) into "001" (binary for 1). Changing a heap of size 3 into a heap of size 1 corresponds to removing 2 objects. Hint: don't take the algorithm instructions too literally. This is a very easy golf if you use the right representations.

6.15.2. Solutions 48, ton -lp $s^=map*{$'-$_^$'}=[$.-1,$_],//..$_}{s//@$s/ 49, mtve -lp0 y/ /^/;s#.#"\$-=$&-($_$&)"x!$-#eeg;s/0*/@+ / 49, ton (rejected) -lp0 $_=/\d/g-(s/ /^/-do${$-=$&-eval$_.$&}).$".$- 51, ton (alternative) -lp0 /\d/g;$_=!s/ /^/g+(do${$-=$&-eval$_.$&}).$".$- 52, tybalt89 -lp0a y/ /^/;$-=pop@F until$--=eval$_.$-;$_=@F." $-" 52, Juho Snellman -p0 s|.|@{[$%+=!y/ /^/,$&-eval$_.$&]}|g;($_)=/. . /g 54, stalker

Edition 2007-01-09 top secret / strictly confidential page 343 of 520 Perlgolf History

-p0 s!.!y/ /^/;$%++.$".eval"$&-($_$&)"!ge;($_)=/. . /g 61, robert -lp $*^=$a{$.}=$_}{1until$_=($o-=($o=$a{$.--})^$*)>0&&"$. $o" 71, topmach for$i(@?=<>){eval join'^',$i,$i-$_,@?or$a="$? $_ "for 1..9;$?++}print$a 73, o0lit3 -pl $X^=chr($X[$.-1]=$_)}{$_=(grep!/-/,map{$i++.$".($_-($_^ord$X))}@X)[0]

6.16. Josephus Problem http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=52&season=1 The game started 2003-12-27 19:00:00 and ended 2003-12-30 20:00:00. Rules by Juho Snellman.

6.16.1. Rules Given a group of N men arranged in a circle under the edict that every Mth man will be executed going around the circle until only one remains, find the position in which you should stand in order to be the last survivor. (Description from MathWorld1). For example using N=6 and M=4, and marking the position of the last man who was killed with a '*': 123456 =>#4killed 123*56 =>#2killed 1*356 =>#1killed *356 =>#3killed * 5 6 => #6 killed 5 * => #5 survives The program will receive N and M as parameters in @ARGV (in that order). The values of N and M can range from 1 to 99. M will never be larger than N. The program should output on STDOUT the position of the survivor, followed by a newline.

6.16.2. Solutions 39, mtve (post-mortem) ($#n+=$_)%=++$,for(pop)x pop;print@n.$/ 40, Daniel -l ($i+=$_)%=++$%for(pop)x pop;print++$i 42, ton -l map$n=($n+$')%$_,pop=~//..pop;print$n+1 42, tybalt89

1 http://mathworld.wolfram.com/JosephusProblem.html

Edition 2007-01-09 top secret / strictly confidential page 344 of 520 Perlgolf History

-l print$a+!!map$a=($a+$')%$_,pop=~//..pop 42, anfi ($a+=$M)%=$_ for$M=pop,2..pop;print++$a,$/ 43, andys -l print$a+!!map$a=("@ARGV"+$a)%$_,1..shift 43, wmeriic -l map+($=+="@ARGV")%=$_,1..shift;print++$= 43, o0lit3 (post-mortem) -l $X=pop,map$J=($J+$X)%$_,1..pop;print$J+1 45, o0lit3 -l $X=pop,map$J=($J+$X)%$_||$_,1..pop;print$J 45, o0lit3 (alternative) -l $X=pop,map$J=($J+++$X)%$_,1..pop;print$J+1 45, o0lit3 (alternative) -l print pop=~//+eval'$_=($_+$\')%++$.;'x pop 47, o0lit3 (alternative) -l $X=pop;print eval'$_=($_+$X)%++$.||$.;'x pop 48, andys (alternative) -l print$_+s//('+('.pop)x($n=pop).')%++$i'x$n/ee 52, Juho Snellman -l $m=pop;$_=1x pop;1while s/1/$|=++$a%$m/ge;print@+ 55, stalker -l $x=pop;1while@x=grep{$z=$_,++$y%$x}@x,1..pop;print$z 56, Szeryf $M=pop;@a=1..pop;++$i%$M&&push@a,$_ for@a;print$a[-1],$/ 62, topmach -l $s=pop;@m=1..pop;$_=splice@m,$o=($o+$s-1)%@m,1while@m;print 62, jas $m=pop;splice@l,$i=($i+$m-1)%@l,1for 2..(@l=1..pop);print"@l " 64, Jurgen Pletinckx -l for(@_=1..shift;@_;++$c%$ARGV[0]&&push@_,$_){$_=shift@_}print 66, thepoet -l $m=pop;@n=1..pop;splice@n,($p+=$m-1)%=$#n+1,1for(2..@n);print@n 67, Paul van Eldijk -l $M=pop;@N=1..pop;$P+=$M-1,$P%=@N,$_=splice(@N,$P,1)while@N;print 70, giovans

Edition 2007-01-09 top secret / strictly confidential page 345 of 520 Perlgolf History

-l $s=pop;@_=1..pop;$p+=$s-1,@_=grep$_^$_[$p%=@_ ],@_ while$#_;print@_ 72, Matthias Schoder -l @_=1..shift;for(2..@_){push@_,shift@_ for 2..$ARGV[0];shift@_}print@_

6.17. Unfragment http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=53&season=1 The game started 2004-01-08 20:00:00 and ended 2004-01-17 20:00:00. Rules by http://acm.uva.es/p/v101/10132.html . Idea by tybalt89.

6.17.1. Rules Your friend, a biochemistry major, tripped while carrying a tray of computer files through the lab. All of the files fell to the ground and broke. Your friend picked up all the file fragments and called you to ask for help putting them back together again. Fortunately, all of the files on the tray were identical, all of them broke into exactly two fragments, and all of the file fragments were found. Unfortunately, the files didn't all break in the same place, and the fragments were completely mixed up by their fall to the floor. You've translated the original binary fragments into strings of ASCII 1's and 0's, and you're planning to write a program to determine the bit pattern the files contained. If there are 2N fragments in the input, it should be possible to concatenate these fragments together in pairs to make N copies of the output string. There will be exactly one unique solution. The file can not be broken up at the same point multiple times; however even so you can have fragments that are the same. There will be no empty fragments. Your friend is certain that there were no more than 8 files on the tray, and that the files were all no more than 9 bits in size. Input Input will consist of a sequence of ``file fragments'', one per line. Each fragment consists of a string of ASCII 1's and 0's. Output Output is a single line of ASCII 1's and 0's giving the bit pattern of the original files followed by the newline. Sample Input 011 0111 01110 111 0111 10111 Sample Output 01110111

6.17.2. Solutions 57, ton (alternative)

Edition 2007-01-09 top secret / strictly confidential page 346 of 520 Perlgolf History

-alp0 s!.+!$;[map%$z,@$z{$&,$_}]=$z=$_.$&for@F!eg;$_=pop@ 57, ton -alp0 s!.+!$;[@$z{$&,$_}=%$z]=$z=$_.$&for@F,@F!eg;$_=pop@ 61, mtve (rejected) -lp0a $"='|'while$_=$x++,s/.//,grep$'!~/^$_(@F)$|^(@F)$_$/,@F 61, Daniel -p0a $_="$F[$?+=!++$^C]$F[$^C] "while~-2**@F^($$_|=2**$?|2**$^C) 62, ton (post-mortem) -ap0 $_="$F[$i=$j]$F[$j=rand@F] "until($$_|=1<<$i|1<<$j)+1>>@F 63, ton (alternative) -ap0 @F=sort{rand 2}@F until$_="@F ",s! !$/x$|--!eg,/ /,s/^$'// 63, Two-Bits (rejected) -lap0 s#.+#$_[$_{$^G=$_.$&}+=map$^G=~/$_/,@F]=$^Gfor@F#eg;$_=pop@_ 64, ton (alternative) -ap0 }{@F=sort{$_.="$a$b "x2;rand 2}@F until($_)=/^(.+ )\1{$#F}/ 64, ton (rejected) -alp0 sub f{splice@F,rand@F,1}$;=f.f;$;eq f.f||redo while@F;$_=$ 65, Juho Snellman -lp0a s/.+/ @{[map"$&$_ $_$&",@F]} /g;($_)=/(\d+)(.* .* \1 )*.*$/ 68, Two-Bits (rejected) -lap0 s#.+#$_[$_{$^G=$_.$&}-=/$&/-map$^G=~/$_/,@F]=$^Gfor@F#eg;$_=pop@_ 68, mtve (alternative) -lp0a $"='|',$_=glob"{,0,1}"x9until//>grep$'!~/^(@F)$_$|^$_(@F)$/,@F 69, Andreas -lap0 for$f(@F){\@{$_.$f}{\$_,\$f}for@F}($_)=grep/\d/&@F==keys%$_,%:: 71, mtve (alternative) -lp0a $"=',',$_=<{@F}{@F}>until$"='|',//>grep$'!~/^(@F)$_$|^$_(@F)$/,@F 72, andys -p0a s#.+ #for$a(@F){$\=$a.$&if!grep{(${$a.$&}.="$a $&")!~/\b$_ /}@F}#eg 75, the score (rejected) -0ap $_=(map{$i=$_;map{$j=$_;grep/$i/&&++$k{$_}>2*$#F,map$_.$j,@F}@F}@F)[0] 77, wmeriic (rejected)

Edition 2007-01-09 top secret / strictly confidential page 347 of 520 Perlgolf History

-lp0a *$_=\(sort{"1$a"-"1$b"}@F)[$_-3]for 1..4;"$3$2 $2$3"=~/$4$1|$1$4/;$_=$& 78, o0lit3 (alternative) -lp0a for$=(@F){@;=map{$*=$_;grep$*eq$_,@;?@;:@*}@*=map{$_.$=,$=.$_}@F}$_=pop@ 79, o0lit3 (post-mortem) -lp0a for$=(@F){@;=grep{$*=$_;grep$*eq$_,@;?@;:@*}@*=map{$_.$=,$=.$_}@F}$_=pop@ 79, radeye -l chomp(@a=<>);0until($a{$_=$a[$i=$j].$a[$j=rand@a]}|=1<<$i|1<<$j)+1>>@a;print 80, o0lit3 -lp0aF for$=(@F){@;=grep{$*=$_;grep$*eq$_,@;?@;:@*}@*=map{$_.$=,$=.$_}@F}$_=pop@ 82, Jasper -lp0 $"="|";($_)=map{//;map{($t=$'.$_)x!grep$t!~/^$_(@_)$|^(@_)$_$/,@_}@_}@_=spli t 109, gibbering (rejected) -lpa0 \@H{@F};$"=',';for$s(glob"{@{[keys%H]}}"x2){$a=$h{$s}+=grep$s=~$_,@F;$m=$a if$a>$m}$_={reverse%h}->{$m} 123, Qtax (rejected) -lp0 for$"(@_=split){$l+=length$";$h{$".$_}+=$_.$"eq$".$_?0:1for@_}$_=(sort{$h{$b }<=>$h{$a}}grep{$l/@_*2==length}keys%h)[0] 137, _-Ani-_ (rejected) -lp0 @X=split;for$i(0..$#X){for(0..$#X){$Y{$X[$i].$X[$_]}++if$i^$_}}z:while(($",$ d)=each%Y){for(@X){next z if$"!~/$_/}$a=$d,$_=$"if$d>$a} 138, _-Ani-_ (rejected) -lp0 @X=split;for$i(0..$#X){for(0..$#X){$Y{$X[$i].$X[$_]}++if$i^$_}}z:while(($",$ d)=each%Y){for(@X){next z if$"!~/$_/}$a=$d,$_=$"if$d>=$a} 166, Grizzley -lp0aF/\n/ sub f{B:while(@_){$s=pop;for$i(@_){$t=pop;next B if/^($s$t|$t$s)$/;@_=($t,@_)}return}last}$a=pop@F;while(@F){$b=pop@F;$_=$a.$ b;f@F;$_=$b.$a;f@F;@F=($b,@F)} 174, _-Ani-_ -lp0 @X=split;$K=9;for$;(@X){$,=length$;;$K=$,if$,<$K;$G=$,if$,>$G;$Y{$;.$_}++for (@X)}z:while(($",$d)=each%Y){for(@X){next z if$"!~/$_/}$a=$d,$_=$"if$d>$a&&length($")==$K+$G} 198, Beeblbrox (rejected) -lp0 $"="";@i=split;@p=f($#i,@i);$_="@p";sub f{my($c,$a,$b,@i)=@_;if(@i){($x,$y)=f($#i,@i);(($a.$b)=~/^($x$y|$y$x)$/)?($a ,$b):(($b.$a)=~/^($x$y|$y$x)$/)?($b,$a):$c+1?f($c- 1,$a,@i,$b):()}else{$a,$b}} 211, Beeblbrox (rejected)

Edition 2007-01-09 top secret / strictly confidential page 348 of 520 Perlgolf History

-lp0 $"="";@i=split;($p,$q)=f($#i,@i);$_=$p.$q;sub f{my($c,$a,$b,@i)=@_;if(@i){($x,$y,$z)=f($#i,@i);(($x.$y)=~/^($a$b|$b$a)$/)? ($x,$y):$z&&(($y.$x)=~/^($a$b|$b$a)$/)?($y,$x):$c?f($c- 1,$a,@i,$b):()}else{$a,$b,1}} 231, Beeblbrox (rejected) -lp0 $"="";@i=split;($p,$q)=f($#i,@i);$_=$p.$q;sub f{my($c,$a,$b,@i)=@_;if(@i){($x,$y,$z)=f($#i,@i);(($x.$y)=~/^($a$b|$b$a)$/)? ($x,$y,$y.$x eq reverse $1):$z&&(($y.$x)=~/^($a$b|$b$a)$/)?($y,$x):$c?f($c- 1,$a,@i,$b):()}else{$a,$b,1}}

6.18. Permutations http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=54&season=1 The game started 2004-01-25 21:00:00 and ended 2004-01-29 20:00:00. Rules by ton.

6.18.1. Rules Everybody knows how to write a program to generate all permutations of a set of values. So prove it! To make things a bit more interesting, some values of the set can be identical, and you should only output the different permutations. When given the arguments abbd, your program should output (in some order): abbd abdb adbb babd badb bbad bbda bdab bdba dabb dbab dbba To be more precise, the program will receive a bag of elements as arguments. Each element will be a single lowercase letter (so matching /^[a-z]\z/) and they will be lexically ordered. There will be at least one and at most 8 elements in the bag. On STDOUT you should output all permutations, one per line where one line is the elements of that permutation concatenated followed by a newline. The order in which you output the permutations does not matter. So output will match /^([a-z]{1,8}\n){1,40320}\z/.

6.18.2. Solutions 50, mtve (rejected) $a{join'',sort{$_<<++$x}@ARGV}=$/for 1..$^T;print%a 51, mtve (rejected) $a{join'',sort{~-rand 3}@ARGV}=$/for 1..1e7;print%a 51, mtve

Edition 2007-01-09 top secret / strictly confidential page 349 of 520 Perlgolf History

$a{join'',sort{$_<<++$x}@ARGV}=$/for 1..1e7;print%a 52, Juho Snellman s/^$/@ARGV /;s/(.) /${$_="$1$`$'"}||=do$0/ge||print 52, o0lit3 (rejected) -l map${$_=join'',sort{rand 2}@ARGV}++||print,1..1e6 53, o0lit3 (alternative) -l ${$_=join'',sort{rand 2}@ARGV}++||print for 1..1e6 53, ton -l $$_||=/^$'$/?print:s!!do$0!egfor$`.$ARGV[y///c].$' 58, o0lit3 (alternative) -l map${$_=join'',@ARGV=sort{rand 2}@ARGV}++||print,1..1e6 59, o0lit3 (alternative) -l ${$_=join'',@ARGV=sort{rand 2}@ARGV}++||print for 1..1e6 62, Daniel s#\w#print$'!~$&&&map$&.$_,$`.$'?`$^X $0 $\`$'`:$/#egfor"@ARGV" 66, stalker sub b{s/(\S)(?! \1)/b("@_$&",$'.$`)/eg||print@_,$/for pop}b"@ARGV" 66, o0lit3 (post-mortem) -l eval'map{$$_||=print;'x8 .'"$`$\'$&"while/./g}'x8 .join'',@ARGV 67, radeye -l @_=join'',@ARGV;$$_||=/\B./&print&&push@_,"$&$`$'","$&$'$`"for@_ 67, radeye -l $"='';eval'map{$$_||=print;'x8 .'"$`$\'$&"while/./g}'x8 ."@ARGV" 67, RobTM -l sub a{$_=pop;s/(\w)(?!.*\1)/a("@_$&",$`.$')/ge||print@_}a"@ARGV" 67, RobTM (alternative) -l sub a{$_[0]=~s/\w/$_.=$&;a($`.$');chop/ge||$$_++||print}a"@ARGV" 75, Two-Bits r("@ARGV");sub r{($_,my$s)=@_;$h{"$s "}=''if!s/\w/r($`.$',$&.$s)/ge}print%h 75, Skeeve sub p{@p=(p(@_,pop@p),@p)for@p;$p{join'',@_}=$/if!@p;pop}@p=@ARGV;p;print%p 75, Jasper (post-mortem) ${0}{''}++;for$l(@ARGV){map{${$n}{"$`$l$'"}=$/while//g}keys%{$n++}}print%$n 81, Grizzley

Edition 2007-01-09 top secret / strictly confidential page 350 of 520 Perlgolf History

sub f{map{@_=(pop,my@y=@_);@y?map$_[0].$_,f(@y):@_}@_}map$h{$_}=$/,f@ARGV;print% h 95, o0lit3 -l sub p{@_<2?@_:map{my$i=$_;$.=0;map$_[$i].$_,p(grep$.++!=$i,@_)}0..$#_}map$$_++|| print,p@ARGV 115, Paul van Eldijk @H{@A}=@;=@A=@ARGV;@;=map{$T=$_;map$T.$_,keys%H}@;for 2..@A;print map!$T{$_}++&&"@A"eq"@{[sort split//]}"&&$_.$/,@; 248, _-Ani-_ -l sub a{my$x=pop||1;$S=pop||$,;my$A=$S;for$;(0..$#ARGV){next if substr($S,$;,1)ne$";substr($S,$;,1,$ARGV[$x]);if($x^$#ARGV){a($S,$x+1)}else{ $Y{$S}++}$S=$A}}print pop if@ARGV==1;$,=$"x@ARGV,substr($,,$_,1,$ARGV[0]),a,for(0..$#ARGV);print for keys%Y

6.19. A1227 http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=55&season=1 The game started 2004-02-04 21:00:00 and ended 2004-02-08 20:00:00. Rules by http://acm.uva.es/p/v102/10290.html . Idea by andys.

6.19.1. Rules All the positive numbers can be expressed as a sum of one, two or more consecutive positive integers. For example 9 can be expressed in three such ways, 2+3+4, 4+5 or 9. For every number starting from 1 and ending at 99 print how many ways that number can be expressed as summation of consecutive numbers. So on STDOUT you should print following 99 numbers with newline after each number: 11212221322 22241232242 22324224214 24322422422 62223342244 24224226144 22442322624 42252244242 26424242236 Hint: this is Sequence A0012271

6.19.2. Solutions 38, ton (rejected)

1 http://www.research.att.com/projects/OEIS?Anum=A001227

Edition 2007-01-09 top secret / strictly confidential page 351 of 520 Perlgolf History

-l print//*grep$1{$'/$_},%1for%1=1..98 39, mtve -l print//*grep$_%2>$'%$_,@,for@,=1..99 39, tybalt89 -l print//*grep$'%$_<$_%2,@=for@==1..99 39, Michael Rybakin -l print//*grep$'%$_<$_%2,@~for@~=1..99 39, ton -l print//*grep$'%$_<$_%2,@;for@;=1..99 39, o0lit3 -l print//*grep$'%$_<$_%2,@*for@*=1..99 39, Daniel -l print//*grep$_%2>$'%$_,@@for@@=1..99 39, terje -l print//*grep$_&$'%$_<1,@:for@:=1..99 39, ton (rejected) -l print//*grep$'%$_<--$|,@;for@;=1..98 40, Jasper -l print//*grep$_&!($'%$_),@;for@;=1..99 40, Juho Snellman -l print~~grep$_%2>$'%$_,//..99for 1..99 40, ton (post-mortem) -l print//*grep$'%$_<1,keys%1for%1=1..99 41, o0lit3 (alternative) -l print~~grep$-%$_<$_%2,1..++$-for$...98 41, IgorK -l print~~grep$_&1>$,%$_,1..++$,for(9)x99 41, stalker -l print//*map$'%$_..$_%2-1,@;for@;=1..99 41, andys -l print//*grep$'%$_?0:$_%2,@;for@;=1..99 41, ErikB (post-mortem) -l print//*grep$'%$_<1,keys%O for%O=1..99 42, o0lit3 (alternative) -l eval'print~~grep$-%$_<$_%2,1..++$-;'x99 42, ErikB

Edition 2007-01-09 top secret / strictly confidential page 352 of 520 Perlgolf History

-l print~~grep$_&$*%$_==0,1..++$*for$*..98 42, Magus -l print~~grep$_&!($;%$_),1..++$;for 1..99 42, o0lit3 (post-mortem) -l print//*grep$'%$_<1,keys(%O)for%O=1..99 43, Two-Bits -l print$a-grep$a%($_*2+1),0..$a++for 1..99 43, o0lit3 (post-mortem) -l print//*grep!($'%$_),keys(%O)for%O=1..99 47, Skeeve for$t(%a=1..99){print grep(!($t%$_),keys%a).$/} 47, Paul van Eldijk -l print 0+grep$_%2&!($@%$_),1..$@while++$@<100 48, shr -l for$i(1..99){print$a=grep$_&1&!($i%$_),1..$i} 54, m.wrenn -l map{$i=$j=0;$_%$i++||$j++while$i++<99;print$j}1..99

6.19.3. Explanation by Ton Hospel Why is the number of ways to write a number as the sum of sequences of consecutive positive integers the same as the number of odd divisors of a number? Consider this image:

The sum of consecutive integers can be drawn as a trapezium. If the number of layers is even, do the top transformation, and get a rectangle whose width is odd. And the black subtrapezium is wider than its high, so the height of the rectangle is below half its width.

Edition 2007-01-09 top secret / strictly confidential page 353 of 520 Perlgolf History

If the number of layers is odd, do the bottom transform, and get a rectangle whose height is odd. The width is that of the middle layer, which must be bigger than half the height. So each trapezium will map to an odd divisor of the sum. Is it unique? Each odd divisor of a number can be represented as a rectangle with that odd divisor as a side. Now divide that odd divisor by two (which won't be a whole number). If the other side is smaller than that, we can split up the rectangle using the top method. Otherwise use the bottom method. So there is in fact a bijection between the two sets. QED

6.20. Loopy http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=56&season=1 The game started 2004-02-09 21:00:00 and ended 2004-02-14 20:00:00. Rules by ton.

6.20.1. Rules Consider a directed graph like this one:

Some graphs have loops, some don't. This one does as shown in red. Your assignment, should you decide to accept it, is to determine if a given graph has loops or not. Input will be a sequence of edges on STDIN, one edge per line. One edge will be given as two consecutive integers, meaning an edge from the vertex named by the first number to the vertex named by the second one. There will be at least one and up to twenty vertices. Each vertex will be a member of at least one edge. The edges are sorted by starting vertex, and if these are equal, by ending vertex. A given directed edge will ever only appear once in the input (but that does not exclude the edge going in the other direction). Vertices are numbered starting at 0 without holes, and there will be at least one edge. So STDIN will match /^(1?\d 1?\d\n){1,400}\z/, and the given example is specified as:

Edition 2007-01-09 top secret / strictly confidential page 354 of 520 Perlgolf History

02 10 23 25 31 43 45 66 78 87 If the graph has a loop, you should print 1 on STDOUT, 0 otherwise, in both cases followed by a newline. So STDOUT should match /^[01]\n\z/, and since the example has loops, that one should output: 1 You may or may not find inspiration by reviewing TPR 4b: Topological Sort (see section 4.5.3).

6.20.2. Solutions 38, ton (post-mortem) -lp0 $_=/\S+/g?/ $& /.s/^$&//m&do$0:// 39, Michael Rybakin -lp0 /$& /,s/^$&//mwhile/\d+/g;$_=0+// 39, o0lit3 -lp0 / $& /|s/^$&//mwhile/\d+/g;$_=//|0 39, ton -lp0 / $&? /||s/$&//while/.+ /g;$_=//*1 39, tybalt89 -lp0 $_=/.+ /g?/ $&? /*s/^$&//m+do$0:// 40, ErikB -lp0 / $& /||s/$&.*//while/\d+/g;$_=//|0 40, ton (alternative) -lp0 / @- /||s/^@- //mwhile/|/g;$_=0+/ / 42, Andreas -lp0 s/^$& //gmwhile/\d+/g+/ $& /;$_=/ /+0 42, ton (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 355 of 520 Perlgolf History

-lp0 $_=!!s#.#!s!.+ !"$&"x/ $&? /!eg#eg-// 42, stalker -lp0 $_=!s;.;!s:\d+:/. ($&) /,$1:ge;ge+!// 42, stalker (alternative) -lp0 $_=1-!eval's:\d+:/. ($&) /,$1:ge;'x21 44, Two-Bits -lp0 $_=eval's!(.+) !"$&"x/ $1 /!eg;'x20?1:0 60, ton (alternative) -lp / /;$x{$`}{$'}=bless\\$x{$'}}{DESTROY{--$.}%x=0;$_+=!!$.

6.21. Card Trick 2 http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=57&season=1 The game started 2004-02-27 11:00:00 and ended 2004-03-02 20:00:00. Rules by Two-Bits. Idea by Riley (o0lit3).

6.21.1. Rules The Trick: In my hand I have 21 cards that I deal out face up, one each to 3 spread piles, until there are 3 rows of 7. You silently chose your card and inform me of which "pile" your card is in (1, 2, or 3). I then pick up each pile making sure to put the pile with your card between the two other piles. I deal them out as before, and again you tell me which pile your card is in. We repeat the process a third time, and when I again pick up the piles, placing the pile with your card in the middle, your card will invariably be the center card (11 of 21 in this case). The Problem: As input you will receive on STDIN an "odd multiple of 3" (9, 15, 21, 27) number of cards, at least 9 and at most 27 total. Cards will be of the form /[2-9TJQKA][HCSD]/ where AC is "ace of clubs" and TH is "ten of hearts", etc. In the trick you made 3 pile choices as the cards we regrouped and re-dealt. Immediately following the list of cards on STDOUT you will receive the 3 pile choices made by the target, followed by a newline. It is your goal to determine what the target's card is, and output to STDOUT the card's name, 5S for example, followed by a newline. Input will match /^([2-9TJQKA][HCSD] ){3,27}([1-3] ){2}[1-3]\n\z/ and output will match /^[2-9TJQKA][HCSD]\n\z/. Note: When picking up the piles to re-deal, ensuring that the pile containing the chosen card is placed between the other two, whichever pile goes above or below the chosen pile is moot. So if pile 3 is chosen, you may regroup as 1, 3, 2 -OR- 2, 3, 1. Example:

Edition 2007-01-09 top secret / strictly confidential page 356 of 520 Perlgolf History

Input: AS5C3H2SKDQS8CTC3C9DJH7H7STD5HAD4C7DTSQHJD223 Deal out cards: AS 5C 3H 2S KD QS 8C TC 3C 9D JH 7H 7S TD 5H AD 4C 7D TS QH JD Pick up piles, 2nd pile in the middle: AS 2S 8C 9D 7S AD TS 5C KD TC JH TD 4C QH 3H QS 3C 7H 5H 7D JD Deal out cards: AS 2S 8C 9D 7S AD TS 5C KD TC JH TD 4C QH 3H QS 3C 7H 5H 7D JD Pick up piles, 2nd pile in the middle: AS 9D TS TC 4C QS 5H 2S 7S 5C JH QH 3C 7D 8C AD KD TD 3H 7H JD Deal out cards: AS 9D TS TC 4C QS 5H 2S 7S 5C JH QH 3C 7D 8C AD KD TD 3H 7H JD Pick up piles, 3rd pile in the middle: AS TC 5H 5C 3C AD 3H TS QS 7S QH 8C TD JD 9D 4C 2S JH 7D KD 7H Output: QH

6.21.2. Solutions 38, ton -alp $_=$F[s/.. //g/2+$_*9%89+3*$&-27] 39, Juho Snellman -lpa $_=$F[s/ ..(.)//g-27+9*$'+3*$1+$&] 39, Stephen Turner -lap $_=$F[s/.. / /g/2+$_+3*$&+9*$'-27] 39, terje -lpa $_=$F[s/.. / /g/2+$_+3*$&-27+9*$'] 39, Michael Rybakin

Edition 2007-01-09 top secret / strictly confidential page 357 of 520 Perlgolf History

-lpa $_=$F[s/.. / /g/2-27+$_+3*$&+9*$'] 40, Stephen Turner (alternative) -lap $_=@F[@F// . //2-28+$&+3*$'+9*chop] 40, terje (alternative) -lpa $_=$F[s/.. //g/2+$_/9+$&*3-27+9*$'] 40, Daniel -lpa $_=@F[map$i+=@F/6-9+$_*pop@F,9,3,1] 40, stalker -pal $_=$F[$F[-/ . /]*9+$'*3+$&-28+@F/2] 40, tybalt89 -lpa $_=$F[/\d /*@F/2-28+$&+3*$'+9*chop] 40, Grizzley (post-mortem) -lap $_=$F[/ . /*@F/2+$&-28+3*$'+9*chop] 41, o0lit3 (post-mortem) -pla $_=$F[@F/2-/ . (.)/*28+9*$'+3*$1+$&] 41, Grizzley -lap $_=$F[/ \d /*@F/2+$&-28+3*$'+9*chop] 42, o0lit3 -plaF $_=$F[@F/2-/ . (.)/*28+9*$'+3*$1+$&] 43, Two-Bits -lap map$i-=9-$_*pop@F,9,3,1;$_=$F[$i-@F/2] 43, Andreas -pal $_=@F[map-@F/2+($m=3*$m-2+pop@F),1..3] 45, Two-Bits (alternative) -lap $_=$F[9*pop(@F)+3*pop(@F)-26-@F/2+pop@F]

6.22. Subproduct http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=58&season=1 The game started 2004-03-15 20:00:00 and ended 2004-03-20 20:00:00. Rules by Juho Snellman.

6.22.1. Rules Given a string of digits and a maximum substring length N, find the largest product of the digits in a substring of 1..N characters. Examples: • For the string 28712347581241 and a N of 4 the correct answer is 1120. (The substring whose digits have the greatest product is 4758, and 4*7*5*8 = 1120).

Edition 2007-01-09 top secret / strictly confidential page 358 of 520 Perlgolf History

• For the string 0120340 and a N of 5 the correct answer is 12 (3*4=12 where the substring is 34, this time using less than the maximum allowed length of 5). Input as two parameters passed in @ARGV: • A string of 1-20 digits. Matches /^\d{1,20}\z/. • Maximum substring length N. Matches /^[1-9]\z/. The N is guaranteed to not exceed the length of the string. Output to STDOUT: • The correct answer (as defined above) followed by a newline (matches /^([1- 9]\d*|0)\n\z/). Please pay attention to genrule #12 ("memory").

6.22.2. Solutions 64, ton s!!$a=1;'($a*=$&*/./g)<$\or$\=$a.$/;'x"@ARGV"!eegfor shift;print 66, 0xF -l ($_,$c)=@ARGV;s!!$r=1;'($r*=/./g*$&)<$%or$%=$r;'x$c!gee;print$% 66, 0xF (alternative) -l $c=pop;$_=pop;s!!$r=1;'($r*=/./g*$&)<$%or$%=$r;'x$c!gee;print$% 66, 0xF (alternative) -l $c=pop;s!!$r=1;'($r*=/./g*$&)<$%or$%=$r;'x$c!geefor pop;print$% 66, 0xF (alternative) -l $_=shift;s!!$r=1;'($r*=/./g*$&)<$%or$%=$r;'x"@ARGV"!gee;print$% 67, mtve $_=shift;$\>($s*=$&)or$\=$s.$/while/./g&"@ARGV">"@+"or$s=s///;print 68, Juho Snellman $_=shift;s/./$^=1;($^*=chop)<$\or$\="$^ "for($`.$&)x"@ARGV"/ge;print 69, tybalt89 -l print~(sort~0,map{s/\B/*/g;~eval}shift=~/(?=([^0]{1,@ARGV}))/g)[0] 71, stalker -l s/\B/*/g,$->eval or$-=eval for shift=~/(?=([^0]{1,@ARGV}))/g;print$- 74, Grizzley -l $l=pop;$_=pop;s!!$;=1;$_=$'&'?'x$l;s/./$%=$;if($;*=$&)>$%/eg!eg;print$% 74, Jasper -l print+(sort{$b-$a}map 0*s/\B/*/g+eval,shift=~/(?=([^0]{0,@ARGV}))/g)[0] 76, andys -l $N=pop;($_)=sort{$b-$a}map s/\B/*/g*0+eval,pop=~/(?=([^0]{0,$N}))/g;print 79, o0lit3

Edition 2007-01-09 top secret / strictly confidential page 359 of 520 Perlgolf History

-l ($_,$%)=@ARGV;map{$-=$@if($@*=$_)>$-}$&=~/./g,s/.//while$@=/.{1,$%}/;print$- 79, ErikB -l $b=pop;for$;(@_=split//,pop){map{$m=$;if$;>=$m;$;*=$_}@_[++$x..$b++]}print$m 79, wmeriic -l eval'$_=pop;s//*/g;/.{1,'.2*pop().'}(??{$_=$_<($x=eval$&)?$x:int;X})/;print' 81, o0lit3 -l ($_,$%)=@ARGV;map{$-=$@if($@*=$_)>$- }$&=~/./g,s/.//while$@=/.{1,$%}/;print$- 81, Stephen Turner -l for$n(1..pop){$_|=(pop|0 x23)x9;s/\B/*/g,$p>eval or$p=eval for/.{$n}/g}print$p 86, Big_Tex (post-mortem) -l for(0..20){$t=1;map{$-=($t*=$_)>$-?$t:$- }split//,substr$s|=shift,$_,$n|=pop}print$- 88, Big_Tex -l for(0..18){$t=1;map{$-=($t*=$_)>$-?$t:$-}split/ */,substr$s|=shift,$_,$n|=pop}print$- 105, Frantisek Darena @n=shift=~/./g;for(1..pop){$i=-1;$m<($==eval join'*',@n[$i..$_+$i- 1])and$m=$=while$i+++$_<@n}print$m|0,$/ 110, Jurgen Pletinckx -l @a=split'',shift;$m=0;for$l(1..shift){for$p(0..$#a){$t=1;map{$t*=$a[$p+$_- 1]}(1..$l);$m=$t if$t>$m}}print$m

6.23. Regex simplification http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=59&season=1 The game started 2004-03-23 19:00:00 and ended 2004-03-28 20:00:00. Rules by ton.

6.23.1. Rules Consider the following regular expression (regex): abc(def(fgh)ij\2)klm This is hardly optimal, since the outer pair of parenthesis is completely unneeded, so you could just as well write: abcdef(fgh)ij\1klm where the outer parenthesis are dropped and the back-reference was changed from \2 to \1 (remember that parenthesis pairs get a number by counting opening parenthesis from left to right). In this challenge you should do these simplifications automatically. On STDIN you get one line matching /^[\\\da-zA-Z()]{1,80}\n\z/. This line represents the regex to be simplified. All parentheses will be properly nested, and the body between parentheses is never

Edition 2007-01-09 top secret / strictly confidential page 360 of 520 Perlgolf History

empty. Any backslash will only be used to start a back-reference, so will be always followed by a digit. In fact, any \ will be followed by only a single digit, no parenthesis pair with an index of 10 or higher will ever be referenced (though there can be more than 10 parenthesis pairs in the input). A back-reference will also never appear too early (when its corresponding parenthesis pair is not yet closed). Also, any digit in the input will be part of a backreference, so it will be preceded by a backslash. On STDOUT you should output the simplified regex, with all parenthesis pairs that have no back- reference removed and all back-reference numbers updated to the new numbering of parenthesis. The output will of course also match /^[\\\da-zA-Z()]{1,80}\n\z/.

6.23.2. Solutions 69, tybalt89 -p s/\)|([ -9])/@$1or$1?$s[@s]=$_=~++$p&&($#$p=$n++,'('):pop@s&&$&/ge 69, 0xF -p s/(\(|\d)|\)/"@$1"or$&x1x chop($s.=$1&&($_=~++$i?@$i=++$j:0)x2)/ge 70, Daniel -p s#[(-9]#$a{$&}or$&^'\x18'?pop@b:do{$b[@b]=$a{$.++}=/$./&&++$@}and$&#ge 70, o0lit3 (post-mortem) -p s![(-:]!$@[$&]or$&^v24?pop@*:do{$*[@*]=$@[$.++]=/$./&&++$*}and$&!eg 74, Andreas -p s#[(-:]#$N[$&]or$&^v24||do{push@P,($N[$.++]=/$./&&++$n)x2},pop@P&&$&#eg 74, o0lit3 -p s![(\d)]!$@[$&]or$&=~/[)]/?pop@*:do{$*[@*]=$@[$.++]=/$./&&++$*}and$&!eg 75, Juho Snellman -p s%\(|(\))%$1or$_.=$'=~++$a?($a[$a]=++$b,')('):__;chop%ge;s/\d|_/$a[$&]/g 77, Stephen Turner -p s/$-/$a[$-]||=++$x/eguntil++$->9;s/(\()|\)/$a[$1?$b[@b]=++$j:pop@b]&&$&/eg 77, Jasper -p s!(\()|[)\d]!$1?($c{$a[@a]=$.++}=/$./&&++$j)&&'(':$c{$&}||$c{pop@a}&&$&!eg 85, Grizzley -p s#[()]#$i='('eq$&?$t[@t]=$x+=$z=1:pop@t;($0=$&)x/$i/#eg;s/$a/$z/g&&$z++while $a++<9

6.24. Matrix http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=60&season=1 The game started 2004-04-06 18:00:00 and ended 2004-04-11 19:00:00. Rules by http://acm.uva.es/p/v8/836.html . Idea by tybalt89.

Edition 2007-01-09 top secret / strictly confidential page 361 of 520 Perlgolf History

6.24.1. Rules Let A be an N*N matrix of zeros and ones. A submatrix S of A is any group of contiguous entries that forms a square or a rectangle. Write a program that determines the number of elements of the largest submatrix of ones in A. Largest here is measured by area. Input The matrix is given line by line on STDIN. Each line consists of 0's and 1's. The order of the matrix is also the number of lines input and 0 < N < 10. Output The output to STDOUT is the number of elements of the largest submatrix found. Sample Input 10111000 00010100 00111000 00111010 00111111 01011110 01011110 00011110 Sample Output 16

6.24.2. Solutions 53, mtve (post-mortem) -lp0 $_=$_&$'||$#:while@:[map$a*y/1//,/1*/g]=++$a,/ / 54, mtve (post-mortem) -lp0 $_=$_&$'||$#:while++$a,\@:[map$a*y/1//,/1*/g],/ / 55, mtve (post-mortem) -lp0 $_=/ /?$_&$'./1+(?{$,|=$&x$^C})^/:length$,while++$^C 55, mtve (post-mortem) -lp0 $_&=$'.!++$B.\@B[map$B*y/1//,/1*/g]while/ /;$_=$#B 56, ton (post-mortem) -lp0 / /,$_&=$'./1+(?{$n|=$&x$^C})^/while++$^C;$_=length$n 57, Juho Snellman (post-mortem) -lp0 (map\$B[$?*y///c],/1*/g),/ /,$_&=$' while++$?;$_=$#B 58, ton

Edition 2007-01-09 top secret / strictly confidential page 362 of 520 Perlgolf History

-lp /.+()(?{$n|=(${"@-"}.=$&)x=-index$&,0})^/}{$_=length$n 59, Juho Snellman -lp0 s/1*/$B[$?*length$&]=$&/ge,/ /,$_&=$' while++$?;$_=$#B 59, o0lit3 (post-mortem) -lp0 s/1*/$$[$^C*length$&]=$&/eg,/ /,$_&=$' while++$^C;$_=$#$ 60, andys (post-mortem) -lp0 \$a[$`*$'*/(.*1{$`}.{$&} ){$'}/]while--$?=~/\B./;$_=$#a 65, andys -lp0i999 \$a[$`*$'*/(.*1{$`}.{$&} ){$'}/]while$^I--=~/\B./;$_=$#a 66, o0lit3 -lp0 s/1*/$*[$^C*($&=~y|1||)]=$&/ge*/ /+($_=$'&$_)while++$^C;$_=@*-1 66, stalker -lp0 $z[$`*$'*/(.*1{$'}.{$&} ){$`}/]=$z++=~/\B./while$z<1e3;$_=$#z 69, Jasper -lp0 \$c[$i++=~/\B./*$'*$`*/(^.{$&}1{$'}.* ){$`}/m]for($_)x999;$_=$#c 90, Shlomi Fish -alp0 for$}(1..81){for$x(1..9){$y=$}/$x-1;$%=$}if/1{$x}(.{@{[@F+1- $x]}}1{$x}){$y}/s}}$_=$% 93, Andreas -lap0 $n=$'-1,$s=@F- $&,$a=$&*$',$;=/(1{$&})(..{$s}\1){$n}/s*$a>$;?$a:$;while++$=~/^\d/;$_=0+$ 94, Andreas -lap0 $n=$'-1,$s=@F- $&,$a=$&*$',$;=/(1{$&})(..{$s}\1){$n}/s*$a>$;?$a:$;while++$^C=~/^\d/;$_=0+$

6.25. Shadow http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=61&season=1 The game started 2004-04-28 10:00:00 and ended 2004-05-04 20:00:00.

6.25.1. Rules There is a three-dimension space consisting of size 6*6*6 cells. Each cell of this space can be empty or occupied, and the occupied cells will make up some three-dimensional shape. This shape will then be projected on the three coordinate planes. You can not restore the original figure from projections in every situation, because some cells can be hidden or projected together with others. However, you can

Edition 2007-01-09 top secret / strictly confidential page 363 of 520 Perlgolf History determine the maximum number of cells that could be occupied by assuming that all hidden cells are indeed occupied. Your task is to determine this number. Consider for example the case where each coordinate plane has one occupied cell in each corner. You can find 3D shapes made up from 4 to 8 occupied cells corresponding to that projection set. The correct answer for this case would be the maximum of these, "8" (corresponding to an occupied cell at all corners of a cube, all other solutions are subsets of this one where in all projections the filled corners hide the ones you left empty). As another example (without the possibility of hidden cubes this time), consider this picture:

Input on STDIN will match /^([.X]{6} [.X]{6} [.X]{6}\n){6}\z/. Output on STDOUT should match /^(0|[1-9]\d*)\n\z/. The input will always correspond to the projection of some real 3D figure, so you don't need to do any checking for invalid input. Example input (corresponds to the picture): ...... XXXX. .X...... X. ....X. .X...... X. ....X. .XXXX. .XXXX. ....X...... Output:

Edition 2007-01-09 top secret / strictly confidential page 364 of 520 Perlgolf History

9

6.25.2. Solutions 57, ton -lp0 / (.*)X.* .*X(.*) (?{$_.=$_&$1.$2x21 .A})^/;$_=y/@// 62, Michael Rybakin -l / /,map$r.=$'&$_&(chop$a)x6,$a=$',@~for@~=<>;print$r=~y/X// 63, ton (alternative) -lp0aF| /X.* .*X(?{$?+=$F[167+"@-"-21*pos]^i})^/for/ .+/g;$_=$? 69, ton (alternative) -lp0 $_=- s#X#$%=6-"@+"/21;$;+=split/ .{@{["@-"%21]}}X.* .{$%}X/#eg+$ 71, RobTM -pal $b.=$F[0]x6;$"=!s/./$m[19-pos].=$&x6&$F[1]/ge}{$_=("@m"&$b)=~y/X// 81, Jed Davis -l @==<>;for$y(0..5){map{$q+=/ .{$-[0]}X.* .*X.{$y}$/}@=while$=[$y]=~/X/g}print$q 82, Grizzley (post-mortem) -lap $F[2]=~s/./$a[$c++%6].=$&x6&$F[1]/eg;$y=($F[$"='']x6).$y}{$_=$y&"@a";$_=y/X/ / 85, o0lit3 -lp $*[$.-1]=$_}{for$x(0..5){map$;+=/ .{$-[0]}X.* .*X.{$x}$/,@*while$*[$x]=~/X/g}$_=$ 89, Roy Johnson @r=<>;for$x(0..5){for$y(0..5){$s+=$r[5-$y]=~/^.{$x}X/*/ .{$x}X.* .{$y}X/for@r}}print"$s " 89, Juho Snellman -lp s|X|$;[(($b="@+"%7).7-$..$_,$b.$_.7-$.,$_.$b.7-$.)["@-"/7]]++for 1..6|ge}{$_=map/3/,@ 92, Grizzley -lap $F[2]=~s/./$a[$c++%6].=$&x6/eg;$,.=$F[1];$y=($F[0]x6).$y}{$_=$y&$,x6&join"", @a;$_=y/X// 98, Two-Bits -lp s!\.!$a=$-[0]%7+1;$b=7-$.;\$;{+("$_$b$a","$b$_$a","$b$a$_")[$+[0]/7]}for 1..6!eg}{$_=216-keys% 109, Jasper -lpaF| for$i(0..19){$s{$_ x($i>13).($i%7).$_ x($i>6&$i<13).(6-$.).$_ x($i<6)}|=$F[$i]for 0..5}}{$_=grep/X/,%s 136, Jurgen Pletinckx

Edition 2007-01-09 top secret / strictly confidential page 365 of 520 Perlgolf History

@i=split//,join'',<>;for$x(0..5){for$y(0..5){map{$t++if$i[112- 21*$_+$x]eq'X'&&$i[119-21*$_+$y]eq'X'&&$i[105-21*$y+$x]eq'X'}0..5}}print$t 139, Jurgen Pletinckx -l @i=split//,join'',<>;for$x(0..5){for$y(0..5){map{$t++if$i[112- 21*$_+$x]eq'X'&&$i[119-21*$_+$y]eq'X'&&$i[105-21*$y+$x]eq'X'}0..5}}print$t

6.26. Mayan number converter http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=62&season=1 The game started 2004-06-06 18:00:00 and ended 2004-06-10 19:00:00. Rules by o0lit3.

6.26.1. Rules Input is mayan number (base 20), with digits composed by following elements (given in order of appearance): • a period (.) represents one stone, • a colon (:) represents two stones, • a pipe character (|) represents a stick (five ones), and • a hyphen (-) represents the null seashell. Digits on STDIN are separated by spaces and terminated by a newline. One digit matches /^([.:]:?\|{0,3}|-)\z/ and there will be from 1 to 7 digits. Example: .:| .:||| ::| ::|| . Output on STDOUT should be the decimal equivalent and a newline, in this case: 1427881 calculated as follows: 20**4*(3+5) + 20**3*(3+15) + 20**2*(4+5) + 20**1*(4+10) + 20**0*(1) = 1280000 + 144000 + 3600 + 280 + 1 = 1427881 More about mayan numbers can be found at http://www.saxakali.com/historymam2.htm

6.26.2. Solutions 37, tybalt89 (post-mortem) -lp s/./$# +=$#*19*"5+1:2-"!~$&+$'/ge 38, mtve -p040 $\=5*y/.:|/43/d-$_%9+20*$\.v10}{ 38, tybalt89 -lp y/ .:|/0125/;s/./$# +=$&||19*$#/ge 38, Michael Rybakin (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 366 of 520 Perlgolf History

-lp s/./$# +=19x"5 1:2-"!~$&*$# +$'/ge 39, o0lit3 (post-mortem) -lp040 $;=$;*20+5*y/.:|/43/d-$_%9}{$_=$ 40, stalker -pl $;+=/ /?$;*19:(56^ord)%7for/./g;$_=$ 41, kcwu -lp $;+=y/.:|-/1250/?$_:19*$;for/./g;$_=$ 41, Daniel -lp $;+=y/-.:|/0125/?$_:19*$;for/./g;$_=$ 41, tybalt89 (alternative) -lp s/.-?/$# +=97**(15+ord$&)%7||19*$#/ge 41, Jasper -lp $;+=y/|:.-/521/d?$_:19*$;for/./g;$_=$ 41, g.allen -pl $;+=y/.:|/125/?$_:$;*19for/.-*/g;$_=$ 41, g.allen (alternative) -pl $;+=y/-.:-|/0-5/?$_:$;*19for/./g;$_=$ 41, Bass -lp $;+=y#.:|-#1250#?$_:19*$;for/./g;$_=$ 42, Peter Haworth -lp y/ .:|/0125/;s/./$;+=$&||$;*19/ge;$_=$ 42, Peter Haworth (alternative) -lp y/ .:|/0125/;$;+=$_||$;*19for/./g;$_=$ 42, shr -pl y/.:|/125/,s!.!$;+=-$&||$;*19!eg,$_=-$ 42, Juho Snellman -lp040 $;=$;*20+y/.://+y/://+5*y/|//}{$_=$ 42, m.wrenn -pl $n+=y/-.:|/0-25/?$_:$n*19for/./g;$_=$n 42, Roy Johnson -lp y/.:| /1250/;s#.#$S+=$&||$S*19#eg;*_=S 42, o0lit3 (alternative) -lp040 $;=$;*20+5*y/|//+y/://+y/.://}{$_=$ 42, o0lit3 -lp040 $;=$;*20+5*y/|//+2*y/://+/\./}{$_=$ 42, Michael Rybakin

Edition 2007-01-09 top secret / strictly confidential page 367 of 520 Perlgolf History

-lp s/./$%+="5 1:2-"!~$&*19*$%+$'/ge;$_=$% 42, Jeff Moore -lp y/.:| /1250/,$;+=$_||$;*19for/./g;$_=$ 42, id5 -pl y/ .:|/0125/;s/./$;+=$&||$;*19/ge;$_=$ 42, scw -lp y/.:| /1250/;s!.!$;+=$&||19*$;!ge;$_=$ 42, thepoet -lp $s+=y/-.:|/0125/?$_:$s*19for/./g;$_=$s 43, Jed Davis -lp y/.:| /1250/;s/./$-+=$&||19*$-/eg;$_=$- 43, Jasper (alternative) -lp y/|:. /521;/;$;+=$_+19*$$_ for/./g;$_=$ 44, Two-Bits -lp040 y/.:|/125/;$;*=20;s/./$;+=$&/ge}{$_=$ 44, Roy Johnson (alternative) -lp y/.:| /1250/;s#.#$S+="$&"||$S*19#eg;*_=S 44, vgod -pl $n+=/ /?19*$n:$_*y/.:|/125/for/./g;$_=$n 44, Bass (alternative) -lp040 $;=eval'+$;*4+y/|43:./43:./d'x5}{$_=$ 44, okrach -pl y/.:|/125/,$n+=$_+$n*19*/ /for/./g;$_=$n 45, vgod (alternative) -pla $S=$S*20+/\./+y/://*2+5*y/|//for@F;$_=$S 46, Mr. Neutron -lap $a=$a*20+y/|//*5+y/://*2+y/.//for@F;$_=$a 46, _-Ani-_ -lp0040 $l*=20;y/.:|/125/;s/./$l+=$&/eg}{$_=$l 47, _-Ani-_ (alternative) -apl $"*=20,y/.:|/125/,s/./$"+=$&/egfor@F;$_=$" 48, J.P. (post-mortem) -lp040 y/.:|/125/;$;*=20;map{$;+=$_}/./g;}{$_=$; 48, Grizzley -pal $;*=20,map$;+=(ord)%21%11-3,/./gfor@F;$_=$ 51, ErikB

Edition 2007-01-09 top secret / strictly confidential page 368 of 520 Perlgolf History

-alp y/.:|-/1250/?$t+=20**$#F*$_:$#F--for/./g;$_=$t 53, Jasper (rejected) -lp s//$`x19/ewhile/ /;y/|:./521/;$;+=$_ for/./g;$_=$ 64, o0lit3 (alternative) -lpa y/-.:|/0125/+s/\d/+$&/g+s/\S+/"+($&)*20**".$#F--/eg,$_=eval 65, J.P. -anl $i=@F;map{y/\.:|/125/;$i--;map{$u+=$_*20**$i}/./g}@F;print$u 66, J.P. (alternative) -nl map{y/.:|/125/;$u+=$_*20**$i;$i++if' 'eq$_}reverse/./g;print$u 68, reto -pal $i=@F;map{$t+=(/\./+2*@{[/:/g]}+5*@{[/\|/g]})*20**--$i}@F;$_=$t 68, tomekM -pl s/\S+/$_=$&;y!-.:|!0125!;$c=0;s!.!$c+=$&!ge;$w=$w*20+$c/ge;$_=$w 75, o0lit3 (alternative) -p 1while s#\d*[-.:|]+ ?#$*+=20**y/ //*(5*$&=~y/|//+2*$&=~y/://+$&=~/\./)#e 163, Paul van Eldijk -alp $N=@F;for(@F){tr/.:|-/1250/;my$f;$f+=$_ fo#!perl -alp $N=@F;for(@F){tr/.:|-/1250/;my$f;$f+=$_ for split//;$t+=$f*20**--$N}$_=$tr split//;$t+=$f*20**--$N}$_=$t

6.27. Rush Hour http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=63&season=1 The game started 2004-06-22 20:00:00 and ended 2004-06-29 20:00:00. Rules by ton.

6.27.1. Rules Rush Hour is a sliding block puzzle designed by famous puzzle designer Nob Yoshigahara. He unexpectedly died on 2004-06-19 (actually during the period I was preparing this golf), so I dedicate this golf to his memory. The real version of the game looks like this:

Edition 2007-01-09 top secret / strictly confidential page 369 of 520 Perlgolf History

The challenge is to move the cars forward and backward (they can't turn) until you can drive the red car out of the slot you see on the right. (Strangely enough they set up a situation different from the cue card in this picture. Both however are solvable). It's a fun puzzle, and many online versions of it exist, though the name is often changed to "Traffic" or "Traffic Jam". A good list is found at http://www.puzzles.com/products/rushhour.htm . We don't do fancy graphics in perlgolf, so we'll play on an ASCII board instead. The situation depicted in the picture will for us be (without the colors even): ######## #aaaBD # # BD # #bb DE #AccddE# #AeeC F# #fffC F# ######## So now let's solve it. Move car b one right.

Edition 2007-01-09 top secret / strictly confidential page 370 of 520 Perlgolf History

######## #aaaBD # # BD # # bb DE #AccddE# #AeeC F# #fffC F# ######## Move car A two up. ######## #aaaBD # #A BD # #Abb DE # ccddE# # eeC F# #fffC F# ######## Move car c one left. ######## #aaaBD # #A BD # #Abb DE #cc ddE# # eeC F# #fffC F# ######## Move car d one left. ######## #aaaBD # #A BD # #Abb DE #ccdd E# # eeC F# #fffC F# ######## Move car D three down. ######## #aaaB # #A B # #Abb E #ccddDE# # eeCDF# #fffCDF# ######## Move car E two up. ######## #aaaB E# #A B E# #Abb #ccddD # # eeCDF# #fffCDF# ######## Move car b four right.

Edition 2007-01-09 top secret / strictly confidential page 371 of 520 Perlgolf History

######## #aaaB E# #A B E# #A bb #ccddD # # eeCDF# #fffCDF# ######## This finally puts the target car in the output slot. Input The playing field will always be exactly 6x6, surrounded by an edge of #, except there will be a hole (space) on the fourth line on the right. The cars are represented by letters. All cars have a length of 2 or 3 and are always 1 wide. Only one car (part) can occupy a given position, and cars can't jump, a move must always be able to occupy all intervening positions. Cars also obviously can't share space with a wall. Horizontal cars will each get a different lowercase letter. The assignment of letters starts with a and proceeds from left to right and then from top to bottom without any holes in the naming. There will be only one horizontal car on the row with the exit, it will have length 2 and it won't start inside the exit. Horizontal cars can only move to the left or to the right. Vertical cars will each get a different uppercase letter. The assignment of letters starts with A and proceeds from top to bottom and then from left to right without any holes in the naming. Vertical cars can only move up and down. The playing field will be given as lines on STDIN, each line properly newline terminated. So input will match: /^#{8}\n(#[a-pA-P ]{6}[# ]\n){6}#{8}\n\z/ Output You should output on STDOUT a sequence of car movements, one per line. A movement is specified as letter representing the car that will move, followed by a space, an integer specifying by how much the car should move and a newline. Negative numbers mean moving to the left or up, positive numbers mean to the right or down (the case of the car letter will determine which of the two it is). Positive numbers may be specified with or without the sign, and you may precede all numbers with as many zeros as you like. Your solution doesn't have to be efficient. You may uselessly move cars around as much as you want as long as all the moves are valid. You may even give 0 as the movement number meaning that the given car stays in its place. The sequence of moves must end with a car in the output slot, though the move that got it there doesn't have to be the last one. It's ok to move some random cars after you basically solved it. It's even ok to move the car out of the output slot again and keep moving around, as long as at the last move it's back there. To avoid the classic random walk solutions, in this golf it's explicitly possibly that there is no solution for a given input. In that case you should output nothing whatsoever. So STDOUT must match: /^([a-pA-P]) ([+-]?\d+)*\z/ So for the given example the output is:

Edition 2007-01-09 top secret / strictly confidential page 372 of 520 Perlgolf History

b1 A-2 c-1 d-1 D3 E-2 b4

6.27.2. Solutions 137, ton -0p @;=$_}{++$#$_||s!((|\w)\2+) !/#\w#/?$\:${$;[@;]=join"",map chop,("$` $1$'"=~/.+/g,$' x8)x8}=$$_.($2&&"$2 @{[1-2*/ | .*$/]} ")!egfor@ 140, tybalt89 -p0aF$ $p=$_,map{for$f($",$c=$_){$.*=- //;$\||=(${$F[$$_.@F]=s/$f((.{8}$c)+.{8}|$c+)($&)/$+$1$f/s&&$_}="${$_=$p}$c $. ")x!/ $/m}}/\w/gfor@F}{ 142, ton (alternative) -0p @;=$_}{/\w /?$\=$$_:s#\w#${$p="$`$4$3 $2$1$'"}||="$$_$1$4 ${$;[@;]=$p,$1?\1:\-1} "if/($&)($&+|..+$&.{8}) | (\G$&+|.{8}\G...+)($&)/s#egfor@ 149, Juho Snellman (rejected) -n0 sub R{$b<0?reverse:$_}sub M{/ /?s^\pL^$b=$#A**pos;$c=8*($< Z);s/$&/ /,s/(($&)\C{$c}) /$1$2/-++${$_=R}or M(@_,"$2 $b ")for~~R^ge:exit print@_}M 157, Juho Snellman -n0 sub R{$b<0?reverse:$_}sub M{/ /?s^\pL^$b=$#A**pos;push@_,"$& $b ";$c=8*($< Z);s/$&/ /,s/(($&)\C{$c}) /$1$2/-++${$_=R}or&M for~~R;pop^ge:exit print@_}M 161, Jasper (post-mortem) -p0 sub g{my($b,$r)=@_;$$b++||map{$s||=$r x$b=~/$c /||g($n=$b,"$r$c ".($n=~s/$_((.{8}$c)+.{8}|$c+)(?!$_)($c| )/$3$1$_/s-2*/ /).$/)for$",$c=$_}$b=~/\w/g;$s}$_=g$_ 164, stalker

Edition 2007-01-09 top secret / strictly confidential page 373 of 520 Perlgolf History

-p0aFX $\||=${$w=$_}x!/ /,map{@a=($s=".{8}"x/\u$_/,$",$_);($x=$w)!~s/($a[$.])(($s$_)+$s)($a[$.*=- 1])/$4$2$1/s||$$x or$$x="$$w$_ $. ",push@F,$x}(a..p,A..Q)x2for@F}{ 170, Szeryf -ln0 sub M{/ /||exit map print,@_;for$c(/\w/g){$r=a gt$c&&'.'x8;for$m(- 1,1){my$a=$_;$u="(($r$c)+$r)";$$_++||M(@_,"$c $m")if$m<0?s/ $u$c/$c$1 /s:s/$c$u / $1$c/s;$_=$a}}}M 173, Jasper -p0 sub g{my($b,$r)=@_;$s{$b}++||map{$p='.'x8x/[A-Z]/;$s||=$r x$b=~/$c /||g($n=$b,"$r$c ".($n=~s/$_(($p$c)+$p)(?!$_)($c| )/$3$1$_/s-2*/ /).$/)for$",$c=$_}$b=~/\w/g;$s}$_=g$_ 180, Jeff Moore -ln $c.=$_}{sub z{for$l(a..o,A..O){for$n($\="",'.'x7){for$,($",$l){$b=$,^$"^$l,/ #\PP/||exit(print@_),s/$,($n($l$n)+)$b/$b$1$,/and$p{$_}++||z("@_$l @{[2cmp$b]} ")for"$_"}}}}z for$c 184, Michael Rybakin -p0 1until!s^.{72}^$r='';$p=$_,map{$e="((.{$_}$p)+.{$_})";$_=$t;$$_ or$r.=$_,$$_="$$t$p $. "if($.=-$.)>0?s/$p$e / $1$p/s:s/ $e$p/$p$1 /s;/ / or$\=$$_}8800=~//gfor($t=$&)=~/\w/g;$r^ges 251, scw -p0 sub r{$_{local$;=$_}++||map{sub k{$b.=pop;&r;$b=$a;$_=$;}local($_,$c,$p,$a)=($;,$_,"(.{8}($_.{8})+)",$b);k"$ c-1 "if s/ $p$c/$c$1 /s;k"$c 1 "if s/$c$p / $1$c/s;$c=lc$c;$\=$b,next if/$c /;k"$c -1 "if s/ ($c+)/$1 /;k"$c 1 "if s/($c+) / $1/}A..P}&r}{ 344, o0lit3 -ln0aF| sub v{my@r;$x=pop;$n=pop;$b=$n>0;$c=71*$b;$d=72-$c-2*$b;for($i=$c;$i!=$d;$i+=$b*- 2+1){if($r[$i+$n]eq($r[$i]=" ")){$_[$i]eq$x?$r[$i+$n]=$x:$r[$i]=$_[$i]}else{$_[$i]eq$x?return:($r[$i]=$_[ $i])}}$r{join'',@r}++?@q:@r}sub b{@_?$_[34]ne" "?do{print for@c;exit}:do{for(@_){for$@(-1,1){push@c,"$_ $@";b(v(@_,$@*(/[a- z]/||9),$_));pop@c}}}:0}b@F

6.28. Balanced Ternary Addition http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=64&season=1 The game started 2004-07-12 19:50:00 and ended 2004-07-19 20:00:00. Rules by Juho.

Edition 2007-01-09 top secret / strictly confidential page 374 of 520 Perlgolf History

6.28.1. Rules Balanced ternary is a positional notation for expressing values in base-3, which uses the symbols -1, 0, and 1 as digits. To convert a balanced tertiary number to decimal, add together the position-dependent values of the digits. The value of the nth digit (counting from the right) is 3**(n-1). For example, the balanced tertiary number -110-1 has the decimal value 27*-1 + 9*1 + 3*0 + 1*-1 = -19. Addition between two balanced ternary digits is defined by the following table: + -101 -1 -11 -1 0 0 -101 1 0 1 1-1 If the adding two digits results in multiple digits, the results are carried over as in normal addition. For example, adding together 1-1-1 (5) and 10-1 (8) results in 111 (13) as illustrated by the following diagram: -1 -1 1-1-1 +10-1 ------111 Or, more detailed: 1-1-1 +10-1 ------1 1 -1 1-1 ------1 -1 1 1-1 ------1 1 -1 1 1 ------0111 Input: On STDIN two lines, both containing a valid number in balanced ternary notation. The input will match the pattern /^((-1|0|1)+\n){2}\z/. The values of the numbers will be between -255 and 255. Example: 1-1-1 10-1 Output: On STDOUT one line (terminated by a newline) containing the sum of the numbers, in balanced ternary notation. Leading zeroes are only allowed if the zero is the only digit. The output should match the pattern /^((-1|1)(-1|0|1)*|0)\n\z/. Example:

Edition 2007-01-09 top secret / strictly confidential page 375 of 520 Perlgolf History

111

6.28.2. Solutions 67, tybalt89 -lp0 $\=-$%+3*($%/=2).$\while s/-?.\s/$%-=$&;$"/ge}{$\=~s/0*(?=.)// 67, Daniel (post-mortem) -pl ``;$!=$_+3*$!for/-?./g;$s+=$!}{$s/=3while$s-=s//$;=++$s%3-1/e+$ 67, stalker -pl $x+=$&*3**y/10//while s/-?.//}{$x/=3while$x-=s//++$x%3-1/e*$x%3 70, Daniel -pl ``;$!=$_+3*$!for/-?./g;$s+=$!}{1while$s-=$r=++$s%3,s//--$r/e,$s/=3 72, Michael Rybakin -lp s/-1/4/g;$r+=$_}{y/514/0/,$r+=$_*5while$_=$r,$r=~y/528/041/;s/4/-1/g 73, Roy Johnson (post-mortem) -pl $s+=eval'('x s/-?./)*3+$&/g.$_}{s//($r=++$s%3)-1/e;redo if($s-=$r)/=3 73, Roy Johnson (post-mortem) -lp $o=0;s/-?./$o=3*$o+$&/ge;$s+=3*$o}{1while$s/=3,s//++$s%3-1/e,$s-=$s%3 74, Szeryf -pl $a+=eval'('x s/-?./)*3+$&/g.$_}{$a/=3while$a-=s//$;=(0,1,-1)[$a%3]/e*$ 74, Roy Johnson -pl $a=0;$a=$_+$a*3for/-?./g;$s+=$a}{s//($r=++$s%3)-1/e;redo if($s-=$r)/=3 77, Andreas -lp $s=$_+$s*3for-3*$s,/-?./g,0+$s}{s##$d=(0,1,-1)[($s/=3)%3]#e;redo if$s-=$d 86, Yenya -ln $o=0;s/-?./$o=3*$o+$&/ge;$s+=3*$o;END{s//++$s%3-1/e,$s- =$s%3while$s/=3;print$_||0} 89, Roy Johnson (post-mortem) -pl s/-1/3/g;$x+=$_}{$_=$x;$_+=0while s/.?([^013])/$&- 4+15*($1==2)+29*($1==6)/eg;s/3/-1/g 97, bgreenlee -ln END{s//$*%3/ewhile$*=$n+(($n/=3)<=>0)/2;s/2/- 1/g,print$_++}$i=1;$n+=$&*($i*=3)while s/-?\d$// 97, ErikB -alp0 map{$t=$x/-3;map$t+=s/-?.$//?$&:0,@F;$z=$t+($x=$t>1?-3:$t<- 1?3:0).$z}0..9;$_=$z;s/0*(.)/\1/ 99, o0lit3 (post-mortem) -lp sub t{my$X;$X=$_+$X*3for/-?./g;$X}$%+=t}{$_=join'',map-1+int 3*rand,0..6while$%ne t+s/0*(?=.)// 102, o0lit3

Edition 2007-01-09 top secret / strictly confidential page 376 of 520 Perlgolf History

-lp sub t{my$X;$X+=$_+$X*2for/-1|./g;$X}$%+=t}{$_=join'',map-1+int 3*rand,0..6while$%ne t+s/^0*(?=.)// 102, wmeriic -lp $i=@i=/-?./g;$a[--$i]+=$_ for@i}{map$a=(($_+=$c)- ($c=abs>1&&$_<=>0)*3).$a,@a;($_)="$c$a"=~/0*(.+)/ 103, Michael Chapman -nl s/-1/3/g;$x+=$_}{$_="0$x";eval's/[457]/$&- 4/ge;s/.2/$&+11/eg;s/.6/$&+25/eg;'x9;$_+=0;s/3/-1/g;print 116, gordoste -pl $a=0;s/-?\d/($a*=3)+=$&/eg;$c+=$a}$c=~s!.*!$e=$&%3*3**$p;$e=- 1if$e==2;$_=$e.$_;($&-3**$p*$e)/3!e while$c;{$_||=0 121, thepoet -lp sub d{($r[$p=pop]+=pop)=~/2/&&d(-($r[$p]/=-2),$p+1)}$c=0;d$_,$c++for reverse/-?\d/g}{$_=join'',reverse@r;s/^0+(?=.)// 133, o0lit3 (alternative) -lp0 s/-1/3/g;map$@+=$_,/.+/g;$_=$@;$@=length,s/\d/$&.'0'x--$@.' '/eg,s/2|6/$&*4.5+4/eg,do$0if/2|6/;y/5784/130/+s/3/-1/g+s/^0*(?=.)// 146, ced-2 -p sub f{my($n,$i);$n+=$&*3**$i++while s/-?[01]$//;$n}sub r{int(rand 3)- 1}$g=f()+f$_=<>;1while f($r=$_=r.r.r.r.r.r.r)!=$g;$r=~s/0*//;$_=($r||0).$/

6.29. Mastermind http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=65&season=1 The game started 2004-07-27 20:00:00 and ended 2004-08-03 20:00:00. Rules by o0lit3.

6.29.1. Rules Mastermind is a logic game in which the object is to guess the sequence of four colored pegs (each one of 6 possible colors) selected by your opponent at the beginning of the game. Players get up to 8 guesses. After every guess, information is given to help narrow the result set. You are given a marker for ever correct colored peg you have chosen. The marker is black if the colored peg is in the correct position, and the marker is white if it is not in the correct position. You can play this game online1 to get a better idea of how it works. Input Input will be a list of guesses (where the values 0-5 correspond to the 6 possible peg colors), followed by the number of black markers received for the guess, followed by the number of TOTAL markers received for the guess. The list will include enough information such that the solution will be obtainable with one more guess. The input will match the pattern /^([0-5]{4} [0-4] [0-4]\n){1,7}\z/.

1 http://thinks.com/java/mastermind/mastermind.htm

Edition 2007-01-09 top secret / strictly confidential page 377 of 520 Perlgolf History

Output Output will be the "hidden" sequence followed by the newline, matching the pattern /^[0- 5]{4}\n\z/. All inputs will have one (and only one) solution. Sample Input 5311 1 1 4221 0 1 2333 1 2 3304 3 3 Sample Output 3344

6.29.2. Solutions 90, tybalt89 -lp @;=grep{"$'"eq(($x=$`)^$_ x5)=~y/\x006-9//.$".grep$x=~s/$_//,/./g}@;,/ /%1x4..5x4}{($_)=@ 91, Daniel -pl @;=grep{$'./[6-9]/eq(($x=$`)^$_)=~y/\x00//.$".grep$x=~s/$_//,/./g}/ /%1x4..5x4,@;}{$_=pop@ 92, o0lit3 -lp @;=/ /&&grep{$'./[6- 9]/eq(($@=$`)^$_)=~y/\x00//.$".grep$@=~s/$_//,/./g}@;,$-x4..5x4}{($_)=@ 97, Roy Johnson (post-mortem) -lp / /;@;=grep{"$'"eq(($P=$`)^$_)=~y/\x00//.$".grep$P=~s/$_//,/./g}@;,glob'{0,1,2 ,3,4,5}'x4}{($_)=@ 98, Szeryf -pal @;=grep!(y/6-9//|(($g=$F[0])^$_)=~y/\x00//-$F[1]|$F[2]- grep$g=~s/$_//,/./g),@;,$|x4..5x4}{($_)=@ 98, Michael Rybakin -lpa @r=grep{$F[!/[6- 9]/].$F[2]eq($_^($~=$F[0]))=~y/\x00//.grep$~=~s/$_//,/./g}0 x4..5x4,@r}{$_=pop@r 99, stalker -pa $x{$_}|=y/6-9//|($_^($z=$F[0]))=~y/\x00//-$F[1]|$F[2]-grep$z=~s/$_//,/./g or$\=$_.$/for$%x4..6x4}{ 104, pengvado -lna @;=grep{not$F[1]^($_^($g=$F[0]))=~y/\x00//|y/6- 9//||$F[2]^grep{$g=~s/$_//}/./g}@;?@;:0 x4..5x4}{print@ 108, Michael Chapman -pl @{$.}=grep!/[6-9]/,0 x4..5x4;/ ./;@1=grep{$&==(($x=$`)^$_)=~y/\x00//&$'==grep$x=~s/$_//,split//}@1}{$_="@1" 113, Stephen Turner

Edition 2007-01-09 top secret / strictly confidential page 378 of 520 Perlgolf History

-l @@=<>;map{$a=$_;/[6- 9]/|grep{$b=($p=$_^($A=$a))=~y/\x00//;$p+=$A=~s/$_//for/\G\d/g;!/ $b $p/}@@or print}0 x4..5x4 115, Roy Johnson -lp / /;@;=grep{$c=0;$P=$_;{$c+=$P=~s/$_//for$`=~/./g}($`^$_)=~y/\0//." $c"eq$'}@;?@;:glob'{0,1,2,3,4,5}'x4}{($_)=@ 121, Jasper -lpaF @a=grep{($i)=($j,$b,$w)=@F;$i=~s/.//,$b-=/$&/,$w- =$j=~s/$_//for/./g;!$b&!$w}@a,grep y/6-9//d<2,6e4..65555}{$_=$a[0] 156, m.wrenn -ln push@_,$_}{T:for('0000'..AAAA){for$m(@_){$a=$b=0;$j=$_;$a+=($s=substr$m,$d++ %4,1)==$_,$b+=$j=~s/$s//for/./g;$m=~/ ./;next T if$a-$&|$b-$'|/[6-9]/}print} 166, dkr -lan ($g,$b,$t)=@F;@;=map{$a=$_;s/^(.{$-[0]})$&/$1b/while$g=~/./g;/^(.{$- [0]})b/||s/$&/w/while$g=~/./g;y/b//==$b&&y/bw//==$t?$a:()}@;?@;:glob"{0,1,2, 3,4,5}"x4}{print@ 217, Roy Johnson (alternative) -lp BEGIN {@S=glob'{0,1,2,3,4,5}'x4}

sub score { ($G,$P)=@_; $b= ($G^$P) =~ y/\0//; $c=0; {$c+=$P=~s/$_// for $G=~/./g} return "$b $c"; }

//; ($g,$s)=($`,$'); @S = grep {score($g,$_) eq $s} @S; }{ ($_)=@S

6.30. Triangles http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=66&season=1 The game started 2004-07-27 20:00:00 and ended 2004-07-31 20:00:00.

6.30.1. Rules Given three side lengths, some triangles are possible and some are not (on Euclid plane):

Edition 2007-01-09 top secret / strictly confidential page 379 of 520 Perlgolf History

There will be no flat triangles (where sum of small sides is equal to big side). Each side length will be an integer number between 1 and 6. In STDIN you will get three lengths separated by spaces and a newline. You should output "1"(one) and a newline if triangle is possible, "0"(zero) and a newline otherwise. So STDIN will match /^[1-6] [1-6] [1-6]\n\z/ and STDOUT should match /^[01]\n\z/ Example: 265 Output: 1

6.30.2. Solutions 31, robert -lp $_^=y/ /+/eval/eg 32, tybalt89 -lp $_=/ ./&$`+$&>$'&abs$`-$&<$' 32, o0lit3 -lp $_=/ ./&$&<$`+$'&$&>abs$`-$' 32, topmach -lp / ./;$_=abs$`-$&<$'&$`+$&>$' 32, Daniel -pl $_=/ ./&$`>abs$&-$'&$`<$&+$' 32, anfi -pl / ./;$_=$`+$&>$'&abs$`-$&<$' 32, m.wrenn (rejected) -lpa $_|=y/ /+/*(sort@F)[2]$'&$'>abs$`-$& 32, kcwu -lpa $_=grep$_*2<($s+=$_),sort@F 32, shr -lp / ./;$_=$'<$`+$&&$'>abs$`-$& 32, scw -lpa $_=grep$_*2<($a+=$_),sort@F 32, mtve -lp / ./;$_=$`<$&+$'&$`>abs$&-$' 32, id5

Edition 2007-01-09 top secret / strictly confidential page 380 of 520 Perlgolf History

-pl $_=/ ./&$`>abs$&-$'&$`<$&+$' 32, g.allen -lp040 $;[$_]=$^F+=$_}{$_+=$^F/2>@ 33, Stephen Turner -pal $_=y* *+**(sort@F)[2]2*@a&1 33, mtve (alternative) -lp $_=s/./$z|=11x$&;1x$&/eg&/$z/ 33, Jasper -lp040 $_[$_*2]=$;+=$_}{$_|=$#_<$ 33, tybalt89 (alternative) -lpa $_=/ ./&grep$`+$&+$'>$_*2,@F 33, stalker -lpa $_=0|y/ /+/*(sort@F)[2]pop@_ 34, Michael Chapman -lpa $_=/ ./&!grep$`+$&+$'<$_*2,@F 34, stalker (alternative) -pa s/.*/"@{[sort@F]}|0"|" + >"/ee 35, ErikB -alp ($a,$b,$;)=sort@F;$_=0|$a+$b>$ 35, pengvado -lpa $_=eval("\x00\x15"^join">",sort@F)|0 36, ErikB -alp ($a,$b,$;)=sort@F;$_=0|$a+$b>$ 36, wmeriic -lap ($a,$b,$c)=sort@F;$_=$a+$b>$c^0 36, colin_zr -lpa ($a,$b,$c)=sort@F;$_=$a+$b>$c|0 36, terje -lpa ($a,$b,$c)=sort@F;$_=0|$a>$c-$b 36, gibbering -pal @;=sort@F;$_=0^pop@;<@;[0]+pop@ 37, Yenya

Edition 2007-01-09 top secret / strictly confidential page 381 of 520 Perlgolf History

-apl @_=sort@F;$_=$_[0]+$_[1]>$_[2]|0 37, Yenya (alternative) -apl $|=2*$_<($s+=$_)for sort@F;$_=$| 37, Shlomi Fish -lpa map$t+=$_,@F;$_=1-grep$_*2>$t,@F 37, Shlomi Fish (alternative) -lpa $"='+';$_=1-grep$_*2>eval"@F",@F 37, integral -pla ($a,$b,$c)=sort@F;$_=1&$a+$b>=$c 37, srushe -apl }{($a,$b,$c)=sort@F;$_+=$a+$b>$c 38, Thomas Insel -pal $_=(@G=sort@F)[2]>$G[0]+$G[1]?0:1 38, gordoste -alp ($a,$b,$c)=sort@F;$_=$a+$b<$c?0:1 38, dantie -lpa ($a,$b,$c)=sort@F;$_=$a+$b>$c?1:0 42, ced-2 -ap ($a,$b,$c)=sort@F;$_=($a+$b>$c?1:0).$/

6.31. Tennis Scoresheet http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=67&season=1 The game started 2004-08-10 07:39:02 and ended 2004-08-15 20:00:00. Rules by TopMach.

6.31.1. Rules Given a sequence of points won by tennis players, one can determine the outcome of a match. A tennis match is won when a player has won either best of 3 or best of 5 sets. In some cases, a deciding Match Tie Breaker may be played instead of an extra set when equality occurs after either 2 or 4 played sets. We won't play by that rule in this golf. Several ways are used to score a set. The one we'll use, for both regular and deciding sets, is called "Tie-break Set". The first player to win 6 games and to have a margin of 2 games wins the set. If the score reaches 6 games all, a tie-break game is played. A standard game is scored as follow:

Edition 2007-01-09 top secret / strictly confidential page 382 of 520 Perlgolf History

No point - "Love" First point - "15" Second point - "30" Third point - "40" Fourth point - "Game" When the 2 players have won 3 points the score is "Deuce". After "Deuce", the score is "Advantage" for the player who wins the next point. If that same player also wins the next point, that player wins the "Game". If the opposing player wins the point, the score is back to "Deuce". A player needs to win 2 consecutive points immediately after "Deuce" to win the game. A Tie-break game is scored as follow: Points are scored as "Zero", "1", "2", "3", etc. The first player to win 7 points wins the game and set provided there is a margin of 2 points over the opponent. The tie-break game shall continue until this margin is achieved. The points will be provided in STDIN and will match /^[12]{1,1000}\n\z/. 1's being points for player 1 and 2's being points for player 2. On STDOUT your output should match /^[0-7]-[0-7](, [0-7]-[0-7]){0,4}\n\z/ and print: For each set, the number of games won by player 1, followed by an hyphen and followed by number of games won by player 2. Each set is comma and space seperated and newline terminated. In the event that there is not enough points to complete a set, as it would happen due to injury or weather delay, you are to print the result of the previous sets, if any, and the result of the unfinished current set if at least 1 game was won.. If interrupted in middle of a game, the game's result is to be discarded and unused. Examples: 1112112222211121221221121112111112121222211112212122212111211111111122111222211 Output: 6-3, 3-2

6.31.2. Solutions 114, Daniel (post-mortem) -p s/./", $^C-$^D@{$^C=$^D=``}"if++$#{$&}>2+3x($!-11)&abs@1- @2>1&&++${chr$&+2}>5+(@1=@2=(),$!++>9)||$!>$'*13/ge;s/, // 115, tybalt89 (post-mortem) -p s/./", $^C-$^D@{$^C=$^D=``}"if++$#{$&}>2+3x($!-11)&abs@1- @2>1and@1=@2=(),++${chr$&+2}>5+($!++>9)or$!>$'*13/ge;s/, // 116, Daniel (post-mortem) -p s/./", $^C-$^D"x!($^C=$^D=``)if++$#{$&}>2+3x($!-11)&abs@1- @2>1and@1=@2=(),++${chr$&+2}>5+($!++>9)or$!>$'*13/ge;s/, // 118, Daniel (post-mortem) -p s/./", $^C-$^D"x!($^C=$^D=$@=0)if++$#{$&}>2+3x($@-11)&abs@1- @2>1and@1=@2=(),++${chr$&+2}>5+($@++>9)or$@>$'*13/ge;s/, // 123, tybalt89 (post-mortem)

Edition 2007-01-09 top secret / strictly confidential page 383 of 520 Perlgolf History

-p s/./", $^C-$^D"x!($^C=$^D=0)if++$#{$&}>2+3x($@=$^C+$^D-11)&abs@1- @2>1and@1=@2=(),++${chr$&+2}>5+($@>-2)or$^C+$^D>$'*13/ge;s/, // 125, Daniel -p s/./", $%-$-"x!($%=$-=0)if++$#{$&}>2+3x($@=$%+$--11)&abs@1- @2>1and@1=@2=(),++($&-1?$-:$%)>5+($@>-2)or$%+$->$'*13/ge;s/, // 126, tybalt89 -lp ++$#$_<($!<12?3:6)|abs@1-@2<2or@1=@2=(),(9,++$!<11)[7- ++${chr$_+2}]and$r.="$^C-$^D, ",$^C=$^D=``for/./g;$_="$r$^C-$^D";s/, 0-0// 127, topmach -lp s`.`$&%2?$%++:$-++,@1=@2=()if$#{$&}++>(y/6//<2||4)&abs@1-@2>1;$_=", $%-$- ";/$'[1-6]/|y/56//&/6|7/?($%=$-=0,$_):""`eg;s/, // 130, Michael Rybakin -lp s^.^$&<2?++$%:++$-,@r=$_=", $%-$-"if$r[$&]++>$r[3- $&]&$r[$&]>3+$l;$'?$r[!($l=/6-6/*3)&/6/&!/5/|/7/?$%=$-=$_='':3]:$_^ge;s/, // 132, Krzysztof Koczyjan -lpaF| sub f{$u=$v=$u+$v&&s/$/, $u-$v/- 1}f;for$a(@F){++${$a|a}<($u&$v^6?4:7)|abs$q-$s<2or$q=$s=25- 4*++${$a|d}$p+3&abs($z[0]-$z[1])>1){$_?$b++:$a++;@z=(0);u if($p|abs($a- $b)>1&($a>5|$b>5));$p=3if$a+$b>11}}u;$_=join", ",@k 190, Roy Johnson -n $T=3,$GG=$G=0;s/./++${*W=P x$&}>$T&$W>${P x($L=3- $&)}+1and$P=$PP=0,$T=++${*W=G x$&}>5&$W>${*X=G x$L}+($T<4)?(print("$,$G- $GG"),$,=', ',$W=$X=0,3):$X>5?6:3/ge;print$G+$GG?"$,$G-$GG\n":"\n" 211, m.wrenn -lp $g=$h=0;for(/./g,0){$a>$b?++$g:++$h,$a=$b=0if($a+=/2/)>($y=$g+$h>11?6:3)|($b +=/1/)>$y&&abs$a-$b>1;(push@s,"$g-$h,"&push@t,"$h- $g,"),$g=$h=0if/0/&&$g+$h||$g>5|$h>5&&abs$g- $h>1|$g+$h>12}$_=@s>@t?"@s":"@t";chop 230, o0lit3 -lp $_=s/\d/chr$&/e?(y/\x01//>$Q+3|y/\x02//>$Q+3)&1s/\x02//g;$@[$*]=$@[$*]=~/-/?($`+$-)."-".($'+!$-):"$--".(!$- |0);$Q=3if$@[$*]=~/-/*$`+$'>11;$*++,$Q=0if($`>5|$'>5)&($`+$'>12|1$i&&$a>$b +1){$c++;i}if($b>$i&&$b>$a+1){$d++;i}if(($c>5||$d>5)&&(abs($c- $d)>1||$c==7||$d==7)){push@s,"$c-$d";j}}push@s,"$c-$d" if$c!=0||$d!=0;print join(', ',@s).$/

Edition 2007-01-09 top secret / strictly confidential page 384 of 520 Perlgolf History

7. Games - Terje’s PGAS season 2 7.1. Beads http://terje2.frox25.no-ip.org/~pgas/score.pl?func=rules&hole=68&season=2 The game ended 2005-09-13 18:00:00. Rules by terje.

7.1.1. Rules A necklace is made up of number of beads forming a closed loop, each bead being of one of X distinct colors. When you consider groups of 3 beads, and X = 7 there are exactly 35 combinations of beads possible. Your task is to list all the combinations of 3 beads in X colors as 3 digit numbers, where the number 0 - (X-1) represents the different colors. The list must be sorted in ascending order and the digits in each number must also be sorted in ascending order. eg. the number 231 is not valid in the list. Input a single digit X and a newline on STDIN matching /^[3-9]\n\z/. Output a list of all the bead combinations, newline separated. The output must match: /^([0-Y]{3}\n)+\z/ where Y = X - 1. Example input 3 Example output 012

7.1.2. Solutions 36, Andreas (post-mortem) -l 9**<>=~/.+?().+?().(?{print@-})^/ 37, banshee -l /.+?(.+?)(.)(?{print@-})^/for$"x<> 37, Andreas -l /.+?().+?().(??{print@-})/for 2x<> 37, Sec -l $_=9x<>;/9+?()9+?()9(?{print@-})^/ 37, Sec (alternative) -l (9x<>)=~/.+?(.+?()).(??{print@-})/ 45, Michael Rybakin -lna /.(??{"[0-$&@F-9]"})/||print for$-x3..$: 46, Daniel

Edition 2007-01-09 top secret / strictly confidential page 385 of 520 Perlgolf History

-nla map/.(??{"[0-$&@F-9]"})/||print,0 x3..9x3 46, tybalt89 -lna map/.(?p{"[0-$&@F-9]"})/||print,00x3..7x3 47, tybalt89 (alternative) -l y///c-3||print for<{${\join',}{',0..<>-1},}> 50, m.wrenn -lna map/\B./&$`<$&&$&<$'&$'<"@F"&&print,0 x3..9x3 53, anfi -lap }for(grep{/\B./,$`<$&&$&<$'&$'<$F[0]}$|x3..9x3){ 54, _-Ani-_ -nal /\B./&$'>$&&$&>$`&$'<$F[0]&&print for"000".."789" 59, Peter Haworth -ln for$a(0..9){for$b($a+1..9){print"$a$b$_"for$b+1..$_-1}} 59, Peter Haworth (rejected) -ln for$a(0..$_){for$,($a+1..$_){print$a,$_ for$,+1..$_-1}} 61, Mitar -nl for$a(0..--$_){for$b($a+1..$_){print"$a$b$_"for$b+1..$_}} 63, gibbering -l $"=',';map/(.)(.)/&$1<$+&$+<$'&&print,glob"{@{[0..<>-1]}}"x3 65, bgreenlee -ln for$i(0..$_-3){for$j($i+1..$_-2){print"$i$j$_"for$j+1..$_-1}}

Edition 2007-01-09 top secret / strictly confidential page 386 of 520 Perlgolf History

8. Games - Kernelpanic season 1 http://www.kernelpanic.pl/perlgolf-list.mx To those who wonder, PCLP means pl.comp.lang.perl USENET newsgroup.

8.1. PCLP #4 - GRAY CMP Master: Robert Szczygiel (RobTM) 03.12.2002 10.12.2002

8.1.1. Solutions 47, Marcin Kaszynski -l $|=!s/./$|^=$&/gefor@ARGV;print-(pop)<=>-pop 47, Przemysław Kowalczyk -l $|=!s/./$|^=$&/gefor@ARGV;print-pop()<=>-pop 48, Wawrzyniec Żurowski -l $b=0,s/./$b^=$&/gefor@ARGV;print-pop()<=>-pop 51, Michał Jankowski -l $z=0,s/(.)/$z^=$1/eg for@ARGV;print-(pop)<=>-pop 52, Piotr Piątkowski -l s/./$&?$x^=3:2/ge,$x=0for@ARGV;print-(pop)<=>-pop 53, Piotr Pawłow s#.#$&^$`=~y/1//&1#eg for@ARGV;print-(pop()<=>pop) 58, Andrzej Filip \sort{print$a<=>$b,$/}map{$*=!s/./$*^=$&/eg;oct"b$_"}@ARGV 63, Artur Czechowski -l ($m,$n)=map{$r=$p=0;$r.=$p^=$_ for/./g;$r}@ARGV;print$m<=>$n 76, Hubert Lubaczewski -l ($x,$y)=map{$?++until$_==unpack B16,pack n,$?^$?>>1;$?}@ARGV;print$x<=>$y 76, Szymon Sokół $b=pop;$a=pop;$_=sprintf"%b",$i/2^$i++until/^($a|$b)$/;print/^$b$/-/^$a$/,$/ 81, Robert Szczygiel -l map{$n=$j;$j=0;$j++while unpack(B16,pack n,$j^$j/2)!~/0*$_/}@ARGV;print$n<=>$j 86, Dariusz Sznajder -l $a=oct"0b".pop;$b=oct"0b".pop;$a^=$a>>(1<<$_),$b^=$b>>(1<<$_)for(0..4);print $b<=>$a

8.2. PCLP #5b – SAPER Master: Marcin Kaszynski (marcink) 19.12.2002 04.01.2003

Edition 2007-01-09 top secret / strictly confidential page 387 of 520 Perlgolf History

8.2.1. Solutions 199, Piotr Piątkowski -lp0 sub v{for$i(0..71){local$_=$_;pos=$i;if(s/\G[b.]/B/){for$j(-10..-8,- 1,1,8..10){$i<-$j||eval{substr($_,$i+$j,1)=~y/1-4./0- 3b/}}y/bB//<6&&&v}}/B/g?print pos()/9%9,$",pos()%9-1:exit until/[1-4b]/}v 203, Szymon Sokół -ln y/./0/;push@x,split//}{@m=0..4;X:$i=0;$m[$i++]=0while++$m[$i]>63;for$j(0..63 ){$s=0;$_-$j?$s+=(abs(($_&7)-($j&7))<2&&abs(($_>>3)- ($j>>3))<2):($s=0,last)for@m;$s-$x[$j]&&goto X}print$_>>3," ",$_&7for@m 234, Mateusz Matuszek while(<>){s/\.|\n|$/0/g;$W.=$_}sub f{if($g<5){f($z[$g++]=$_)for(1+pop..77)}@Y=split'',$W.$W;for$p(@z){$Y[$p+$_] --for(-11..-9,-1,1,9..11)}$Y[$_]=0for@z;$_=join'',@Y;s/- //g;if(/^(0{8}..){8}/){for(@z){/.$/;print"0$` $&\n"}exit}$g--}f(-1) 249, Michał Jankowski -nl $q.=$_}T((0)x66);sub T{my($i,$l,@p,$r)=@_;if($l){for$x($i%8..$i%8+2){$x*$_&&$x<9&$_<9&&$p[$_*8+$x -9]++for$i>>3..($i>>3)+2}$p[$i++]=-9}$l- 5&&T($_,$l+1,@p)for$i..63;$r.=$_>0?$_:'.'for@p;if($r eq$q){for$X(0..7){$p[$X+8*$_]<0&&print"$_ $X"for 0..7}} 453, Wojciech Gazda $/=\1;@t=map[int,int$i/8,$i++%8,[]],grep/./,<>;map@$_[3]=[grep$_,$j%8&&($j>8&&$ t[$j-9],$t[$j-1],$j<57&&$t[$j+7]),$j%8<7&&($j>6&&$t[$j- 7],$t[$j+1],$j<55&&$t[$j+9]),$j>7&&$t[$j- 8],$j++<56&&$t[$j+7]],@t;do{for(;grep{(@u=grep!@$_[0],@{@$_[3]}),(@$_[0]eq'n 'or!@$_[0]&& $#{@$_[3]}eq$#u)&&map@$_[0]=n,@u}@t;){};}while(grep{@$_[0]>0&&((@u=@{@$_[3]} ,@$_[0]==grep@$_[0]eq'o',@u)?@$_[0]=n:(@f=grep@$_[0]=~/0|o/,@u)==@$_[0]&&map {@$_[0]=o,print"@$_[1..2]\n"}@f)}@t);

8.3. PCLP #6 – SPIRALA Master: Mateusz Matuszek (magus) 17.01.2003 23.01.2003

8.3.1. Solutions 92, Mateusz Matuszek -l substr($_,$x+=$z*print,$a-=$a-$z--?++$z*2:$z--)^='\x03'x$a,/.#/&&redo for'#'x($a=++$z+4*pop) 92, Przemysław Kowalczyk print+($z=2*pop)?map{$y=$_;map(($y>-$_^$y<$_?$y>0^$y:$_)&1?$":'#',-$z..$z),$/}- $z..$z-1:'# ' 94, Robert Szczygiel @a=($"x2x$_,map('\x03'^$".$_.$",@a),@a?($"^='\x03')x2x$_:@b)for 0..2*pop;print"#$_\n"for pop@a?@a:$i 102, Krzysztof Koczyjan

Edition 2007-01-09 top secret / strictly confidential page 388 of 520 Perlgolf History

@_=(3x($_*=4),$i=4x--$_.3,map(" 3$_ 3",@_),$#_?$i|d3:(),d.3x$_)for(@_='')..pop;print"#$_ "&'+'x99for@_ 110, Michał Jankowski $y=(@z=(("#")x($z=1+4*pop),$/)x($z-1||1))+1;for$x(-$z+++3..0){map$z[$y+=($z,- 1,-$z,1)[$x%4]]=$",0..-$x}print@z 117, Marcin Kaszynski $p=--($a=$b=2+4*pop)*$b/2;$_=("#"x$a.$/)x(--$a||1);@m=(1,-$b,-1,$b)x99while pos=$p+=$m[.5+sqrt 2*$i++],s/\G#/ /;print 118, Wawrzyniec Żurowski -l @p="#";for(1..pop){$_*=4;@p=("#"x(--$_+2),map{"# $_ #"}" "x($_-2),@p,"#"." "x($_-3));$p[$_]="# "."#"x$_}print for@p

8.4. PCLP #7 – KOMIWOJAŻER Master: Przemysław Kowalczyk (szeryf) 28.01.2003 04.02.2003

8.4.1. Solutions 178 (post-mortem), Przemysław Kowalczyk -pl $a+=s/\w/$A{$&}=pos;$B{$&}=$./eg}sub k{$b=$m="@_"!~/$_/&&k(@_,$_)for sort keys%A;map{for$r(@_){$m+=($$r{$_}- $$r{$b})**2if$b}$b=$_}@_;$^I=$m,$s="@_"if$#_+2>$a&&$m<$^I}k;$_=$s;{ 183, Mateusz Matuszek -pl $a+=s/\w/$A{$&}=pos;$B{$&}=$./eg}sub k{$b=$m="@_"!~/$_/&&k(@_,$_)for sort keys%A;map{for$r(@_){$m+=($$r{$_}- $$r{$b})**2if$b}$b=$_}@_;$f=$m,$s="@_"if$#_+2>$a&&$m<$f}$f=$^T;k;$_=$s;{ 183, Robert Szczygiel -lp s/(\S)/$#$1=pos,$$1=$.,@x=sort@x,$1/ge}sub o{for$i(@_){$r.=$i,o(grep!/$i/,@_),chop$r}$r=~s/(.)/$"=$`?$"+(@$1- @$p)**2+($$1-$$p)**2:1,$p=$1/ge;$_=$r,$a=1/$"if!@_/$">$a}o@x;{s/\B/ /g 213, Adam Ryba -nl while(/\S/g){$x{$p=$&}=pos;$y{$p}=$.;@_=();for(@w){push@_,"$`$p$'"while/()/g }@w=@w?@_:$p}}{@w=sort map{$z=split//;$z+=($x{$1}-$x{$2})**2+($y{$1}- $y{$2})**2while/(.)(.)$/&&chop;Z x$z."@_"}@w;$w[0]=~/Z*/;print$' 217, Przemysław Kowalczyk -pl s|\S|$X{$&}=pos;${$&}=$.;push@p,$&|ge}sub p{my$c;for(my$N=pop;$c<=$N;$l=$d=0){p($N-1);$d+=$l&&($X{$l}-$X{$_})**2+($$l- $$_)**2,$l=$_ for@p;$^T=$d,$_="@p"if$^T==$d&&"@p"le$_||$^T>$d;@p[$a,$N]=@p[$N,$a=$N%2*$c++]}} {p$#p 230, Michał Jankowski

Edition 2007-01-09 top secret / strictly confidential page 389 of 520 Perlgolf History

-pl $&eq$"or$N++,$x{$&}=[pos,$.]while/./g}for$n(1..8**$N){$s=sprintf"%0${N}o",$n ;map{$s=~/$_/||next}0..$N-1;$s=~y/0-7/A- H/;@p=$s=~/./g;$l=0;for$w(1..$#p){$l+=($x{$p[$w]}[$_]-$x{$p[$w- 1]}[$_])**2for 0..1}$m=$l,$_="@p"if$l<$m||!$m}{ 230, Krzysztof Koczyjan s/\S/$X{$&}=pos,$Y{$&}=$./ge while<>;sub p{my$n=pop;my$x=sub{@a[$_,$n]=@a[$n,$_]};$n&&map{&$x,p($n- 1),&$x}0..$n;$~=$a[0]=~//;$~+=($X{$_}-$X{$&})**2+($Y{$_}- $Y{$&})**2,//for@a;$v="@a ",$m=$~if$~<=$m||!$m}@a=sort keys%X;p$#a;print$v 247, Szymon Sokół -nl $j=0;$y{$_}=$i,$x{$_}=$j++for/./g;$i++}{sub v{@_?map{my$f=shift;my@z=v(@_);push@_,$f;map[$f,@$_],@z}1..@_:[]}map{$d=@p=@ $_;$q=$p[0];map{$d+=($x{$_}-$x{$q})**2+($y{$_}- $y{$q})**2;$q=$_}@p;$m=$d,$b="@p"if$d<$m||!$m}v grep!/ /,sort keys%x;print$b 285, Wawrzyniec Żurowski -ln $x=split"";/\S/?($x{$_},$y{$_})=($x,$.):1,$x++for@_}{sub p{my($i,@l,$s)=@_;$q=$l[0];if($i<=$#l){($l[$i],$l[$_])=($l[$_],$l[$i]),p($i+ 1,@l)for$i..$#l}else{$s+=($x{$_}-$x{$q})**2+($y{$_}-$y{$q})**2,$q=$_ for@l;$n{"@l"}=$s}}p(0,keys%x);print+(sort{$n{$a}<=>$n{$b}||$a cmp$b}keys%n)[0]

8.5. PCLP #8 – SZACHY Master: Mateusz Matuszek (magus) 11.02.2003 20.02.2003

8.5.1. Solutions 218, Mateusz Matuszek -pl y/p/r/;s/\w/$z{$..pos}=$&/ge}map{$H=($W=ZcXO).($G=($R=bd).($P=PN));$S=aelnQM FD;$x=$f,map{$x=32S,p,P )[$b++],map{$y=$a{$f=$e&$"^k};1until$j=$z[$y-=98- ord]or$b>4;$e=~/$j/and$$f=$f}/./gfor(Xacl,WYkm)x2,(MOVZjnuw)x2,WY,km;$_=$k.$ K||none;{ 301, Adam Ryba -pl s/(\w)/$X[pos].=$C[$$1=10*$.+11+pos]=$&;$X[$.+8].=$&;$L[$.+pos].=$&;$L[24- $.+pos].=$&/eg}{sub e{$_.=reverse;$m+=/[$_[0]H]k/;$d+=/[$_[1]h]K/}$_="@X ";e W,w;$_="@L ";e G,g;sub d{$m+=$C[$k+$_]eq"@_";$d+=$C[$K-$_]eq lc"@_"}d P for 9,11;for(8,12,19,21){d S for-$_,$_}$_=$m?k:'';$_.=K if$d;$_=$_?$_:none 378, Wawrzyniec Żurowski

Edition 2007-01-09 top secret / strictly confidential page 390 of 520 Perlgolf History

-lp s#.#$a[$.+9][9+pos]=$&;$k{$&}=[$.+9,9+pos]#ge}{%o=(w,' -$_#-$_ # $_#$_ ',g,'-$_ -$_#$_ $_#-$_ $_#$_ -$_',p,'$l -1#$l 1');$o{h}="$o{w}#$o{g}";for$i(-2..2){$o{s}.="$i $_/($i/2)#"for- 1,1}A:for$l(1,- 1){$k=$l>0?k:K;($y,$x)=@{$k{$k}};for$R(keys%o){for$Z(split"#",$o{$R}){$Z=~/ /;$f=$a[$y+eval$`][$x+eval$'],$f eq($l<0?$R:uc$R)?($V.=$k,next A):$f=~/\w/?last:1for 1..8}}}$_=$V||none

8.6. PCLP #9 - KWADRATY Master: Robert Szczygiel (RobTM) 26.02.2003 05.03.2003

8.6.1. Solutions 52, Robert Szczygiel -l map$$_=(${A&$_}^=$_ x pop)=~y/\x04//,a..h;print$g*$h 63, Adam Ryba (would be rejected?) $a[$i%2]|=chr(2**$i++)x$_ for@ARGV;$_="@a";print y/\x0ffffffb3//*y/D//.$/ 63, Mateusz Matuszek -l ${a.$|--}+=1x$_<<($k^=$|)for@ARGV;print$a0=~y/2//*$a1=~y/2// 78, Marcin Kaszynski -l for(0,1,4,5){$a+=$_++for@{*a=$_&1?b:c}[$ARGV[$_]..$ARGV[$_+2]-1]}print$b*$c 81, Przemysław Kowalczyk -l print$j+grep{map$$_=pop,a..d;for$x($c..$a-1){$i[$x.$_]++&&$j++for$d..$b- 1}}0,1 85, Krzysztof Koczyjan -l sub p{@q=sort@_;$q[1+"@_[0,2]"=~/$q[2]/]-$q[1]}print p(map{push@_,pop;pop}0..3)*&p 85, Piotr Piątkowski -l for$x(@ARGV){map{$c+=($a[$_]+=($_/($d&1?10:1)%10>=$x^$d/2&1))>7}0..99;$d++}p rint$c 91, Michał Jankowski -l sub i{$ARGV[$i=pop]..$ARGV[$i+2]- 1}map{for$x(i$_){$t+=grep$s{$x.$_}++,i$_+1}}0,4;print$t 96, Szymon Sokół map$$_=pop,a..h;$x=(($b<$f?$b:$f)-($h>$d?$h:$d))*(($e<$a?$e:$a)- ($g>$c?$g:$c));print$x>0?$x:0,$/ 104, Wawrzyniec Żurowski -l $j=A;$$j=$_,$j++for@ARGV;$D=$H if$D>$H;$D-=$B>$F?$B:$F;$D*=($C<$G?$C:$G)- ($A>$E?$A:$E);print$D>0?$D:0 104, Robert Garwacki

Edition 2007-01-09 top secret / strictly confidential page 391 of 520 Perlgolf History

-l @_=@ARGV;for$x($_[0]+1..$_[2]){for$y($_[1]+1..$_[3]){$_+=$x>$_[4]&$x<=$_[6]& $y>$_[5]&$y<=$_[7]}}print 112, Tomek Machalski -l @t=@ARGV;sub z{(($m=$t[++$i+1])<($n=$t[$i+5])?$m:$n)-(($x=$t[$i- 1])>($y=$t[$i+3])?$x:$y)}$_=&z*z;print$_*!/-/ 115, Filip Rembiałkowski -l sub b{$r=($_[0]<$_[1]?$_[0]:$_[1])-($_[2]>$_[3]?$_[2]:$_[3]);$r<0?0:$r}print b(@ARGV[2,6,0,4])*b(@ARGV[3,7,1,5]) 127, Paweł Różański @z=@ARGV;sub X{$i*=-1;$b=@z[4+@_[0]];$i*@z[@_]<$i*$b?@z[@_]:$b}$i=-1;$w=X(2)- X(0);$B=X(3)- X(1);$w*=$w>0&&$B>0?$B:0;print$w,$/

8.7. PCLP #10 - OKRES Master: Adam Ryba (pooh) 11.03.2003 14.03.2003

8.7.1. Solutions 21, Hubert Lubaczewski -p s/(.*?)\1*$/$+[1]/ 21, Marcin Kaszynski -p s/(.*?)\1*$/$+[1]/ 21, Mateusz Matuszek -p s/(.+?)\1*$/$+[1]/ 21, Michał Jankowski -p s/(.+?)\1*$/$+[1]/ 21, Piotr Piątkowski -p s/(.+?)\1*$/$+[1]/ 21, Wawrzyniec Żurowski -p s/(.+?)\1*$/$+[1]/ 28, Robert Szczygiel -pl /^(.+?)\1*$/;$_=length$1 47, Tomek Machalski -pl {$a=substr($_,0,++$i),/^($a)+$/||redo}$_=$i

8.8. PCLP #11 - SZYFRANT Master: Hubert Lubaczewski (depesz) 18.03.2003 25.03.2003

8.8.1. Solutions 81 (post-mortem), Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 392 of 520 Perlgolf History

-pl map$q.=$&x/[^ $q]/,chop..z,/./gfor$_.$",$q,$/=a;$_=lc<>;eval"y/a-z\n \x9 \xc\xd/$q/d" 84, Mateusz Matuszek -pl map$q.=$&x/[^ $q]/,chop..z,/./gfor$_.$",$q,$/=a;$_=lc<>;s/\s//g;eval"y/a- z/$q/"; 86, Przemysław Kowalczyk -lp sub T{$$_||=$C.=$A=$_}T for/\S/g;$/=!T for$A..z,a..z;$_=lc<>;eval"y/a-z \x09\xc /$C/d" 92, Robert Szczygiel -pl $/=''while grep{!$$_++and$K.=$L=$_}$K?($L..z,a..z):/\w/g;$_=lc<>;s/\s//g;eval"y/a- z/$K/" 97, Michał Jankowski -lp0777 / /;$_=lc$';map$g.=$_,a..z;$g=~/$_/and$f.=$_,$g=$'.$`for$`=~/\S/g;eval"y/a-z\x09 \xc /$f$g/d" 97, Tomasz Kuczyński -lp sub _{s#.#$`!~/$&/?$&:""#ge}_;$/=$_.=join'',chop..az;_;y/ //d;eval"\$_=<>;y/A- Za-z \n/$_$_/d" 108, Hubert Lubaczewski -pl @_=grep!$x{$_}++,lc=~/\S/g;push@_,grep!$x{$_}++,$_[-1]..z,a..z;$_=lc join$A,<>;s/[\sa-z]/$_[-97+ord$&]/g 111, Wawrzyniec Żurowski -plaF// sub e{grep/\S/&&!$a{$_}++,@_}$.<2?@b=(@b=e(@F),e$b[- 1]..z,a..z):s/\S/$w.=$b[ord(lc$&)-97]||$&/ge}{$_=$w 119, Szymon Sokół -p BEGIN{$_=<>;y/ //d;$i=a;sub v{$x{$_}||$x{$y{$i++}=$k=$_}++for@_}v/./g;v$k..z,a..z}END{print$/}s/[a- z\s]/$y{lc$&}/ige

8.9. PCLP #12 - KRATY Master: Mateusz Matuszek (magus) 28.03.2003 07.04.2003

8.9.1. Solutions 80, Robert Szczygiel ($_,$:)=reverse(sprintf"%b %b",@ARGV)=~/1.*/g;s#.#$:.$/^$:x$&#ge;y/01\0/ #/;print 83, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 393 of 520 Perlgolf History

-l map{$k=pop;$_.=$k&1||$_&&$",$k>>=1while$k}$_,$q;s!.!$_=$q;s/1|[^$&]/#/g;prin t!eg 84, Przemysław Kowalczyk -l map{$*=pop;s/^0//while$_.=1&$*,$*/=2;$u='#'x y/01/ #/}$_,$.;print/#/?$u:$.for/./g 84, Filip Gralinski s//#/;for$a(@ARGV){$x=$p;$x.=$a%2?$_:$x&&$",$a>>=1while$a;$_=$"=$x.$/;y/ /#/}print$x 88, Michał Jankowski -l sub z{$_=sprintf"%b",@_;reverse/(?=.*1)./g}for$Y(z pop){print map$_+$Y?'#':$",z@ARGV} 91, Zbigniew Lukasiak ($i,$_)=map{$_=reverse sprintf"%b0",$_;y/01/ #/;/ */;$'}@ARGV;s!(.)!print~$i&$1x32|"$i "!ge 92, Artur Mac -l sub B{$_=reverse sprintf"%b",$ARGV[!$_];s/^0+//;split''}for$i(B){print map$_|$i?"#":$",B} 97, Grzegorz Brzeski -l ($_,$~)=map{$_=reverse sprintf"%b",$_;s#^0+##g;$a=y/10/# /;$_}pop,pop;print/#/?$&x$a:$~for/./g 97, andrzej x -l ($_,$a)=map{(unpack"b*",pack I,$_)=~/0*(.*1)/}@ARGV;y|10|# |;$a=~s/./print$&?'#'x length:$_/eg 101, Tomek Machalski -l sub o{$_=sprintf"%b",pop;s/0*$//;y/10/# /;reverse split//};@b=o shift;map{print/#/?'#'x@b:@b}o pop 107, Marcin Bieńkowski -l for(a..b){for($i=shift;$i;$i>>=1){$$_.=$i&1?"#":" "}$$_=~s/^ *//;@$_=split//,$$_}for(@b){print$_ x@a|$a} 109, Filip Rembiałkowski -l map{$$_=pop;$$_/=2 until$$_%2;{push@$_,$$_%2;redo if$$_>>=1}}qw/y x/;for$b(@y){print map{$_|$b?'#':' '}@x} 110, Adam Ryba -l ($x,$y)=map{$_>>=1until$_&1;$_}@ARGV;$a.=$x&1?'#':' ',$t.='#',$x>>=1while$x;print($y&1?$t:$a),$y>>=1while$y 112, Tomasz Kuczyński ($a,$_)=map{my$x;while($_){$x.=$_%2;$_>>=1}$x=~s/^0*//;$x}@ARGV;$b=$a=~y/01/ #/;s!.!($&?'#'x$b:$a)."\n"!eg;print 113, Piotr Wysocki

Edition 2007-01-09 top secret / strictly confidential page 394 of 520 Perlgolf History

sub x{$_=reverse sprintf'%b',shift @ARGV;s/0*/$1/}x;tr/01/ #/;$b=$_;tr/ /#/;$c=$_;x;s/0/$b\n/g;s/1/$c\n/g;print$_ 113, Paweł Różański sub L{$_=sprintf"%b",@_;s/^0+|0+$//;reverse}map{$a=$_;$_=L(@ARGV);$a>0?y/10/#/:y /10/# /;print$_,$/}split//,L(pop) 121, Wawrzyniec Żurowski -l sub b{$_=unpack"b*",pack L,pop;s/^0+//;s/0+$//;$_}@V=b(pop)=~/./g;$H=b pop;$H=~y/10/# /;print$_?"#"x length$H:$H for@V 121, Hubert Lubaczewski -l ($x,$y)=map{$_/=2 until$_&1;$_}@ARGV;for($j=1;$j<=$y;$j*=2){$_="";$i=1;$_.=$x&$i||$y&$j?"#":$" ,$i*=2 until$x<$i;print} 157, Slawomir Szczyrba ($y,$x)=@ARGV;($x=unpack"b*",pack"V",$x)=~s/^0*|0*$//g;($y=unpack"b*",pack"V",$ y)=~s/^0*|0*$//g;for($x=~/./g){for$j($y=~/./g){print$_+$j?"#":" ";}print"\n";} 164, Michal Wrobel $p=pop;$_=reverse(unpack("B32",pack("N",pop)));y/10/# /;s/^\s*|\s*$//g;$b=$_;y/ /#/;until($p%2){$p>>=1};do{if($p%2){print("$_\n")}else{print("$b\n")}}while( $p>>=1);

8.10. PCLP #13 - SEKWENS Master: Robert Szczygiel (RobTM) 11.04.2003 16.04.2003

8.10.1. Solutions 59, Filip Gralinski -l $_=A23456789XWDKA until/.*([@ARGV]{$=})/*$=--%14;print$1 60, Marcin Kaszynski -l $i=13;$i--until A23456789XWDKA=~/.*([@ARGV]{$i})/;print$1 74, Mateusz Matuszek -l map$r[length]=/A(.*A)/?$1:$_,A23456789XWDKA=~/[$ARGV[0]]*/g;print pop@r 79, Robert Szczygiel -l $_=A23456789XWDKA;eval"y/@ARGV/ /c";map$m[y///c]=$_,/.{1,13}$/gm;print$m[-1] 91, Michal Wrobel -l $_="A23456789XWDKA";s/[^$ARGV[0]]/ /g||s/A//;print((sort{length$a<=>length$b}split)[-1]) 126, Michał Jankowski -l $_=pop;s/A/A1/;for$x(1..9,X,W,D,K,A,z){/$x/?($s.=$&,$l++):(($l<$,or$o=$s,$,= $l),$s='',$l=0)}$_=$o;y/1/A/;s/A(?=.*A)//;print 173, Nicolas Mendoza

Edition 2007-01-09 top secret / strictly confidential page 395 of 520 Perlgolf History

-l $_=pop;tr/XW/BC/;s/A/X1/;map$B.=$_,sort split//,$_;for$a(0..14){for$b(0..14- $a){$;=substr"123456789BCDKX",$b,$a;$_=$;if(index($B,$;)+1)}}/X$/&&s/1//;tr/ BCX1/XWAA/;print$

8.11. PCLP #14 - LIFE Master: Filip Gralinski (ptlen) 23.04.2003 02.05.2003

8.11.1. Solutions 141, Mateusz Matuszek @T=@T?map{@e=grep$T[($_/3%3-1+int$v/@X)%$.*@X+($v+$_%3- 1)%@X]!~/o/,5..12;$v+=/./;(@e-2?@e-3?o:"#":$&).$'}@T:map@X=/. */g,<>for 0..pop;print@T 142, Robert Szczygiel -p0 INIT{$e=pop}$#b=y/o#///s/.*(.)/$1.$&.(o&$&)/ge,s!.!$&^''.map/'/g,$`."$_\004\ 004\004@b"x3^"1111@b".$_ x9!ge,y/\020\027\\/#/,y/ #/o/c,s/^.|.$//gmfor($_)x$e 147, Przemysław Kowalczyk -0p INIT{$a=pop}/ /;($m)=@-;@p=/./g,s!.!$c=++$#a;3-($i=grep{/e/;o ne$p[($c-$c%$m+($c+$')%$m+$`*$m)%@p]}glob'{-1,0,1}e'x2)?4- $i?o:$&:'#'!gewhile$a-- 177, Michał Jankowski -p0 INIT{$c=pop}$k=y/ / /;$l=(@t=/./sg)/$k,s@.@$x-=($==($x=pos)/$l)-$l;$s=0;for$X($x- 2..$x){$s+=grep$t[($k+$_)%$k*$l+$X%($l-1)]^_,$=-1..$=+1}$&ne o&$s==4|$s==3?'#':o@egwhile$c-- 243, Marcin Bieńkowski $n=shift;while(<>){chop;y/o#/01/;$c=split/|/;push@A,@_}while($n--){for$a(- 1..1){for$b(-1..1){$i=0;map{$_+=2*($A[($i+$b*$c- $i%$c+($i+++$a)%$c)%@A]&1)}@A}}map{$_=($x=$_- 3*($k=$_&1))==6?1:$x==4?$k:0}@A}$_=join'',@A;y/01/o#/;s/(.{$c})/$1\n/g;print 254, Szymon Sokół -l $"="";$c=pop;chomp(@b=<>);@a=split//,"@b";$m=@a/@b;while($c-- ){for$i(0..$#a){$s=0;$s+=$a[($i+@a+(-1,1,-$m,$m,$m-1,1-$m,$i%$m-$m+1?1+$m:1- 2*$m,$i%$m?-$m-1:2*$m-1)[$_])%@a]eq'#'for 0..7;$b[$i]=$a[$i]ne o&&$s==2||$s==3?'#':o}@a=@b}print for"@a"=~/.{$m}/g 355, Michal Wrobel ($u,$_)=(pop,join"",@x=<>);s/(.*)\n/$1/g;$q=y/o#/01/;$l=$q/@x;while($u-- ){$c=0;$p="";map{@d=();$s=0;map{$r=$c+$_;($c%$l)||$_+1||($r=($r+$l)%$q);(($c +1)%$l)||$_-1||($r=($r-$l)%$q);map{push@d,($r+($l*$_))%$q;}qw(-1 0 1);}qw(-1 0 1);map{$s+=$a[$_]}@d;($t=$a[$c++])&&($s>4||$s<3)&&($t=0)||$s- 3||($t=1);$p.=$t;}@a=split//;$_=$p;}y/01/o#/;s/(.{$l})/$1\n/g;print

Edition 2007-01-09 top secret / strictly confidential page 396 of 520 Perlgolf History

8.12. PCLP #15 - ŁAMANA Master: Robert Szczygiel (RobTM) 09.05.2003 13.05.2003

8.12.1. Solutions 29, Przemysław Kowalczyk -lp0a $_=grep$_*$F[$^F++]<0,@F 29, Michał Jankowski -lpa0 $_=grep$F[$^F++]*$_<0,@F 29, Mateusz Matuszek -lp0a $_=grep$_*$F[$^F++]<0,@F 41, Marcin Kaszynski -pla $s+=$_*$a<0,$a=$b,$b=$_ for@F}{$_=$s 44, Tomek Machalski -lan $i+=grep$_*$a[$|--]<0,@F;@a=@F}{print$i 45, Marcin Bieńkowski -lp0 s/\S+/$%++if$x*$&<0;$x=$y;$y=$&/ge;$_=$% 65, Marcin Gryszkalis -ln /(.). ?(.)/;$;="$1$;$2";END{$_=$;;y/-1-9/ba/s;print y//y/c-3} 67, Robert Szczygiel -pl ($i,$j)=split/\s/,$_;$c+=($i*$k<0)+($j*$l<0);$l=$j;$k=$i}{$_=$c 75, Paweł Różański sub M{$i+=@b[@_]*@a[@_]<0?1:0}while(<>){@a=split;M(0);M(1);@b=@a}print$i,$/ 105, Michał Kurek -l for(<>){($x,$y)=split;$_=($x>0?0:3)+($y>0?1:2);y/54/32/;$r=$_- ($l?$l:$_);$a+=$r>0?$r:-$r;$l=$_}print$a

8.13. PCLP #16 - DEKODER Master: Przemysław Kowalczyk (szeryf) 16.05.2003 23.05.2003

8.13.1. Solutions 80, Piotr Fusik -ln sub\011d{/./glt$&?(d(d(splice@_,d,@_/2)),d(&d)):map$_.$&x@_,@_}print\011d!e, ($/)x7 118, Michał Jankowski -nl sub J{map$_[$s-$_].=pop,1..$s;@_}$s=8;sub S{/./g;$&^t||!($s/=2)?($&x$s)x$s:(J(&S,&S),J&S,&S)x!!($s*=2)}print for S 140, Krzysztof Koczyjan

Edition 2007-01-09 top secret / strictly confidential page 397 of 520 Perlgolf History

-paF| sub a{$w|="\000"x(9*$_+$x-9).1x$s for 1..$s*($~=shift@F);$s/=2,(map a($x+=$s*$_),0,1,8,1),$x-=5*($s*=2)if$~eq D}a$s=8;$_=$w|'00000000 'x8 142, Marcin Kaszynski -paF'' $a=(($|x8).$/)x8;sub f{my($p,$w)=@_;($*=shift@F)eq D?map{f($p+$w/2*$_,$w/2)}0,1,9,10:map{substr($a,$p+9*$_,$w)=$*x$w}1..$w}f- 9,8}{$_=$a 155, Marcin Bieńkowski -nlaF| sub T{my($s,$x,$y)=@_;D eq($*=$F[$i++])?map{T($s,$x,$y+$_);T($s,$x+$s,$y+$_)}0,$s/=2:map{@{$A[$y+$_] }[$x..$x+$s-1]=$*x$s}0..$s-1}T 8;map{print@$_}@A 162, Przemysław Kowalczyk sub d{my($d,$e,$f,$g)=@_;($;=getc)ne D?map{substr$m||=(1x8 .$/)x8,$_*9+$d,$e,$;x$e}$f..$f+$g-1:map d($d+$_%2*$e/2,$e/2,$f+($_>1)*$g/2,$g/2),0..3}d 0,8,0,8;print$m 183, Marcin Gryszkalis -paF// $_=$.x64;sub r{my($x,$y,$l)=@_;if(($p=shift@F)eq D){for$j(0,$l/=2){for$i(0,$l){r($x+$i,$y+$j,$l)}}return}for$q(0..$l- 1){substr$_,($y+$q)*8+$x,$l,$p x$l}}r 0,0,8;s/(\d{8})/$1 /g 242, Piotr Koper @s=split('',<>);sub r{my($x,$y,$w)=@_;for$f(0..3){$l=shift@s;if('D'ne$l){for$k($y..$y+$w- 1){$o[$k][$_]=$l for$x..$x+$w-1}}else{r($x,$y,$w/2)if int$w}if($f==1){$y+=$w;$x- =$w}else{$x+=$w}}}r(0,0,8);for$i(0..7){print$o[$i][$_]for 0..7;print"\n"}

8.14. PCLP #17 - PAŃSTWA Master: Piotr Fusik (0xF) 04.06.2003 11.06.2003

8.14.1. Solutions 79, Piotr Fusik -lp0 / /while s/F(.{@-})?@x|@x(.{@-})?F/F$+F/s or$_=lc,s/\d/$r+=@x=$&,F/e;$_=$r 81, Michał Jankowski -lp0 $_=s/$x@1c|c@1$x/c$+c/s||y/c/d/+s:\d:$x=$&,$i+=/ /,@1="(|.{@-})",c:e?redo:$i 81, Mateusz Matuszek -lp0 $_=s/$x$~b|b$~$x/b$+b/s||y/b/c/+s#\d#$x=$&;$s+=/ /;$~="(.{@-})?";b#e?redo:$s 93, Robert Szczygiel

Edition 2007-01-09 top secret / strictly confidential page 398 of 520 Perlgolf History

-0p / /,$l=$-[0];1while s/a(.{$l})?$:|$:(.{$l})?a/a$+a/s||y/a/ /||s/./$c++;$:=$&;a/e;$_="$c " 94, Michal Szafranski -lp0 for($s='.'x index$_,$\;s/./s/;$x++){$y=$&;4until!s/$y($s)?s|s($s)?$y/s$+s/s;y/s/\n/}$_=$ x 117, Przemysław Kowalczyk -paF// push@p,@F}sub r{my$l=pop;$p[$l]=x,map r($l+$_),1,1*@F,-@F,-1if$p[$l&511]eq$&}{$_=grep({$i++;r$i-1if/\d/}@p).$/ 145, Marcin Grzesiek -l sub d{my$z=pop;if($z<@T&$z>=0&$T[$z]==$x){$T[$z]=4;map{d($z+$_);d($z- $_)}(1,@T/$.)}}map{if($_^4){$x=$_;d $i;$w++}$i++}@T=map{/./g,4}<>;print$w 157, Marcin Bieńkowski -p0 sub S{my($x,$v)=@_;if($x>=0&$A[$x]==$v){$A[$x]=9;map{S($x+$_,$v)}-1,1,- $c,$c}}$c=y/0123/1234//y/ /9/+1;@A=/./g;$_=(grep{S $_,$A[$_]if$A[$_]<9}0..$#A).' ' 162, Marcin Zukowski -lnaF// $z=$i="";map{if($_ ne$z){@T[$X]=$x;$x=++$X}$b=\@T[@K[$i]];if(@L[$i]eq($z=$_)){$S- =$x!=$$b;($x<$X)?$$b=$x:$x=$$b}@C[$i++]=$X}@F;@L=@F;@K=@C;END{print$X+$S} 205, Kuba Majocha sub w{my($l,$i,$j,$c)=@_;while($a[$l]=~/$k+/g){my@p=(1+$- [0],$+[0]);$a[$l]=$`.(5x length$&).$',0<$l?w($l+1,@p):0,w($l+1,@p),$c++ if$i<=$p[1]&$j>=$p[0]}$c}@a=<>;for$k(0..3){map{$N+=w$_,1,20}0..19}print$N.$/ 215, Tomek Machalski -lnaF'' push@t,[@F]}{sub f{my$y=pop;my$x=pop;$t[$y][$x]=9,f($x- 1,$y),f($x+1,$y),f($x,$y- 1),f($x,$y+1)if$x>=0&&$x<@F&&$y>=0&&$y<@t&&$t[$y][$x]==$z}for$i(0..@F- 1){for$j(0..@t-1){f($i,$j),$_++if($z=$t[$j][$i])<9}}print 345, Robert Garwacki -l while(<>){chomp;push@m,split"";$r++}$c=@m/$r;@p=('0')x@m;for(0..$#p){if(!$p[ $_]){$p++;z($_)}}print$p;sub z{my$o=shift;$p[$o]=$p;z($o- 1)if($o%$c>0&&$m[$o-1]==$m[$o]&&$p[$o- 1]==0);z($o+1)if(($o+1)%$c>0&&$m[$o+1]==$m[$o]&&$p[$o+1]==0);z($o- $c)if($o>=$c&&$m[$o-$c]==$m[$o]&&$p[$o-$c]==0);z($o+$c)if($o<($r- 1)*$c&&$m[$o+$c]==$m[$o]&&$p[$o+$c]==0)}

8.15. PCLP #18 ROBAK Master: Michał Jankowski (michalj) 03.07.2003 10.07.2003

Edition 2007-01-09 top secret / strictly confidential page 399 of 520 Perlgolf History

8.15.1. Solutions 89 (post-mortem), Przemysław Kowalczyk -pl @{$a++}=/./g}{map$|--?$i:$j+=abs$_%8-3<=>2,$_+=$$i[$j],$_- 2while$f{$i%=$a,$j%=@0}++<3 92, Piotr Fusik -lpaF| @{$h++}=@F}{$_+=$$y[$x],$x+=abs$_%8-3<=>2,$y+=abs$_%8- 5<=>2while++$f{$x%=@F,$y%=$h}<4 95, Robert Szczygiel -plaF| push@a,[@F]}{map$|--?$i:$j+=abs$_%8-3<=>2,$_+=$a[$i][$j],$_- 2while$e[$i%=@a][$j%=@F]++<3 96, Mateusz Matuszek -lpaF| push@T,@F}{$z=$_+=$T[$p],map$$_-=1-2240/3**($z++%8)%3,a..c while$N[$p=$c%@F+$a%$.*@F]++<3 100, Przemysław Kowalczyk -lp @{$y++}=/./g}{$y+=(($;=($_+=$$y[$x])%8)<3)-456=~$;,$x+=607=~$;- 234=~$;while${$y%=$.}{$x%=@0}++<3 104, Maciej Jastrzębski -alpF| push@a,@F}{@_=((1)x3,0,(- 1)x3,0)x($_+=$a[$v])while++$p[$v=($y+=$_[$_])%$.*@F+($x+=$_[$_+2])%@F]<4 106, Filip Gralinski -l @t=map@F=/./g,<>;$x+=$%=2*cos.1+($_+=$t[$i])%8,$y+=$%=2*sin$_%8*7+1while++$v [$i=$y%$.*@F+$x%@F]<4;print 108, Tomek Machalski -plaF'' push@p,@F}{$x+=(@a=(1,0,(-1)x3,0,1,1))[$r=($_+=$p[$t])%8],$y+=$a[$r- 2]while++$L[$t=$y%$.*@F+$x%@F]<4 111, Michał Jankowski -aplF| push@t,[@F]}{@d=(1,1,1,0,(- 1)x3);$_+=$t[$y][$x],$x+=$d[($_+2)%8],$y+=$d[$_%8]while$b[$y%=$.][$x%=@F]++< 3 117, Marcin Grzesiek -l sub k{$r%4?$r&4?1:-1:0}for(@T=map@X=/./g,<>;++$I[$p=$x%@X+$y%$.*@X]<4;$y- =k){$r=($s+=@T[$p])-1;$x+=k;$r+=2}print$s

8.16. PCLP #19 - GIF Master: Piotr Fusik (0xF) 16.07.2003 25.07.2003

8.16.1. Solutions 144, Robert Szczygiel

Edition 2007-01-09 top secret / strictly confidential page 400 of 520 Perlgolf History

sysread STDIN,$d,99;@^A=($",'#')x2;map$=+=vec($d,248+$e++,1)<<$_,0..1.44*log@^Auntil $^A[-1].=g&$^A[$=],$_.=$^A[@^A]=$^A[$=],$==8&s/(.{8}) ?/$1 /g;print 146, Mateusz Matuszek for(@d=($","#",(sysread STDIN,$h,$$)x3);s!.{8}!$& !g<8;$e+=2**$;++*vec$h,++$j+250,1){@d>>$;or$_=$i.=$e=$;=$g=$d[$d[@d]=$g.=$d[$e] .$g&"#",$e]}print 168, Tomek Machalski sysread STDIN,$a,99;@s=($",'#',1,1,1); until($z=$k=/.{64}/){$k+=2**$z++*vec$a,251+$i++,1while@s>>$z;$s[@s]=$s[$m].($s[ $k<@s?$k:$m]&'#');$_.=$s[$m=$k]}s/.{8}/$& /g;print 171, Piotr Fusik binmode\011STDIN;@0=$",@1="#",split$/=$d,unpack"b*",<>;for($e=5;$g<64;$e++){$d= $f=.5;$d|=$f*$_[++$h+250]until$e<($f*=2);@$e=(@d,$$d[d]||$d[d]);print$_,++$g %8<1&&" "for@d=@$d} 184, Przemysław Kowalczyk -p INIT{binmode STDIN}$i.=unpack'b*',$_}@d=($",'#');$f=5;$f>>$^F&&$^F++,$d[$f++]=$d[$g].(c&$d[$ f-($h=ord pack"b$^F",substr$i,$e+251)?$h:$g]),$_.=$d[$g=$h],$e+=$^Funtil/.{64}/;{s/.{8}/$ & /g 196, Michał Jankowski -0777 binmode STDIN;($_)=unpack"x31b*",<>;@0=$";@1='#';$S=6;while($==log($S)/log 2,/..{$=}/g,@O<64){$k=ord pack"b*",$&;@{$S++}=(@$o,${$k<$S?$k:$o}[0])if@O;push@O,@{$o=$k}}printf~("\33 2\214"x8 ."\365")x8,@O

8.17. PCLP #20 - KRĘGLE Master: Robert Szczygiel (RobTM) 02.09.2003 08.09.2003

8.17.1. Solutions 69, Piotr Fusik -l print~~map 1..lc,@ARGV,map@ARGV[0..!($f=-10+shift)||$f+shift],1..9 73, Michal Szafranski ($a,$b,$c)=@ARGV,shift>9||shift,$r+=$a+$b+$c*($a+$b>9)for-0..9;print$r.$/ 75, Michał Jankowski -l for$w(a..j){$w>9?($t+=$ARGV[-$_]):$_&&($w+=shift)for-2..0;$t+=$w}print$t 91, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 401 of 520 Perlgolf History

map{$s+=$ARGV[$_]for 0..($e+=!$|)<10&&($|--?$v+$_>9:$_>9&&$|-- +1);$v=shift}@ARGV;print$s.$/ 93, Przemysław Kowalczyk -l $i++,$s+=$_,(($r*=$|-- )+=$_)<10|($c+=$|)>9or$s+=$a[$i]+$a[$i+1]*$|,$|=0for@a=@ARGV;print$s 99, Maciej Misiak

8.18. PCLP #21 - KOD PASKOWY Master: Piotr Fusik (0xF) 18.09.2003 21.09.2003

8.18.1. Solutions 37, Michal Szafranski print$_=pop,(map$_*3.1..999,/../g)%10 37, Ton Hospel print$_=pop,(map$_*3.1..309,/../g)%10 37, Robert Szczygiel print pop=~/..(?{$=-=3.1*$&})/g,$=%10 39, Piotr Fusik print$_=pop,-map(1..3**$|--*lc,/./g)%10 42, Pawel Chmielowski print+(grep$s-=int$_*3.1,pop=~/../g),$s%10 42, Mateusz Matuszek print,($r-=3**$|--*lc)%=10for pop=~/./g,$r 42, Przemysław Kowalczyk print$_=pop,-map((/./)x(3*$'+$&),/../g)%10 46, Maciej Jastrzębski print$_=pop;s/(.)(.)/$s-=$1+$2*3/eg;print$s%10 46, Marcin Kaszynski $_=pop;$a-=$_*3**$i,$i^=1for/./g;print$_,$a%10 46, Michał Jankowski map$x-=$_+$_*2*$|--,pop=~/./g;print$`,$&,$x%10 52, Michal Wrobel map{$s+=$_*(3-($m^=2));print}split"",pop;print-$s%10

8.19. PCLP #22 - KANJI Master: Michal Szafranski (stalker) 03.10.2003 09.10.2003

Edition 2007-01-09 top secret / strictly confidential page 402 of 520 Perlgolf History

8.19.1. Solutions 57 (post-mortem), Robert Szczygiel -lp0aF[+-]+ $_=y'/\|+'798'+$#F%s,.,/$&..{$&}\G/s,eg-y/1// 58, Ton Hospel -lp0aF[+-]+ $_=y!/\\|+!798!+$#F%s,.,/$&..{$&}\G/s,eg-y/1// 64, Michal Szafranski -lp0 $_=s/[-+]+/$&/g+!y: \\/|+:I978:+s/\d(??{"(?!..{$&}$&)"})//g 66, Piotr Fusik -lp0aFF $_=map"@F"=~/(){$_(?!.{$_)/gs,qw(0}[-+] 8}/ 10}\\\ 9}[|+]) 68, Robert Szczygiel -lp0 $_=map{$j=-$i++%11;y'\322\324\/|+'11243';/$i(?!.{$j}$i)/gs}~$_,($_)x3 68, Przemysław Kowalczyk -lp0 $_=s/[-+]+/$&/g+s:/(?!.{8}/)|[|+](?!.{9}[|+])|\\(?!.{10}\\)::gs 70, Michał Wojciechowski -0pl12 $a='(?!.{8}';$_=s:[|+]$a.[|+])|/$a/)|\\$a..\\):$&:sg+s/[+-]+//g 71, Michał Jankowski -lp0 push@a,/[$&](?!.{$1}[$&])/sgwhile'0+-9+|8/10-a'=~/(\d+)\D+/g;$_=@a 74, Mateusz Matuszek -lp0 $n=$_;$_=map{$q+=$_;$n=~/[$_](?!.{$q}[$_])/sg}"+-","8/","1+|","1\\\\" 104, Maciej Misiak -lp0 $c=@a=/[-+]+/g;$s=8;for$y(qw(/ +| \\\\)){while(s#[$y](.{$s}[$y])# $1#s){}$c+=@a=m{[$y]}g;$s++}$_=$c 115, Marcin Grzesiek -lp0 @Y=/[-+]+/gs;while($i++<81){s/[+|](.{9}[+|])/-\1/s;s/\\(.{10}\\)/- \1/s;s/\/(.{8}\/)/-\1/s}$_=@Y+s/[+|\\\/]//gs 116, Pawel Chmielowski -p00 s/$|\n/1x9/ge;chop,$c+=grep$_,/[+-][^+- ]$/,/[+|].{17}[^+|]$/,/\/.{16}[^\/]$/,/\\.{18}[^\\]$/while($_);$_="$c\n"

8.19.2. Explanation by Ton Hospel From: [email protected] (Ton Hospel) Subject: Re: [golf] edycja #22 – podsumowanie Newsgroups: pl.comp.lang.perl Date: 09 Oct 2003 14:29:47 GMT Message-ID: <[email protected]> As I understand it, i's traditional to post an explanation of the top solution here, so here follows mine. I'll do it in a very long style, hopefully showing beginners how golf thinking goes. Advanced readers don't need this text anyways :-)

Edition 2007-01-09 top secret / strictly confidential page 403 of 520 Perlgolf History

The code is: -lp0aF[+-]+ $_=y!/\\|+!798!+$#F%s,.,/$&..{$&}\G/s,eg-y/1// The -0 options uses \x00 as input line terminator. Since the input will contain no \x00, this means the whole input will be slurped on read. The -p option causes the classic while (<>) { .....} continue {print} to be added about the main body. This means that the input will come in on $_, and I should make sure the result goes out to $_ The -l makes \n the output record separator, so that on the final print a newline will be added. It also causes a chomp to be added to the body, but that's no problem, since it will chomp \x00 (not \n !) and so not change the input. Notice that the order of these options is important, otherwise -l will copy the contents of the input separator, so become \x00 -aF[+-]+ will cause the following to be added before the body: our(@F) = split(/[+-]+/, $_, 0); So it splits up the input around sequences of + or - (the horizontal lines). Since the chomp did not remove the final \n, there will always be an unmatched sequence at the end (important since split drops empty end fields, which would cause the solution to fail if the last char in the field was a - or +). There will also always be a leading field, though that can be empty if the first char is + or -. These however don't get dropped. So in the end @F will contain all strings between +- sequences with an extra string at start and end, so @F has size = horizontal lines +1. And then obviously $#F = horizontal lines. Horizontal lines need to be handled special since in the next step I will loose information about the "+" characters. Also, "+" characters sometimes contribute 2 to the linecount, which can't be easily represented with simple counters like s/// and y///. Next we need to count diagonal and vertical lines. I'll do that by actually counting how many lower side endpoints there are. That basically means: • count any \ if its not preceded be another \ exactly 11 chars before 11 = fieldwidth(9) + newline(1) + right slant(1) • count any | or + if its not preceded by a | or + exactly 10 chars before • count any / if it's not preceded by a / exactly 9 before About the best you can do here with a plain regex is like in this length 60 solution by mtve (looks forward instead of backward, but the idea is the same): -lp0aF[+-]+ $_=s#(?!/.{8}/|\pS.{9}\pS|\\.{10}\\|-)\S##sg+$#F This however has a lot of repeated pieces. It would be neat if we had a kind of lookup table matching so we knew that for / we need to skip 8, for | 9 and for \ skip 10. Constructing and reading such a table is pretty big though, but we can try to use the characters themselves as their own lookup table by using a transliteration to change each to its right skip. Unfortunately we can't represent 10 in one char, so we'll use 7, 8 and 9 instead and later skip one extra. So the next statement becomes: y!/\\|+!798! mapping each char to it's offset (| and + both become 8, since +'s only role is in vertical lines now we've already counted horizontal lines. This returns the total number of line characters too.

Edition 2007-01-09 top secret / strictly confidential page 404 of 520 Perlgolf History

Next comes checking for each line character if it's the lower endpoint or not. Running code for each character in a string is usually best done using s/./code here/eg or /.(??{code here})/g in case you need to construct part of the regex. While inside an s/// body, $_ is still available, with the current match position at the start of the string being matched, and the string being matched in $&. So my test for lower end of line becomes: "and before the current point we should not have the same digit as the one under consideration followed by our calculated skip plus one more char to compensate that our table counts skips one too low, and directly after that we should have our match char at the current position (\G)", so: !/$&..{$&}\G/s (the s modifier makes . match \n). In reality I don't actually use the ! negation, so I'm actually counting the internal characters in a line. But remember that the y/// returned the amount of total line characters, so subtracting from that will give the number of lower endpoints. In the s/.///eg I also don't match on \d, but on ., so I spuriously match the spaces too. But these will cause the {} to be interpreted as a literal match, and since there are no { or } in the input, they will never cause an extra match. So after this substitute we still need to count how many times the internal test was true (number of internal line characters). Each of them will be recognizable in $_ as a "1" (and there will be no other "1" since "1" is no a valid input character. So we can easily count them with y/1//. So finally we get: $#F (horizontal lines) + y!/\\|+!798! (number of characters in vertical or diagonal lines) (here we need to do the substitution) - y/1// )number of internal characters in vertical or diagonal lines) The problem is of course that the s/.//eg must be executed between the two transliterations while the subtraction still goes. So how to ignore the return value of s/.//eg (which will be 9*9=81)? Well, $#F is the number of horizontal lines, which will be lower than 81, since the only way to get that much is to fill everything with - and +, and then you actually only get 9 horizontal lines since they connect. So $#F is strictly smaller than 81, and we can use modulo 81 on it and it will remain unchanged. So the final counter becomes: y!/\\|+!798!+$#F%s,.,/$&..{$&}\G/s,eg-y/1// which I then assign to $_. -- I wouldn't quite call it "mark-and-sweep", it's more like "nuke-and-pave". Matthias Neeracher in comp.lang.perl about perl garbage collection

8.20. PCLP #23 - Double Linear Crosswords Master: Ton Hospel (thospel) 18.10.2003 24.10.2003

8.20.1. Rules A double linear crossword is a string of lowercase alphabetic characters arranged in a line in such a way that there are exactly two ways (so called decompositions) to split this string into words from a given word list (and it's ok to use a given word multiple times).

Edition 2007-01-09 top secret / strictly confidential page 405 of 520 Perlgolf History

Look at this example: |||| andatareallastask ||||| where the used list of valid words was: all, an, and, are, area, as, ask, at, data, last, or, read, real, task. The two decompositions should also not start or end with the same word. So the next example is invalid because the two decompositions share "or" at the end: ||||| andatareallastaskor BAD |||||| On STDIN you will get a list of at least two and at most 99 valid words. Each word will consist entirely of lowercase characters and be no longer than10 characters. So the input matches: /^([a- z]{1,10}\n){2,99}\z/. The list of words will be sorted alphabetically (low to high) and have no duplicates. On STDOUT you must print one of the double linear crosswords that can be constructed from the given word list, followed by a newline. It doesn't matter which one you choose to print if many solutions exist. The generated word should be no longer than 60 characters. If no such word exists (either because no double linear crossword exists at all, or because all the existing ones are too long), you should print nothing (not even a newline). So the output should match: /^[a- z]{2,60}\n\z|^\z/ It is in principle possible to give word lists where the amount of work needed to generate a valid double linear crossword explodes and the program will not finish within years. You don't have to worry about that extreme case, all input will be relatively nice. Some of the tests still might need to work through a pretty big search space, but it will all be doable within a few minutes and not run you out of memory. You can use the --brief option to the test-script during development to skip the slow tests. Run the full test before submitting though. Algorithm hints The main thing to observe is that the number of sixty character string you can build from a given list of words can be HUGE. At least one of the tests has all the single letters, so there every string is in fact valid, which is 26**60 possibilities. Not a chance of trying them all. So the only realistic way to solve this problem is to only build word sequences that can be part of a double linear crossword. That is most obviously done by building two decompositions together and uses them to constrain each other. Let's call the places in a double linear crossword where we put a "|" in the above examples "internal edges", the complete string before that point the prefix and the string after that point suffix. Every prefix can be written in exactly one way. At least one since it’s part of a double linear crossword. And if it had more than one way, we could append the suffix to each and get two ways to write the crossword. Since that has exactly two decompositions, these must be it. But the suffices obviously end on the same word, so this is invalid. Also, the two decompositions never can share the position of any internal point:

Edition 2007-01-09 top secret / strictly confidential page 406 of 520 Perlgolf History

A|B prefix suffix C|D Where A, B, C and D represent some way of splitting that part of the string. A must differ from C or they would share a start word. And B differs from D or they would share an end word. So A|D prefix suffix is a decomposition different from both, and we get three decompositions, which is invalid. Now suppose that you have two partially built decomposition candidates (each a sequence of words from the word list) with no shared internal points where one is a substring of the other and at least one is not the empty string. There are two possibilities: 1. They are equal length In that case the strings are equal since one is a substring of the other. So at this point you have a valid candidate for output, since you have a string with two different decompositions. You still have to check if it maybe has even more. Even better, whether this test succeeds or not, it makes no sense to extend any of the strings further, since you would then be working on a prefix with multiple decompositions. 2. They are of unequal length, and so look something like abcdefghi abcdef In this step we are going to try to extend the shorter of the two decompositions. So in turn try to append each of the words in the word list to "abcdef". A number of things can happen: a. It's a random word like xy: abcdefghi abcdefxy That won't work since the string aren't substrings anymore. b. It's a proper substring of "ghi" like gh: abcdefghi abcdefgh So we are again in the one word is longer than the other case, and can recursively repeat the process. c. It's a proper superstring of "ghi" like ghijk: abcdefghi abcdefghijk Again we are in the one word is longer than the other case, and can recursively repeat the process, but now with the longest and shortest word interchanged. d. It is EXACTLY "ghi": abcdefghi abcdefghi And we will be in the equal length case. Check if we found a solution, but no recursive extending. At any point we could decide to see if we have more than one decomposition of the short word. If so, we know we can forget about extending this candidate pair since no prefix can have multiple decompositions. Here is an example starting with "and" and "an" for the all, an, and, are, area, as, ask, at, data, last, or, read, real, task word list:

Edition 2007-01-09 top secret / strictly confidential page 407 of 520 Perlgolf History

and an We try to extend the shorter one (an), and the next word must start with "d", so only "data" will work: and andata So now the second is longer, switch them around (and possibly check the number of decompositions of "and"): andata and The only candidate for extending the short string is "at": andata andat Next we must extend with something that starts with an "a", of which there are several: all, an, and, are, area, as, ask, at. We must actually try them all, so suppose the next one to try is "ask": andata andatask and switching them around: andatask andata But now we are stuck, since no string starts with "sk". Ok, drop back to andata andat where we now will try another word, let's say "at": andata andatat and switch (and possibly check decompositions of "andata"): andatat andata Next a word that starts with "t", so "task": andatat andatatask Switch (and maybe check): andatatask andatat Next we maybe check a word like "as", but that path will fail because no word starts with "k". So after trying that and dropping back here, at some point it will be the turn of "ask" to be checked, giving: andatatask andatatask Checking for number of decompositions, this gives two, so we found a double linear crossword and can stop. If there had been three or more decompositions, we would still have stopped extending at this point, and have dropped back to:

Edition 2007-01-09 top secret / strictly confidential page 408 of 520 Perlgolf History

andatatask andatat where there were no more strings to try (we already did "as" and "ask"), so we would then drop further back to andatat andata But we already tried the only possible word ("task") there, so again a failure, and drop back to andata andat where we already tried "at". The next word to try for extending would for example be "area". Anyways, you get the general idea. All possibilities are checked, and if you come all the way back to your starting point, there is no way to extend your starting point to a double linear crossword. You can of course play around with a lot of details here, like when you check which words for decompositions, and in which order you try do extensions. In fact, I said nothing yet about how to check how many decompositions a string has. Maybe you even find a way to combine that with the building. You'll need to decide all that for yourself. And if you find a better algorithm than this one, by all means use it.

8.20.2. Solutions 105, Ton Hospel -ln0a map{eval"'$&$''!~/^$_/-/^$&$'/|/.{61}|^(@F)+".'$(?{++$@})Z/?$"=x|t:2- $@?do$0:exit!print'for$&.lc}@F 159, Andreas Bühmann -lan0 use re 'eval';$"='|';sub t{for(my$c=shift){if(/^(?!.{61})@_/){$i=2,/^(@F)+$(??{$i--})/,$i?last:exit print if$&=~$_&&$_;t($c,"@_$_")*t("@_$_",$c)for@F}}}t 172, Przemysław Kowalczyk -ln0a sub n{my$n=pop;$n=~/^$_/?$'?n($'):$^F--:0for@F}sub r{my($i,$j)=sort@_;n$;or$^F?exit:print$;if$i eq$j&&$i;length($;=$i.$_)<61&&$j=~$;|$;=~/^$j/&&$_ ne$j&&r($;,$j)for@F}r 187, Jasper McCrea

Edition 2007-01-09 top secret / strictly confidential page 409 of 520 Perlgolf History

-lan0 $"=')?('; @b=(@F)x9;

sub t{ my($o)=@_; !$o||@_==grep$o=~/^$_(?=(@b)?$)/&&t($'),@F }

sub d{ my$o=pop; if($o=~/^(?!.{61})@_.|^$/){

return print$o if$o&&t$o,2; d(sort$o,"@_$_")&&return$"for@F } }

d 242, Maciej Jastrzębski -ln push@a,$_}{sub r{my($s,$r)=@_;if(61>($d=length(my$p=$r.$s))){@r=1;for$D(0..$d){$t=substr$p, $D;map$t=~/^$_/&&($r[$D+length]+=$r[$D]),@a}map{exit if$r[$d]==2&&print$p;/^$s/&&r($',$p)if$s lt$_;$s=~/^$_/&&r($',$r.$_)if$s gt$_}@a}}map r($_),@a

8.20.3. Explanation by Ton Hospel From: [email protected] (Ton Hospel) Subject: Re: [golf] edycja #23 - Explanation of my solution Newsgroups: pl.comp.lang.perl Date: 24 Oct 2003 15:23:01 GMT Message-ID: <[email protected]> The basic idea is already explained in the algorithm hints section at http://kernelpanic.pl/perlgolf- view.mx?id=25. The used options are -ln0a. The -l will cause the final \n when a solution gets printed, the -n causes the implicit read loop so the input will appear in $_ (no use in this case), but it also makes -a work so that the input word list will appear in @F. The -0 causes all input to be slurped and assigned to @F at once since there is no \0 in the input. The basic invariant of the code is that at the start of a recursion level the short string is in $& and the extra string to make up the long one is in $'. The outer map{..}@F will cause $_ to be equal to all words in the word list in turn. The for$&.lc makes $_ the attempt under consideration (the short string with a word appended). A naive $_=$&.$_ wouldn't work since it would destroy the contents of @F (and isn't actually shorter). So now we are in one of the 4 basic cases: 1. word was the irrelevant "xy" $&=abcdef $'=ghi $_=abcdefxy

Edition 2007-01-09 top secret / strictly confidential page 410 of 520 Perlgolf History

2. word was the longer "ghijk" $&=abcdef $'=ghi $_=abcdefghijk 3. word was the shorter "gh" $&=abcdef $'=ghi $_=abcdefgh 4. word was the equal "ghi" $&=abcdef $'=ghi $_=abcdefghi Next comes the eval whose role becomes clear later. The body is basically: "$&$'"!~/^$_/-/^$&$'/|/.{61}|^(@F)+$(?{++$@})Z/?$"=x|t:2-$@?do$0:exit!print "$&$'"!~/^$_/ checks for "word is shorter (gh)" case, basically 0 if so /^$&$'/ checks for the "word is longer (ghijk)" case, returns 1 if so For both of these, if the regex matches, $& and $' will be properly set up to be the new "short string" and "extension". The subtraction will give 0 for both cases If the word is the irrelevant (xy), neither regex matches and the subtraction will give 1. If the word is exactly equal to the "extension", both regexes will match and their subtraction will be -1. Notice that the first regex matching already sets $& to the full string and $` to nothing. That makes the second regex do the same match as would have happened without that assign. This is however irrelevant for this particular solution since actually the string substitutions happened before the eval. The value of the subtraction will be bit-orred with something either 0 or 1 and if that gives a non-zero value, the $"=x|t will be executed and it will not recurse deeper. So only the proper substring and proper superstring case will be available for extension (this takes care of stopping for irrelevant words and if the two strings are equal length). For the "word is a proper substring of $`" case, $_ will be the new short word, and for the "word is a proper superstring of $`" case, $_ will be the new long word. So every time the long string is extended, $_ will be the new long string and be a candidate for a solution or further recursion. That's why we can directly drop the "equal string" case, because to get there, the long string must have been set up earlier, so it was already checked for being a solution. Next comes /.{61}|^(@F)+$(?{++$@})Z/, which does two things: a) It checks if the string is too long. It will return 1 if so and give up on the current candidate word. Exactly what we want for early exit if we just extended the long string. And it can't trigger for the case where we extend the short string, since the long string would be even longer, and we will have run afoul of this test at some earlier point. b) If you assume $" is "|", the ^(@F)+$ will expand to ^(word1|word2...|wordn)+$, so basically it checks if $_ can be built form the word list. If so, it will progress through the (?{}) to the Z which will not match. So it backtracks and tries another way until all ways to built $_ from the word list are tried. The (?{}) body will be executed that many times. This is in fact a pretty dangerous operation, since the number of ways to combine the input words can explode exponentially. Perl regexes seem to be very well optimized, since I couldn't really make this explode on exponential amounts of failing attempts even with "cooked" strings and word lists. Notice that's it's also possible to check ways to write a string in linear time, e.g. see the code by Maciej Jastrzębski.

Edition 2007-01-09 top secret / strictly confidential page 411 of 520 Perlgolf History

The combination of a interpolation with a eval body (?{}) is actually forbidden unless you have a "use re 'eval'" (fixes a security hole where external strings could otherwise cause code to run). That is the first reason for the eval around the code block: the interpolation will be done before the regex is evaluated, so the regex never sees an interpolation. The second reason is that the eval will set $@ to "" inside the body, so the ++$@ inside the (?{}) will start counting from zero. So if $_ is not too long, $@ will contain the number of ways it can be written with the given word list. The "irrelevant word" case, the "two strings are equal" and the "just extended string is too long" case, it will now execute $"=x|t, which is $"="|", but with a better tie. But... isn't that too late ? The | was needed to make the @F interpolation work so that the regex indeed checks the number of ways you can write a word. If you work it out though, you will see that what happens is a start with "" "" then the first word gets tried: "word1" "" the check regex won't match with $" still "space", and next the short word gets extended, again with the first word: "word1" "word1" Again the check regex won't match, and now $" will be set to "|". And this is in fact exactly the scenario that would have happened if $" was "|" from the start too, so the assign is actually in time. The assign will get executed a lot of times later too, but they are essentially no-ops. The other case is for the proper substring ($_ is the new short string) or proper superstring case ($_ is the new long string). Then it will do 2-$@?do$0:exit!print So if the number of matches is exactly two, we found a solution and stop, otherwise the do$0 will recurse. Recursing will do the same things as described. It's however important to notice that in perl the regex vars like $&, $` etc. are connected with the code for the regex, which means you normally can't recurse on them, since when they get set for a new level, they destroy the values of the previous level as demonstrated by this:

Edition 2007-01-09 top secret / strictly confidential page 412 of 520 Perlgolf History

perl -wle ' $_="123"; subf{ my $n = 1+pop; /$n/; print "$n: $&"; f($n) if $n<2; print "$n: $&" } f(0) '

1: 1 2: 2 2: 2 1: 2 So it's important that the "$&$'"!~/^$_/-/^$&$'/ regexes happen under an eval. That makes sure they are a new regex each time with their own $` and $&. Actually it's very much ok for this solution, since both "do" is also an implicit eval. So the final code is: -ln0a map{eval"'$&$''!~/^$_/-/^$&$'/|/.{61}|^(@F)+".'$(?{++$@})Z/?$"=x|t:2- $@?do$0:exit!print'for$&.lc}@F I have no confidence whatsoever this is optimal though, since there are a number of clear flaws in the code: 1. The ^(@F)+".'$(?{++$@})Z is actively silly. We already recurse over word combinations, so doing it again in a regex should be unneeded. I found no way to combine the jobs though. The closest I came is to not exit as soon as a solution is found, but just continue searching for strings. Any decomposition pair A B will again be found later as B A, so every solution will actually be found exactly twice. Unfortunately there are also non-solutions with more than two decompositions that are found exactly twice, since the stopping of the recursion when the two strings get equal causes some decompositions to be dropped. "multi fail" is the prime example of this case. 2. The double match on $_ in /^$&$'/|/.{61}|^(@F)+".'$(?{++$@})Z/ feels wrong. It should be possible to do that with one match, since actually the check match is only relevant in case it's indeed the /^$&$'/ matching (that's the "extend long word" case). Maybe even using something like s/^$&$'/ do the @F number of solutions check here /ee which would nicely allow the extra e to do the "eval" 3. First I prefix $_ with $&, then I explicitly match against the extra $& in both "$&$'"!~/^$_/ and /^$&$'/. If these two could somehow be interchanged, that could save up to six strokes.

8.21. PCLP #24 - WYKREŚLANKA “Remove The Letters” Master: Przemysław Kowalczyk (szeryf) 03.11.2003 10.11.2003

8.21.1. Rules The object of this contest is to remove a list of words from a diagram and display remaining letters as a result. Standard input

Edition 2007-01-09 top secret / strictly confidential page 413 of 520 Perlgolf History

The script gets on its standard input a rectangular diagram of lowercase letters. Input matches the regular expression /^(([a-z]{x}\n){y})\z/, where 1 ≤ x ≤ 30 and 1 ≤ y ≤ 30. Script's arguments The script's arguments (the @ARGV array) is the list of words to be removed. Each word consists of 1 to 30 lowercase letters, matching the regexp /^[a-z]{1,30}$/. Results The script's result, which should be printed on standard output, are the letters remaining after removal of all the words on the list. The result is at least 1 character long, but no longer that 100 characters. After the result, a newline character should be printed. So, the result matches /^[a-z]{1,100}\n$/. Word removal The words in the @ARGV array are to be located and removed from the diagram. Each word occurs exactly once. Words can be located horizontally (read from left to right), vertically (from top to bottom) and diagonally (from top-left to bottom-right). Here's the example: ccneulhsacfa hfoeriotrlie edoplnlngaxt csmayeefsdue kcountskepps mainofiletbt udatadhighcz compareageth On the diagram, the word in violet color is “check” vertically, in green color is “compare” horizontally and in blue color is “copy” diagonally. Additional assumptions Each letter in the diagram is utilized exactly once. It belongs to one of the words or is a part of result. So, you can assume also that: • the words do not cross, • there are no duplicate words, • the sum of lengths of words and result is equal to the count of letters in the diagram, • the order of removal of words is not important. Rules The contest runs under standard perlgolf rules. You cannot, however, use any external modules, even those in standard Perl distribution.

8.21.2. Solutions 88, Piotr Fusik -la0 $_=;s/@_/$"^=$";"@_"^$&/sewhile$"='.'x$-[$!-=/ ()/]or split``,pop;print/\w/g 102, Robert Szczygiel -0 $j=;$j=~s/$_/$&^$_&'P'x999/se,s#(\.)+|\B#$1.'.'x index$j,$/#gefor(@ARGV)x3;print$j=~/\w/g,$/ 109, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 414 of 520 Perlgolf History

-0 /.+/,$b="."x"@+",map$z=~s!$_!y/./ /;$_^uc$&!se&s/\w(?=.)/$&$b/g,@ARGV for$z=,1,1;print/ $|\w/gfor$z 120, Michał Jankowski -lX0 ($t=)=~/ /;for$i(0,@-,@+){map{s/\B/).{$i}(/g;$t=~/($_)/s&&map{vec($t,$_,8)=10}@- }@a=@ARGV}$t=~y/ //d;print$t 120, Andreas Bühmann -la0 ($m=)=~$\;for$r(@ARGV){map{($x=$r)=~s/\B/).{$_}(/g;$m=~/($x)|$/s;subs tr$m,$_,1,$\for@-}@-,0,@+}print$m=~/./g 122, Krzysztof Kościuszkiewicz -la0 $_=;/ /g;for$L(0,$P=pos,$P- 1){for$R(@A=@ARGV){$R=~s/.\B/$&(.{$L})/g;$_=join$\,/(.*)$R(.*)/s if/$R/s}}print/./g 131, Przemysław Kowalczyk -la0 sub R{($m=$_)=~y/./\000/;$t=~s/$_/$&^$m/se}($t=)=~/ /;map{R;R$_=join'.'x$-[0],/./g;s/\.+/$&./g;R}@ARGV;$t=~y/\000 //d;print$t 134, Maciej Jastrzębski -0l12 $_=;/ (.)/;for$s(0,@-){for$w(@ARGV){$z=(join"(.{$s})",@w=split//,$w).'/';$z.=" \$$_"for 1..@w;eval"s/$z/s"}}s/\s//g;print 134, Maciej Misiak -l $/="";$_=;/\n/;$w=$- [0];for$i(0,$w,$w+1){for$f(map{join'(.{'.$i.'})',/./g}@ARGV){s/$f/join"",map {$".$$_}1..@+/es}}print/\w/g 169, Pawel Chmielowski -0 $_=." "x30;/ /;$p=$+[0]- 1;for$a(@ARGV){$b='';$b.="($_.{$p})"for$a=~/./g;($c=$b)=~s/{/.{/g;s/$a/\U$a/ ;s/$b|$c/join"",map"\u$$_",1..$#+/es}s/[^a-z]//g;print"$_ " 273, Tomek Machalski -l $P.=$_,$w=-1+length$_ while; for$x(@ARGV){ $b=$x;$b=~s/./ /g;$P=~s/$x/$b/s;$x=~s/./#$&/g;$x=~s/.(.*)/$1/;$m="."x$w; $a=$x;$a=~s/#/($m)/g;$b="\"$x\"";$i=0;$b=~s/#(?{$i++})/\$$i/g;$b=~s/[a-z]/ /g; $P=~s/$a/$b/see;$a=~s/.\)/..)/g;$P=~s/$a/$b/see} $P=~s/\s//g;print$P

8.22. PCLP #25 - MASZYNA TURINGA “Turing Machine” Master: Piotr Fusik (0xF) 24.11.2003 01.12.2003

Edition 2007-01-09 top secret / strictly confidential page 415 of 520 Perlgolf History

8.22.1. Rules The object of this contest is to simulate a Turing machine. Introduction The concept of a Turing machine is familiar to everyone who has at least started studying computer science. I refer other people to a book about basics of computer science. There are different variants of the Turing machine, so let's specify some details: • The machine is deterministic. • The alphabet consists only of zero and one. • The machine moves, not the tape. • Input data begins from the current position of the machine and spreads to the right. Infinite parts of the tape on both sides are filled with zeros. • The result is the data on the left side of the machine in its final position. The result starts with one or is empty. We are only interested in cases when the machine stops in a finite time. Input data The definition of the machine is given in the standard input. Each line contains (separated by single space characters): 1. The number of the state of the machine (in range of 0 to 100_000, zero is the initial state). 2. The symbol that is being read. 3. The next state. 4. The symbol that should be written. 5. Direction of movement (left, right) and whether the machine should be stopped. In a single step, the machine, basing on its current state and the symbol read from the tape, writes a symbol to the tape, moves and changes its state. L means move left, R means move right, S means move right and then stop. The standard input is matched by: /^((0|[1-9]\d*) [01] (0|[1-9]\d*) [01] [LRS]\n)+$/. The input data for the machine is passed as the only argument of the program: /^[01]*$/ (the argument is required, but may be empty which means that whole tape is filled with zeros). Output Your program should print on the standard output the result of the Turing machine's work, which consists of data on the left side of the machine in its final position, with infinite amount of leading zeros skipped. You should print the newline character. The output must be matched by /^(1[01]*)?\n$/. Rules Standard perlgolf rules apply. You cannot, however, use any external modules, even those from standard Perl distribution. Example input in ARGV

Edition 2007-01-09 top secret / strictly confidential page 416 of 520 Perlgolf History

11 Example input on STDIN 0000R 0111R 1001S 1111R Example output 111

8.22.2. Solutions 96, Ton Hospel -lp0 INIT{$L=reverse pop}$$5.=$3while/^0?$1 $S@{[1*chop${$5=~L?R:L},'(.+)'x5]}/m;$_=$R.$S;s/0*// 96 (post-mortem) -lp0 INIT{$0=pop}$$5=$5?$R.$3||!1:chop$R|"0$3$0"while/^@{[$1>>y!LS!0_!,$0=~s!.!!* $&,'(.+)'x5]}/m 97, Piotr Fusik -lp0 INIT{$0=pop}$$5=$5?$R.$3||!1:"0$3$0"|chop$R while/^@{[$1>>y!LS!0_!,$0=~s!.!!*$&,'(.+)'x5]}/m 105, Robert Szczygiel -la0 $_=R.pop;$m=<>;s!(.?)L|R(.?)!($-)=$m=~/^$- $^N0? (.*) (.) (L)?(.)?/m;"$3$2$4"!euntil/0*(.*)S/;print$1 113 (would be rejected, .{$var} will stop stop working if $var > 32766), Michal Szafranski -la0 $_=(pop).'0 '.<>;s/(.{$g})(.)(\d*)(.* 0?$5 \2 (\d+) (.) )/0$1$6$3$%$4/suntil($g+=$'^'`')&1;print/(1.*)$3$% / 121, Mateusz Matuszek -lp0 INIT{@X=pop=~/./g}/^0?$1 $X[$p]0? (.+) (.) (.)/m,$X[$p]=$2,$p+=2&ord$3,@X=(0,@X)while$3^c;$"='';$_="@X"&1x$p;s/^0+// 127, Tomek Machalski -lp0 INIT{@t=pop=~/./g}($^D,$t[$i],$c,$")=/^$^D $t[$i]0? (\d+) (.) (.)/m,$i+=2*$c!~/L/,@t=(0,@t)while$c^c;$_="@t[0..$i-1]";s/0*// 132, Krzysztof Kościuszkiewicz -la0 $S=;$_=pop;s|\G.?|@w=$S=~/^@{[$w[0]-0,$&- 0,('(\w+)')x3]}/m;$2|e,s/^/0/,pos=$p+=2x(L ne$w[2])while$w[2]ne S;print/1.*\G/g 134, Maciej Misiak -la0 split//,pop;for($_=<>;83-ord$';){$w=$_[$p]+0;($-,$_[$p])=/^$- $w (.+) (.) /m;$p+=ord$'&3;@_=(0,@_)}$"="";print"@_[0..$p-2]"=~1,$' 135, Maciej Jastrzębski

Edition 2007-01-09 top secret / strictly confidential page 417 of 520 Perlgolf History

-la0 split//,pop;$m=<>;@_=(0,@_,0),$I+=/R/-/L/+1,$m=~/^$% $_[$I] /m,($%,$_[$I],$_)=split$",$' until/S/;$_=join'',@_[0..$I];s/0*//;print 140, Przemysław Kowalczyk -l split//,pop;/\d+ ./,${$&}=$' for<>;${1*$`.$".1*$_[$?]}=~/(.) (\D)/,$_[$?]=$1,M gt$2?@_=(0,@_):$?++while$2!~S;print grep$x+=$_,@_[0..$?-1] 149 (would be rejected), Alain Dupuis -l -0 $t=pop;$_=<>;/(0)/;until($3eq S){$f=(substr$t,$p,1)|0;/^$1 $f (\d+) (.) (.)/m;substr$t,$p,1,$2;$3eq L?$t="0$t":$p++}$t=~/.{$p}/;print$&=~/1.*/g 168, Michał Jankowski -lpa INIT{@t=split'',pop}$s{$F[0].$F[1]}=[@F]}{$s=${$k=$s{1*$s.1*$t[$p]}}[2],$t[$ p]=$$k[3],($p+=2*($;=$$k[4]^c)- 1)<0and@t=($p=0,@t)while$;;$_=join'',@t[0..$p+1];s/^0+// 236, Mariusz Czulada while(){($s,$i,@P)=split;$T{$s.$i}=[@P];}$s=0;$_=pop; do{($s,substr($_,$p,1),$d)=@{$T{$s.(substr($_,$p,1)+0)}}; if(($d eq L?--$p:++$p)<0){$_=0 .$_;$p++;}; }until($d eq S);$b=index$_,1;$b=$b<0?$p:$b;print substr($_,$b,$p-$b)."\n";

8.22.3. Explanation by Ton Hospel From: [email protected] (Ton Hospel) Subject: Re: [golf] golf 25: explanation (eng) Newsgroups: pl.comp.lang.perl Date: 03 Dec 2003 17:07:41 GMT Message-ID: <[email protected]> Like I do traditionally I'll try to explain the reasoning in a way that a beginning golfer might appreciate. I take a little bit of freedom against how I actually found this result, since there I entered a few unnecessary byways. Piotr's solution is very simular in many respects, so see his explanation if you prefer it to my very wordy one. For the Turing golf the basic problem was how to represent the tape. I first played a bit with using a variable to keep it's position, but gave that up when I noticed that .{$var} cannot handle biggish numbers. Next I played a bit with using a marker, but I found nothing elegant there either (Robert Szczygiel did however). So finally I decided to go with separate variable for the tape on the left and the tape on the right. Moving right then becomes "Add the new char to the left, and remove the next char under consideration from the right", with left and right interchanged for moving left. If I put the initial string as the right side of the tape, then the first time I want to consider the first character from that, so I should start as if making a move to the right. However, there is an asymmetry here. The remove is from the end or start of the tape, and the add is from the start or end respectively. Conditionally doing that means basically handling these two cases separately, which I thought would lead to too long code. Piotr Fusik proved me wrong there since he found a very clever way to do this which avoids the need for an endgame (explicitly testing when S is reached, copying the left tape to $_ and removing 0's). Since both removing a char and adding a char is shorter if done from the end, i decided to reverse the order of the right tape.

Edition 2007-01-09 top secret / strictly confidential page 418 of 520 Perlgolf History

So the removal of the char under consideration becomes: chop $side_variable and the add of the result char becomes: $other_side .= $new_char depending on if I hit a L or an R the last time (ignore S for now). Obviously if I have the direction in a variable, I can use a symbolic reference. But only on one of these two, since the other must refer to the other side of the tape. So one of the two will be a more complex expression. Which one to choose? The first time the direction variable will contain nothing yet, but I know it must behave as an R. So that one needs some test for "empty", so more complex code. So if only one of the two needs the this test, it's that one that is most natural to do the "change side" for too. Now suppose I know the current state and the digit under consideration, how to find the next step? A regex match to look it up seems logical here. So I want all the sets in one string on which to do a match. Therefore, let's start with -lp0 (0 to slurp the whole string, p since I will in the end print the result from $_ and l because I'll need an extra newline in the output). That puts the whole machine specification in $_. So the match becomes: /^$current_state $current_char (.+) (.) (.)/m where $1 will be the new state, $2 the new char and $3 the new direction. Now, if I always keep the current state in $1, the basic loop becomes something like: ${one side determined by $3} .= $2; $current_char = chop ${other side determined by $3}; /^$1 $current_char (.+) (.) (.)/m; A classic optimization is to move the current char into the regex: ${one side determined by $3} .= $2; /^$1 @{[chop ${other side determined by $3}]} (.+) (.) (.)/m; So I must loop over this until done. Let's ignore for the moment how to exactly end the loop and just start from this conceptual skeleton: ${one side determined by $3} .= $2 while /^$1 @{[chop ${other side determined by $3}]} (.+) (.) (.)/m The first time $3 won't have a value yet for the chop, but it will for the append, so I'll do the "other side" operation in the chop. That means that the left side of the tape will be named $L and the right side $R. The best way I found to choose L if $3 is R and R is $3 is L or empty was $3=~L?R:L. This disturbs $1, but that's no problem since it's already interpolated at that point. The initial tape should to $L, but I need to do this before the -p will open the commandline arguments as files, so pop the argument away in an INIT block. So I can fill out the code to: -lp0 INIT{$L=reverse pop}$$3 .= $2 while /^$1 @{[chop ${$3=~L?R:L}]} (.+) (.) (.)/m This still has several problems: • The first time $1 will not be the initial state 0, but empty. Easily solved by putting 0? in front of $1: normal numbers don't start with 0, and if $1 is empty, this forces the 0 since no machine line starts with a space.

Edition 2007-01-09 top secret / strictly confidential page 419 of 520 Perlgolf History

• The chop can work on a piece of the tape that's currently empty. In that case the chop returns "", and I must convert that to 0, while 0 and 1 remain unchanged. Easily done by multiplying by 1 • All that (.+) (.) (.) is pretty long. But if you view it as (.+) (.+) (.+) (the last two strings on a line are only one long, so this will be the same), you get a clear repetition, of "(.+)" three times. So this gives: -lp0 INIT{$L=reverse pop}$$3 .= $2 while /^0?$1 @{[1*chop ${$3=~L?R:L},("(.+)")x3]}/m Next comes the endgame. The very last time $3 will be S, and $$3 .= $2 will put a 0 or a 1 into $S, which for the first time will differ from "". So if I put $S at the right place in the regex, it will have no effect until meeting the stop state, after which it will should the match impossible. E.g. by putting it in front of the current char, that would ask for a 2-digit current char after reaching the stop state, making the regex not match. Unfortunately, the last added character is now in $S, while I wanted it in $R, since it's part of the result. So the left side of the tape is now $R.$S. Assigning that to $_ and removing 0's will get the result printed: -lp0 INIT{$L=reverse pop}$$3 .= $2 while /^0?$1 $S@{[1*chop ${$3=~L?R:L},("(.+)")x3]}/m;$_=$R.$S;s/0*// Remains one optimization: by writing the end of the regex as (.+)(.+)(.+)(.+)(.+), backtracking will put the last char (the direction) in $5, the second to last (a space) in $4, the one before (the new digit) in $3, the one before (a space) in $2 and all the rest (the new state) in $1. So that finally gives: -lp0 INIT{$L=reverse pop}$$5.=$3while/^0?$1 $S@{[1*chop${$5=~L?R:L},"(.+)"x5]}/m;$_=$R.$S;s/0*// Nowhere in this solution do I have much of a choice in which characters to use, so the tie score is pretty much fixed. This made seeing the other scores on the board with a different tie pretty scary, since I knew this probably meant these people (mainly Robert Szczygiel and Piotr Fusik) had some different solution and there was no reason to think their horses weren't actually better. In fact, Piotr's solution could also be made into a 96, but fortunately "reverse" has a lot of letters, which gives a lower tie.

8.23. PCLP #26 COIN SLIDING Master: Ton Hospel (thospel) 08.12.2003 13.12.2003

8.23.1. Rules Introduction Consider a directed graph without loops like the next one:

Edition 2007-01-09 top secret / strictly confidential page 420 of 520 Perlgolf History

On it we can play a coin game where a coin is put on any node, like the topnode 0. Then each player in turn must move the coin along one edge (in the direction of the arrow) to a neighboring node. Since there are no loops, at some point one of the players won't be able to move anymore and he loses. For any given node, if the coin is there and it's your turn, there will be two possibilities. Either you will at each point in the game be able to find a move where your opponent loses whatever he does (and you'll therefore win), or your opponent will be able to hold you to positions where in the end you cannot move (and you lose). The first type of nodes are traditionally called P positions (positive, you win), the other type are called N positions (negative, you lose). Determining the P and N positions is easy. If from a given node any N is directly reachable, it's clearly a P position since you win by moving the coin there, leaving your opponent (whose turn it will be now) with a lost position. If from a given node all reachable nodes are P positions, this node is an N position, since you will have no choice but to move to a won position for your opponent (it will be his turn next). And nodes without outgoing arrows are clearly lost, so you can assign an N to them. Since the given graphs will contain no loops, this method will in the end assign a value to each node

In the given example it works out as follows: • Node 9 has no valid moves, so its an N. • So all nodes that allow you to reach 9 are won (by moving the coin to 9), so 7 and 8 are P positions. • Next, node 1 connects to node 7, but we don't know its status yet. Obviously if the coin is on 1, you don't want to move it to node 7 since that gives your opponent a won position. But you can

Edition 2007-01-09 top secret / strictly confidential page 421 of 520 Perlgolf History

still hope to move it to node 2 or 6, whose status we don't know yet. So we can't determine the status of node 1 yet. • Node 6 also connects to node 7. It's in fact the only valid move. So if the coin is on node 6, you must move it to 7, giving your opponent a win. So you lose, and it's an N position. • Therefore all nodes that allow you to move the coin to 6 win. So nodes 1, 2, 3 and 5 are P positions. • All moves from 4 give the opponent a win, so you lose and it's N. The same with node 0. That gives a value to all nodes, and now we completely know who wins in a given position without even bothering to move a coin. In the example we were using with the coin on node 0, the player whose move it is loses. Input The graph will be given on STDIN, one edge per line. An edge is given as the number of the starting node followed by a space and then the number of the ending node. The input will be sorted, first on starting node and then on ending node. So the input for the example will be: 01 02 12 16 17 23 26 34 36 45 56 67 78 79 89 The input graph will be non-empty, have no loops, no singletons (a node with no ingoing or outgoing arrows) and will be connected (every node will be reachable from every other node though you may need to go against the arrows). Notice that this implies that every node in the graph will appear somewhere in the input. There will be at most 10 nodes, and they are assigned consecutive natural numbers starting with 0. There will be at most one edge between any two nodes, so the input will match /^(\d \d\n){1,45}\z/. Output Starting from node 0 and ending with the highest numbered node, suppose it's your turn and print a P if you win for a coin on that node, and an N otherwise. Finish up with a newline. So STDOUT matches /^[PN]{2,10}\n\z/.

In the given example, you are to print: NPPPNPNPPN

8.23.2. Solutions 54, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 422 of 520 Perlgolf History

-ln0 s^^s!.?(\d)!($X[$1]=/($1)N/?P:N).$1!eg^eg;print@X 55, Robert Szczygiel -ln0 s#\d#$;[$&]=/$& N/?P:/($&) \d/?$1:N#ge?redo:print@ 56, Michal Szafranski -ln0 /$& \d/||s^$&^$;[$&]=/$& N/?P:N^gewhile/\d/g;print@ 78, Krzysztof Kościuszkiewicz -lp0 sub T{for$a(/$_[0] (.)/g){T($a)&&return}1}$x.=T($i++)?N:P while/$i/;$_=$x 82, Maciej Jastrzębski -la0 $_=<>;for$n(0..99){$n%=10;s/$n/$b[$n]=$k/eg if$k=/$n N/?P:/$n \d/?0:N}print@b 88, Tomek Machalski -nla0 for$j((/\S/g)x10){$a=N;s/$j (.)/$a=$W[$1]eq N?P:$W[$1]&&$a;$&/ge;$W[$j]=$a}print@W 113, Maciej Misiak -ln0 s/\d/$p[$&]=C;$&/eg;$s=$_;while("@p"=~C){$_=$n%=@p;$s=~s/$n /$_.=$p[$'];$&/eg;$p[$n++]=/N/?P:/C/?C:N}print@p

8.24. PCLP #27 - NARTY “SKI” Master: Mateusz Matuszek (magus) 16.12.2003 22.12.2003

8.24.1. Rules The task is to count all different paths through the given ski slope. Changes and explanations 1. Each point can be reached 2. There is a way from point i to point j only when point j is later in alphabetical order (so there will be no vertex H->D) 3. If the oldest point is H so there will be all letters B..H Introduction The problem was taken from the Alghoritm's Smashers contest. As Input, the description of a Directed Graph is given as follows: 1. Each crossing of the paths is set as a point. Each point has assigned a letter A..Z 2. For each crossing there are given all crossings which can be directly accessed 3. There is only one starting point - A The task for the script is to count all different paths through the given graph. A /\ BC /\/\ DEF For the above slope the result is 4.

Edition 2007-01-09 top secret / strictly confidential page 423 of 520 Perlgolf History

Input and Output The graph is described using arguments in the following way: • argument 0 - description for A point • argument 1 - description for B point • argument 2 - description for C point • etc... Each description is a string of letters (/[A-Z]*/). If a string is empty there is no way out of this point. There is at least one non-empty string (the description of point A). The output is a number of counted paths: /\d+\n/ Examples For the given slope (see above) there will be the following input data: • argument 0 - BC • argument 1 - DE • argument 2 - EF All other are empty.

8.24.2. Solutions 45 (post-mortem, slow) -l 1while/\w/+s//$ARGV[@b=B..$&]|v0/e;print@+ 47, Ton Hospel -l map{split$_,"A@_+";$"=shift||Z}A..Z;print$#_ 47, Piotr Fusik -l s/w|^$/$ARGV[-65+ord$&.A]|v0/e?do$0:print@+ 47, Alma Media Golf Team $a=shift||Z,$\=$0=~s/$_/$a/g.$/for$0,B..Z;print 49, Terje Kristensen -l sub z{$x+=!map&z,$ARGV[ord()%65]=~/./g}print z 50, Michal Szafranski -l for$c($A,B..Z){s/$c/$x/g if$x=shift}print y!!!c 50, Mateusz Matuszek -l $s=shift,$e=~s/$_/$s||$c++/egfor$e,B..Z;print$c 50, Robert Szczygiel -l for$l(A..Z){s/$l|^$/$k/g if$k=shift}print y///c 51, Krzysztof Kościuszkiewicz -l for$l($_,B..Z){s/$l/$p/g if$p=shift}print length 54, Michał Jankowski

Edition 2007-01-09 top secret / strictly confidential page 424 of 520 Perlgolf History

-l $_=$p=A;for$x(@ARGV){$x&&s/$p/$x/g,$p++}print y///c 55, Tomek Machalski -l sub r{$i+=!map r(-65+ord),$ARGV[pop]=~/./g}r;print$i 61, Maciej Jastrzębski -l sub a{my$s;$s+=a(-65+ord)for$ARGV[pop]=~/./g;$s||1}print a 61, Maciej Misiak -l sub f{!(map$_[0]+=f(-65+ord),$ARGV[pop]=~/./g)|pop}print f 67, Mariusz Czulada -l while(@ARGV){$_=pop;s/./${chr(65+@ARGV)}+=(${$&}or 1)/ge}print$A

Edition 2007-01-09 top secret / strictly confidential page 425 of 520 Perlgolf History

9. Games – Kernelpanic season 2 9.1. PCLP #2.1 (28) - UŁAMKI ŁAŃCUCHOWE Master: Przemysław Kowalczyk (szeryf) 28.01.2004 04.02.2004

9.1.1. Solutions 52 (post-mortem) -pl do$0for$'/?/?.$&.$_%$',$z.=','-.~~eval;$_=w^"$z]" 55 (post-mortem) -pl $z.=v29^/\D/.int$_/$';do$0for$-'.A.$_%$';$_=w^"$z]" 55, Ton Hospel -lp $^H=eval;$_=$'.$&x?/?.$_%$';do$0&s/./[$^H,/||s/.$'/]/ 56, Piotr Fusik -pl $_=eval"\$s.=','.$_%~0"?$'.$&.$_%$':w^"$s]"while/\// 60, Michal Szafranski -p s!\d+/(.+)!$1&&(~~eval).",$1/".$&%$1!e?redo:s//[/,s/,0/]/ 60, Michał Jankowski -pl $_=$'.-$`%-$',push@a,$%=$`/$' while/\D/;$_="[@a]";y/ /,/ 61, Mateusz Matuszek -p s!\d+/(.+)!int(eval).",$1/".$&%$1!euntil s!(.+),.+/0![$1]! 61, Robert Szczygiel -pl $_=$'?($i.=','x$|++.int$`/$',"$'/".$`%$'):"[$i]"while/\//

63, Przemysław Kowalczyk -p s@(\d+)/(.+)@($1/$2|0).",$2/".$1%$2@euntil s@(.+),.+/0@[$1]@ 65, Krzysztof Kościuszkiewicz -lp /\D/,$_="$'/".$`%$',push@A,int$,while$,=eval;$_="[@A]";y/ /,/ 66, Maciej Jastrzębski -pl push@b,$==eval;m'/';$_="$'/".$`%$';eval&&redo;$_="[@b]";y/ /,/ 66, Maciej Misiak -lp s/(.*),$/[$1]/while s#\d+/(.+)#$1?int($&/$1).",$1/".$&%$1:''#e 69, Tomek Machalski -lp 1while s|(\d+)/([^0].*)|int($1/$2).",$2/".$1%$2|e;s|(.*),.*|[$1]| 78, Wawrzyniec Żurowski -lpaF/ ($a,$b)=@F}{push@c,int$a/$b;($b,$a)=($a%$b,$b);$"=$b?redo:",";$_="[@c]" 82, Mariusz Czulada

Edition 2007-01-09 top secret / strictly confidential page 426 of 520 Perlgolf History

-plaF/ ($l,$m)=@F;while($m){push@U,int($l/$m);($l,$m)=($m,$l%$m)}$_="[@U]";y/ /,/;

9.2. PCLP #2.2 - PERMUTATION CYCLES Master: Ton Hospel (thospel) 14.02.2004 19.02.2004

9.2.1. Rules Introduction A permutation of objects can be specified in several ways. E.g. if I have a sorted list of objects a, b, c, d, e and f and reorder them to b, d, e, a, c, f then that sequence completely determines the permutation. If you write them over each other you get: abcdef bdeacf And by reading that from top to bottom, you can trace out that a gets replaced by b. Looking under b shows which element goes to that now empty spot, which turns out to be d. And d in turn gets replaced by the a that was pushed away by b. So if we continue this "replaced by" game, we keep cycling around a, b and d. We didn't follow c yet though, which gets replaced by e, which in turn gets replaced by c again. And finally f goes to itself. So we can also specify the permutation by these loops, the so called cycles: a<-b<-d<-a c<-e<-c f<-f You can simplify that notation a bit by dropping the arrows and dropping the last element (equal to the first). giving: abd ce f Notice that the notation is not unique. E.g. the cycle abd can just as well be written as bda. And the order in which you write the cycles isn't fixed either. Your task is to convert from "order notation" to "cycle notation". Input and Output The objects will be named by consecutive lower case letters starting with a and there will be at least one and at most 9 objects. On STDIN you will get one line which specifies a permutation by giving the resulting order of objects separated by spaces, so bdeacf in the given example. As you can see, STDIN will match /^([a-i] )*[a-i]\n\z/ On STDOUT you should output the cycles in simplified form, one cycle per line. The cycles are again written as a sequence of objects separated by spaces. You may output each cycle starting with any of the elements in that cycle (which fixes all the rest), and the cycles themselves in any order. So one valid output will be:

Edition 2007-01-09 top secret / strictly confidential page 427 of 520 Perlgolf History

abd ce f Another good one is: ec f dab As you can see, STDOUT will match /^(([a-i] )*[a-i]\n){1,9}\z/.

9.2.2. Solutions 51, Piotr Fusik -pal s*.*$_=delete$F[(P^lc)-1]||o&$/x@F*ge;s/\B/ /g 54, Ton Hospel -ap0 }{1while$z=$F[(/$z/?1..s/ $/ /:$z^Q^s/\z/$z /)-1] 57, Andreas Schaumeier -p $\=$&.(/$;/?$":$/).$\,s// /,$;=chr"@-"/2+97while/\w/}{ 60, Michal Szafranski -lna map{s/.$/$& $F[-97+ord$&]/until/(.+) \1/;$'||print$1}@F 65, Mateusz Matuszek -ln for$x(a..i){$a=$&,s/$x/$x$a/||print"@{[$a=~/./g]}"if s/\w+//} 67, Robert Szczygiel -nl pos=2*(P^($a[@a]=$&))-2while s/\G\S/ / or$#a=s/\S/ /*-print"@a" 82, Przemysław Kowalczyk -p $a=a;s/(.)./$a++."$1 "/egs;1while s/(.)(.*)\1(.) /$1$3$2/s;s/./$& /g;s/... / /g 83, Krzysztof Kościuszkiewicz -lna for(@F){print"@O",@O=()if$O[-1]eq$_;$$_++&&next;push@O,$_;$_=$F[- 97+ord];redo} 99, Mariusz Czulada -n $L=a;s|\w|${$L++}=$&|ge; for(a..i){while($$_){($_,$$_,@P)=($$_,$z,@P,$$_)};print"@P "if@P;@P=@R} 130, Wawrzyniec Żurowski -plaF $a=a;$z{$a++}=$_ for@F;for(@F){$f{$_}&&next;$b=$_;my@X;{$f{$b}=push@X,$b;($b=$z{$b})ne$_&&red o}$x{"@X"}++}$_=join"\n",keys%x

9.3. PCLP #2.3.0xF – XXX (Arabic to roman number conversion) Master: Piotr Fusik (0xF) 04.03.2004 11.03.2004

Edition 2007-01-09 top secret / strictly confidential page 428 of 520 Perlgolf History

9.3.1. Rules The object of this contest is to translate a number written using Arabic digits (decimal system) to the Roman notation. Input The standard input contains a number in range 1..3999 followed by the newline character: /^(?=[1- 9])[1-3]?\d{0,3}\n\z/

Output Your program should print the given number in Roman notation, and the newline character: /^M{0,3}(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])\n\z/

9.3.2. Solutions 55, Ton Hospel (deep post-mortem) -lp s!.!($#.=5x$&*8%29628)=~y$IVCXL4620-8$XLMCDIXV$d!eg 56, Ton Hospel (post-mortem) -lp s!.!y$IVCXL91-I0$XLMCDXVIII$dfor$#.=4x$&%1859^7;5!eg 60, Ton Hospel -lp s;.;y$IVCXL91-I0$XLMCDXVIII$dfor$I.=4x$&%1859^7;eg;$_=$I 63, Piotr Fusik -p y/IVXLC/XLCDM//s//$&-9?$&-4?I x$&:IV:IX/e&s/I{5}/V/while/\d/ 63, Michal Szafranski -p y/IVXLC/XLCDM//s//$&-9?$&-4?I x$&:IV:IX/e&s/I{5}/V/while/\d/ 67, Maciej Misiak -lp y/XCVLpIx/CMLDIX/,s/IIII/IV/,s/IVI/V/while s/\d/$&-9?p x$&:px/e 68, Mateusz Matuszek -p y/IVXLC/XLCDM/,s//I x$&/,s/I{5}/V/,s/I{4}/IV/,s/VIV/IX/while/\d\/ 72, Maciej Jastrzębski -pl y/IVXLC/XLCDM/,$_.=($I,I,II,III,IV,V,VI,VII,VIII,IX)[$&]while s/\d// 88, Krzysztof Kościuszkiewicz -lp $_=I x$_;$I='s/I{10}|(I){9}/$1X/g.s/I{5}|(I)III/$1V/';$I=~y/IVXLC/XLCDM/while eval$I 96, Przemysław Kowalczyk -pl $_=I x$_;($e=M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4)=~s=(\D+)(\d+)="s/I{$2 }/$1/g"=gee 109, Tomek Machalski -lp $i=$_;$_="1000M900CM500D400CD100C90XC50L40XL10X9IX5V4IV1I";s/(\d+)(\D+)/$s.= $2,$i-=$1while$i>=$1/eg;$_=$s 128, Mariusz Czulada

Edition 2007-01-09 top secret / strictly confidential page 429 of 520 Perlgolf History

-lp $_=reverse;@C=('',a,aa,aaa,ba,b,ab,aab,aaab,ca,M,CDM,XLC,IVX);s|\d|$b=$C[$&] ;$c=pop@C;eval"\$b=~tr/abc/$c/";$b|ge;$_=reverse 135, Wawrzyniec Żurowski -pl %a=split/(\D+)/,"1I4IV5V9IX10X40XL50L90XC100C400CD500D900CM1000M";for$k(sort {$b<=>$a}keys%a){until($_<$k){$_-=$k;$b.=$a{$k}}}$_=$b;

9.3.3. Explanation by Ton Hospel From: [email protected] (Ton Hospel) Subject: Re: [golf] XXX - finito Newsgroups: pl.comp.lang.perl Date: 12 Mar 2004 11:39:15 GMT Message-ID: <[email protected]> If I understood correctly, the next golf should be prepared by Michal Szafranski, not by me? Is the rule now "prepare at most one in 4"? Anyways, the obligatory explanation of the winning solution. (Very long, but I actually enjoyed this a lot, even though you saw almost no activity from me on the scoreboard, because I happened to hit on a nice solution very early). The basic idea was pretty obvious: convert one digit to it's normal roman form. Then go to the next one while "multiplying" the last one by 10 by transforming I->X->C->M and V->L->D-> (impossible) The obvious way to do that is: s#.#$a=~y/IVXLCDM/XLCDM/;$a.=single_digit($&)#eg;$_=$a (As other solutions show it's shorter to not introduce a help variable like $a, and work directly in $_, distinguishing the fact that the unprocessed piece of $_ are digits and the processed pieces are letters. But in my solution that doesn't work since I will go through digits for the result too). But how to map 0..9 to "", I, ...., IX ? A table lookup is possible, but long: s#.#$a.=($a!~y/IVXLC/XLCDM/,I,-II,III,IV,V,VI,VII,VIII,IX)[$&-]#eg;$_=$a (74) You can do a quite a few clever things (as seen in other solution), but the conversion step tends to remain long. There's just no sane regularity in this thing. But in "random" mappings with a very small result set like this, the shortest solution is often to make up some magic formula that has no particular meaning, but just happens to give the wanted result. So I started considering $a.= magic_formula($&) where then I add a mapping from the result digits of magic formula in the y///. A little bit of thinking showed me there was not much chance of this working as a perfect direct mapping (only 3 different digits in the result, for I, V and X), nor for a many to one mapping (some of I, V, X represented by many digits). So there would also be extra digits to be gotten rid of, which fortunately still works quite well with y/// if you use the d option. The next step was searching for such a magic formula. Doing this by hand is way too much work, so I needed a classic backtracking program that given 10 numbers would try to find an assignment of each of the digits to I, V, X and "nothing", so that in the end you'd get "", I, II, ..., IX respectively.

Edition 2007-01-09 top secret / strictly confidential page 430 of 520 Perlgolf History

I first did that as perl code, but it still got annoyingly long with all the special cases and early tests so it didn't need to try ALL possible combination. And even so all that checking is SLOW, so I wanted the code in C really. So I decided to write a program that would generate the C program that would generate the parameters to use in the golf solution :-) The perl code generating the C program can be found at http://www.xs4all.nl/~thospel/-golf/romanc.pl In the code that generates, you need to add the C equivalent of the perl "magic formula" that you want to try, and a loop to try this one for all kinds of parameter values. The resulting code with such a formula filled in for $mx$&%$n^$x can be found at: http://www.xs4all.nl/~thospel/-golf/romangen.c Running this will output: a b cd efg hi j kl mno pqrs tu =>aIIIIIIIVVVIVIIVIII IX I=[bcdefghlnoqrst] V=[ijkmp] X=[u] 0=0 7 3 43 443 721 1680 136 1437 1332 298 =>7IIIIII7IVV680 VI6 VII7 VIII IX8 I=[234] V=[1] X=[9] m=4,n=1859,x=7 1 6 76 776 1749 5428 37 366 3676 602 =>1IIIIII1I4V V428 VI VII VIII IX2 I=[67] V=[359] X=[0] 1 6 76 776 1749 5428 37 366 3676 602 =>1IIIIII1IV9 5V28 VI VII VIII IX2 I=[67] V=[34] X=[0] 1 6 76 776 1749 5428 37 366 3676 602 =>1IIIIII1I4V 542V VI VII VIII IX2 I=[67] V=[389] X=[0] m=7,n=6029,x=1 That is a list of solutions, each time all working assignments, followed by the parameter values used to get that one. The first two lines are a sanity check so I know the assigner works. E.g. the third and fourth line say that for the parameters m=4, n=1859, x=7 the values 0, 1,..9 map to 7 3 43 443 721 1680 136 1437 1332 298 and if you then map 2, 3 and 4 to I, 1 to V and 9 to X, you get the strings: 7 I II III 7IV V680 VI6 VII7 VIII IX8. Next suppress 7, 6, 8 and 0 and you get the wanted result. The next step is to write this as a good y///d thing with a nice use of ranges so it gets short. That also turned out to be a boring task, so I wrote a program to solve that. The post-processor for that is found at: http://www.xs4all.nl/~thospel/-golf/rangegen.pl (A very interesting problem to do efficiently in fact, but this text is already long enough so I'll skip the explanation of the method here). Piping the previous set through that you get: a I II III IV V VI VII VIII IX I=[bcdefghlnoqrst] V=[ijkmp] X=[u] y/b-ua/IIIIIIIVVVIVIIVIIIIX/d 0=0 7 I II III 7IV V680 VI6 VII7 VIII IX8 I=[234] V=[1] X=[9] y/91-80/XVIII/d m=4,n=1859,x=7 1 I II III 1I4V V428 VI VII VIII IX2 I=[67] V=[359] X=[0] y/035-791-8/XVVIIV/d m=7,n=6029,x=1 1 I II III 1IV9 5V28 VI VII VIII IX2 I=[67] V=[34] X=[0] y/034671-9/XVVII/d m=7,n=6029,x=1 1 I II III 1I4V 542V VI VII VIII IX2 I=[67] V=[389] X=[0] y/036-91-5/XVIIVV/d m=7,n=6029,x=1 Which summarizes things in such a way that the shortest line in the result is the best solution. In this case that's: y/91-80/XVIII/d m=4,n=1859,x=7 Combining all pieces then gives:

Edition 2007-01-09 top secret / strictly confidential page 431 of 520 Perlgolf History

-lp s/./y!IVCXL91-80!XLMCDXVIII!d for $a.=4x$&%1859^7/eg;$_=$a and dropping spaces and choosing all places where you have choice to be chars that repeat as often as possible, you get: -lp s;.;y$IVCXL91-I0$XLMCDXVIII$df-or$I.=4x$&%1859^7;eg;$_=$I I tried many magic formulas, but this happens to be one of the first ones I tried since the $mx$& tends to multiply the result by 10 each time, so getting a result that's one longer each time, about the only somewhat regular pattern in roman numerals. The modulo makes the result shorter (so there's more chance for an assignment existing), but we must allow the result to grow to at least 4 digits so we can get VIII. The $x allows the mapping of 0 to move around, otherwise the fact that 0 can never be assigned to I, V or X tends to be a too severe constraint. The only other good one was $mx$&*$x%$n, which has the same sort of properties. That one also has a nice solution leading to a 60, but with a worse tie: -lp s;.;y$IVCXL426.-X$XLMCDIVX$dfo-r$X.=5x$&*8%29628;eg;$_=$X All other formulas I tried tended to be longer to much longer (if they had solutions at all).

9.4. PCLP #2.4 - TABLICA Master: Maciej Misiak (grizzley) 15.04.2004 21.04.2004

9.4.1. Rules The object of this contest is to return a value from given 2D table Input As argument there are given two digits in format (row,col): /\A\(\d,\d\)\z/ Output Print to standard output proper value: /\A\d{1,2}\z/ knowing, that the table looks like this: 0: 1: 2: 3: 4: 5: 6: 7: 8: 9:

0:3315144109021 1:10414110147130 2:1261211634151510 3:15126412100412 4:5129124412127 5:513101169958 6:21094914147514 7:813116126131011 8:102131310141312814 9:71191408101139 Values are range <0..15>

9.4.2. Solutions 56, Przemysław Kowalczyk (rejected) srand\t1487867093;$%=rand\t16for$d..10*(pop|"\003\000\002");print$% 78, Piotr Fusik

Edition 2007-01-09 top secret / strictly confidential page 432 of 520 Perlgolf History

print\tvec"3\357\244\t\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",("# \002"|pop)*10,4 78, Michal Szafranski print\tvec"3\357\244\t\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",("#\000&"|pop)*10,4 78, Pawel Chmielowski print+vec'3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223',$_=pop,s~\D~~g+1 78, Przemysław Kowalczyk print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",$_=pop,1+s!\D!!g 79, Terje Kristensen print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",pop=~/.,/*$&.$',4 81, Robert Szczygiel print vec'3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223',join("",eval pop),4 81, Mateusz Matuszek s|\D||g,print vec'3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223',lc,4for pop 81, Tomek Machalski s|\D||g,print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",$_,4for pop 81, Maciej Misiak $_=pop,y!,(!!d|print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",$_,4 81, Maciej Jastrzębski

Edition 2007-01-09 top secret / strictly confidential page 433 of 520 Perlgolf History

$_=pop,s/\D//g,print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",$_,4 81, Michał Jankowski $_=pop;s/\D//g;print vec"3\357\244\011\022J\036\032t l\2746\364\257\037b\304 \304\025\222L\304|\325\001k\231\205\242I\351~\345\330k!\326\272*\335\352\315\35 0\267\351\200\272\223",$_,4 104, Radosław Zieliński ($d=pop)=~y!(,)!!d,print hex((unpack'(H@0h)*','3\376J\220!\244\341\241G\320\306\313cO\372\361&L\240LQ )\304L\307]\020\266\231X*\224\236\347^\215\266\022m\253\242\335\256\334\216{ \236\010\2539')[$d]) 113, Robert Garwacki $_=pop;s/\D//g;$v=ord(('3\376J\220!\244\341\241G\320\306\313cO\372\361&L\240LQ) \304L\307]\020\266\231X*\224\236\347^\215\266\022m\253\242\335\256\334\216{\ 236\010\2539'=~/./g)[$_/2]);$_%2or$v>>=4;print$v&15 127, Wawrzyniec Żurowski pop=~/(.),(.)/;split"","3\376J\220!\244\341\241G\320\306\313cO\372\361&L\240LQ) \304L\307]\020\266\231X*\224\236\347^\215\266\022m\253\242\335\256\334\216{\ 236\010\2539";push@b,int ord()/16,(ord)%16for@_;print$b[$1*10+$2] 309, Krzysztof Konkowski @t=([3,3,15,14,4,10,9,0,2,1],[10,4,14,1,10,1,4,7,13,0],[12,6,12,11,6,3,4,15,15, 10],[15,1,2,6,4,12,10,0,4,12],[5,1,2,9,12,4,4,12,12,7],[5,13,1,0,11,6,9,9,5, 8],[2,10,9,4,9,14,14,7,5,14],[8,13,11,6,1,2,6,13,10,11],[10,2,13,13,10,14,13 ,12,8,14],[7,11,9,14,0,8,10,11,3,9]); $ARGV[0]=~/(\d),(\d)/; print $t[$1][$2];

9.5. PCLP #2.5 - INTERPRETER BF Master: Przemysław Kowalczyk (szeryf) 12.05.2004 19.05.2004

9.5.1. Rules Task Your task is writing a Brainfuck interpreter. A nice tutorial to Brainfuck can be found at http://cydathria.com/bf/brainfuck.html . Let's assume that Brainfuck programs are interpreted on a `virtual machine', which has: • a memory — an array of 30000 numbers (called a) • a pointer (called p), which points at a memory cell and can be moved to the next or previous cell. Additionally, all the Brainfuck test programs adhere to the following: • each memory cell can store an integer from the range [-1000, 1000],

Edition 2007-01-09 top secret / strictly confidential page 434 of 520 Perlgolf History

• at the beginning, all the memory cells are filled with zeros (or undefined values, which is almost the same in Perl in most cases), • the p pointer points to the first memory cell (at 0 index), • the p pointer never leaves the memory range [0, 29999], Brainfuck consists of the following instructions: Instruction Description Pseudocode > Increment the pointer ++p < Decrement the pointer --p + Increment memory cell pointed to by p ++a[p] - Decrement memory cell pointed to by p --a[p] . Output the number from the memory cell a[p] print a[p] , Input number to a[p] (see section 2) a[p] = shift @ARGV [ Start loop — execute code to matching ] only if a[p]!=0 while (a[p]) { ] End loop — jump to matching [ } Input Your program will receive on STDIN a Brainfuck source code to interpret. Input data is not empty, contains only characters mentioned in tab. 1 and has no more than 1000 characters. Thus, input matches the regular expression /^[<>+\-.,[\]]{1,1000}\z/. The input data for interpreted Brainfuck program is given as command line arguments to your program. Thus, the ',' operation — input number to a[p] — is just shifting the next value off the @ARGV table. @ARGV contains from 0 to 20 elements. If the input is empty, a zero (undefined) value is read to the memory. In most implementations, Brainfuck programs read bytes from input and output ASCII values of stored numbers. Here, to ease things a little, only numbers are input and output, so no ASCII conversions are needed. Output Your program should print to STDOUT the output of the interpreted program for given parameters (a sequence of numbers or nothing at all). No newline is to be printed.

9.5.2. Solutions 95, Piotr Fusik s!.!qw/${ -- 0}while$ F ++$ $$p=shift; --$ print$ ++/[ord($&)%13%9].'$p;'!eg,eval for X. 96, Michal Szafranski s//a.'.\';$_=$a[$p]\'.qw[=shift -- ;print ++ ;$p-- } ;$p++ ;while(uc){][ord(d|getc)%12]'x1e4/eee 102, Mateusz Matuszek s!.!'%}#while(x){#Sx++#Ux--#D$p--#F$p++#Vprintx#Tx=shift ;'=~($&^x);$'!eg,s'x'$A[$p]'g,eval for 104, Przemysław Kowalczyk $_=;s/./qw(++A ++$p . --$p } printA --A A=shift while(A){)[(ord$&^3)%10].';'/eg;s'A'$a[$p]'g;eval 106, Maciej Jastrzębski

Edition 2007-01-09 top secret / strictly confidential page 435 of 520 Perlgolf History

y/+-.>[ 107, Pawel Chmielowski $_=;y/][+-.>$p++#<$p--#.printx#,x=shift# ;'=~/$b$&/;$'|ge,s'x'$a[$p]'g,eval for 112, Radosław Zieliński %h=qw#> ++$p < --$p + ++A - --A . printA , A=shift [ while(A){ ] }#;$_=;s#.#$h{$&};#g;s/A/\$a[\$p]/g;eval 112, Wawrzyniec Żurowski $_=;%m=qw/> ++$p < --$p + X++ - X-- . printX , X=shift [ whileX{ ] }/;s/./$m{$&};/g;s/X/(\$a[\$p])/g;eval 116, Robert Szczygiel s/\[/while(A){/g,s/,/A=shift;/g,s/[<>+- ]/$&|N^"Zi$&=1;"/ge,s/\./printA;/g,y/]> 122, Maciej Misiak $_=;s/\[/while(x){/g;s/[+- ]/x$&=1;/g;s/>| ;y/]/}/;$f='($a[$p])';s/\[/while$f {/g;s/\+/$f++;/g;s/\-/$f-- ;/g;s/>/\$p++;/g;s/

9.6. PCLP #2.6 MACIERZ KWADRAT “Matrix2” Master: Michal Szafranski (stalker) 24.05.2004 31.05.2004

9.6.1. Rules Given a square matrix of values 0 and 1 output square of this matrix. Input Input will contain matrix representation with rows separated with eols, columns are not separated. Thus, input matches following regex /\A([01]{1,9}\n){1,9}\z/. Output Output should contain matrix squared in the same form, matching regular expression: /\A(\d{1,9}\n){1,9}\z/.

9.6.2. Solutions 54, Ton Hospel -ap0 s#.?#$@.=$&x/./gfor@F;map/2/g,$@+$&if/.*\G.+/#eeg 58, Robert Szczygiel

Edition 2007-01-09 top secret / strictly confidential page 436 of 520 Perlgolf History

-pa0 s!.!map/1/g,$_&2x($i%@F).($F[$i++/@F]x9&10**@F x9)!ge 63, Mateusz Matuszek -lpa0 s/./$X[$a++%@F].=$&/eg}for(@F){s!.!($X[pos]&lc)=~y/1//!eg 65, Michal Szafranski -lan0 s!.!$x[pos].=$&!egfor@F;s!.+!print map y/1//,map$&&$_,@x!ge 66, Przemysław Kowalczyk -p0a map$a[$i++%@F].=$_,/./g;s|.|($a[$j%@F]&$F[$j++/@F])=~y/1//|eg 73, Maciej Misiak -pa0 s#\d#$_=$F[$i++/@F];s!!"+$&*".substr$F[$c++%@F],$i%@F-1,1!eg;eval#eg 83, Maciej Jastrzębski -p0 @p=/ /g;@F=/./g;s#.#my$s;$s+=$F[$i-$i%@p+lc]*$F[$i%@p+@p*lc]for 0..9;$i++;$s#eg 85, Marcin Bieńkowski -p0 @A=map[/./g],@B=split/ /;s#.#grep$A[$_][$-[0]%($d=@B+1)]*$A[$-[0]/$d][$_],0..9#ge 99, Wawrzyniec Żurowski -p push@a,[/./g]}{for$x(0..--$.){for$y(0..$.){my$z;$z+=$a[$x][$_]*$a[$_][$y]for 0..9;$_.=$z}$_.=$/} 107, Tomek Machalski -lnaF// push@A,[@F]}{for$b(0..$.*$.){$B[$b]+=$A[$b/$.][$_]*$A[$_][$b%$.]for(0..$.)}p rint splice@B,0,$.for@B

9.7. PCLP #2.7 BULGARIAN SOLITAIRE Master: Ton Hospel (thospel) 15.06.2004 19.06.2004

9.7.1. Rules Introduction Put a number of playing cards in piles on the table. The basic step in Bulgarian Solitaire is to take one card from each pile, and then add the removed cards as a new pile. So if you start with three piles of five, seven and respectively: 578 removing one card from each pile gives you: 467 and adding the three removed cards on a new pile gives you after one step: 4673 The following steps will be: 35624 245135 On the next step the pile of one card will get completely removed, and so we'll drop it from the list:

Edition 2007-01-09 top secret / strictly confidential page 437 of 520 Perlgolf History

134246 On the next step the first pile will disappear: 231356 Pile 3 goes away: 122456 And the first pile again: 113456 Now two piles go away: 23456 Now compare this with what we had after two steps: 35624 you see that it's the same set of piles, only their order is different. So from here on we will basically repeat what we've already seen, just with the piles in a different order. So we can just as well stop here, after having done eight steps. Your task will be to determine the number of steps before the system loops. Input and Output On the command-line you will receive a list of pile sizes, no pile being empty and each pile containing at most 9 cards, so each argument will match /^[1-9]\z/. There will be at least one pile and at most 9 piles, and the piles will be ordered from smallest to biggest (notice that during play you can end up with more than nine piles, and piles can contain more than nine cards). On STDOUT you must output after how many steps you will reach a configuration you've seen before (ignoring order), followed by a newline. So STDOUT will match /^[1-9]\d*\n\z/.

9.7.2. Solutions 57, Ton Hospel -l @0=sort!++$_+@0,grep--$_,@0until$s{*0=ARGV,@0}++;print 60, Mateusz Matuszek -l @0=@ARGV;@0=sort@0+!++$_,grep--$_,@0until$Z{"@0"}++;print 61, Przemysław Kowalczyk -l @1=@ARGV;$_++,@1=sort@1+0,grep--$_,@1until$h{"@1"}++;print 63, Michal Szafranski -l *1=ARGV;++$_,@1=sort@1*1,map$_-1||@2,@1until$1{"@1"}++;print 67, Tomek Machalski -l @1=@ARGV;$_.="@1,",@1=sort@1+0,grep--$_,@1until/@1,/;print y/,// 68, Maciej Misiak -l @a=@ARGV;$_.="@a#",@a=sort grep--$_,@a,@a+1while!/@a/;print y/#// 84, Maciej Jastrzębski

Edition 2007-01-09 top secret / strictly confidential page 438 of 520 Perlgolf History

-l @a=@ARGV;${s//P@a/;my@r;push@r,--$_||()for@a;@a=sort@r,@a+0}until/@a/;print y/P//

9.8. PCLP #2.8 PANORAMA Master: Mateusz Matuszek (magus) 23.06.2004 02.07.2004

9.8.1. Rules Introduction Draw a panorama of mountains using the photo from the air. The panorama shall be done from the south. Input STDIN contains the photo of the mountains: /([ 1-9]{10}\n){10}\z/ Digits shall be recognized as the mountain high. The mountains are flat so the mountain: ...... 5...... {a dot is used instead of a space char} is really: ...... 555555555...... Each slope is 45 degree. The mountains have not common space so there will be no such case: ...... 5..4...... An example of input: STDIN:

Edition 2007-01-09 top secret / strictly confidential page 439 of 520 Perlgolf History

...... 1...... 7...... 2...3...... 5...... 2....1 ...... Output A draw of a panorama shall contain filled contour of mountains. STDOUT shall contain a panorama using the following format: /([ 1-9]{10}\n){K}/ (K - the high of the highest mountain) Output for the example: ...... 7...... 777. ..5..77777 .555777777 5555537777 5555253777 5552225371

9.8.2. Solutions 73, Ton Hospel -p0aF| s!.!($",grep$_-abs$q/110%10-$q%11>10-++$q/1100,@F)[-1]!eg;s/\D+ // 79, Robert Szczygiel -p0 s|.|$c=$";s!!abs$i++%10-$a%10<$&-9.9+$a/10?$c=$&:$&!ge;$a++;$c|ge;s/\D+\n// 96, Mateusz Matuszek -ln0 $q=@0=($")x10;s/ (?=([$q-9]))|(?<=([$q-9])) |([$q-9])/$0[$-[- 1]%11]=$+/eg&&print@0while--$q 97, Michal Szafranski -nl s/./$a=$b=9+pos;@$_[$a--..$b++]=($&)x20for-$&..-1/ge}{@$_&&print map$_||$",@$_[9..18]for-9..0 101, Przemysław Kowalczyk -lp s/./substr$o[9-$&+$_]|=$"x30,11+$-[0]-$_,$_*=2,$&x--$_ for 1..$&/ge}for(grep$_=(/.{10}/g)[1],@o){ 103, Tomek Machalski -n s^.^$a=$b=pos;$b+=$b<10,substr($W[$_]|=($"x10).$/,$a,$c=$b-$a,$&x$c),$a- =$a>0for-$&+9..8^ge}{print@W 114, Maciej Jastrzębski -ln0 @r=($"x30)x9;s/./substr$r[8-$&+$_],@-[0]%11-$_+9,$l,$&x($l=$_*2-1)for 1..$&/eg;/\d/&&print substr$_,8,10for@r 122, Stephen Gordon

Edition 2007-01-09 top secret / strictly confidential page 440 of 520 Perlgolf History

-pl push@|,split/&*/}@&=(' 'x10)x10;for$;(@|){map{s!(.)!abs$-[0]-$//10%10<$;- (9-$/)%10?$;:$1!eg;$/++}@&}for(grep{/\d/}@&){ 130, Wawrzyniec Żurowski -nl s/./for$y(0..9){($_+=$+[0])>=0?$b[9-$y][$_]=$&:0for$y-$&..$&-$y- 2}/ge}{for$K(@b){$_=join'',map$K->[$_]|" ",0..9;/^ *$/||print} 155, Maciej Misiak -0apF\n y/0-9/ /,$_.=" "for@F;s/\d/$c=length($`)%11;$l=0;map{for$j($c- $l..$c+$l++){substr($_,$j,1)=$&if($j>=0&&$j<10)}}@F[9- $&..8]/eg;$_=join"",grep/\d/,@F 188, Marcin Bieńkowski -l for(0..8){@{$A[$_]}=(' ')x10}while(@L=<>=~/./g){for$i(0..9){$r=8- $L[$i];$l=0;while(++$r<9){for$k($i- $l..$i+$l){$A[$r][$k]=$L[$i]if($k<=9&&$k>=0)}$l++}}}map{$_=join'',@$_;print if/\d/}@A

9.9. PCLP #2.9 KOŚCI Master: Robert Szczygiel (RobTM) 08.07.2004 16.07.2004

9.9.1. Rules Introduction The task is to count the score of a single turn in the dice game "Thousand". The original rules are more convoluted, so I had to simplify them a bit. Scoring rules Each time we roll 1 - 5 dice (rolling rules are described in section 3). For each rolling the score is counted as follows: • A one has a score value of 10, all the other dice have a score value equal to the number of spots. Only sets, one's and five's are included into score. • A set is created of three or more of dice with the same number of spots. E.g. a result 3, 3, 4, 3, 3 includes a set of four three's. • A score value of a set is calculated as follows: $c = a score value of a single die; $d = a number of repetitions of a die; $score = (10 * $c) * (2 ** ($d - 3)); • Adding one's and five's not included into sets (remember that one stands for 10 points). • The result of rolling sums up. Example: 2,5,5,1,5 => 60 3,4,6,2,2 => 0 3,2,5,3,3 => 35 Rolling rules • First time we roll 5 dice;

Edition 2007-01-09 top secret / strictly confidential page 441 of 520 Perlgolf History

• Next time we roll the dice which were not included into scoring before. E.g. after 2, 5, 5, 1, 5, we will roll a single die (2 was not included into scoring). • If all the dice were used for scoring - next time we roll 5 dice again. • We stop when the score for current rolling is 0; Example: 1 rolling: 3,4,4,5,4, => score: 45 sum: 45 2 rolling: 5, => score: 5 sum: 50 3 rolling: 2,3,4,5,6, => score: 5 sum: 55 4 rolling: 4,3,3,2 => score: 0 sum: 55 Input The program will receive on STDIN the values of the dice /^[1-6]{5,20}\n\z/ E.g. for the above-mentioned example: "344545234564332\n" Output The program should print to STDOUT the sum of the points for the given turn /^\d+\n\z/. E.g. for the above-mentioned example: "55\n"

9.9.2. Solutions 93, Michal Szafranski -lp $_=5*eval'+($_^=$"x(s/\D//g||5),/(\pC).*\1.?\1/&&(ord$1)%9+2<2?5<<$a-2:$_%5?$x[$i- =$a]:$a),10,2..6for/./g;$_=$ 104, Przemysław Kowalczyk -l @e=map"+(2>1).0:/1|5/||!++$n)*$_.0 x/1/,($k=$&)=~/./guntil$m=$n=!/.{$n}|.{5}/g;$_=$

120, Marcin Nowak -lp for(;($*or$*=5),/.{$*}/;$_=$'){$_=$&;$;+=($1>1?$1:10)*1<2?2**$z/0.8*g:$_%5?0:$z*g,2..10;@a=$k= $n||=5}s/1/10/;$a[$_]++;$k--}@F;$_=$r 138, Tomek Machalski

Edition 2007-01-09 top secret / strictly confidential page 442 of 520 Perlgolf History

-pl s^.^$i=$j=5if!$j;$L[$&<2?10:$&]++;(map{$s+=$w=($c=$L[$_])>2?10*$_*2**($c- 3):$_*$c*/1|5/;$j-=$c*!!$w}1..10),$i=$j,@L=()if!--$i^ge;$_=$s 152, Stephen Gordon -alpF"" $x=5;while(@F){@l=(0)x6;for(1..$x){$l[- 1+shift@F]++}map{$m=$b++%6+1;$c+=($m-1?$m:10)*($a=$_>2?10/8*2**$_:5% $m?0:$_);$x-=$_ if$a}@l;$x||=5}$_=$c 154, Cédric Barboiron -p sub c{$n=5if!$n;s/\d{$n}/$d=$&;$n=$r=0;($a=$d=~s!$_!s:1$:10:!eg)>2?$r+=10*$_*2** ($a-3):m!1|5!?$r+=$_*$a:($n+=$a)for(1..6)/e;$s+=$r;c()if$r>0}c;$_=$s.$/ 171, Tomasz Trojanowski $x=5;split//,<>;while(map{@c[$_]++}splice@_,0,$x){$i=1;$n=10;map{$r+=$q=$_>2?10 *$n*2**($_-3):$_*($i=~/1|5/?$n:0);$x=($x-!!$q*$_- 1)%5+1;$n=++$i;}@c[1..6];@c=0;}print"$r\n";

9.10. PCLP #2.10 - AKORDY Master: Maciej Misiak (grizzley) 22.07.2004 30.07.2004

9.10.1. Rules Your job is to identify a chord on basis of tones it is made from. Used tones: ...a ais b c cis d dis e f fis g gis a ais b c cis d dis e f fis g gis a ais b ... (1) Description The basic set of tones is scale and it includes 8 tones, i.e. scale C-Dur - c d e f g a b c Scale is cyclic, so after 7 basic tones you get the first once more which at the same time starts new scale. Beside 7 basic tones (c d e f g a b) there are 5 tones extra: cis, dis, fis, gis, ais. By the way: in Poland instead of 'b' we use name 'h', and 'b' is 'h' lowered by halftone, but to make problem easier we use British notation with 'b' instead of 'h' Major chord is created in such way, that you take any tone, a tone 4 halftones away (4 halftones are interval of major third) and third tone 3 halftones away from second tone (minor third interval) E -> e - 4 halftones (major third=3w) - gis - 3 halftones (minor third=3m) - b Minor chord is built by minor third and major third e -> e - (3m) - g - (3w) - b Augmented chord is built by two major thirds Ezw -> e - (3w) - gis - (3w) - c Diminished chord is built by two minor thirds ezm -> e - (3m) - g - (3m) - ais By the way: a tone can have more than one name. Rising a tone by halftone causes adding to its name ending 'is'. Lowering by halftone causes adding to name ending 'es'. So fis=ges, ais=bes. In music

Edition 2007-01-09 top secret / strictly confidential page 443 of 520 Perlgolf History

theory chord is built on basic tones, i.e. e-g-b and, if needed, notes/tones are raised/lowered, so Ezw -> e - (3w) - gis - (3w) - bis. But in the problem we will only use names from line (1). Additionally because tones appear cyclically, minor and major chords can be in inversions. If we move first tone of the chord to the end - we get first inversion, if we move second tone to the end - we get second inversion, and if we move third tone to the end we get back to root position: • c - e - g C-major, root position • e - g - c C-major, first inversion • g - c - e C-major, second inversion • c - dis - g c-minor, root position • dis - g - c c-minor, first inversion • g - c - dis c-minor, second inversion NOTE: in our problem augmented and diminished chords are only in root position. Input data On STDIN there are three note names and a newline character. Note name meets /^[a-g](is)?\z/. Result Result is a chord name /^[a-gA-G](is)?(zm|zw)?\n\z/: • major chord - first letter big, the rest is small: Cis - Cis-major • minor chord - all letters small: g - g-minor • augmented chord - first letter big, the rest small and 'zw' at the end: Aiszw - Ais augmented • diminished chord - all letters small, 'zm' at the end: bzm - b diminished

9.10.2. Solutions 94, Michal Szafranski -lpa s/\S+ ?/(-$%+($%=1.6*($&^PGF)))%12x$|++/ge;$_=$F[/5/+/5$/].zw x/44/.zm x/33/^$"x44354=~uc 126, Marcin Nowak -pal $i|=$k++%3*!(-y/a-g/0235789/+($_=(- $p+($p=$_+y/9i//))%4))for@r=(@F,@F);$_=$F[$i].(zw,$X,zm)[$r[$i+3]];$r[$i+1]| |s/./\u$&/ 128, Robert Szczygiel -apl $"='(.{2,5}?i?s?)';@F=@F[2,0,1]until($j)=map$i+=1&y/a- g//,('aaisbccisddiseffisggis'x2)=~/@F/;$_=' 'x$j^$F[0].(zm,$m,zw)[$i] 167, Maciej Misiak -lap @d=map/i/-/[c-g]/-/f|g/+2*ord,@F; $x-=($d[$_+1]-$d[$_])%12>4for 0,0,1; $_=$F[$x].(($s=($d[2+$x]-$d[$x])%12)==8?'zw':'zm'x($s==6)); ($d[1+$x]-$d[$x])%3&&s/./uc$&/e 176, Stephen Gordon

Edition 2007-01-09 top secret / strictly confidential page 444 of 520 Perlgolf History

-alp y/a-g/1346235/;s!(.)is!$1+1!eg;s/(.) (.) (.)/$m=(($2-$1)%6).($3- $2)%6/e;for(3543,4534){if(/$m/){$l=2-$-[0];$m=$_}}$_=$F[$l].$m;$_=ucfirst if/4.$/;s/33/zm/;s/44/zw/;s/\d//g 176, Przemysław Kowalczyk -nal $$_++for@F;map{print eval$N.qw(zm , ^$" zw^$")[$_]if${$N=(@N=grep!/ei|bi/,map{$_,$_.is}(a..g)x2)[$^F]}*${$N[$^F+3+$_/2] }*${$N[$^F+6.5+$_/2]}*($_-3|$F[0]eq$N)}0..3while$^F++<14 177, Wawrzyniec Żurowski -lpa %a=map{$_,2*($a=-96+ord$_)+/i/- int$a/3}@F;for$t(@F){$_=join"",map{($b=$a{$_}-$a{$;=$t})>0?$b:$b+12}@F;last if/4/&&($;="\u$;")&&(/7/||/8/&&($;.=zw))||/7/||/6/&&($;.=zm)}$_=$

9.11. PCLP #2.11 – OPERATORY “INTERCAL OPERATORS” Master: Przemysław Kowalczyk (szeryf) 25.08.2004 31.08.2004

9.11.1. Rules The task The task is to evaluate an arithmetic expression, containing INTERCAL language operators. The expression consists of following terms: Term Type Description Value constant unary an integer constant in range value of expression of [0, 65535], matching that constant /^[1-9]\d{,4}\z/ '(' expression unary any parenthesized expression value of the ')' expression expression in parens '&' unary unary '&' (AND) operator, applied see unary expression expression to this expression operators

'V' unary unary 'V' (OR) operator, applied see unary expression expression to this expression operators

'?' unary unary '?' (XOR) operator, applied see unary expression expression to this expression operators

M-expression M- '~' (SELECT) operator applied see binary '~' unary expression to values of left and right operators expression expressions

expression '$' expression '$' (MINGLE) operator applied see binary M-expression to values of left and right operators expressions Unary operators have equal priority and are evaluated from right to left. Thus the expression ?V&VV1234 is evaluated as ?(V(&(V(V1234)))). Binary operators have lower priority than unary ones and $ operator has lower priority than ~. These are evaluated from right to left, unless parens indicate otherwise. Thus the expression 1$2$3~4~5 is evaluated as (1$2)$((3~4)~5). Grammar

Edition 2007-01-09 top secret / strictly confidential page 445 of 520 Perlgolf History

If you have background in computer science, you may find the following grammar table useful. Mere mortals may skip to the example in the next section. E → M | E '$' M M → U | M '~' U U → '&' U | 'V' U | '?' U | '(' E ')' | interger Example Here is an example of how is ?(51818$29686~V2256) expression evaluated step by step. Expression Evaluated subexpression Result of subexpression ?(51818$29686~V2256) V2256 3320 ?(51818$29686~3320) 29686 ~ 3320 30 ?(51818$30) 51818 $ 30 2693278172 ?(2693278172) (2693278172) 2693278172 ?2693278172 ?2693278172 4039916850 Operators All operators treat their operands as 32-bit unsigned integers and return 32-bit unsigned integers. One exception to this rule is $ (MINGLE) operator, which only uses lower 16 bits of its operands (but returns 32 bits). Unary operators Unary operators perform bitwise AND (&), OR (V) and XOR (?) on all pairs of adjacent bits, the result from the first and last bits going into the first bit of the result. The effect is that of rotating the operand one place to the right and ANDing, ORing, or XORing with its initial value. Some examples: 0000 0000 0000 0000 0000 0000 0100 1101 (original value) 1000 0000 0000 0000 0000 0000 0010 0110 (after rotation) ------&77 = 0000 0000 0000 0000 0000 0000 0000 0100 = 4

0000 0000 0000 0000 0000 0000 0100 1101 (original value) 1000 0000 0000 0000 0000 0000 0010 0110 (after rotation) ------V77 = 1000 0000 0000 0000 0000 0000 0110 1111 = 2147483759

0000 0000 0000 0000 0000 0000 0100 1101 (original value) 1000 0000 0000 0000 0000 0000 0010 0110 (after rotation) ------?77 = 1000 0000 0000 0000 0000 0000 0110 1011 = 2147483755 Binary operators The binary operators are MINGLE ($) and SELECT (~). The MINGLE operator takes two 16-bit values and produces a 32-bit result by alternating the bits of the operands. E.g.

Edition 2007-01-09 top secret / strictly confidential page 446 of 520 Perlgolf History

1111111111111111 0000000000000000 ------65535$0=10101010101010101010101010101010 = 2863311530

0000000000000000 1111111111111111 ------0 $ 65535 = 01010101010101010101010101010101 = 1431655765 The select operator takes from the first operand whichever bits correspond to 1's in the second operand, and packs these bits to the right in the result. All other bits are set to 0. E.g. 1011 0011 (leading zeroes skipped) 1100 1001 (leading zeroes skipped) ------179~201=10 0 1=9

1100 1001 1011 0011 ------201~179=100 01=17

1011 0011 1011 0011 ------179~179=111 11=31

1100 1001 1100 1001 ------201~201=11 1 1=15 Further reading The syntax of arithmetic expressions in INTERCAL is as bizarre as the operators themselves, so in this contest we only borrow operators from INTERCAL and use a traditional syntax. The original INTERCAL Reference Manual may be found at http://www.muppetlabs.com/~breadbox/intercal-man/ and it is probably the most funny programming document ever written (operators and arithmetic syntax are covered in section 3.4). Input The expression to be evaluated is provided on STDIN. The expression will follow syntax described above. Input will not be empty, will only consist of above mentioned characters and will be no longer than 120 characters. Thus, input matches /^[0-9$~&V?()]{1,120}\z/. Output Your program should output the result of expression evaluation, followed by a newline character. Thus, output matches /^\d{1,10}\n\z/.

9.11.2. Solutions 172, Michal Szafranski -lp y/V?/|^/;``while$x='(\d+\b)',s/\($x\)/$1/||s![&|^]$x!($1/2|$1%2<<31).$&!ee|| s^$x~$x|$x.$x(?!~)^"+(@{[A&$3?'(${4-$x%2}>>$x/2':'$2&1<<$!++&&($1>>$!- 1']}&1)<<\$x++)"x32^ee 196, Przemysław Kowalczyk

Edition 2007-01-09 top secret / strictly confidential page 447 of 520 Perlgolf History

-pl sub R{$r|=(pop>>$_)%2<<$?++}sub P{$r='(\d+)';s/\(([^()]+)\)/$_=$1;&P/e|s@[|^&]$r@($1%2<<31|$1/2).$&@ee||s/$r ~$r/$2&2**$_&&R$1for``..31;0+$r/e||s/$r\$$r/map{R$2;R$1}``..15;$r/e?&P:$_}y/ ?V/^|/;P 218, Mateusz Matuszek -pl y/?V/^|/;sub r{$c=0while s/\(([^(]*?)\)/r($_=$1);$_/e|s/([&^|])$q/"$2$1($2>>1|($2&1)<<31)"/ee||s^$q~$ q^map{$c+=$c+!!($1&$z)if$z=$2&1<<-$_}-31..0;$c^e||s^$q\$$q^map$c|=${1+-- $|}&1<<$_/2&&1<<$_,0..31;$c^e}r$q='(\d+)' 226, Maciej Misiak -lp y/V?$/|^,/;s#(^|\()[^()]*(\)|$)#$_=$&;$x=$w=0while s/[&|^](\d+)/(($1&1)<<31)+($1>>1).$&/ee||s@(\d+)(?(?=(.*?~))~|,)(\d+)@map{$s =$3&2**$_;$f=$1&2**$_;$w+='~'eq$2?$s&&$f>>$_- $x++:$_<16&&$f*2+$s<<$_}0..31;$w@ee;$_#eewhile/\D/ 233, Roy Johnson -pl y/V?/|^/;sub P{map{$s=$y=0while s#\(([^()]+)\)#P($1)#e||s#([&|^])(\d+)#"$2$1($2/2|$2<<31)"#ee||s#\d+~(\d+)#m ap{$s|=($&>>$_)%2<<$y++if$1&1<<$_}0..31;$s#e||s#\d+\$(\d+)#map$s+=(($&&1<<$_ )*2|$1&1<<$_)<<$_,0..15;$s#e}$X=pop;$X}$_=P$_ 242, Peter Haworth -lp y/V?/|^/;s#(?(?=.*\()\(([^()]+)\)|(.*))#local$_=$+;$n=0while$m=1,s:[&|^](\d+ ):($1/2|$1%2<<31).$&:ee||s/(\d+)~(\d+)/$2&($b=2**$_)and$n+=$1&$b&&$m,$m*=2fo r 0..31;$n/e||s/(\d+)\$(\d+)/$n+=($2&$m|2*($1&$m))*$m,$m*=2for a..p;$n/e;$_#ewhile/\D/ 269, Wawrzyniec Żurowski -pl sub b{split"",unpack"B*",pack N,pop}sub d{oct"0b@_"}sub f{$_=pop;1while s/([&^|])(\d+)/@b=b$2;"$2$1".d pop@b,@b/ee||s/(\d+)~(\d+)/d map{(b$2)[$_]?(b$1)[$_]:''}0..31/e||s/(\d+)\$(\d+)/d map{(b$1)[$_],(b$2)[$_]}16..31/e;$_}$"='';y/V?/|^/;s/\(([^()]+)\)/f$1/e?redo :f$_

Edition 2007-01-09 top secret / strictly confidential page 448 of 520 Perlgolf History

10. Games – Kernelpanic season 3 10.1. PCLP #3.1 OBRAZKI LOGICZNE “GRIDDLERS” Master: Maciej Misiak (grizzley) 21.09.2004 29.09.2004

10.1.1. Rules The task Create numerical description of given griddler. Griddler is a rectangular grid. Every field of grid can be empty or filled. More description you can find here http://www.puzzlemuseum.com/griddler/griddler.htm . One describes griddler by describing its every row and every column separately in such way, that one counts lengths of filled blocks. E.g. (filled field is marked with hash '#', empty with space) row '### ## ##### #' is described as 3 2 5 1 (amount of spaces between blocks doesn't count). For hypothetical input (characters '-' and '|' are only to show lines' limits and don't appear in tests): |||||| -### # - - ### - - ### - |||||| you should achieve following result: |||||||| -1- - 12321 - -31### # - - 3 ### - - 3 ### - |||||||| Input Griddler of 1-16 rows x 1-16 columns filled with combination of '#' and ' ' is provided on STDIN. Thus, input matches /^([ #]{1,16}\n){1,16}\z/. Output Program should output the griddler with its numerical description to the STDOUT, followed by a newline character. As in example, if a row/column is empty (there are no '#' characters) you leave it filled with spaces. Result should be aligned to the right and to the bottom (fill empty place with spaces). No block of hashes is longer than 9, so to describe row/column you will need only ciphers.

10.1.2. Solutions 112, dmitry kim sub f{$l=my@t;$t=($"x(9-map{$t.=y/#//}/#+/g).$t.$_)!~s/./@t[@- ].=$&/egfor@_;grep{$_|++$l>9}@t}print f(f<>),$,=$/ 112, Robert Szczygiel -lp0 s!^!9e9+join$a,map y/#//,/\G *#+/g!gme,/ /,($_.=$/x"@-")x="@-",s/(.).{@-}/$1/gs,s/^9*0* //gm,y/0/ /for$_,$_ 132, Maciej Misiak

Edition 2007-01-09 top secret / strictly confidential page 449 of 520 Perlgolf History

-l sub h{@k=@q=$"=$u;s/./$k[my$i++].=$&/egfor@_;$q[()=/#+/g]++for@k;map' 'x($#q-(@m=map length,/#+/g))."@m$_",@k}print for(h h<>),'' 143, Marcin Nowak -lp0 for$m(8..9){$q="";s!\G.!$r=$c="";s/^./$r.=$&;""/gem;$;=8;$;-- ,$c.=y/#//for$r=~/#+/g;$m=$;if$;<$m;$q.=$"x$;."$c$r\n"!eg;$_=$q;s/^ {$m}//gm}

10.2. PCLP #3.2 Kwadraty II “SQUARES II” Master: Robert Szczygiel (RobTM) 13.10.2004 18.10.2004

10.2.1. Rules Introduction The task is to count the number squares drawn in the field. The squares are drawn with the '#' signs in the 9 x 9 field filled with '-' signs. The square means the edges here, we don't care what is inside. A single '#' is not a square. The squares may partially overlap. Input On STDIN we get: /([\-#]{9}\n){9}\n/ Example: ------####---- -######-- -##-#-#-- -####-#-- --#---#-- --#####------In the example there are 5 squares of the edge length equal 2, and three of the edge length 3, 4, and 5, respectively. So the program should write 8 to the STDOUT. Output The program should write to the output the number of square + end of line character (/^\d+\n\z/).

10.2.2. Solutions 66, Michal Szafranski -lap0 $_=map"@F"=~/(?=((?=.$_)#.{9})$_$_)(?=#$_)/g,map"{$_}#",1..8 75, Terje Kristensen -lp0a $_=map{$i=8-lc;"@F"=~/(?=(##{$_}#).{$i}(?:#.{$_}#.{$i}){$_}\1)/g}0..7 76, Przemysław Kowalczyk -lap0 $_=map{$k='.'x(8-$_);"@F"=~/(?=###{$_}($k#.{$_}#){$_}$k###{$_})/g}0..8 79, Robert Szczygiel -lp0 $s='.'x(8-$^H),$k+=s/#(?=(##{$^H})$s(#.{$^H}#$s){$^H}#\1)/$&/gswhile$^H-- ;$_=$k 81, Leonid Kalmankin

Edition 2007-01-09 top secret / strictly confidential page 450 of 520 Perlgolf History

-lp0 $_=($F=$_,map{$z=8- $_;$F=~/(?=(###{$_}).{$z}(#.{$_}#.{$z}){$_}\1)/gs}0..7)/2 91, Wawrzyniec Żurowski -lp0 {for$j(2..9){$b=8-($c=$j- 2);$;+=/^(#{$j}).{$b}(#.{$c}#.{$b}){$c}\1/s}s/.//s&&redo}$_=$ 94, Maciej Misiak -lp0 for$r(2..9){$d=10-$r;$e=$r- 2;$a+=s/(^|.)(?=#{$r}.{$d}(#.{$e}#.{$d}){$e}#{$r})/$1/gs}$_=$a

10.3. PCLP #3.3 - Base64 Master: Wawrzyniec Żurowski (Vava) 25.11.2004 02.12.2004

10.3.1. Rules The object of this contest is to translate string using Base64 algorithm Input The standard input contains a string followed by newline character: For better portability, input string will not contain chars chr(10), chr(13) and chr(26). Length of input string is limited to 57 chars (for compliance with MIME::Base64) /\A[^\x0A\x0D\x1A]{0,57}\n\z/ Output Your program should print base64 encoded string, followed by newline character: /\A[a-zA-Z0- 9+\/]*={0,2}\n\z/ Base64 algorithm 1. We take three chars from beginning of given string 2. We convert those chars to binary representation. We achieve 24 bits. 3. Obtain bits string divide for four, six bits parts 4. Conquering strings must be completed to 8bist by adding '0' on beginning. 5. Obtained strings convert to chars using table shown below In case, we don't have three chars on input, we add '=' chars on the end of output string. E.g. if we have only one char, then output will be followed by two '=' chars. In case, when we have only two chars on input - we add on '=' char on the end of output string. 0A 8I 16Q 24Y 32g 40o 48w 564 1B 9J 17R 25Z 33h 41p 49x 575 2C 10K 18S 26a 34i 42q 50y 586 3D 11L 19T 27b 35j 43r 51z 597 4E 12M 20U 28c 36k 44s 520 608 5F 13N 21V 29d 37l 45t 531 619 6G 14O 22W 30e 38m 46u 542 62+ 7H 15P 23X 31f 39n 47v 553 63/ Example: Let's encode string ANUBIS using Base64 algorithm

Edition 2007-01-09 top secret / strictly confidential page 451 of 520 Perlgolf History

A - 01000001 N - 01001110 U - 01010101 When concatenated, we achieve: 010000010100111001010101 Divide for 4 6-bits strings: 010000 010100 111001 010101 Complete to 8bits: 00010000 00010100 00111001 00010101 In decimal notation this will be: 00010000 - 16 00010100 - 20 00111001 - 57 00010101 - 21 Finding values in table and write down: QU5V Doing the same with the rest chars (BIS).

10.3.2. Solutions 62 (post-mortem) -lp $_=z|pack(u99,$_)&pack u99,"$_\1\1";y# -`\0-\377#=B-Za-z0-9+/A#d 62 (post-mortem) -p $_=pack u99,$_.;s/^.|.{4}(`*)$/~$1/ge;y^\n^"-Za-z0-9+/A=^c 63, Ton Hospel -p $_=pack u,$_.xs;s/^.| .|.{4}(`*)$/~$1/ge;y^ ^"-Za-z0-9+/A=^c 64, Michal Szafranski -lp $_='\377'.'\200'x(y///c/.75+.7)|pack u99,$_;y!`\235-\377 !=-Za-z0-9+/A!d 70, Przemysław Kowalczyk -p $_=pack u99,$_;s/.//;y| |"-Za-z0-9+/A|c;s/K$/=/;s/oA$/==/;s/CgAA$// 76, Mateusz Matuszek -lp $_=unpack"B*",$_;s/.{1,6}/pack B8,bb.$&/eg;$_.="="x(-y!!A-Za-z0-9+/!c%4) 103, Tomek Machalski -pl s/..?.?/unpack B32,$&/ge;$_.='='x(3-(s|.{1,6}|(A..Z,a..z,0..9,'+','/')[ord pack B8,"00$&"]|ge-1)%4)

10.4. PCLP #3.4 Labirynt “The Maze” Master: Mateusz Matuszek (magus) 13.12.2004 27.12.2004

Edition 2007-01-09 top secret / strictly confidential page 452 of 520 Perlgolf History

10.4.1. Rules The task is to find the shortest way inside the maze between the points A & B, and to raw it. Introduction This is very old and well known problem: You get the maze with two points set inside it - your task is to draw the shortest path between them. In the output the program should draw a given maze with the path drawed by 'x' chars. If there is more than one possible (but still the shortest) path - you should draw any of them. And if there is no way between the given points the program should return "NO WAY\n" string. The maze is alwas closed - surrounded by # chars. There are always two points - A & B. All rows of the maze are the same length - area outside the maze are ' '. Input and output You get the maze from the STDIN: /^([ .#AB]{3,99}\n){3,30}\z/ The program should return the solution to the STDOUT in the format: /^((([ .#ABx]{3,99}\n){3,30})|(NO WAY\n))\z$/ Examples STDIN: #################### #.#..#.#..####.....# #.#....#...... #.#.## #.#.#..######.#.#..# #...#..#...... ###.## #.####.#..###...#..# #.#..#...B....#.#..# #.##...#..#####.#..# #A#..###...... #....# #################### STDOUT: #################### #.#..#.#..####.....# #.#xxxx#...... #.#.## #.#x#.x######.#.#..# #xxx#.x#...... ###.## #x####x#..###...#..# #x#..#xxxB....#.#..# #x##...#..#####.#..# #A#..###...... #....# #################### STDIN: ##### #A#B# ##### STDOUT:

Edition 2007-01-09 top secret / strictly confidential page 453 of 520 Perlgolf History

NO WAY

10.4.2. Solutions 122, Michal Szafranski -p0aFF / /;$x="@-";s:([A.]):$A[pos]++or$$1=$_,push@F,"$`x$'"if map/^(.{$x})?[Bx]/s,$',~~reverse$`:gefor@F;$_=$A||'NO WAY ' 128, Mateusz Matuszek -n0aF| @$B=@F,s![.AB0]!${$&}=$x=pos;$$x[$x]=~y/./x/if map@$x||(@$x=@{$x+$_}),- 1,/ /,@+,-"@+"!egfor($_)x@F;print@$A?@$A:"NO WAY " 156, Robert Szczygiel -p0 1while/ /,$k="((?<=[Bz].{@-})|(?<=[Bz]))[Ax]|[Ax](?=(.{@- })?[Bz])",$i=!/$k/sand$k=~y/x/./,s/$k/z/gs or$k=~y/BAzx/ACxz/,s/$k/x/s*y/z/./;$_="NO WAY\n"if$i 156, Przemysław Kowalczyk -p0 /A/;@q=@-;for$v(@q){for$i(map{$v+lc,$v-lc}@+,/ /){/^.{$i}#/s+@$i or@$i=$v,push@q,$i}}@{$b=$-[!/B/]}or$_='NO WAY ';$_^=$/x$b.V while@$b*$q[0]-($b=$$b[0]) 275, Maciej Misiak -n0 @n=@m=/./gs;/A/;@t=@-;/ /;$l=$+[0];$c=121;A:while($p=shift@t){for(@h=(1,-1,$l,- $l)){$e=$p+$_;$m[$e]=chr$c,push@t,$e if$m[$e]eq'.';$f=$p=$e,last A if$m[$e]eq B}$c++,$i=@t-1 if!$i--}if($f){while($c-- >121){$p+=($c==ord$m[$p+$_])*$_ for@h;$n[$p]=x}print@n}print"NO WAY "if!$f 311, Stephen Gordon -anF// push@c,@F;$l=@F}for(@c){last if'A'eq$_;$a++}f($a);while(1){for(keys%p){f(split/;/,$p{$_})}if(!$z-- ){print"NO WAY\n";exit}}sub f{$s=pop;for($s-$l,$s- 1,$s+$l,$s+1){if($c[$_]eq'.'&&(!$q{$_}||$q{$_}>@_)){$p{$_}="$p{$s};$_";$q{$_ }++;$z=1}if('B'eq$c[$_]){grep{$_ and $c[$_]='x'}split/;/,$p{$s};print@c;exit}}}{ 365, Wawrzyniec Żurowski -p0 /(.*)A/;$X=length$1;/(.*)A/s;$A=$1;push@s,"$X,".$A=~s/\n//g;X:while(@s){@S=@ s;@s=();for$U(@S){$U=~/(\d+),(\d+)$/;@K=map{($1+$_).",$2","$1,".($2+$_)}- 1,1;for$g(@K){$g=~/(.+),(.+)/;/(.*\n){$2}.{$1}(.)/;$2=~/B/&&($M=$U,last X);push@G,$g,push@s,"$U#$g"if$2 eq'.'&&!grep/^$g$/,@G}}}for$h($M=~/#([^#]*)/g){$h=~/(.*),(.*)/;s/((.*?\n){$2 }.{$1})./$1x/}$M||($_="NO WAY ")

Edition 2007-01-09 top secret / strictly confidential page 454 of 520 Perlgolf History

10.5. PCLP #3.5 Zegarek LED Master: Michal Szafranski (stalker) 31.12.2004 07.01.2005

10.5.1. Rules

Edition 2007-01-09 top secret / strictly confidential page 455 of 520 Perlgolf History

10.5.2. Solutions 107, Robert Szczygiel -pl $h=sprintf"%02d:%02d",$i/60,$i++%60;$_=/$h/?$-:$_<(map$-+=y/0- 9/6255456376/*$_,$h=~/./g)[4+/:/]?$h:redo 107, Mateusz Matuszek -lp ($0=$n=5e4+$T++)=~s/5(..)/$1:/until/$0/||$'<60&&!/:/*$n=~s/./$^P+=vec'\025DC %V',$&,4/eg&&$_<$^P;$_=/:/?$^P:$0 108, Przemysław Kowalczyk -pl @c=map{map{y/0-9/6255456376/;($s)x$_}split'',$s=substr gmtime$_,14,5}0..2e3;$_=/:/?$-["@c"!~uc]/6:$c[uc] 108, Michal Szafranski -p $a=s/://?_:v37;$i=$_}{$$a>$i||s/[0-5].$/:$&/&&($\="${$a^z} ",y/0-3789/6255376/,s/./$%+=$&/eg)for$-x4..3x4 155, Maciej Misiak -ln sub e{print@_;exit}for$a(0..2){for$b(0..9){for$c(0..5){for$d(0..9){e$s+0 if/$a$b:$c$d/;map{$s+=vec"&UT6g",$_,4}$a,$b,$c,$d;e"$a$b:$c$d"if!/:/&$s>$_}} }} 162, Tomek Machalski -lp sub q{$c=sprintf"%02d:%02d",$g,$m;$c=~s/\d/$i+=930794326>>$&*3&7;$&/ge;$m=0,$g++ if++$m==60}$i=0;$t=$_;if(/:/){$_=$i,&q while$c ne$t}else{&q while$i<=$t;$_=$c}

10.6. PCLP #3.6 Dekompresja “DECOMPRESSION” Master: Przemysław Kowalczyk (szeryf) 13.01.2005 20.01.2005

10.6.1. Rules The task Your task is to decode a message that has been compressed using Huffman's algorithm. The input data consists of:

Edition 2007-01-09 top secret / strictly confidential page 456 of 520 Perlgolf History

1. a binary tree that defines character codes, 2. a message encoded using these codes. Huffman codes tree Please don't be scared, you don't have to know anything about compression algorithms to solve this task. All the necessary information about Huffman codes tree that will be useful, I will present below. If you are interested in the theory, you could read http://pl.wikipedia.org/wiki/Kod_Huffmana (in Polish) or http://www.arturocampos.com/cp_ch3-1.html (in English, there is also an example of building the tree). However, the knowledge of how the tree is constructed and why, is not essential. The most important property of Huffman codes tree is that it is full. This means that every node in the tree has two child nodes or it has no children at all (it is called a leaf in latter case). The leaves store additional information – character code. Here's an example tree: * /\ /\ ** /\ /\ k*sa /\ rb This property can be used to easily encode the tree as a string of zeroes and ones. Each node with two children (denoted by * in out example) is encoded as 0. Each leaf is encoded as 1 (see Input data for details). The tree is encoded in infix order, that is: 1. node definition, 2. left subtree, if not empty, 3. right subtree, if not empty. The code tree always contains at least two characters. Each character appears only once. The way in which the tree is encoded determines where it ends. No stop code of any kind is needed. We omit the first 0 (which would be the root of our tree), because we know that the tree is not empty. Our example would be encoded as: 001011011. Reading Huffman codes Having built the tree, we can assign a Huffman code to each character. Let's mark each branch in the tree with 0 if it goes left (from the parent node's point of view) or with 1 if it goes right. The Huffman code for each character is the path from root of the tree to the character. In our example: Character Code k00 r 010 b 011 s10 a11 Huffman codes have a property that is useful when reading: no code is a prefix of any other code. This means the codes do not have to be separated in any way – we always know when each code ends. Decoding programs can use this property by having a special tree pointer ptr. It initially points at the root. When a 0 is read from the input, we move ptr to the left child, when 1 – to the right child. If a leaf is reached, we output this leaf's character and move ptr back to root. If we encoded the word abraksas using codes from our example, it would be 110110101100101110.

Edition 2007-01-09 top secret / strictly confidential page 457 of 520 Perlgolf History

Input data The encoded message is provided on STDIN as a string of 0's and 1's, ended with a newline character. The input data is not empty and not longer that 1000 characters. Input matches the regular expression /\A[01]{1,1000}\n\z/. Character codes In the tree encoding example in the first section the character codes were omitted for simplicity. However input will not contain etc., but only 0's and 1's. Since the encoded message contains only spaces and a-z, they are stored on five bits as follows: Character Code space 0 a-z ord(character)-ord('a')+1 All the codes for clarity: Character Code Character Code Character Code space 00000 i 01001 r 10010 a 00001 j 01010 s 10011 b 00010 k 01011 t 10100 c 00011 l 01100 u 10101 d 00100 m 01101 v 10110 e 00101 n 01110 w 10111 f 00110 o 01111 x 11000 g 00111 p 10000 y 11001 h 01000 q 10001 z 11010 Codes not mentioned in the above table are not used in the task. The example tree is really encoded as: 0010101101100101000100110011100001. If we encoded the word abraksas using the example tree, it would be: 0010101101100101000100110011100001110110101100101110. Output The result of our script is the decoded message, which should be output to STDOUT, followed by a newline character. The message is not empty and its length does not exceed 100 characters. Output matches /\A[ a-z]{2,100}\n\z/.

10.6.2. Solutions 88, Mateusz Matuszek -p @{$Z.=$1}=pack B8,ba.$&*s/(0*).{6}//;$z.="$Z|";$Z=~s/01*$/1/?redo:s/$z/@{$&}/g;y/`/ / 89, Michal Szafranski -p @{$a.=$1}=pack B8,B.s/(0*)(.{6})//.$2;$z.="|$a";$a=~s/01*$/1/?redo:s/($z)/@$1/g;y/`/ / 94, Wawrzyniec Żurowski -p sub U{s/0|.{6}//;$q=$&?oct"b1$&":[&U,&U]}$b=&U;s/./$b=$q,chr$;if!@{$;=$b=$$b[$&] }/eg;y/`/ / 95, Maciej Misiak

Edition 2007-01-09 top secret / strictly confidential page 458 of 520 Perlgolf History

-p /1.{5}/;$h{$x.=$`}=chr oct"0b1$&";$_=$';$x=~s/01*$/1/&&redo;$"='|';s/@{[%h]}/$h{$&}/g;y/`/ / 103, Przemysław Kowalczyk -lp sub p{s/.//;$&?b1.s/.{5}//.$&:[&p,&p]}$c=$;=p;@{$c=$$c[$&]}or$_.=chr oct$c,$c=$;while s/\d//;y/`/ / 105, Tomek Machalski -p sub d{s/0|1.{5}//;$&?[0,0,pack B8,ba.$&]:[&d,&d]}$;=$w=d;s|.|$w=$;if$c=($w=$w->[$&])->[2];$c|ge;y/`/ / 111, Benoit Chauvet -p $j=~s/01*$/1/;s/(0*)1(.{5})//;$t{$j.=$1}=- $2?oct"0b11$2":32;$j=~/0/&&redo;s/.*(??{6if!($z=$t{$&})})/chr$z/eg

10.7. PCLP #3.7 - TABULATURA Master: Maciej Misiak (grizzley) 04.02.2005 13.02.2005

10.7.1. Rules Introduction Tab is a notes' notation for guitar. Tab contains 6 horizontal lines, each representing one guitar string. If on some line appears number, e.g. 2, it means, that musician must press corresponding string fret. Notation is simple and intuitive, and one doesn't need knowledge of reading notes. However, we will need it for the task. Names of notes used in the task: ...gis, a, ais, b, c, cis, d, dis, e, f, fis, g, gis, a, ais, b, c, cis, d, dis... as you see they make cycles, distance between two consecutive tones is named halftone. A chord is made in the task by 3 tones. Distance between 1st and 2nd tone and between 2nd and 3rd is constant and depending on kind of chord is 4 and 3 halftones in case of major chord and 3 and 4 in minor chord. In the task you get a list of chords, e.g. C a F# Gb. How to read it? First letter 'C' means major chord beginning from note c. Count 4 halftones - from the list of notes choose a note 4 positions right, which is e. Next, lets count 3 halftones right so we get note g. So chord 'C' is made from notes c-e-g. Next chord is 'a'. Small letter means minor chord. We count 3 places from 'a', and than 4 and we get a-c-e. F# is a major chord beginning from note halftone higher than f, its name is fis. F# -> fis-ais-cis. Gb is major chord from note g lowered by a halftone - fis. Gb -> fis-ais-cis. As you see Gb is the same as F#. Now you only need information about how chord, e.g. C looks like on the guitar. Strings have names e, B, G, D, A, E what means, if you play string A you get tone a. If you close string A tight to the first fret you get tone halftone higher - ais, on second fret is b, etc. To play a chord you must close tight every string to such fret, that you get one of the chord's tones. Tab for single chord C can look like this: (Add=Added halftones, Fin=Final tone)

Edition 2007-01-09 top secret / strictly confidential page 459 of 520 Perlgolf History

Tab Add Fin Tab Add Fin Tab Add Fin Tab Add Fin C a F# Gb e-0- 0 e -0- 0 e -2- 2 fis -2- 2 fis B-1- 1 c -1- 1 c -2- 2 cis -2- 2 cis G-0- 0 g -2- 2 a -3- 3 ais -3- 3 ais D-2- 2 e -2- 2 e -4- 4 fis -4- 4 fis A-3- 3 c -0- 0 a -1- 1 ais -1- 1 ais E-0- 0 e -0- 0 e -2- 2 fis -2- 2 fis Of course such tab is correct too: Tab Add Fin Tab Add Fin Tab Add Fin Tab Add Fin C a F# Gb e-8-- 8 c -5- 5 a -2- 2 fis -2- 2 fis B-8-- 8 g -5- 5 e -2- 2 cis -2- 2 cis G-9-- 9 e -5- 5 c -3- 3 ais -3- 3 ais D-10- 10 c -7- 7 a -4- 4 fis -4- 4 fis A-10- 10 g -7- 7 e -4- 4 cis -4- 4 cis E-8-- 8 c -5- 5 a -2- 2 fis -2- 2 fis You have to find possibly lower correct frets. General health warning: trying out in real chords generated in this edition can cause dislocations. Don't try them home! Task Write a program which produces tab on the basis of given chords. Input On standard input STDIN is one space and sequence of chords names and spaces, np. ' CaF#Gb' and newline character. Input matches /\A ( |[a-gA-g][b#]?)*\n\z/. Output On STDOUT program should print out a tab. First row should be exactly like input. Next 6 rows should start with guitar string name (e, B, G, D, A, E), and than contain a cipher in columns upon every first chord's letter (see first row) and '-' (minus) otherwise. Rows should end with '|' (should be this one char longer than first row). Output should match following regexp: /\A( |[a-gA- g][b#]?)*\n([eBGDAE][-0-9]\|\n){6}\z/.

10.7.2. Solutions 121 (post-mortem), Michal Szafranski -lpaFX map{$.-=5^/j/;s|\b\w|((lc$&^P)-*1.6-/\G.b/+/\G.#/-$.)%12%(8^$-> Z)%5|eg,y/b# /-/for$x="@F| ";$\.=$_^$x}H,o,j,i,l,h 135, Piotr Fusik -plaFx $b-=$#=print}for(Ebgdae=~/./g){$.-=7+/g/;$_^="@F|";s/ (\w)(\S?)/b.($$2+$.+index xBCxDxEFxG,uc$1)%12%(8^$1ge a)%05.$2/eg;y/ b#/-/ 135, Maciej Misiak -n / /g;@a=/ |\S+/g;print$_,map{$d+=5-/G/;$_,(map{((32-10*ord uc)%35+/#/- /.b/+$d)%12%(9-/[A-G]/)%5x/\S/,'-'x/ |../}@a),"| "}e,B,G,D,A,E 139, Michal Szafranski

Edition 2007-01-09 top secret / strictly confidential page 460 of 520 Perlgolf History

-lp for$w(H,o,j,i,l,h){s|\b\w|vec"#\001\022@"x2^($> Z)x2,(/\G.b/- (lc$&^P)*1.6-/\G.#/-o5j9i2l7=~$w*$'-5)%12,4|eg,y/b# /-/for$x=$_;$\.=$w^"$x| "} 179, Przemysław Kowalczyk -p sub N{/#/-/.b/+vec"\212W#",7&~ord,4}/\wb|.#?/g;@z=map{$_,/../}//g;$_.=join'| ',(map{$b=N;join'',$_,map/\pL/?($a)=sort{$a-$b}map{($_-$b)%12}N,3+y/A- Z//+N,7+N:"-",@z}e,B,G,D,A,E),'' 181, Wawrzyniec Żurowski -nlaF0 sub L{2*($x=ord lc pop)-int$x/3}for$n(eBGDAEx=~/./g){print;$_="@F ";y/ /-/;s/(\w)(.)/(sort{$a<=>$b}map{(('-'cmp$2)-L($n)+$_+L$1)%12}0,7,3+($1lt a))[0].'-'/ge;s/.(.*)./$n$1|/}

Edition 2007-01-09 top secret / strictly confidential page 461 of 520 Perlgolf History

11. Games – Kernelpanic season 4 11.1. PCLP #4.1 - UKRYTY OBRAZEK Master: Piotr Fusik (0xF) 17.02.2005 22.02.2005

11.1.1. Solutions 96, Michal Szafranski -p0 s/\d +/49+$&-ord$'&61?$&:'\377'^~$&/ge,($_.=" "x8)x=8,s/(.).{8}/$1/gs,y/\337|/|-/for$_,$_;y/0-9/+/ 97, Piotr Fusik -p0 s!(?<=(\d))( +|.{8} .+)(??{1+$1.'|'.~-$1})!$_=$&;s/(.{8}) /$1|/gs||y/ /- /;lc!se?redo:s/\d/+/g 114, Przemysław Kowalczyk -p0 eval((';$b^=a;s/\d +(??{$&+1})/($a=$&)=~s@ @$b@g;$a/e;$_=$r'.'.(reverse/^./mg)." ".!s///g'x8)x96);y/a\0001-9/-|+/ 128, Maciej Misiak -lp0 for$x('-','|'){s/\d.*?(?=\d)/$_=$&;s! !$x!g if abs(ord()- ord$')==1;$_/eg;my@a;$a[$i++%8].=$_ for/./g;$_=join" ",@a}s/\d/+/g

11.2. PCLP #4.2 Master: Stanislaw Klekot (dozzie) 20.04.2005 30.04.2005

11.2.1. Solutions 115, Mateusz Matuszek -naF\W $R.=lc;s`=$`$_=$R;@F=grep!$Y{$_}++,sort@F,$&=~/\w+/gwhile%Y=$"="|",s/ (@F)(,(@F))*=.*//;$"^=P;"=@F"`e&&print 125, Tomek Grodzki -n /=/;$z{$l=$`}.=$';my%r;grep!exists$r{$_},/\w+/g or@r{"$l,$z{$_}"=~/\w+/g}=1for(%z)x99;s/=$/$&.join',',sort keys%r/e&&print 127, Przemysław Kowalczyk -lp0a }sub g{pop=~/\w+/g}for(grep/=$/,@F){my%w;@w{g$_}=g$_;map{/=/;grep!$w{$_},g$`or@w{g$' }=g$'}(@F)x99;$_.=join',',sort keys%w 158, Maciej Misiak -lp BEGIN{<>;<>;<>;$h{$`}.=",$'"while$_=<>,/=/}%w=map{$_,1}/\w+/g;1while grep!$_,map{grep(!$w{$_},//g)||map$w{$_}++,$h{$_}=~//g}keys%h;$_.=join",",so rt keys%w 408, Stanislaw Klekot

Edition 2007-01-09 top secret / strictly confidential page 462 of 520 Perlgolf History

sub c{ my($c,$d,$z,%z,@t)=@_; %z=map{$_,1}@$c; do{ @t=keys%z; for my$f(@$d){if(!grep{!$z{$_}}@{$f->[0]}){$z{$_}=1for@{$f->[1]}}} }until@t==keys%z; return[keys%z]; } while($_=lc<>){ chomp;$s=$1and next if/\[(.*)\]/; if($s=~/z/){push@d,[map{[split/,/]}split/=/]} elsif($s!~/h/){chop;push@c,[[split/,/]]} } push@$_,[sort@{c$_->[0],\@d}]for@c; $"=","; print"@{$_->[0]}=@{$_->[1]}\n"for@c;

11.3. PCLP #4.3 Ogrodzenie “The Fence” Master: Mateusz Matuszek (magus) 11.05.2005 22.05.2005

11.3.1. Rules The task is to find the convex area of the given set of points. 1. Introduction A young man (let call him John) have bought a house in the country with a beautiful orchard. Although the property was not surrounded by any fence. So John has built a wonderful wall around the house :) He was very happy with it but he forgot to keep money for the fence of orchard. He founds an idea to build very cheap fence by joining some trees by planks. Our task is to help John to choose the less number of trees to be used in the fence. In the mathematical language we have to find a complex area of the given set of points. 2. Input and output In the standard input we get a map of orchid. The map is built as follows: /^([.#]{1,30}\n){1,20}\z$/ To standard output we have to give a map containing only the trees used in the fence.

3. Examples STDIN: ...... #..#...... #...... #...... #..#...#...... #....#...... #...#...... STDOUT:

Edition 2007-01-09 top secret / strictly confidential page 463 of 520 Perlgolf History

...... #..#...... #...... #...... #...#...... STDIN: ...... #..#..#...... #..#..#...... #..... STDOUT: ...... #..#..#...... #.....#...... #..... 4. Rules The standard perlgolf rules apply. Using of any modules is forbidden (even built-in ones). The tie for this golf is "letters and digits", meaning that for two equally long solutions the one with a higher fraction of letters and digits wins.

11.3.2. Solutions 147, Piotr Fusik -p0a $w=y///c/@F;s|#|$x="@-";(grep{($t="@F")=~s!#!("@-"/$w%99-int$x/$w)*($_%64- 32)+("@-"%$w-$x%$w)*((lc>>6)-20)!ge;$t!~v45-/1312/}0..3e3)?$&:v46|ge 156, Maciej Misiak -p0 sub f{$_="$`.$'";$-[0]%$l-$x[0],-$x[1]+int$-[0]/$l}/ /g;$l=pos;s^#^@x=0;@x=f;!s##($c,$d)=f;s@@($e,$f)=f;1+($c*$f<=>$d*$e)@eg;!/0/|!/ 2/#eg|/1/?"#":"."^eg 179, Przemysław Kowalczyk -p0 / /;($l)=@+;push@%,@-while/#/g;sub f{($n,$t)=@_;($t%$l-$n%$l)*($q-$n)>($q%$l- $n%$l)*($t-$n)}s"#"($q,$u)=@- ;for$a(@%){/^/,map$u+=f($',$_)*f($a,$')*f($_,$a),@%for@%}$u?'.':$&"ge 208, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 464 of 520 Perlgolf History

-paF| s!#!@{++$i}=(@-,$.- 1)!eg;push@L,@F}for$A(@z=1..$i){($b,$c)=@$A;for$B(@z){$Q=$W=0;$Q|=($R=("@$B" -$b)*($$_[1]-$c)-($$B[1]-$c)*("@$_"- $b))>0,$W|=$R<0for@z;$L[$b+$c*@F]|=$Q^$W}}for(@L){$i>3?y/1#0/#./:y/0/#/ 1414, Mateusz Łącki @in=; $rn=0;$rl=0; sub a{$x=$_[2]-$_[0];$y=$_[3]-$_[1];if($x==0 && $y==0){return 5;}if($x>=0){if($y>=0){$u=$y;$v=$x+$y;}else{$u=4*$x-3*$y;$v=$x- $y;}}else{if($y>=0){$u=-2*$x+$y;$v=-$x+$y;}else{$u=-2*$x-3*$y;$v=-$x- $y;}}return $u/$v;} sub d{return(($_[2]-$_[0])**2+($_[3]-$_[1])**2);} sub abs2{if($_[0]<0){return-$_[0];}else{return$_[0];}} foreach$row(@in){$rn++;$rl=0;for($i=0;$c=substr($row,$i,1);$i++){$rl++;if($c eq"#"){push @x,$rn;push @y,$i;}}} $x1=$x2=$x[0];$y1=$y2=$y[0]; for($i=1;$i<@x;$i++){$a=$x[$i];$b=$y[$i];if($b<$y1||($b==$y1&&$a<$x1)){$y1=$b;$ x1=$a;}if($b>$y2||($b==$y2&&$a>$x2)){$y2=$b;$x2=$a;}} push @ox,$x1;push @oy,$y1; if(@x!=1){while(1){$m=5;$k=-1;for($i=0;$i<@x;$i++){$a=$ox[@ox-1];$b=$oy[@oy- 1];if(($t=a($a,$b,$x[$i],$y[$i]))<=$m){$l=1;if($t==$m){if(d($a,$b,$x[$i],$y[ $i])

11.4. PCLP #4.4 - Jasio Forecaster “Johnny the Jasnowidz” Master: Mateusz Łącki (lacek2) 08.06.2005 21.06.2005

11.4.1. Rules The task is to forecast the weather. 1. Introduction Johnny a child prodigy has been learning weather forecasting for two years. Some day as it was raining heavily, John, not being able to go out to play Zertz, decided to calculate when his gehenna will finish. After a while, he decided not to think only about himself: he wanted to forecast the weather several days from then. As he was only four years old, he did not have neither specialized satellite network nor a multitude of coworkers, but only himself and a computer with Perl interpreter installed on it. For a good start Johnny wants to evaluate statements included in the article he has just read. The author claims that if it rains only slightly it will rain heavily next day or it will be sunny. The chances are equal. If one day it rains heavily the probability that it will be raining heavily, raining only slightly, sunny are equal to: a, b, c. (a+b+c=1). When it is sunny, the weather the next day will be the same or it will be raining, but only slightly - the probability are equal to d and e. (d+e=1) 2. Input and output

Edition 2007-01-09 top secret / strictly confidential page 465 of 520 Perlgolf History

Read numbers (not necessarily integer - x is always integer): a,b,c,d,e,x from the standart input (all the numbers are in one line and are separated by space) Evaluate the probability that it will be raining heavily in x<17 days. If the probability is in [0,1/3] you should write 'A', if it is in (1/3,2/3], you should write 'B', if it is in (2/3, 1] write 'C'. Test cases will not require implementing any high precision floating point numbers. All the output probabilities p will satisfy the condition |1/3-p|>0.01 AND |2/3-p|>0.001, which means the output probabilities will differ significantly from the thresholds. Print "\n" at the and of your output 3. Examples Sample Input #1: 010014 Sample Output #1: B Sample Input #2: 0.88 0.1 0.02 0.1 0.9 16 Sample Output #2: C Sample Input #3: 0 0.1 0.9 0.1 0.9 2 Sample Output #3: A ACHTUNG! read only from STDIN and write only to STDOUT 4. Rules The standard perlgolf rules apply. Using of any modules is forbidden (even built-in ones). The official version of Perl interpreter is 5.8.6. That version will be used to judge solutions. The solutions may make use of bugs in 5.8.6 interpreter. However, they should not use bugs present in previous versions of the interpreter which have been already removed. The tie for this golf is "letters and digits", meaning that for two equally long solutions the one with a lower fraction of letters and digits wins.

11.4.2. Solutions 76, Piotr Fusik -pal $;=3;$#=$;*$'+(3-$;-$#)*$F[$;=$#/2+$;*$`,4]for/ /..$F[5];$_=C^chr$^F>>$; 77, Michal Szafranski -pla $;=3;$:=$&*$;+(3-$;-$:)*$F[$;=$:/2+$;*$`,4]for/ .* /..$';$_=(A..C,C)[$;] 80, Robert Szczygiel -alp $l=2.999;$d=$F[4]*(3-$l-$d)+$'*$l+!($l=$`*$l+$d/2)for/ /..$F[5];$_=chr$l+65 91, Wojciech Kurowski

Edition 2007-01-09 top secret / strictly confidential page 466 of 520 Perlgolf History

-pal $@++;($@,$*)=map$@*$F[$_*2]+$_*$**$F[3]+(1-$@-$*)/2,0,1for 1..$F[5];$_=chr$@*3+65-$@%2 99, Jacek Fedorynski -pal $/=2.999;$_='($/,$*,$~)=(0#3*2#1/4*);'x$F[5];s/\d/+\$F[$&]*\$/g;s'#'/+$~/2,' g;eval;$_=chr$/+65 102, Maciej Misiak -lpa $;=3;($;,$,,$")=($;*$_+$,/2,$;*$F[1]+$"*$F[4],$;*$F[2]+$,/2+$"*$F[3])while$F [5]--;$_=(A..C,C)[$;] 102, Przemysław Kowalczyk -pl $L=$_=~('(.+) 'x5);($L,$D,$S)=($1*$L+$D,($2*$L+$5*$S)/2,$D+$4*$S+$3*$L)for 1..$';$_=chr$L*2.999+65 106, Paweł Siennicki -pa $l=1;($l,$d)=($d/2+$F[0]*$l,$F[4]*$s+$F[1]*$l),$s=1-$l-$d,while$F[5]-- ;$_=$l<1/3?'A ':$l>2/3?'C ':'B ' 213, Daniel Kopczyński -nl ($a,$b,$c,$d,$e,$x)=split;sub L{my$y=$_[0];$y?$a*L($y-1)+$b*D($y- 1)+$c*S($y-1):1}sub S{my$y=$_[0];$y?$d*S($y-1)+$e*D($y-1):0}sub D{my$y=$_[0];$y?0.5*(L($y-1)+S($y- 1)):0}print(($x=3*L($x))>1?($x>2?"C":"B"):"A") 227, Robert Garwacki -l ($f,$g,$c,$d,$e,$x)=split(" ",);@t=([$d,$e,0],[0.5,0,0.5],[$c,$g,$f]);print chr(65+int(p($x,2)*3));sub p{my($x,$p)=@_;if($x>1){return$t[0][$p]*p($x- 1,0)+$t[1][$p]*p($x-1,1)+$t[2][$p]*p($x-1,2);}else{return$t[2][$p];}} 382, Mateusz Łącki #!/usr/bin/perl sub l{my@t;for(0..2){my@e;$e[$_]=0 for 0..2;push@t,\@e;}\@t;}sub w{($a,$b)=@_;$c=[];for$i(0..2){for$j(0..2){$c->[$i][$j]+=$a->[$i][$_]*$b- >[$_][$j]for 0..2;}}$c;}@h=split(' ',<>);$p=&l;$k=&l;$p->[0][$_]=$h[$_]for 0..2;$p->[1][$_]=0.5 for 0,2;$p->[2][1+$_]=$h[4-$_]for 0,1;$k->[$_]=$p- >[$_]for 0..2;$k=w($k,$p)for 1..--$h[5];$a=$k- >[0][0];$o=B;$a<1/3?$o=A:$a>2/3?$o=C:0;print"$o\n";

11.5. PCLP #4.5 – WISIELEC “hungman” Master: Piotr Fusik (0xF) 05.07.2005 11.07.2005

11.5.1. Solutions 35, Piotr Fusik -p //;($_=$s)?$;:$s.=$';s/[^$;]/-/g 36, Piotr Fusik (alternative)

Edition 2007-01-09 top secret / strictly confidential page 467 of 520 Perlgolf History

-p/()/;${$_=lc$$1}.=$';s/[^$$_]/-/g 38, Michal Szafranski -p INIT{$x=<>}$z.=lc;$_=$x;s/[^$z]/-/g 38, Mateusz Matuszek -p INIT{$s=<>}$z.=lc,$_=$s,s/[^$z]/-/g 38, Tomek Machalski -p INIT{$s=<>}$l.=lc;$_=$s;s/[^$l]/-/g 38, Jacek Fedorynski -p INIT{$w=<>}$x.=lc;$_=$w;s/[^$x]/-/g 38, Przemysław Kowalczyk -p INIT{$s=<>}$p.=lc;$_=$s;s/[^$p]/-/g 38, Maciej Misiak -p INIT{$s=<>}$F.=$_;$_=$s;s/[^$F]/-/g 41, Robert Szczygiel -p INIT{$a=<>}$b.=$_;$_=$a;eval"y/$b/-/c" 42, Michał Kwiatkowski -p BEGIN{$a=<>}push@l,$_;$_=$a;s/[^@l]/-/g 42, Wojciech Kurowski $@=<>;$*.=$_,$_=$@,s/[^$*]/-/g,print for<> 51, Michal Wrobel -ln BEGIN{$a=<>}$c.=$_;$_=$a;s/[^$c]/-/g;chop;print 54, Cédric Barboiron -naF// !@a?@a=@F:do{$l.=$_;print$l=~/$_/?$_:'-' for@a}

11.6. PCLP #4.6 deROTer Master: Mateusz Matuszek (magus) 14.07.2005 21.07.2005

11.6.1. Rules The task is to decode a message coded by using a kind of ROT13 algorithm with unknown shift. Introduction Probably all of you know the ROT13 algorithm. To code a message by using ROT13 it is needed just to replace each letter with the one shifted 13 positions to the right. Let's consider the following scheme: a bcdefghijklmnopqrstuvwxyz n opqrstuvwxyzabcdefghijklm Letter 'a' will become a letter 'n'.

Edition 2007-01-09 top secret / strictly confidential page 468 of 520 Perlgolf History

In our problem, coding is made by using a ROT algorithm with any (it is unknown) shift. To be able to decode the message a dictionary is given. Decoded message will contains only the words included in the dictionary and all not coded characters. Assumptions Only letters are coded. Upper case letters and lower case letters are coded independently although the shift is the same For the given input there is only one possible output. Input and output To the standard input the coded message is given /^([\x20-\x7f]{0,999}\n){1,10}\z$/ The dictionary is given by arguments. It is a list of words containing at least one character. Each word is: /^[a-zA-Z]{1,20}$/ The decoded message shall be provided to the standard output Examples STDIN: Zmbczva bpm izkbivomvb wn G/F qv bpm zivom -XQ bw XQ. arguments: PI X Y Returns to in of range arctangent the STDOUT: Returns the arctangent of Y/X in the range -PI to PI.

11.6.2. Solutions 62, Juho Snellman (rejected) -p0 INIT{$$_=1while$_=pop}$$1||y/B-ZA-Gb-za/A-z/while/(\pL+)/g 63, Piotr Fusik (would be rejected due to genrule #20.f “-0”) -p0 INIT{@{-pop}=1until@0}@{-$&}||y/B-ZA-Gb-za/A-z/while/\pL+/g 63, Piotr Fusik (rejected but correct) -p0 INIT{$$_=1while$_=pop}$$$1||y/B-ZA-Gb-za/A-z/while/(\pL+)/g 65, Juho Snellman -p0 INIT{%a=map{pop,1}@ARGV}$a{$&}||y/B-ZA-Gb-za/A-z/while/\pL+/g 65, Piotr Fusik (alternative) -0 $_=;$$1||y/B-ZA-Gb-za/A-z/while${~~pop}=/(\pL+)/g;print 64 (post-mortem golfed from previous) $_=`$^X -pe1`;$$1||y/B-ZA-Gb-za/A-z/while${~~pop}=/(\pL+)/g;print 66, Przemysław Kowalczyk -p0 INIT{$$_=1while$_=pop}y/A-Za-z/B-ZAb-za/while grep!$$_,/\pL+/g 69, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 469 of 520 Perlgolf History

-p0 INIT{$$_=1while$_=pop}y/a-zA-Z/b-zaB-ZA/while grep!$$_,/[a-z]+/ig 75, Roy Johnson $/='';$_=;"@ARGV"=~/\b$&\b/||y/b-zaB-ZA/a-zA-Z/while/[a-z]+/gi;print 76, Robert Szczygiel -0 $_=;y/a-zA-Z/za-yZA-Y/while grep"@ARGV"!~/\b$_\b/,/[a-z]+/gi;print 76, Maciej Misiak -0 $_=;y/a-zA-Z/b-zaB-ZA/while grep"@ARGV"!~/\b$_\b/,/[a-z]+/ig;print 77, Michael Wrenn -0p INIT{$A{$a}=1while$a=pop}1while"@A{/[a-z]+/ig}"=~/\B/&&y/A-Za-z/B-ZAb-za/ 82, Stanislaw Klekot -p BEGIN{$d{pop,}=1while@ARGV;$/=$x}y/a-zA-Z/b-zaB-ZA/while grep!$d{$_},/[a- z]+/gi

11.6.3. Explanation by Juho Snellman From http://www.cs.helsinki.fi/u/jesnellm/blog/archive/2005-07-23.html Long time since the last golf. Inspired by the recent announcement of a Perl Golf book I took part in a Polish golf that was announced on the mailing list. Given a input string that has been "encrypted" with ROT-n on STDIN and a dictionary of words (sequences of letters A-Za-z, not of \w) in @ARGV the program needs to output to STDOUT the original plaintext. (Formal rules). My best solution was 62 characters, but I figured out about an hour before the golf ended that it was actually broken, and didn't have time to figure out anything better than the 65.44 below, which is currently good for a second place. The apparent winning solution of 63 doesn't seem to work either, for unrelated reasons. So the explanation might be for the winning entry, or it might not. #!perl -p0 You know the drill. -p handles reading the input and printing the output. Use -0 to read the input in one go, instead of a line at a time. INIT{%a=map{pop,1}@ARGV} In the INIT block, pop all command line parameters to make -p read from STDIN. Use the removed arguments as keys in a hash table for detecting dictionary words. Using the symbol table with something like $$_=1while$_=pop would save a few characters, but that's incorrect since $ARGV is automatically set to '-' on entering the main loop. $a{$&}||y/B-ZA-Gb-za/A-z/while/\pL+/g At the start of the main body $_ contains the whole ROT-n text. On the first iteration /\pL+/g will match the first word (letters only; \pL is essentially [a-zA-Z]). //g works differently in scalar than in list context: it will only match once per call, but the next call will start at the location in the string where the last match ended. If a match was found it returns true, otherwise false.

Edition 2007-01-09 top secret / strictly confidential page 470 of 520 Perlgolf History

In the body of the while we first check if the word we matched is in the dictionary. If it isn't (i.e. $a{$&} is untrue) $_ obviously isn't plaintext yet, so we rotate it by one step with y///. This contains the only tricky bits in the program: Changing $_ causes the scalar //g to be reset, and start matching from the start of the program. Doing the rotation backwards (A -> Z, B -> A, ..., Z -> Y) instead of the more intuitive direction (A -> B, B -> C, ... Z -> A) allows writing the transliteration in a way that saves one character. There are six characters ([\+]^_`) between Z and a. By adding six extra characters into the right place on the left side of the transliteration operation (with -G) we can use the range A-z on the right side, instead of specifying separate ranges for upper- and lowercase letters. Compare: y/A-Za-z/B-ZAb-za/ y/B-ZA-Gb-za/A-z/ FWIW, the 65.48 by Piotr Fusik by far the coolest solution. Wish I'd thought of that...

11.7. PCLP #4.7 Circle Master: Juho Snellman (jsnell) 09.08.2005 16.08.2005

11.7.1. Rules Draw a filled circle of a given diameter with ASCII graphics. If you consider the output for a diameter d as a d*d grid, a cell in the grid should contain a * if the distance from the center of the cell to the center of the grid is less than or equal to d/2. Input and Output The diameter d is a number from 1 to 80, given in @ARGV. The test script contains a test for all valid inputs. The output on STDOUT should consist of d lines, each being at most d+1 characters long and matching /^ *[*]+\n$/. Example For diameter 12 the output should be as follows: ....**** ..******** .********** .********** ************ ************ ************ ************ .********** .********** ..******** ....**** (Spaces replaced with ".")

11.7.2. Solutions 25, Piotr Fusik

Edition 2007-01-09 top secret / strictly confidential page 471 of 520 Perlgolf History

-l $_-=.5,print$"x($_=@d/2+.5-sqrt$_*(@d-lc)),'*'x(@d-2*int)for@d=1..pop 74, Christian Schuster -l //,print map@i**2>$_**2+$'**2?"*":$"x/-/,@,for@,=map$_*2-@i-1,@i=1..pop 74, Michal Szafranski -l $|--&&print$/x($-=($d+1-sqrt$d*$d-$_*lc)/2)^'*'x($d-$-)for-($d=pop)..$d 77, Jasper McCrea -l for$y(@a=map$_*2-@a-1,@a=1..pop){print map$y**2+$_**2>@a**2?$"x/-/:'*',@a} 78, Michael Wrenn -l $l=++$l+print map$l*(2*@1-$l)>(2*$_-@1-1)**2?'*':2*$_<@1&&$",@1for@1=1..pop 81, Przemysław Kowalczyk -l sub b{($_*2-1-@0)**2}$i=@0**2-&b,print map$i>&b?'*':$_*2<@0&&$",@0for@0=1..pop 82, Wojciech Kurowski -l print' 'x($x=($d+1-sqrt$d*$d-(2*$_-$d-1)**2)/2),'*'x($d-2*int$x)for 1..($d=pop) 86, Shlomi Fish -l map{$t=sqrt@d**2-$_**2;print map$_<$t?$_>-$t?'*':'':$",@d}@d=map@d+1- 2*$_,@d=1..pop 102, Rafał Roppel -l $d=@a,$r=$d/2+.5,$p=$_,print map{($r-$_)**2+($r- $p)**2>($d/2)**2?$_>$d/2?'':' ':'*'}@a for@a=1..pop 105, Wawrzyniec Żurowski -l $a=pop()/2;for$y(1..2*$a){$b=grep{$a*$a>($_+.5-$a)**2+($y-.5- $a)**2}0..$a*2;print" "x($a-$b/2),"*"x$b} 140, Cédric Barboiron $d=$ARGV[0];$c=$d/2;for(0..$d**2-1){$j=$_% $d;sqrt((int($_/$d)+0.5- $c)**2+($j+0.5-$c)**2)<=$c?print"*":($j<$c?print$":());print$/if$j+1==$d}

11.8. PCLP #4.8 Kwadraty III (Squares III) Master: Mateusz Matuszek (magus) 16.09.2005 28.09.2005

11.8.1. Rules Just draw a square depending on a given number: 0 #

1 ### ## ###

Edition 2007-01-09 top secret / strictly confidential page 472 of 520 Perlgolf History

2 ##### ### # ### ## #####

3 ####### ## # ##### #### # # ### ## # #######

4 ######### ## ####### # ### # ##### # ##### # # ### # ## ## #########

5 ########### ### ####### # # # ### # ##### # # ###### ####### ## ### ######### # ## ###########

6 ############# ## ## # ####### # # ## ### # # ##### # # ####### ######## ### ### # ######### # ## # # ########### ## ############# ...

Edition 2007-01-09 top secret / strictly confidential page 473 of 520 Perlgolf History

Input & Output The number of a square to draw is given as and argument to the script. The value is from 0 up to 20. The Square shall be drawn into the standard output. /^(#([# ]*#)*\n)+\z/

11.8.2. Solutions 103, Rick Klement ($n+=--$|?$t=${$t.=$/while s/.$/$t.=$&/gmee;$_=$t}:s/ #$/##/-pop)&&s/\n/ #\n/g+s/ /#/for($_=v35)x42;print 104, Piotr Fusik $/x=$x.=FF&1x(4&map$a[$y- lc]|=$x.((c&/^0|$#s/*3x1)x$#s."#$/"|v3),@s=2*lc..0),$y+=~$_&2for- pop..0;print@a 116, Mateusz Matuszek $c=("#".$"x(++$w&2?s/^/# /mg:s/ /# /g)."# ")x2,$_=$w+1&2?$_.$c:$c.lc,s/^.+|.+$/"#"x y! !!/egfor($_="# ")x pop;print

126, Michal Szafranski -l @x="#";map{@x=map{$z=$y;map$z.=chop,@x;$z}@x;@x=(($f="##".pop@x),(map"# $_",$"x@x."#",@x),$f)if"@ARGV">lc}0..22;print for@x 130, Przemysław Kowalczyk -l $_='#';$d.='##',$c=$"x(++$i&2?s/^/# /gm:s/$/ #/gm),$i%4%3?s/# /##/+s/$/ #$c# #$d/:s/(.+)# /#$d #$c# $1##/swhile$i<"@ARGV";print 133, dmitry kim -l for$y(0..2*($N=pop)){print map{$Y=$y,$n=$N;$r+=!(sort map$_*($n*2- $_),$_,$Y)[0],$_-=$n--&2,$Y-=$n&2while$n+1;$r=$r?"#":$"}0..$N*2} 172, Maciej Misiak -l sub f{($x,$y,$d)=@_;$e=$d*2;$d&&!(0>$x|$x>$e|0>$y|$y>$e)&&!($x%$e&&$y%$e&&!f($x- ($d&2),$y-(($d-1)&2),$d-1))} for$w(@a=0..2*($c=pop)){print map!$c||f($_,$w,$c)?'#':$",@a} 208, Christian Schuster -l $x=0;@L=(' 'x($n=2*(@i=0..pop)-1))x$n;for(reverse@i){$v=($w=2*$_+1)- 2;substr($L[$y],$x,$w)=substr($L[$y+$w- 1],$x,$w)='#'x$w;map$L[$_]=~s/(.{$x}).(.{$v})./$1#$2#/,$y..$y+$w- 1;$x+=$_&2;$y+=$_+3&2}print for@L

11.9. PCLP #4.9 TAC Master: Piotr Fusik (0xF) 10.10.2005 20.10.2005

Edition 2007-01-09 top secret / strictly confidential page 474 of 520 Perlgolf History

11.9.1. Rules Problem Create a filter that reverses the order of bytes. Your script should write to the standard output bytes read from the standard input in reverse order. The script will be run without arguments. Operations on standard input and output must be done in binary mode. The thing is that on any system the order of bytes should be reversed. Thus, you should for example: • execute binmode STDIN and binmode STDOUT before using getc, read, print etc. (binmode does not affect seek and tell) or • perform I/O using sysread, syswrite and sysseek exclusively (of course you can use different ways on STDIN and STDOUT). The length of the input stream is limited to 2**31-1. You may not assume that all input data fits in the memory. Warning: this is not checked by the test script, but non-conforming solutions will be rejected after the contest deadline. You may use seek, sysseek and tell on STDIN (but not STDOUT). You must never try to set the position before the stream (offset < 0) or after its end (offset > length; positioning right after the last byte is fine). The tests do not check it! Your script must not create additional files or directories (even temporarily) or modify itself (by writing to the script file). Writing to STDERR is forbidden, too.

11.9.2. Solutions 57, Piotr Fusik 1while tell(binmode seek*1=STDIN,$o--,2)<0;){seek$s,$l,0;syswrite STDOUT,getc} 76, Maciej Misiak binmode$_ for$_=*STDIN,STDOUT;seek($_,$c--,2),print getc while$c>=-(stat)[7]

Edition 2007-01-09 top secret / strictly confidential page 475 of 520 Perlgolf History

12. Games – Kernelpanic season 5 12.1. PCLP #5.1 Poker Master: Mateusz Matuszek (magus) 08.12.2005 16.12.2005

12.1.1. Rules For the given 5 card set find the best set name in poker notation. Set Name Description Royal Flush A,K,D,J,T in the same color [1] Straight Flush Any 5 consecutive cards in the same color [2] Four of the kind Four cards with the same high. Full House Three cards with the same high and other 2 cards the same high Flush 5 cards in the same color Straight Any 5 consecutive cards. [2] Three of the kind Three cards with the same high. Two Pairs 2 cards with the same high and other 2 cards with the same high Pair 2 cards with the same high High Card Any other set of cards Notes: [1] T - means 10 [2] A is one higher than K or one lower than 2, but not both. That is, AKDJT and 5432A are consecutive card sets, but 32AKD is not. Input & Output In the STDIN the set of 5 cards will be given. The set will be given in 4 lines for each color. For each color there will be not sorted set of cards. /^([AKDJT98765432]{0,5}\n){4}\z/ The set contains always 5 cards. All the given sets are valid. On the standard output the name of best set shall be given.

12.1.2. Solutions 179, Mtv Europe (post-mortem) -lp0 $_=Straight x A23456789TJDKA=~/[$_]{5}/.Flush x!/. +./||(X,FourX,HighCard,Pair,TwoPairs,ThreeX,FullHouse)[map$x+=$#$_++,/./g];$'|| s/.+t/Royal/;s/\B[A-Z]/ $&/;s/X/of the kind/ 181, Michal Szafranski -lp0 $x+=$#$_++for/./g;$_=Straight x A23456789TJDKA=~/[$_]{5}/.Flush x!/. +./||(X,FourX,HighCard,Pair,TwoPairs,ThreeX,FullHouse)[$x];$'||s/.+t/Royal/;s/\ B[A-Z]/ $&/;s/X/of the kind/ 184, Piotr Fusik

Edition 2007-01-09 top secret / strictly confidential page 476 of 520 Perlgolf History

-lap0 $_=A23456789TJDKA;s!.!map/$&/,@F!eg;$_=(Full_House,Two_Pairs,(/3/?Three:Four )._of_the_kind,Pair,$'.$#F?Straight:Royal,High_Card)[/1{5}/^~chop^y/14//]._F lush x!$#F;s/.+d_//;y/_/ / 245, Maciej Misiak -lap0 @x=map{1+(@c="@F"=~/$_/g)}A,2..9,T,J,D,K,A;$_=(split/,/,"High Card,,Flush,Pair,Three of the kind,Four of the kind,Two Pairs,Full House".(',Straight'x3)." Flush,Royal Flush")[/[A-Z]{5}/+/.{5}/*2+8*"@x"=~/2( 2){4}/+map{1..$_>2&&$_}@x[1..15]] 250, Mateusz Matuszek -lp0 y/TJDKA/:-?/;$H[++$A[ord]]++for/./g;$A[49]=$A[62];$R=join'',@H[2..4];"High Card1Pair2Two Pairs11Three of the kind111Four of the kind21Full House"=~/$R(\D+)/;$_=($1,$f=Flush,$s=Straight,"$s $f","Royal $f")[/[:- ?]{5}/*4||"@A"=~/( 1){5}/*2+/\S{5}/] 277, Przemysław Kowalczyk -lp sub p{$_=join'',sort/./g}y/ATJDK/1A-D/;$z.=p.$\}sub r{/.+/,4660==hex($&)%69905}{$_=$z;$_=/1ABCD/?Royal40:&r?140:/.{5}/?0:p&&s/(. )\1+/chr length$&/ge?/\004/?Four2:/\003/?/\002/?Full4House:Three2:/\002.*\002/?Two43s :3:r|/1ABCD/||High4Card;s/\d/(Flush,Straight,' of the kind',Pair,$")[$&]/ge 297, Wawrzyniec Żurowski -plaF// $K=AKDJT98765432A;$W[@F>4?$K=~/[@F]{5}/?/A/&&/K/?9:8:5:0]=$S.=$_;$a{$_}++for @F}{$W[2**($_-1)-1]=$V.=$_ for sort values%a;$W[$V=~/2(2|3)/?$1*4- 6:4*$K=~/[$S]{5}/]=$o=" of the kind";$_=("High Card",Pair,"Two Pairs","Three$o",$n=Straight,$f=Flush,"Full House","Four$o","$n $f","Royal $f")[$#W]

12.2. PCLP #5.2 PIGOLF Master: Maciej Misiak (grizzley) 28.02.2006 14.03.2006

12.2.1. Rules Display on the screen 1000 digits of π. Output One single line matching /^\d{1000}\z/, starting with 314159.

12.2.2. Solutions 77, Ton Hospel (post-mortem) ($c,@0)=map P|($c=$c%($d=10+20*$?).0+$_*$?)/$d,@0while$?-=@0[0,1e3]=3;print@0 78, Rick Klement ($c,@0)=map P|($c=$c%($d=20*$?+10).0+$_*$?)/$d,@0while@0[0,1e3]=3,--$?;print@0 78, Ton Hospel print!s!\w+!$\=($z=$&.0+$?--*$\)/++($b=2*$?||239)|0;$z%$b!egfor(-48x65536)x1e3 97, Mateusz Matuszek

Edition 2007-01-09 top secret / strictly confidential page 477 of 520 Perlgolf History

@a=(2)x3888;for$m(@q=(7x4)x1000){$_=($^F=($^F/=$m--)*$m/2+lc)%-- $m.0for@a;s!.?0*9*$!$&.0+$^F!e}print 109, Przemysław Kowalczyk map{$$_=(($-*=-$_)+=$e?$$_.e4:2e7)%($%=$_*-2-1),$-/=$%for$_*14+1..- 1;printf'%04d',$e%1e4+($e=$-)/1e4}-250..-1 119, Maciej Misiak $k=4e3;$_='0 'x1e3;$q=!s!!($q=$q%($p=1+2*$k).0+$&*$k)/$p|0!egwhile$k- =s!\d+!2!;1while s/\d 1(?=\d)/1+$&.$"/e;print/\d/g 119, Robert Szczygiel @a=(2)x3332;eval'$p=6x4;$_=($x=$_.0+$=*$p--/2)%$p,$==$x/$p-- for@a,$^F;$^F=chop$=;$=<10?$_.=$=:s/.9*$/$&.9+1/e;'x1e3;print 126, Zbigniew Hałas for(-250..-1){$_*=-14;$d=$h*$_+1e4*($e?$f[$_]:2e3),$h=int$d/--$g,$f[$_]=$d%$g while$g=--$_*2;printf"%04d",$e+$d/1e4,$e=$d%1e4} 130, Jacek Fedorynski for(@a=(2e3)x($c=3514);$b=$c-=14;printf"%04d",$e+$d/1e4){for($e=$d%1e4;$g=-- $b*2;$d=int$d/$g){$d=$d*$b+1e4*$a[$b],$a[$b]=$d%--$g}} 131, Wojciech Kurowski for(@f=(2e3)x($c=3514);$b=$c-=14;printf"%.4d",$e+$d/1e4,$e=$d%1e4){@f[$b-- ]=($d=$d*$b+@f[$b]*1e4)%($,=2*$b-1),$d=int$d/$,for 1..$c} 136, Rafał Roppel for($c=3514,$f=1e4;$b=$c- =14;$h=printf"%.4d",$e+$d/$f){$e=$d%=$f;$d=$d*$b+$f*($h?$a[$b]:$f/5),$a[$b]= $d%--$g,$d=int$d/$g while$g=--$b*2} 143, Andrzej Jackiewicz $r=1e3;@a=($b=2)x1e4;for(0..333){for($k=$#a;$k;$q=$k-- *int$q/$t){$q+=$a[$k]*$r;$t=2*$k+1;$a[$k]=$q%$t}printf("%0*d",$d,$b+$q/$r);$ b=$q%$r;$d=3} 160, Paweł Siennicki $a=1e4;$c=3500;@f=(2e3)x$c;while($c){$-;$g=2*($b=$c);while($b){$- +=$f[$b]*$a;$f[$b--]=$-%--$g;$-/=$g--;if($b){$-*=$b;}}$c- =14;printf("%.4d",$e+$-/$a);$e=$-%$a;} 251, Zbigniew Kempczyński sub p{-- $n,return$v==10?0:9if$n;for(;;){$q=0;$i=$#a;$p=6665;while($i){$x=10*$a[$i]+$ q*$i;$q=$t=int$x/$p;$a[$i--]=$x%$p;$p-=2;}$a[1]=$t%10;$v=int$t/10;++$n,next if$v==9;($s,$e)=($v==10)?($e+1,0):($e,$v);last;}$s;}@a=split//,2x3334;for(0. .1000){print p}

Edition 2007-01-09 top secret / strictly confidential page 478 of 520 Perlgolf History

13. Games – Fonality http://www.fonality.com/golf/

13.1. Fonality 1 - Roman Numeral Calculator

13.1.1. Rules In a nutshell, this is a Roman Numeral Calculator. The program will take a single line of input containing upper-case Roman Numerals with the words " plus " or " minus " between them. The challenge is to create a Perl program in as few characters as possible to perform the calculation and print out the answer in Roman Numerals back to the screen. The program is a filter: it must read from STDIN, and send output to STDOUT. • Input will consist of a single line, which will match /\A[IVXLCDM]+( (plus|minus) [IVXLCDM]+){1,3}\n\z/. This means that the input will consist of three to seven words separated by single spaces. • The input will be between two and four upper-case Roman Numerals between I and MMMCMXCIX (1 to 3999) joined by plus or minus, all separated by a single space. Your program need not test the input for validity, and its behavior on invalid input is not important. • The output should be a single line, matching /\A[IVXLCDM]+\n\z/, and be the Roman Numeral representation of the calculation. The output will be between I (1) and MMMCMXCIX (3999). • Roman Numerals will always be in upper-case and in short-hand form. For example, you will always receive an input of "IV" rather than "IIII". You must also always output "IV" rather than "IIII". • At no time during the various math operations will a number be less than I (1) or greater than MMMCMXCIX (3999). That means you will never have a calculation such as "I minus V plus X". Even though the output is >= I (1) and <= MMMCMXCIX (3999), during the process (I minus V) becomes < I (1) which is not allowed. • You may not use any Perl modules. • Anyone, anywhere is able to play and win! • More information on Roman Numerals can be found at Wolfram MathWorld1. Roman Numerals I=1 C=100 V=5 D=500 X = 10 M = 1000 L=50 Example

1 http://mathworld.wolfram.com/RomanNumerals.html

Edition 2007-01-09 top secret / strictly confidential page 479 of 520 Perlgolf History

$ perl romancalc.pl in: I plus I out: II $ perl romancalc.pl in: MDCCCXXIV plus DCCVI out: MMDXXX $ perl romancalc.pl in: MCCXIII minus LXIV plus MMDXXX out: MMMDCLXXIX $ perl romancalc.pl in: MMXIX plus MCCCXCVI minus DCXCV plus CI out: MMDCCCXXI

13.1.2. Solutions 99, ton -pl s!.!y$IVCXL426(-:$XLMCDIVX$dfor$$_.=5x$&*8%29628;$$$_=$_!egfor-4e3..y/iul- }/-$+ /%s''$';*_=eval 102, Juho Snellman -pl $_=${s!.!y$XLIVC246,-:$CDXLMVIX$dfor$$_.=8x$&*5%29628;$$$_=$_!gefor- 4e3..s''$'/y/isl-~/-$+/d;eval} 107, TedYoung -lp y,iul-~,-$+,d,$_=eval,${$@}=1..!s/./y@IVCXL91- :0@XLMCDXVIII@dfor$@.=4x$&%1859^7/egfor$...4e3,u.$_;$_=$@ 111, jojo -pl s|.|y;CLXVI624.-=;MDCLXXVI;dfor$$_.=5x$&*8%29628;$&|ge,$$$_=$_^Kfor- 4e3..o;s;\w+;${$&}|$&&'-';ge;$_=${+eval} 111, jojo -pl s,.,y;CLXVI624+-=;MDCLXXVI;dfor$$_.=5x$&*8%29628;$&,ge,$$$_=$_^Kfor- 4e3..o;s;\w+;${$&}|$&&'-';ge;$_=${+eval} 114, szeryf -pl @;=map{$a=0;($a.=4x$_%1859^7)=~y!IVCXL91- 80!XLMCDXVIII!dfor/./g;$$a=$_;$a}s''$'>y/isl-{/-$+ /..4e3;$_=$;[eval] 118, pijll -pl y/i-z/-+/s;for$a(1..4e3){$a=~s#.#($n[$a].=4x$&%1859^7)=~y$IVCXL91- I0$XLMCDXVIII$d;s/\b$n[$a]\b/$a/g#ge}$_=$n[eval] 119, Sec -lp @%=map{my$a;s/./y!IVCXL91-80!XLMCDXVIII!dfor$a.=4x$&%1859^7/eg;$$a=$/-- ;$a}0..4e3;y/i/-/;s/\w+/${$&}/g;$_=$%[-eval] 122, eyepopslikeamosquito -lp sub'_{$;=0;($;.=5x$_*8%29628)=~y$IVCXL426.-X$XLMCDIVX$dfor/./g;$;}y;mp;- +;;s>\w+>(grep$&eq&_,1..1e4)[0]>eg;$_=_$_=eval 125, Jasper -lp map{y/IVXLC/XLCDM/,s!\d!$&^4?$&^9?V x($&>3).I x($&%5):IX:IV!ewhile//;$$_=$n++}@d=0..4e3;y/m/-/;s/\w+/+${$&}/g;$_=$d[eval] 129, Util

Edition 2007-01-09 top secret / strictly confidential page 480 of 520 Perlgolf History

-lp $==$_,s!.!y$IVCXL91- I0$XLMCDXVIII$dfor$_[$=].=4x$&%1859^7;5!egfor+0..3999;@&{@_}=0..@_;y/il-z/- +/d;s/\w+/$&{$&}/g;$_=$_[eval] 130, jchsw map{y/IVXLC/XLCDM/,s//$&-9?$&-4?I x$&:IV:IX/e,s/I{5}/V/while/\d/;$$_=$i++}@n=0..4E3;$_=<>;y/pm/+- /;s/\w+/${$&}/g;print"$n[eval]\n" 135, Daniel Tuijnman -pl s#\d#$@+=$.*$&*(2gt$'^$`=~/m[^p]*$/||-1),""#ge,$..=0while y/MDCLXVI/CLXVI51/;$@=~s!.! $_.=4x$&%1859^7;y$IVCXL91-z 0$XLMCDXVIII$d!eg 137, ambrus -lp sub k{my$t;$t=~y/IVXLC/XLCDM/,$t.=("",I,II,III,IV,V,VI,VII,VIII,IX)[$_]for/./g;$ $t=$_;$t}y/iul-z/-$+ /;k for 1..4e3;$_=k$_=eval"\$$_" 143, DWilson -alp sub r{$#='';s!.!y$IVCXL91- I0$XLMCDXVIII$dfor$#.=4x$&%1859^7;5!eg;$#}%%=map{$~=$_;r,$~}1..3999;y$mp^- ~$-+$d||($_=$%{$_})for@F;$_=eval"@F";r 145, Shlomi Fish -lp sub f{split//;reverse map{(/./g)[map{vec'\xff\xfc\xf0\xc0\xf1\xfd\xf4\xd0@\xf2',$_++,2}(4*pop)x4]} qw(IVX XLC CDM M)}y/pm/+-/;s!\w+!(grep$&eq f,1..4x4)[0]!ge;$_=f$_=eval 147, mmultima -pa $_=${{map{$q+=$u{$t=$_}*$*;$*=5-/m/;s/./--$*x!($&%5- 4).($*+4**($&<9))x($&>3).$*x($&%5&3)/ge;y/1- 7/IXCMVLD/;$u{$_}=$t+0,$_}$|x4..4x4,@F}}{$q}.$/ 148, Honza Pazdziora -lp ($c=F1000M900CM500D400CD100C90XC50L40XL10X9IX5V4IV1I)=~s/\d+(\D+)/${$$1=0 x$&}=$1,"|$$1|$1"/eg;sub p{s!$c!${$&}!g}p;1while s!\D+|(0+) m\D+\1!!;p 155, tybalt89 -lp ++$I;$$_=$.*=$^F^=7for@@=VXLCDM=~/(.)/g;s//pm1=~$&?$-=$':$%+=$$1<${_&$'}^$- ?-$$1:$$1/ge;$_=I x$%;$I+=2while+s/(.)\1{3}(\1{5})?(\1?)/$1x!$+.$@[$I^!$2]/ge 166, SubStack -lp @r{map@q{$_}=I x(10,9,5,4)[$@%4]x10**int 3- ++$@/4,@s}=@s=MCMDCDCXCLXLXIXVIV=~/(.)(..)/g;1 while$"="|",s/@s|[^mpI]/$q{$&}/g+s/p|(I+)m(I+)/$1^$2/e;s/@q{@s}/$r{$&}/g 169, m.wrenn -lp @@{@@=map{$_,$_.0,$_*100}4,5,9,10}=qw(IV XL CDVLDIXXCCMXC M);for$~(@@){s/$@{$~}/"I "x$~/ge}s/I//while s/m\w* +I/m /;$~=y/I//cd;s/I{$~}/$@{$~}||$&/gewhile$~-- 170, `/anick

Edition 2007-01-09 top secret / strictly confidential page 481 of 520 Perlgolf History

-lp040 $s=/m/ if/u/;($y=I1V5X10L50C100D500M1000IV4IX9XL40XC90CD400CM900)=~/$&/,$i=$t+=$s^"$;" >($;=$')?-$;:$;while s/.$//}{1while$y=~/(\D+)$i/&&$t>=$i?($_.=$1,$t-=$i):$i-- 172, sf -pl %v=@a=M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1=~/\d+|\D+/g;$n+=/m/../ p/?-$v{$_}:$v{$_}for/C[MD]|X[CL]|I[XV]|./g;$_<1?$s=$_:$n<$_||($r.=$s,$n- =$_,redo)for@a;$_=$r 174, grizzley -pl sub f{s/[-+]\d/$&0/g;s/C(?=[MD])/- 1/g;s/M/DD/g;s/D/+5/g;y/XCVLpIx/CMLDIX/}y/mpi-u/-+ /;s/\w+/($&)/g;f;f;f;s/M/+1/g;$_=eval;f,s/IIII/IV/,s/IVI/V/while s/\d/$&-9?p x$&:px/e 176, carldr -p for($i=4e3;$j=-- $i;){for$y(3,2,1,0){map{$e=$m[$i].=(M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I)[- 3+$f++%16]x($j/($u=$_*10**$y));$j%=$u}(9,5,4,1)}s/\b$e/$i/g}y/pma-z/+- /d;$_="$m[eval] " 178, Lester/Krawczyk -lpa sub e{$z=I x$t;/\d+/,eval"\$z=~s/$`$`\{$&\}/$'/g"for I9X,X9C,C9M,C8CM,C4D,C3CD,X8XC,X4L,X3XL,I8IX,I4V,I3IV;$z}for$t(1..4e3,0){$x{&e} =$t}$t+=($.=/p/-/n/||$.)*$x{$_}for@F;$_=e 182, pengvado -alp use utf8;y/IVXLCDM/^A^E 2d\xc7\xb4\xcf\xa8/,$%=/s/?/m/:s/./$:+=("$&\xcf\xbf"lt$'^$%||- 1)*ord$&/sgefor@F;$,=(($^=1+chop$:)%5?"":$_).($^>4&&int$_+$^/5).$_ x($^%5- 1).$,for 0,2,4,6;$_=$,;y/0-6/IVXLCDM/ 186, davidrw -lp @V{@I=(M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I)}=unpack w13,'\x87h\x87^D\x83t\x83^PdZ2( ^E^D^A';y/i-u/- +/s;s/\w+/($&)/g;s/C[MD]|X[CL]|I[VX]|\w/+$V{$&}/g;$d=$_=eval;for(@I){$#.=$_, $d-=$/while$d>=($/=$V{$_})} 186, Andy Lester -pla %n=I1V5X10L50C100D500M1000=~/(.)(\d+)/g;sub d{$#_-=$z*2*(@_&&$z<$_)-($z=$_)for@n{/./g};@_}$t+=($.=/p/-/n/||$.)*d for@F;map{$s.=$_ x($t/d),$t%=d}M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I;$_=$s 189, alankila -pliIV4IX9XL40XC90CD400CM900I1V5X10L50C100D500M1000 $^I=~s!\D+!$={$==+$'}=$&;s/$&/+$=/g!ge;y/ipul-s/- )(+)/d;$_=eval"($_)";$==10**y///c;s!.!$={$&*($=/=10)}||($&>5&&$={5*$=}).$={$ =}x($&%5)!ge 195, Venky Iyer

Edition 2007-01-09 top secret / strictly confidential page 482 of 520 Perlgolf History

-pla @v=(M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I,10,9,5,4);sub R{$s=1x$_[0];map{$A=$v[13+$_%4]*10**(2- int$_/4);$s=~s/1{$A}/$v[$_]/g}0..12;$s}@s=map{/m/?'-':/p/?'+':grep{$' eq R$_}//..4e3}@F;$_=R eval"@s" 206, sgifford -lp sub g{s/\d/$_[-$&]/ge for my@l=(1,11,111,12,2,21,211,2111,13);$#_- =2;@_&&(@l,map{my$y=$_;map{$y.$_}('',@l)}&g);}@A=('',g(K,G,M,D,C,L,X,V,I));t r/pm/+\-/;s/\w+/(grep{$A[$_]eq$&}(0..@A))[0]/ge;$_=$A[eval]; 206, explorer -lp %r=@r='M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1'=~/(\D+)(\d+)/g;$"=1; map{$"=/p/?1:/m/?- 1:s/CM|CD|XC|XL|IX|IV|\w/$?+=$"*$r{$&}/ge}split;$?=~s/./y!IVCXL91- I0!XLMCDXVIII!dfor$a.=4x$&%1859^7/eg;$_=$a 225, Tom Hargreaves -p @a='IVXLCDM'=~/./g;for$g(0,2,4){map{s/[012]/\$a[$&+$g]/g;eval"unshift\@b,[$_ ];push\@d,[reverse$_]"}@w=qw<1,0x5 0.1,0x4 2,1.1 0.2,1.0.1>}sub c{for$m(@_){s/$m->[0]/$m->[1]/g}}c@b;1while s/^(I+) plus /$1/+s/(I+) .{5} \1//;c@d 229, mjskier -lp %T=qw/I 1 IV4V5IX9X10XL40L50XC90C100CD400D500CM900M 1000 plus 0)+( minus 0)- (/;$P=join'|',sort{$T{$b}<=>$T{$a}}keys%T;s/$P/'+'.$T{$&}/eg;$_=eval"($_)";s !.!y$IVCXL91-I0$XLMCDXVIII$dfor$#.=4x$&%1859^7;5!eg 231, shmem -lp y/pma-z/+- /d;s/\w+/($&)/g;$c=.5;@l=IVXLCDM=~/./g;for$i(0..6){$c*=$i%2?5:2;s/$l[$i]([@l [$i+1,$i+2]])?/($1?'-':'+').$c.$1/eg}$_=I x eval;for$i(- 1..4){$u=$i%2?5:2;($c,$d,$e)=@l[$i..6];s/($d){$u}/$e/g;s/($d)?$c{4}/$c.($1?$ e:$d)/eg} 232, femto %H=@H='M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1'=~/(\D+)(\d+)/g;$_=<>;s/ m\w+/-/g;s/p\w+/+/g;s/\w+/($&)/g;s/CM|CD|XC|XL|IX|IV/- $&/g;s/\w/"+$H{$&}"/ge;$n=eval;for(grep{/\D+/}@H){while($n>=$H{$_}){$s.=$_;$ n-=$H{$_};}}print"$s\n" 232, C_Is_Better -alp @v=(M1000,CM900,D500,CD400,C100,XC90,L50,XL40,X10,IX9,V5,IV4,I1);/(\D+)/;map {$n=$_,$i=0;$o=/p/?1:/m/?-1:$o;grep{s//$a+=($o||1)*$',$i+=$0while substr($n,$i,$0=length$1)eq$1/e}@w=@v}@F;grep{s//$z.=$1,$a-=$' while$a>=$'/e}@v;$_=$z 236, rir -pl push@a,{split/([(-5]+)/,'I1V5X10L50C100D500M1000p)+(m)-('}->{$_}for split'';while ($i<=$#a){for($a[$i]){$_*=-1if$_+0&&$a[$i+1]>$_;$_='+'.$_ if$_>0;$i++;}}$_=eval join'','(',@a,')';s!.!y$IVCXL91- I0$XLMCDXVIII$dfor$#.=4x$&%1859^7;5!eg 237, jql

Edition 2007-01-09 top secret / strictly confidential page 483 of 520 Perlgolf History

-lp y/IXCMVLDpmslia-z/0123456))(+-/d;s// /g;s/\d/qw(+ - )[$'%4>=$&&$'>$&].10**($&&3)*($&<4||5)/eg;$_=join"",map{(4- $x++)x$_}split//,eval"1000+($_)";s/([^4])(\1{3}(\1{1}(\1{4})?)?)/$4?$1.($1+1 ):$3?$1+4:$1.(4+$1)/eg;y/1234567/IXCMVLD/;s/.// 238, mreece -lpa %r=qw(I1V5X10L50C100D500M1000);sub a{$l=1000;$n=0;for(split//,shift){$d=$r{$_};$l<$d&&($n- =2*$l);$n+=$l=$d}$n}sub R{$_=a shift;$_+=a(pop)*(pop=~/p/||- 1)while@_;s;.;y$IVCXL91-I0$XLMCDXVIII$dfor$I.=4x$&%1859^7;eg;$_=$I}R@F 241, Pete Krawczyk -alp sub a{$_='I'x$_[0];for$z(qw(I10X X10C C10M C9CM C5D C4CD X9XC X5L X4XL I9IX I5V I4IV)){$z=~/(.)(\d+)(.*)/;eval"s/$1\{$2\}/$3/g"}$_}for$b(1..4e3){$x{a($b)}=$ b}$c=$x{$F[0]};for$p(1,3,5){$y=$x{$F[$p+1]};$c+=($F[$p]ne'plus'?- $y:$y)}$_=a($c) 241, miraso sub a{($c)=@_;join'',map{$e=int($c/$n{$_});$c-=$n{$_}*$e;$_ x$e}@a}$n=M1000CM900D500CD400C100XC90L50XL40X10IX9V5IV4I1;@a=$n=~/\D+/g;@n{@ a}=$n=~/\d+/g;%m=map{a($_),$_}1..4000;$m{plus}='+';print a(eval join'',map{$m{$_}||'-'}split' ',<>)."\n" 247, dcutter -an @a=qw(IV IX XL XC CD CMMDCLXV);@b=qw(I VI X LX C DC DD CC LL XX VV II);s/[IXC]\b/$&x4/e for@b;for(@F){for$f(0..12){s/$a[$f]/$b[$f]/g}}($r)=@F;$d++,/p/and$r.=$F[$d]o r$r=~s/$F[$d]//for@F;for($f=12;$f-->0;){$r=~s/$b[$f]/$a[$f]/g}print"$r\n" 248, dirving -n @c=(M,D,C,L,X,V,I);$n=5e3;%v=map{$_,$n/=$z++%2?2:5}@c;for(split''){$.=- /m/||/p/||$.;$c=$v{$_};$t+=($l<$c?- $.:$.)*$l;$l=$c}for(@c){$i++;$p=int$t/$v{$_};$t%=$v{$_};push@o,$p>3?$o[- 1]eq$c[$i-2]?do{pop@o;$_,$c[$i-3]}:($_,$c[$i-2]):$_ x$p}print@o," " 252, lumpshiper -pl %r=reverse%n=split/(\d+)/,'I1V5X10L50C100D500M1000';s#.#$c=$n{$_=$&};$i+=($o =/p/<=>/m/||$o||1)*($c-2*$t*($t<$c));$t=$c#eg;$i- =$_*($j=int$i/$_),$x.=$j==4?/100/?'CD':/10/?'XL':'IV':$r{$_}x$j for sort{$b<=>$a}keys%r;$_=$x;s/VIV/IX/;s/DCD/CM/;s/LXL/XC/ 255, Snowhare %t=map{r($_),$_}1..3999;$_=<>;s/m\S+/-/g;s/plus/+/g;s/\b(\S+)/$t{$1}/g;print r(eval)."\n";sub r {($d,$o)=@_;@l=qw(QQQMCMDCDCXCLXLXIXVIV I);$s=1000;while(@l){foreach $v qw(9 5 4 1){$q=shift @l;$n=$s*$v;while($d>=$n){$o.=$q;$d-=$n}}chop $s}$o} 270, ciscoqid -an @t=(IV,4,IX,9,I,1,V,5,XL,40,XC,90,X,10,L,50,CD,400,D,500,CM,900,C,100,M,1e3) ;for(@F){$e.=/m/?'- ':/p/?'+':sub{for($i=0;$i<26;$i+=2){s/$t[$i]/"$t[$i+1]+"/ge};"($_ 0)"}- >()}$n=eval$e;for(sort{$b<=>$a}keys%{$t={reverse@t}}){while($n>=$_){$o.=$$t{ $_};$n-=$_}}print"$o\n"; 275, BasharTeg

Edition 2007-01-09 top secret / strictly confidential page 484 of 520 Perlgolf History

-nl %_=(I,1,V,5,X,10,L,50,C,100,D,500,M,1000,CM,900,CD,400,XC,90,XL,40,IX,9,IV,4 );$l=split//;$o=1;while($i<$l){$_=$_[$i];$o=/m/?- 1:/p/?1:$o;$_=$_{$_};$y=$_{$_[++$i]};$_=$y- $_,$i++if$_&&$_<$y;$a+=$_*$o}map{$s.=$_,$a-=$_{$_}while$a>$_{$_}- 1}sort{$_{$b}<=>$_{$a}}keys%_;print$s; 298, dr -lp split'','IVXLCDM';y~m A-Z~~cd,s~m (\S+)~- ($1)~g;for$b(0..3){$d=10**$b,$b*=2;do{for$s(1,2){s~$_[$b]$_[$b+$s]~- $d+5*$s*$d~g,s~$_[$b+1]~+5*$d~g}}if$b<6;s~$_[$b]~+$d~g}$k=eval,$_='';do{$t=1 0**$p,$f=2*$p++;s~^~($i=chop$k)%5==4?$_[$f].$_[($i>4?2:1)+$f]:$i>4?$_[$f+1]. $_[$f]x($i-5):$_[$f]x$i~e}while$k 309, solo -an @v=(1000,500,100,50,10,5,1);@q=('',qw(0 00 000 01 1 10 100 1000 02));@r=qw(IVX XLC CDM M);for(@F){if(/(n|p)/){$o=$1;next}$l=$s=0;for(split//){$r=index('MDCLXVI',$_ );$s-=2*$v[$l]if$r<$l;$s+=$v[$r];$l=$r;}$t+=$o=~/n/?- $s:$s;}$i=length$t;for(split//,$t){$i-- ;$_=$q[$_];eval"y/012/$r[$i]/";$z.=$_;}print$z.$/; 313, TeamSPAM -lp %r=(I,1,IV,4,V,5,IX,9,X,10,XL,40,L,50,XC,90,C,100,CD,400,D,500,CM,900,M,1E3) ;while(s/(\w+) (\w+) (\w+)/d(r($1)+(-1,1)[$2eq plus]*r($3))/e){}sub r{$o=$d=0;for(split(//,pop)){$n=$r{$_};$d+=($n>$o)?$n-2*$o:$n;$o=$n;}$d;}sub d{my$s;for(sort{$r{$b}<=>$r{$a}}keys%r){while($_[0]>=$r{$_}){$_[0]- =$r{$_};$s.=$_;}}$s;} 325, tryit -n @d=grep/\d/,(@m=split/((?:\d+|[A- Z]+))/,'4IV9IX40XL90XC400CD900CM1I5V10X50L100C500D1000M');@r=grep/[A- Z]/,@m;@v=split/0/,'M0CM0D0CD0C0XC0L0XL0X0IX0V0IV0I';@q=sort{$b<=>$a}@d;s/ m\S+ (\w+)/-($1)/g;for$n(0..12){s/$r[$n]/+$d[$n]/g}s/ \w+ //g;$t=eval;for(0..12){$b=int($t/$q[$_]);if($b){print$v[$_]x$b;$t- =$b*$q[$_]}}print"\n" 349, NumberCruncher @o=<>=~/(\S+)/g;%r=(I=>1,V=>5,X=>10,L=>50,C=>100,D=>500,M=>1000,IV=>4,IX=>9,XL= >40,XC=>90,CD=>400,CM=>900);foreach$e(@o){@d=$e=~/(.)/g;$c=$r{shift@d};$x=$# d>-1?0:$c;map{$n=$r{$_};$x+=$n>$c?-$c:$c;$c=$n}@d;$x+=$n;$s.= $x>0?$x:$e=~/plus/?"+":"- "};$z=eval$s;foreach$g(sort{$b<=>$a}values%r){while($z>=$g){print grep{$g==$r{$_}}keys%r;$z-=$g}}print"\n"; 391, derek_smalls

%x=(1,1,2,11,3,111,4,12,5,2,6,21,7,211,8,2111,9,13);@y=(z,zIVX,zXLC,zCDM,zMM M);@A=split(/\s+/,<>); sub c{$d=shift;my$r;foreach$p(4,3,2,1){map{$r.=substr($y[$p],$_,1)}(split(//,$x{ (split(//,$d))[-$p]}))};[$r,$d]}; sub f{$v=shift;map{if(c($_)->[0]eq$v){return $_}}(0..4000)}; $t+=f($A[0]);map{if($A[$_]=~/p/){$t+=f($A[$_+1])}elsif($A[$_]=~/m/){$t- =f($A[$_+1])}}(1..$#A);print c($t)->[0]."\n"; 437, jimbo

Edition 2007-01-09 top secret / strictly confidential page 485 of 520 Perlgolf History

%t=(0,':0:0:0:0:0',1,':I:X:C',2,':II:XX:CC',3,':III:XXX:CCC',4,':IV:XL:CD',5,': V:L:D',6,':VI:LX:DC',7,':VII:LXX:DCC',8,':VIII:LXXX:DCCC',9,':IX:XC:CM');for $i(1..16384){$x{rt($i)}=$i}$_=uc;chomp;@a=split/ /;$t=shift@a;$u=$x{$t};while(@a){$o=shift@a;$b=shift@a;$u+=($o=~/^P/?$x{$b}: $x{$b}*-1)}sub rt{@r=split//,$_[0];$z='';while(@r){$y=shift@r;$y+=10if(@r>3);$z.=(@r>2?'M'x $y:(split/:/,$t{$y})[@r+1])}$z=~s/0//g;$z}print rt($u)."\n" 461, cdman83 %b=(0,'');sub a{$j=0;$b{$c*++$j} = $_ for@z;}$c=1;@z=qw{I II III IV V VI VII VIII IX};a;$c*=10;@z=qw{X XX XXX XL L LX LXX LXXX XC};a; $c*=10;@z=qw{C CC CCC CD D DC DCC DCCC CM};a;$c*=10;@z=qw{M MM MMM};a;foreach(1..3999) {next if($b{$_});@d=reverse split //,$_;$b{$_}=$b{$d[3]*1000}.$b{$d[2]*100}.$b{$d[1]*10}.$b{$d[0]};}%e=();$e{$ b{$_}}=$_ for keys%b;$g=0;$h=1;foreach(split /\s+/,<>){$h=1 if(/p/);$h=-1 if(/min/);$g+=$e{$&}*$h if(/[A-Z]+/);}print $b{$g}."\n"; 486, Friar %h=(M=>1000,D=>500,C=>100,L=>50,X=>10,V=>5,I=>1);%r=reverse%h;sub plus{$v+=shift}sub minus{$v-=shift}sub i{$b=$w=0;split//,reverse shift@n;for(0..$#_){$x=$h{@_[$_]};$b+=$x<$w?- $x:($w=$x);}$b}$_=<>;s/\+/plus/;s/- /minus/;@n=split;$v=i();while(int@n){$f=shift@n;&$f(i())}@n=split//,$v;while (defined($v=shift@n)){$v*=10**int@n;for(sort{$b<=>$a}keys%r){$k=$r{$_};m/^(. )/;$g=$r{$_/($1==1?10:5)};while($v>$_){$o.=$k;$v- =$_}if($v==$_){$o.=$k;last}if($v+$h{$g}==$_){$o.=$g.$k;last}}}print"$o\n"; 488, reveng -l sub a{$@=pop;$a=0;$l=1e3;for(split//,$@){$d=$r{$_};$a-=2*$l if$l<$d;$a+=($l=$d)}$a}%r=qw(I1V5X10L50C100D500M1000);%Z=qw(1 IV 10 XL 100 CD 1000 MMMMMM);@f=reverse sort keys%Z;grep($Z{$_}=[split(//,$Z{$_},2)],@f);sub R{$y=pop;for(@f){($d,$i,$v)=(int($y/$_),@{$Z{$_}});if(1<=$d&&$d<=3){$r.=$i x$d}elsif($d==4){$r.="$i$v"}elsif($d==5){$r.=$v}elsif(6<=$d&&$d<=8){$r.=$v.$ i x($d-5)}elsif($d==9){$r.="$i$@"}$y- =$d*$_;$@=$i}$r}$_=<>;s/plus/+/g;s/m\w+/-/g;s/\w+/a$&/eg;print R+eval 493, corps -l @F=split' ',<>;@L=qw(IIII VIIII XXXX LXXXX CCCC DCCCC);@S=qw(IV IX XL XC CD CM);@Q=qw(IIIII VV XXXXX LL CCCCC DD);@R=qw(VXLCDM);sub x{index('MDCLXVI',"@_")}sub f{$_[0]=~s/$Q[$_]/$R[$_]/gfor(0..5)}sub a{$_[0]=~s/$S[$_]/$L[$_]/gfor(0..5)}$_=$F[0];while($F[$I+1]){a$_;a$F[$I+2];i f($F[++$I]eq'plus'){$_=join'',sort{x($a)<=>x($b)}split//,$_.$F[++$I];f$_}els e{++$I;while($F[$I]){$F[$I]=~s/$&//&&s/$&//while(/./g);for$i(0..5){s/$R[$i]/ $Q[$i]/g}}f$_}for$i(1..6){$i*=-1;s/$L[$i]/$S[$i]/g}}print

Edition 2007-01-09 top secret / strictly confidential page 486 of 520 Perlgolf History

14. Games – Perlmonks 14.1. MD5 Short implementation of MD5, http://perlmonks.org/?node_id=190213 #!perl -lp0777 sub n{unpack$_[0],pop}sub f{"@_"%2**32}@Y=n V4,n u,'0`2-%9XFKS>_^W+J8=E0R$';$_= pack'a*Bx8x!64X8VV',$_,1,8*y///c;s!\C{64}!$_='forK(0..3){(C,D,A,B)=@:=@:[-1..2] ,$:[1]=fA+((D=fD+(A&B|~A&C,A&C|B&~C,A^B^C,A|~C^B)[K]+V[K**2.55+(1+K+K%2*3)*_&15 ]+2**32*abs sin++$@)<<(N=31&n x.(K*4+_%4).c,glqvein4dkpwfjou)|D>>32-N)forE..15} _=f_+shift@:for@Y';@V=n V16,$&;@:=@Y;s/[A-V_]/\$$&/g;$_!eeg;$_=n H64,pack V4,@Y

14.2. Friday Golf: All 2-digit combinations http://perlmonks.org/index.pl?node_id=294388

14.3. Kaprekar Numbers http://www.perlmonks.org/?node_id=472564

Edition 2007-01-09 top secret / strictly confidential page 487 of 520 Perlgolf History

15. Games – Assorted Games from other places

15.1. Resistor Colour Codes

15.1.1. Rules From: [email protected] (Shabble) Newsgroups: comp.lang.perl.misc Subject: Anyone For Golf? (Resistor Colour Codes) Date: 16 Mar 2003 18:01:12 -0800 Message-ID: <[email protected]> For no good reason, I decided to write a resistor colour code translator in perl. Well, actually, it was to prove to a random heathen that it was easier and shorter than doing it in C++ (!) Anyway, after a brief attempt, I realised its something that could be quite small, and decided to trim it down. You can see the initial attempt, and my current work below. Rules: take 3 strings on the command line, space seperated, each being the name of a colour in the following list: #my % = ("black" => 0, "brown" => 1, "red" => 2, "orange" => 3, "yellow" => 4, "green" => 5, "blue" => 6, "violet" => 7, "grey" => 8, "white" => 9 ); Convert it to a number and print its value (and a \n) It should be fairly obvious from the code below how to calculate the value. --sample code-- my %colours = ("black" => 0, "brown" => 1, "red" => 2, "orange" => 3, "yellow" => 4, "green" => 5,"blue" => 6, "violet" => 7, "grey" => 8, "white" => 9 ); my ($band1, $band2, $band3) = @ARGV; $band1 = $colours{$band1}; $band2 = $colours{$band2}; $band3 = $colours{$band3}; my $futile = (($band1 * 10) + $band2) * (10**$band3); print "Resistance is $futile\n"; --shorter code (153 chars)-- @c=qw(bla brroygreebvgw);for(reverse@ARGV ){$i=0;while(1){if(/^\Q$c[$i]/i){push@x,$i;last}$ i++}}print((@x,pop(@x)*10+pop@x)*10**pop@x)."\n"; Any comments/suggestions/entries? Have Fnu! Shabble!

15.1.2. Solutions 62, jasper -l print map{.5*index acowdzanlleeueoleyit,/..(..?)/-&&$1}@ARGV 58, ton

Edition 2007-01-09 top secret / strictly confidential page 488 of 520 Perlgolf History

printf"%d%d%.*d ",map{vec crypt(rQdlz0,reverse),18,4}@ARGV

15.2. Factors

15.2.1. Rules Newsgroups: perl.golf Subject: Minigolf Date: Thu, 16 May 2002 00:23:37 +0000 (UTC) Organization: lunix confusion services Message-ID: From: [email protected] (Ton Hospel) Here's a small challenge that I set people on ircnet #perl: minigolf: write a program that, given argument n, prints to STDOUT the sum of the factors of n followed by a newline, e.g. "program 12" should print "16\n" (because factors 12 = 1 2 3 4 6. 1+2+3+4+6=16) (the number itself is not counted as a factor. the argument will be a positive integer >= 2, < 2**16). testcases: ([2,1],[6,6],[9,4],[12,16],[13,1],[15,9],[28,28],[65535,45921]) (the so called restricted divisor function) This is in fact unexpectedly challenging. A 43 is easy. A 40 is hard. Rick Klement won with a 39. But there exists in fact a 37 (at least, who knows what this list can find) ! How well can you do?

15.3. Sudoku Solver 2006-09-17 parts from http://markbyers.com/moinmoin/moin.cgi/ShortestSudokuSolver The following Perl program that can solve Sudoku is 121 bytes: $_=$`.$_.$'.<>;split//;${/[@_[map{$i-($i="@-")%9+$_,9*$_+$i% 9,9*$_%26+$i-$i%27+$i%9-$i%3}0..8]]/o||do$0}for/0/||print..9 Example usage: echo 0000100003014008609005002007001600000208050100000970040030040060480069070000 80000 | perl sudoku.pl The output is: 4526183793714298659865732417341625986298457138153976242937541861482369575679814 32 Notes: The program still works if ${...}for is changed to map{...} , saving one byte. However now the program can consume large amounts of memory: $_=$`.$_.$'.<>;split//;map{/[@_[map{$i-($i="@-")%9+$_,9*$_+ $i%9,9*$_%26+$i-$i%27+$i%9-$i%3}0..8]]/o||do$0}/0/||print..9 Contributors:

Edition 2007-01-09 top secret / strictly confidential page 489 of 520 Perlgolf History

• This program is a slightly modified version of another three line Sudoku Solver1 (page includes a description of how it works). • Mark Byers reduced it to 187 bytes. • Gordon McCreight reduced it to 186 bytes. • Pablo Carbonell2 reduced it to 181 bytes, and provided this comment: The difference with the original perl algorithm is that in this version I am taking in every iteration a slice @B with the values of the contiguous cells. The trickiest thing, I think, is the way this slice is used as a regular expression range in the grep. • Simon Stroh changed @A=split//,<> to $/=\1;@A=<> to reduce the program to 179 bytes. • Mitsuru Kariya changed @A[map{ ... }] to map@A[ ... ] to reduce the program to 178 bytes. • Ton Hospel shortened the program to 121 bytes.

1 http://www.ecclestoad.co.uk/blog/2005/06/02/sudoku_solver_in_three_lines_explained.html 2 http://personales.alc.upv.es/~pjcarbon/

Edition 2007-01-09 top secret / strictly confidential page 490 of 520 Perlgolf History

16. Around The Perl Golf 16.1. Maps Interactive perlgolf map by Sec, http://www.42.org/~sec/golf/map.html The red dots are Veterans, and the purple dots are Beginners.

16.1.1. World map

16.1.2. USA closeup

Edition 2007-01-09 top secret / strictly confidential page 491 of 520 Perlgolf History

16.1.3. Europe closeup

16.2. Participation Intensity

16.2.1. Terje’s Season 0

45

40

35

30

25

20

15

10

5

0

s p 1 lf s r ii s e er els ble ay c ex ing er es nge d 1 ting b l s nd xe y ums ep nc otes mma nces Forth tion e o go he r l golf ra Spiral A l s e ox ue te gtim umber ueeze o a isp bo w le r Beam" g Starma Ad G q s Sc Sou h F s al N e E s rev n s Ide " D ' Di s d frac r' lf s NA Card trick etric Digit tley b sic a e Power Crisis D o u ts L er Se mn D Roug Mine M is " ting sen d Clock patience LE som ming seq M r Spinningolu w " I m Vigenere Cipher olf ota O Canto C Crossing (s)words Strange Numbers olog R Modular Fibonacci Ha he illag ll roads leads where ? dz A Arc Linear Cellular Automata he Go T

Edition 2007-01-09 top secret / strictly confidential page 492 of 520 Perlgolf History

16.2.2. Terje’s Season 1

40

35

30

25

20

15

10

5

0

s e s r r t t r s t r g 2 n r et gle s n de he k uc dow te bag e tin a tc Nim lem 1227 r Hou he y og di e a gmen ric atio ition an gle s B Align 2 r rob a A Loopy prod ic Matrix Sha nve h ri re lindromel forr E M P fr d T o o a ED n r lif Rus Add T Cand Pa tic L a Sub r c y Mastermind Sc Perl Bowling U C imp r ma Permutations na matic to Huffman code x s mbe r nis e osephus Au Entropy compress J nu Ten nother 2D Perl Golf Rege Math Goldbach's Conjectu A et Mayan Y Balanced Te i - PERT/Gantt chart conversio evers R

16.2.3. Conclusion Easy tasks are more attractive.

16.3. Money

16.3.1. Career Money Leaders Newsgroups: perl.golf Message-ID: <[email protected]> Date: Wed, 20 Nov 2002 18:33:30 +1100 (EST) Subject: Career Money Leaders Update From: [email protected] (Andrew Savige) This month's leaderboard was more crowded than usual, resulting in some exciting sprints to the finish in both categories. Congratulations to Rick Klement and Stephen Turner on their joint victory in the open category, the first time the victor's spoils have been shared. I thought this was fitting because Rick and Stephen have often duelled before (I remember tpr04, where they were tied on 172.25 for quite a while, before Rick finally spurted clear). Not forgetting master beginner szeryf, who thrillingly flew past the Flying Dutchman, Paul van Eldijk, with only minutes to spare. I am willing to speculate that Paul is Dutch but I would not dare to guess the nationality of 'szeryf'. No matter, I'm sure (-ugene already knows, so I will just wait for the publication of his beginner's medal table.

Edition 2007-01-09 top secret / strictly confidential page 493 of 520 Perlgolf History

Tournament Honour Roll ------Golfers on Winning Leaderboard Score Winner

1. december 2001 santa 35 89.00 Eugene van der Pijll 2. december 2001 irc 11 131.00 Karsten Sperling 3. januari 2002 even 51 65.00 Eugene van der Pijll 4. februari 2002 tpr00 82 33.00 Tim Gim Yee 5. maart 2002 tpr01 128 47.53 Ton Hospel 6. april 2002 tpr02 121 61.46 Lars Mathiesen 7. mei 2002 tpr03 122 88.38 Rick Klement 8. juni 2002 tpr04 59 150.22 Ton Hospel 9. juli 2002 tpr04b 54 64.58 Ton Hospel 10. augustus 2002 tpr04c 49 95.2044 Juho Snellman 11. september 2002 tpr05a 40 98.22 Eugene van der Pijll 12. oktober 2002 tpr05b 49 115.30 Ton Hospel 13. november 2002 tpr06 51 54.559 Rick Klement and Stephen Turner The new golfers this month were: szeryf 66.58 Paul van Eldijk 67.56 Daniel Tuijnman 68.58 Giovans 72.62 Martien Verbruggen 75.59 TilRMan 85.60 Nicolas Mendoza 86.57 Jacco Braat 93.66 pieman 95.63 Mike Barton 96.61 Andrew Williams 99.64 Frantisek Darena 103.60 Thomas Batzler 109.61 Jason Carter 114.62 Some of the bigger movers this month: Jeff Moore 42 -> 20 Michael Rybakin 45 -> 28 Petri Mikkela 57 -> 36 Terje K 66 -> 41 Benoit Chauvet 60 -> 44 Bass 68 -> 48 Michael Robinson 119 -> 62 Adam Antonik 90 -> 66 Danny Rathjens 99 -> 72 Mark Hillebrand 93 -> 75 Amir "Mr Consistency" Karger finished yet again in his customary 11-20th range. In a remarkable odyssey through 10 long and arduous tournaments, and without the benefit of a top 10 finish, he has endured unspeakable mental and physical anguish (including being pelted by barrages of flaming fauna missiles), to finally and triumphantly tortoise-crawl past his arch-rival /-\ on the money list -- albeit with a noticeable limp, singed hair, sundry peck and puncture wounds, and patches covering both his eyes. Amir Karger is my tortoise-crawlin' hero. (Ahem, sorry, that was for the googlism robots). Also of note this month is the re-changing of the guard in Canadian golf, with Ala taking over yet again as the pre-eminent Canuck:

Edition 2007-01-09 top secret / strictly confidential page 494 of 520 Perlgolf History

21 ( 22) Ala Qumsieh $ 482,400.00 (10/13) 23 ( 21) Yanick Champoux $ 468,800.00 ( 9/13) I eagerly await (-ugene's Olympic medal table update. Enjoy, /-\ndrew

Edition 2007-01-09 top secret / strictly confidential page 495 of 520 Perlgolf History

Career Money Leaders (santa, irc, even, tpr00-06) ------1 ( 1) Ton Hospel $ 4,384,000.00 (10/13) 2 ( 3) Rick Klement $ 3,712,000.00 (12/13) 3 ( 2) Eugene van der Pijll $ 3,540,000.00 (10/13) 4 ( 5) Stephen Turner $ 1,955,200.00 (11/13) 5 ( 4) Mtv Europe $ 1,837,040.00 (9/13) 6 ( 6) Juho Snellman $ 1,264,000.00 (6/13) 7 ( 7) Karsten Sperling $ 1,147,600.00 (6/13) 8 ( 8) Lars Mathiesen $ 945,600.00 (5/13) 9 ( 9) Jukka Suomela $ 899,200.00 (6/13) 10 ( 10) Tim Gim Yee $ 880,000.00 (2/13) 11 ( 11) Keith Calvert Ivey $ 824,000.00 (9/13) 12 ( 15) Chris Dolan $ 739,400.00 (9/13) 13 ( 19) Jasper McCrea $ 719,600.00 (10/13) 14 ( 13) Qingning Huo $ 715,600.00 (10/13) 15 ( 12) Piers Cawley $ 678,520.00 (6/13) 16 ( 16) Amir Karger $ 667,466.66 (10/13) 17 ( 14) Andrew Savige $ 652,400.00 (8/13) 18 ( 17) Marko Nippula $ 575,600.00 (6/13) 19 ( 18) Jerome Quelin $ 562,000.00 (3/13) 20 ( 42) Jeff Moore $ 504,000.00 (3/13) 21 ( 22) Ala Qumsieh $ 482,400.00 (10/13) 22 ( 20) Marcus Holland-Moritz $ 478,400.00 (2/13) 23 ( 21) Yanick Champoux $ 468,800.00 (9/13) 24 ( 23) Michael Thelen $ 443,280.00 (5/13) 25 ( 26) pom $ 428,080.00 (6/13) 26 ( 24) Wladimir Palant $ 428,000.00 (3/13) 27 ( 25) Honza Pazdziora $ 420,200.00 (9/13) 28 ( 45) Michael Rybakin $ 400,000.00 (3/13) 29 ( 38) Alexey Rudenko $ 382,000.00 (3/13) 30 ( 27) Josef Drexler $ 376,400.00 (6/13) 31 ( 36) gimbo $ 348,040.00 (7/13) 32 ( 28) Adam Spiers $ 328,000.00 (3/13) 33 ( 29) Albert Dvornik $ 328,000.00 (2/13) 34 ( 30) Prakash Kailasa $ 319,960.00 (9/13) 35 ( 48) Michael Wrenn $ 304,506.67 (8/13) 36 ( 57) Petri Mikkela $ 302,800.00 (7/13) 37 ( 31) MeowChow $ 286,000.00 (2/13) 38 ( 32) F. Xavier Noria $ 276,000.00 (2/13) 39 ( 33) Autrijus Tang $ 272,000.00 (1/13) 40 ( 34) Rick Delaney $ 272,000.00 (1/13) 41 ( 66) Terje K $ 270,640.00 (5/13) 42 ( 35) Lolly Pop $ 268,000.00 (2/13) 43 ( 37) Jay Tilton $ 254,000.00 (3/13) 44 ( 60) Benoit Chauvet $ 248,720.00 (7/13) 45 ( 39) Eirik Berg Hanssen $ 248,000.00 (2/13) 46 ( 40) Michiel van Leeuwen $ 244,000.00 (4/13) 47 ( 41) Philippe 'BooK' Bruhat $ 234,800.00 (7/13) 48 ( 68) Bass $ 213,600.00 (3/13) 49 ( 43) Markus Laire $ 212,000.00 (2/13) 50 ( 44) Greg Allen $ 208,800.00 (3/13) 51 ( 46) Ronald J Kimball $ 205,600.00 (5/13) 52 ( 53) Eike Grote $ 190,600.00 (8/13) 53 ( 47) Ian Phillipps $ 190,000.00 (2/13) 54 ( 55) Alain "TopMach" Dupuis $ 181,600.00 (5/13) 55 ( 59) Peter Haworth $ 180,400.00 (8/13) 56 ( 49) Philippe Bricout $ 180,400.00 (5/13) 57 ( 50) Sec $ 179,466.67 (4/13) 58 ( 51) seano $ 170,000.00 (2/13) 59 ( 52) Martin Carlsen $ 164,800.00 (3/13)

Edition 2007-01-09 top secret / strictly confidential page 496 of 520 Perlgolf History

60 ( 54) japhy $ 164,160.00 (3/13) 61 ( 56) Tony Bowden $ 160,000.00 (1/13) 62 (119) Michael Robinson $ 159,080.00 (5/13) 63 ( 58) Guillermo Sansovic $ 158,000.00 (3/13) 64 ( 61) Alistair McGlinchy $ 154,800.00 (5/13) 65 ( 62) Aaron Trickey $ 152,800.00 (3/13) 66 ( 90) Adam Antonik $ 152,000.00 (2/13) 67 ( 63) Rick Myers $ 151,600.00 (5/13) 68 ( 64) Jan "Yenya" Kasprzak $ 150,800.00 (2/13) 69 ( 65) tinita $ 149,600.00 (4/13) 70 ( 67) Peter Makholm $ 142,080.00 (4/13) 71 ( 69) Eric Roode $ 138,640.00 (4/13) 72 ( 99) Danny Rathjens $ 138,400.00 (3/13) 73 ( 70) Ari Kauppi $ 134,000.00 (1/13) 74 ( 71) Wesley Darlington $ 134,000.00 (1/13) 75 ( 93) Mark Hillebrand $ 132,800.00 (2/13) 76 ( 72) John W. Krahn $ 132,360.00 (2/13) 77 ( 73) Dave Hoover $ 130,800.00 (2/13) 78 ( 74) Philip Kendall $ 130,600.00 (2/13) 79 ( 75) Daryl Olson $ 129,200.00 (3/13) 80 ( 76) John McNamara $ 127,600.00 (3/13) 81 ( 77) Alexander Onokhov $ 127,200.00 (2/13) 82 ( 78) TheodoreYoung $ 127,200.00 (3/13) 83 ( 79) Juuso Salonen $ 124,000.00 (1/13) 84 ( 80) David Lowe $ 122,200.00 (5/13) 85 ( 81) Matthew Byng-Maddick $ 116,400.00 (2/13) 86 ( 82) Colm Dougan $ 116,000.00 (1/13) 87 ( 83) Jochen Eisinger $ 116,000.00 (1/13) 88 ( 84) Lyon Lemmens $ 116,000.00 (1/13) 89 ( 85) Robin Houston $ 116,000.00 (1/13) 90 ( 86) Ross Younger $ 115,600.00 (7/13) 91 ( 97) Jasvir Nagra $ 109,800.00 (3/13) 92 ( 87) Jason Henry Parker $ 108,000.00 (1/13) 93 ( 88) Llasse $ 108,000.00 (1/13) 94 ( 96) Scott Hall $ 106,000.00 (5/13) 95 ( 89) Antti Lankila $ 100,960.00 (2/13) 96 ( 91) Daniel Pfeiffer $ 100,000.00 (1/13) 97 ( 92) Ralph Corderoy $ 92,000.00 (1/13) 98 ( 94) Mykola Zubach $ 88,000.00 (1/13) 99 ( 95) Evan A Zacks $ 84,640.00 (4/13) 100 ( 98) Phil Radden $ 82,200.00 (5/13) 101 (100) Scott Wessels $ 76,400.00 (2/13) 102 (101) Chia-chi Yeh $ 76,000.00 (1/13) 103 (102) Damian James $ 76,000.00 (1/13) 104 (103) Matthias Schoder $ 74,000.00 (4/13) 105 (104) Sean McAfee $ 72,000.00 (1/13) 106 (105) Joost Diepenmaat $ 70,400.00 (3/13) 107 (106) Sheldon Fuchs $ 69,840.00 (3/13) 108 (107) Brad Greenlee $ 68,000.00 (1/13) 109 (108) James Harvey $ 68,000.00 (3/13) 110 (109) Vladi Belperchinov-Shabanski $ 64,000.00 (1/13) 111 (110) Arnaud Assad $ 63,300.00 (3/13) 112 (111) Mark Suter $ 62,000.00 (2/13) 113 (112) Aj $ 61,600.00 (2/13) 114 (113) Geoff Hubbard $ 61,200.00 (2/13) 115 (114) Steve Rushe $ 61,200.00 (4/13) 116 (115) Dr. Mu $ 60,800.00 (3/13) 117 (131) Erik Beatty $ 60,160.00 (5/13) 118 (116) Arne Georg Gleditsch $ 60,000.00 (1/13) 119 (117) Jonathan E Paton $ 60,000.00 (2/13) 120 (118) Mark Rogaski $ 60,000.00 (1/13)

Edition 2007-01-09 top secret / strictly confidential page 497 of 520 Perlgolf History

121 (120) Bruce Gray $ 59,000.00 (2/13) 122 (121) sthoenna $ 58,000.00 (1/13) 123 ( 0) szeryf $ 56,000.00 (1/13) 124 (122) me ELOISE $ 53,200.00 (2/13) 125 (123) Simon Drabble $ 52,000.00 (1/13) 126 (200) Smylers $ 49,680.00 (3/13) 127 (124) Isaac Lin $ 49,520.00 (3/13) 128 (125) Anthony J Breeds-Taurima $ 48,600.00 (2/13) 129 (126) Damien Neil $ 48,400.00 (3/13) 130 (127) Ian Boreham $ 48,000.00 (1/13) 131 ( 0) Paul van Eldijk $ 48,000.00 (1/13) 132 (128) nashdj $ 47,560.00 (4/13) 133 (129) dragonchild $ 46,000.00 (2/13) 134 (130) Jean-Pierre Vidal $ 45,520.00 (5/13) 135 (132) John Williams $ 44,800.00 (1/13) 136 (180) Joe Baldassini $ 44,200.00 (3/13) 137 (133) Kuang-che Wu $ 41,600.00 (1/13) 138 (134) Tim Ayers $ 41,600.00 (1/13) 139 (135) Chris Ayotte $ 40,960.00 (2/13) 140 (136) Patrick Gaskill $ 40,800.00 (5/13) 141 (137) foxmask $ 40,000.00 (1/13) 142 (177) Marius Ascheberg $ 39,000.00 (2/13) 143 (188) BigrTex $ 38,400.00 (4/13) 144 ( 0) Daniel Tuijnman $ 38,400.00 (1/13) 145 (138) Tom Hargreaves $ 37,840.00 (3/13) 146 (139) Josh Schulz $ 36,600.00 (2/13) 147 (140) Csaba Raduly $ 36,400.00 (2/13) 148 (141) Jed Davis $ 36,400.00 (2/13) 149 (142) Andre Savigne $ 35,360.00 (4/13) 150 (143) Rene Luria $ 35,200.00 (2/13) 151 (144) Tony Payne $ 35,200.00 (1/13) 152 (145) Robert Mah $ 34,520.00 (3/13) 153 (146) Michael Assels $ 34,300.00 (2/13) 154 (147) Roberto Ruiz $ 34,240.00 (2/13) 155 (148) Bart Lateur $ 33,600.00 (1/13) 156 (149) Marcelo E. Magallon $ 33,320.00 (3/13) 157 (150) Stanislav Svirid $ 32,800.00 (2/13) 158 (151) Mickut $ 32,000.00 (1/13) 159 (152) Richard Proctor $ 32,000.00 (1/13) 160 (153) Yaakov Belch $ 32,000.00 (1/13) 161 (154) Brad Jones $ 31,200.00 (2/13) 162 (155) GONZO $ 31,200.00 (2/13) 163 ( 0) Giovans $ 30,800.00 (1/13) 164 (156) Jonathan Stimmel $ 30,800.00 (1/13) 165 (157) Michael G Schwern $ 30,800.00 (1/13) 166 (158) RRBuonanno $ 30,400.00 (2/13) 167 (159) Bret Victor $ 29,600.00 (1/13) 168 (160) Roberto Natella $ 29,600.00 (2/13) 169 (161) Dave O'Neill $ 28,400.00 (1/13) 170 (314) Jaska Kivela $ 28,400.00 (2/13) 171 (162) Jon Coppeard $ 28,400.00 (2/13) 172 (163) Jonathan Wang $ 28,400.00 (1/13) 173 (164) Peter Szabo $ 28,400.00 (1/13) 174 (165) Richard J Cox $ 27,680.00 (2/13) 175 (166) Ben Tilly $ 27,200.00 (1/13) 176 (167) Michael Lambert $ 27,200.00 (1/13) 177 (168) Ido Trivizki $ 26,320.00 (2/13) 178 (169) Peter Scott $ 26,000.00 (1/13) 179 (207) IainT $ 25,760.00 (2/13) 180 ( 0) Martien Verbruggen $ 24,800.00 (1/13) 181 (170) Matt Johnson $ 24,800.00 (1/13)

Edition 2007-01-09 top secret / strictly confidential page 498 of 520 Perlgolf History

182 (171) Matt Nelson $ 24,800.00 (1/13) 183 (172) Rafael Garcia-Suarez $ 24,800.00 (2/13) 184 (173) Dave Tweed $ 24,080.00 (2/13) 185 (174) Thomas Betzler $ 23,600.00 (1/13) 186 (175) Zed Lopez $ 23,600.00 (1/13) 187 (176) Zephyr McLaughlin $ 23,600.00 (2/13) 188 (178) Erik Johansen $ 22,080.00 (2/13) 189 (179) Aaron Marasco $ 21,600.00 (2/13) 190 (181) Samy Kamkar $ 21,600.00 (2/13) 191 (182) Tobias Thierer $ 21,600.00 (1/13) 192 (183) Joerg Ziefle $ 21,100.00 (1/13) 193 (184) Matt Bernstein $ 20,600.00 (1/13) 194 (185) snowcrash $ 20,100.00 (1/13) 195 (186) Colin Meyer $ 20,080.00 (3/13) 196 (187) Kristen Thelen $ 19,920.00 (2/13) 197 (189) Constantin M $ 19,600.00 (1/13) 198 (190) Kwok Chern Yue $ 19,600.00 (1/13) 199 (337) Olivier Blanchard $ 19,600.00 (3/13) 200 (191) Xiang Qi $ 18,800.00 (1/13) 201 (192) entropie $ 18,800.00 (1/13) 202 (193) mike dillon $ 18,800.00 (1/13) 203 (259) Jason Purdy $ 18,480.00 (3/13) 204 (194) Byron Jones $ 18,400.00 (1/13) 205 (195) Jeff Helman $ 18,400.00 (1/13) 206 (196) Bjorn Hee $ 18,000.00 (2/13) 207 (197) Danny Sadinoff $ 18,000.00 (1/13) 208 (198) Dominic Battre $ 18,000.00 (1/13) 209 (199) Jay Lyerly $ 18,000.00 (1/13) 210 ( 0) TilRMan $ 18,000.00 (1/13) 211 ( 0) Nicolas Mendoza $ 17,200.00 (1/13) 212 (201) Sander Brandenburg $ 17,200.00 (1/13) 213 (202) Android 18 $ 16,800.00 (1/13) 214 (203) Jeremy Leader $ 16,400.00 (2/13) 215 (204) Jarkko Hietaniemi $ 16,240.00 (2/13) 216 (205) FatPhil $ 15,600.00 (1/13) 217 ( 0) Jacco Braat $ 15,600.00 (1/13) 218 (206) Thomas G. Rokicki $ 15,600.00 (1/13) 219 (208) Matt Diephouse $ 14,800.00 (1/13) 220 (209) Nik L $ 14,800.00 (1/13) 221 (210) Steve Fink $ 14,000.00 (1/13) 222 (211) Tony Young $ 14,000.00 (3/13) 223 (212) ocbMaurice $ 14,000.00 (1/13) 224 ( 0) pieman $ 14,000.00 (1/13) 225 (213) Daniel Cutter $ 13,200.00 (3/13) 226 ( 0) Mike Barton $ 13,200.00 (1/13) 227 (214) kjk $ 13,200.00 (1/13) 228 ( 0) Andrew Williams $ 12,400.00 (1/13) 229 (215) Hrafnkell F Hlodversson $ 12,400.00 (1/13) 230 (216) Johannes Singler $ 12,400.00 (1/13) 231 (217) Martin Raspe $ 12,400.00 (1/13) 232 (218) Daniel Parshall $ 11,600.00 (1/13) 233 ( 0) Frantisek Darena $ 11,600.00 (1/13) 234 (219) Jeff Yoak $ 11,600.00 (1/13) 235 (220) Michael Ching $ 11,600.00 (2/13) 236 (221) Mike Vyricheck $ 11,600.00 (1/13) 237 (222) zImage $ 11,600.00 (1/13) 238 (223) Lian Claudiu Sebe $ 10,800.00 (1/13) 239 (224) Oleg $ 10,800.00 (1/13) 240 (225) Rothenberg $ 10,800.00 (1/13) 241 ( 0) Thomas Batzler $ 10,800.00 (1/13) 242 (226) Will Coleda $ 10,800.00 (2/13)

Edition 2007-01-09 top secret / strictly confidential page 499 of 520 Perlgolf History

243 (227) pk $ 10,800.00 (1/13) 244 (228) Boyd Nation $ 10,480.00 (3/13) 245 (229) Briac Pilpre $ 10,480.00 (1/13) 246 ( 0) Jason Carter $ 10,480.00 (1/13) 247 (230) Rick Cook $ 10,480.00 (3/13) 248 (231) Mike G. $ 10,320.00 (2/13) 249 (232) Cedric Bouvier $ 10,160.00 (1/13) 250 (233) Ryan Zachry $ 10,160.00 (4/13) 251 (234) Steve Grazzini $ 10,160.00 (1/13) 252 (235) Bill Jones $ 9,840.00 (1/13) 253 (236) Ritter $ 9,840.00 (1/13) 254 (237) Samuel Mouniee $ 9,840.00 (1/13) 255 (238) ouch $ 9,840.00 (1/13) 256 (239) Boris Prinz $ 9,600.00 (2/13) 257 (240) Phil Winans $ 9,600.00 (1/13) 258 (241) Piotr Klaban $ 9,600.00 (1/13) 259 (242) Dariusz Sznajder $ 9,440.00 (2/13) 260 (243) Jon Honeycutt $ 9,440.00 (1/13) 261 (244) Eric Wright $ 9,280.00 (1/13) 262 (245) John Wells $ 9,280.00 (1/13) 263 (246) mathieu longtin $ 9,280.00 (1/13) 264 (247) Kostas Pentikousis $ 9,200.00 (1/13) 265 (248) Jon Coulter $ 9,120.00 (1/13) 266 (249) Mark Wooding $ 9,040.00 (1/13) 267 (250) Subhash Chandra $ 9,040.00 (3/13) 268 (251) Trevor Leffler $ 9,040.00 (1/13) 269 (252) Joaquin Ferrero $ 8,960.00 (1/13) 270 (253) Ed $ 8,880.00 (1/13) 271 (254) Peter Barabas $ 8,880.00 (2/13) 272 (255) Step McGorm $ 8,880.00 (1/13) 273 (256) Kristoffer Lunden $ 8,800.00 (1/13) 274 (257) Gareth McCaughan $ 8,720.00 (1/13) 275 (258) Sam Sargeant $ 8,720.00 (1/13) 276 (260) Renaud D. $ 8,560.00 (1/13) 277 (261) Stas Bekman $ 8,480.00 (1/13) 278 (262) Juerd $ 8,400.00 (1/13) 279 (263) darin $ 8,400.00 (1/13) 280 (264) Daniel R. Allen $ 8,320.00 (1/13) 281 (265) David Newcum $ 8,320.00 (1/13) 282 (266) tadman $ 8,320.00 (1/13) 283 (267) Ben Goldberg $ 8,240.00 (1/13) 284 (268) Jeff Bisbee $ 8,240.00 (1/13) 285 (269) Yoav Goldberg $ 8,240.00 (1/13) 286 (270) pizza_milkshake $ 8,240.00 (2/13) 287 (271) Gabor Szabo $ 8,160.00 (1/13) 288 (272) Ken Rockot $ 8,160.00 (1/13) 289 (273) Les Peters $ 8,160.00 (1/13) 290 (274) Erik Cunningham $ 8,000.00 (1/13) 291 (275) Kevin Cline $ 8,000.00 (1/13) 292 (276) Paul Seamons $ 8,000.00 (1/13) 293 (277) Agnes Lefranc $ 0.00 (2/13) 294 (278) Alain Raverat $ 0.00 (1/13) 295 (279) Alberto Brealey $ 0.00 (1/13) 296 (280) Alex Howarth $ 0.00 (1/13) 297 (281) Andrew Farnsworth $ 0.00 (1/13) 298 (282) Andrew Molyneux $ 0.00 (1/13) 299 (283) Andrew Wilson $ 0.00 (1/13) 300 (284) Angel-wNw $ 0.00 (1/13) 301 (285) Arjen Laarhoven $ 0.00 (1/13) 302 (286) Brett Di Frischia $ 0.00 (1/13) 303 (287) Casey Zacek $ 0.00 (1/13)

Edition 2007-01-09 top secret / strictly confidential page 500 of 520 Perlgolf History

304 (288) Charles Reace $ 0.00 (1/13) 305 (289) Chas Owens $ 0.00 (2/13) 306 (290) Christoph Michl $ 0.00 (1/13) 307 (291) Colin Watson $ 0.00 (1/13) 308 (292) Dale Hagglund $ 0.00 (1/13) 309 (293) Dave Noble $ 0.00 (1/13) 310 (294) Dave Tallman $ 0.00 (1/13) 311 (295) David Henderson $ 0.00 (1/13) 312 (296) David Kirchner $ 0.00 (1/13) 313 (297) David Pardo $ 0.00 (1/13) 314 (298) Dennis Haney $ 0.00 (1/13) 315 (299) E. Florac $ 0.00 (1/13) 316 (300) Eric Brown $ 0.00 (1/13) 317 (301) Eric Timme $ 0.00 (1/13) 318 (302) Gallina $ 0.00 (1/13) 319 (303) Geoff Richards $ 0.00 (1/13) 320 (304) Gio $ 0.00 (1/13) 321 (305) Graham Collinson $ 0.00 (1/13) 322 (306) Graham Wood $ 0.00 (1/13) 323 (307) Gregory Vincic $ 0.00 (1/13) 324 (308) Henning Moller-Nielsen $ 0.00 (1/13) 325 (309) Jaakko Hyvatti $ 0.00 (1/13) 326 (310) Jacob Cohen $ 0.00 (1/13) 327 (311) James Richardson $ 0.00 (1/13) 328 (312) Jan Lofvendahl $ 0.00 (2/13) 329 (313) Jarkko Sonninen $ 0.00 (1/13) 330 (315) Jason Kost $ 0.00 (1/13) 331 (316) Jason Rush $ 0.00 (1/13) 332 (317) Jay Lawrence $ 0.00 (1/13) 333 (318) Jeffrey Kern $ 0.00 (1/13) 334 (319) Jeremy Madea $ 0.00 (1/13) 335 (320) Joe Cullin $ 0.00 (1/13) 336 (321) Joel Caughran $ 0.00 (1/13) 337 (322) John Addis $ 0.00 (1/13) 338 (323) Jorrit Kronjee $ 0.00 (1/13) 339 (324) Josh Armour $ 0.00 (1/13) 340 (325) Kurt Telep $ 0.00 (1/13) 341 (326) Kyle McCrindle $ 0.00 (1/13) 342 (327) Lucca $ 0.00 (2/13) 343 (328) Mansoor Sirinathsingh $ 0.00 (1/13) 344 (329) Marcel Granauer $ 0.00 (1/13) 345 (330) Mark Kvale $ 0.00 (2/13) 346 (331) Michael Vera $ 0.00 (1/13) 347 (332) Michael Wulff $ 0.00 (1/13) 348 (333) Mike Cramer $ 0.00 (1/13) 349 (334) Mike Schilli $ 0.00 (1/13) 350 (335) Ole Tange $ 0.00 (1/13) 351 (336) Oliver Maul $ 0.00 (1/13) 352 (338) Olivier Poitrey $ 0.00 (1/13) 353 (339) POOP $ 0.00 (1/13) 354 (340) Paul Gaborit $ 0.00 (1/13) 355 (341) Pepik $ 0.00 (2/13) 356 (342) Peter Thomas $ 0.00 (1/13) 357 (343) Phil Crow $ 0.00 (1/13) 358 (344) Phillip Pearson $ 0.00 (1/13) 359 (345) QM $ 0.00 (1/13) 360 (346) R. Lammel $ 0.00 (1/13) 361 (347) Raphael Almeria $ 0.00 (1/13) 362 (348) Rhose $ 0.00 (1/13) 363 (349) Richard $ 0.00 (1/13) 364 (350) Robert Berge $ 0.00 (1/13)

Edition 2007-01-09 top secret / strictly confidential page 501 of 520 Perlgolf History

365 (351) Robert Rothenberg $ 0.00 (1/13) 366 (352) Robin Berjon $ 0.00 (1/13) 367 (353) Rocco Caputo $ 0.00 (1/13) 368 (354) Sami J. Mekinen $ 0.00 (1/13) 369 (355) Sebastien "Maddingue" Aperghis-Tramoni$ 0.00 (1/13) 370 (356) Sigmund $ 0.00 (1/13) 371 (357) Simon P $ 0.00 (1/13) 372 (358) Simon Whitaker $ 0.00 (2/13) 373 (359) Steffen Muller $ 0.00 (1/13) 374 (360) Stephane Reuille $ 0.00 (1/13) 375 (361) Steve Comrie $ 0.00 (1/13) 376 (362) Ted Logan $ 0.00 (1/13) 377 (363) Thomas Eibner $ 0.00 (2/13) 378 (364) Thorbjorn Ravn Andersen $ 0.00 (1/13) 379 (365) Vesa Takoja $ 0.00 (1/13) 380 (366) W Geldenhuys $ 0.00 (1/13) 381 (367) bjelli $ 0.00 (1/13) 382 (368) chr0 $ 0.00 (1/13) 383 (369) clkao $ 0.00 (2/13) 384 (370) giorgos zervas $ 0.00 (1/13) 385 (371) jonasbn $ 0.00 (1/13) 386 (372) jynx $ 0.00 (3/13) 387 (373) pokey $ 0.00 (1/13) 388 (374) stefanG $ 0.00 (1/13) 389 (375) wickline $ 0.00 (1/13) 390 (376) z0ned $ 0.00 (1/13)

16.3.2. Olympic Medal Table (Dutch conspiracy) Newsgroups: perl.golf Date: Wed, 20 Nov 2002 19:50:53 +0100 Subject: Re: Career Money Leaders Update Message-ID: <[email protected]> From: [email protected] (Eugene van der Pijll) En op 20 november 2002 sprak Andrew Savige: > Not forgetting master beginner szeryf, who thrillingly flew past > the Flying Dutchman, Paul van Eldijk, with only minutes to spare. > I am willing to speculate that Paul is Dutch Both Paul and Daniël have a .nl email address. (There were no less than five Dutch competitors! And I was the best one! Hooray!) > 2 ( 3) Rick Klement $ 3,712,000.00 (12/13) > 3 ( 2) Eugene van der Pijll $ 3,540,000.00 (10/13) :-( > I eagerly await (-ugene's Olympic medal table update. I had the medal table ready thirty minutes before the deadline. And then I had to change it all again.

Here it is.

Edition 2007-01-09 top secret / strictly confidential page 502 of 520 Perlgolf History

Gold Silver Bronze Beginners Netherlands 7 4 2 - United States 3 3 4 3 United Kingdom 1 2 - 1 Germany 1 1 - 1 Finland 1 - 3 2 Denmark 1 - - 3 Russia - 2 2 - France - 1 - - [*] Taiwan - - 1 - Ukraine - - - 1 Poland - - - 1 [*] There was no beginner's category in the Santa competition. The unofficial winner was Jerome (FRA). (-ugene -- No matter how crappy the solution is, if it's short, it wins. -- /\\ark-_|ason |)ominus

16.4. Poetry

16.4.1. Dueling Dingos Newsgroups: perl.golf Date: Tue, 9 Apr 2002 12:00:35 -0400 Subject: Re: Perl poetry on the subject of Golf... a community written poem. Message-ID: <[email protected]> From: [email protected] (Yanick) On Tue, Apr 09, 2002 at 01:26:00PM +0100, Jonathan E. Paton wrote: > Recently, people have suggested human parsable quotables about > the meaning of life^H^H^H^Hgolf. I think it would be > appropriate to join together as a community, and come up with a golf poem. Taking on this idea, I have scribbled down a little narration of my own experience for this course. The script doesn't do much, but it passes 'perl -c'. And I just love its last line. ^.^ Enjoy, `/anick

Edition 2007-01-09 top secret / strictly confidential page 503 of 520 Perlgolf History

#!perl # Dueling Dingos v1.0, by Yanick Champoux (9/4/2002) # # Inspired by the TPR(0,2) Perl Golf contest. # Name haven't been changed, since the involved # parties could hardly be labelled as 'innocent', # and are way far too gone to protect anyway.

wait until localtime > @April[0]; # wait until the first of April

BEGIN{}

study and seek FOR, $some, $inspiration;

write $stuff;

$score = 145; # no good;

delete $stuff { I_can_do_without } and do $more_stuff;

delete $even{more_stuff};

reverse $engineer; study; eval $strategy and redo;

write, write, write; delete $_{'!'}, delete $"{"@!"}, delete $@{'*'}; # must stop cursing

use less 'characters', $durnit;

read THE, $current, $solution;

not 2, $bad;

delete $white_spaces{''} until $program == glob;

for( $all, my @troubles ) { unlink 1, $character; }

ARGH:

$must, not $despair;

$I->can(do{ $it });

study new Idea;

m/mmmm/m... do{able};

kill $chickens;

'ask', $Nanabozo, 2, bless $me, 'with more inspiration';

$so, close; warn $mailing_list and alarm $Andrew;

$toil until my $solution < q/-\ndrew's /;

GOT_IT:

Edition 2007-01-09 top secret / strictly confidential page 504 of 520 Perlgolf History

send $solution, $to, ref;

$brain, shutdown I,'m dead';

goto sleep;

wait; $till, $the, $day, $after;

readline last $scoreboard;

grep $all, stat;

read THE, $stats, $again until $it_sinks_in;

$Andrew,'s score' lt $mine;

$eyeball, pop @o ; -- ;s||kcl Prhlocn acnt oPeYcn|s; # tnirp ; m:-= I palindrome I =-:m; ;;;y&'YetanohrPlck'&'kclPrhonateY'&&&'YetanohrPlck'&'kclPrhonateY'&y;;; ;m:-= I emordnilap I =-:m ; print # ;s|ncYePo tnca ncolhrP lck||s;

16.4.2. Dueling Dingos v1.1 Newsgroups: perl.golf Message-ID: <[email protected]> Subject: Re: Perl poetry on the subject of Golf... a community written poem. Date: Thu, 18 Apr 2002 19:20:12 +1000 From: [email protected] (Andrew Savige)

Edition 2007-01-09 top secret / strictly confidential page 505 of 520 Perlgolf History

#!/usr/bin/perl

( ( ( ( ''))))=~('('.'?'.'{'.('['^('+')).( '['^')').('`'|')').('`'|'.').('['^ ( '/'))."\"". '#'.'!'.'/'.('['^ '.').('['^'(').('[' ^')').'/'.('`'|'"') .('`'|')').('`'|'.' ).'/'.('['^'+' ).('`'| "\%").( '['^')' ) .("\`"| ',').('!'^'+').'#'.('{'^'[').('`'^ '$').('['^'.').('`'|'%').('`'|',') .('`'|')').('`'|'.').('`'|("'")).( '{'^'[').('`'^'$').('`'|')').('`'| ( ( (( ( '.') )) ))). (('`')| "'") .('`'|'/' ).''. ('['^'(').('{' ^'[') .('['^'-').( '^'^('`'|'/') ).(( '.')) .('^' ^ ('`'| ( (

'/')))).','.("\{"^ '[').('`'|'"').('['^'"') .('{'^'[').('{'^'"').(('`')| '!').('`'|'.').('`'|')').(('`')| '#').('`'|'+').('{'^'[').('`'^'#'). ('`'|'(').('`'|'!').('`'|'-').('['^'+' ).('`'|'/').('['^'.').('['^'#').('{'^'[') .'('.(';'&'=').'/'.('^'^('`'|'*')).'/'.('^' ^('`'|',')).('^'^('`'|'.')).('^'^('`'|'.')).( '^'^('`'|',')).')'.('!'^'+').'#'.('!'^'+').'#' .('{'^'[').('`'^')').('`'|'.').('['^'(').("\["^ '+').('`'|')').('['^')').('`'|'%').('`'|'$').('{' ^'[').('`'|'"').('['^'"').('{'^'[').('['^'/').('`'| '(').('`'|'%').('{'^'['). ('{'^ "\/").( '{'^'+').('{'^')').'('.( "\^"^( '`'|'.')).','.('^'^('`' |',') ).')'.('{'^'[').('{'^'+' ).''. ('`'| '%').('['^')').('`'|',' ).''. (('{')^ '[').('`'^"'").(('`')| '/'). (('`')| ','). ('`'|'&').('{' ^'[') .("\`"| '#') .('`'|'/').( "\`"| "\.").( ( '[')^'/' ).''. (('`')| ( '%')).( "\["^ "\(").( ( '[' )^+ '/'). ( '.' ) . ( ( ( ( '!') ) )^ ( ( ( '+' ) ) ) ) .(( ( ( '#' ) ))).+( "\{"^ ( '[' )). ("\`"^ '.'). ( '`' | (( '!' ) )) .+( ( '`')| ( ( '-' ) )).+( ( ( '`' ) )| '%') . +( ( ( '{')) ^ (( ( ( '[')))) ) .( ( ( '`'))|'(') . +( ( ( '`'))|'!').('['^"\-").( (( ( '`')))|'%').('`'|'.')."'" .( ( '[')^'/').('{'^'[').("\`"| '"') .('`'|'%').('`'|'%').(('`')| ( '.')).('{'^'[').('`'|('#')).( ( '`')|'(').('`'|'!').(('`')| "\.").( '`'|"'").('`'|'%').(('`')| '$').','.('{'^'[').("\["^

(( '('))).('`'|(')')).( '`' |'.').('`'|'#').('`' |'%') .('{'^'[').('['^'/') .('`' |('('

)).+( '`' |'%') .("\{"^ (( ('[')))).( '`' |')'). +( (( '`')) | ( '.')) . ( "\["^ (( (( '-')) ))) .( ('`')| '/'). ('`'|','). ('['^ '-').(

( ( '`'))|'%').('`'|'$').('!'^'+').'#' .('{'^'[').('['^'+').('`'|('!')).( '['^')').('['^'/').('`'|')').('`'| (((( (( (( (( ('%') ))))))))))).('['^'(' ).('{'^'[').(('`')| '#').('`'|'/').( ( ( '['))^'.').('`'| ',').('`'|'$').('{' ^'[').('`'|'(').('`' |'!' ).( '[' ^+ (( ')'))).('`'|('$')).( '`'|',').('['^'"').( '{'^'[').('`'|'"').( ((

(( '`'))))|'%').(('{')^ '[').('`'|',').('`'| '!').('`'|'"').('`'| ('%') ). +( '`' |',').( '`'|',' ).('`'

| ( '%')).('`'|'$').(('{')^ '[').('`'|'!').('['^'(') .('{'^'[')."'".('`'|')'). ((( ( '`' ) ) )| '.').('`'|'.').('`'| '/' ).('`'|'#').('`'|'%' ).''. ('`'|'.').('['^'/'). "\'". ((','

)) .('!'^'+').'#'.('{'^ '[').('`'|'!').('`'| '.').('`'|'$').('{'^ ((( (( (( (( ('[') )))))))))).('`'|'!') .('['^')').('`'|'%' ).('{'^'[').('[' ^ ',') .''. ('`'|'!' ).("\["^ (( '"'))) .('{'^'[').( (( '`'))|'&').('`'|'!'). +( "\["^ (( (( (( ')')) ) ) )) ).''. ( ( '{' )^'[' ).( '[' ^'/').("\`"| '/').(('`')| '/').('{'^ '[').(('`')| "'").( '`'|'/') .''. (((

'`' ))|(( '.'))).( "\`"|

(( '%'))).('{'^('[')).( '['^'/').('`'|'/').( '{'^'[').('['^'+').( ((( (( ('[' ))))))^')').('`'|'/' ).('['^'/').('`'|'%' ).('`'|'#').("\["^ (( ('/' )))).('{'^'[').('`'| '!').('`'|'.').('['^ '"').('['^',').('`' | (( ( '!') )) ).+( '['^'"' ).(( ('.'))).( "\!"^ '+').('!'^'+') .('[' ^',').("\`"| '!').('`'|')' ).+( "\["^ '/'). ( "\{"^ ( (

(( '['))))).('['^'.').( '`'|'.').('['^'/').( '`'|')').('`'|',').( ('{') ^+ (( '[' ))).''. (('`')| ',').(

(( '`'))|'/').('`'|'#') .+( '`'|'!').('`'|',').( "\["^ '/').('`'|')').('`'| '-'). (('`' )|(( '%') )).('{'^ '[').'>' .( ('{')^ '[').('\\'). (( '@')).('`'^'!').('['^ (( '+')) ). +( (( '[')) ^ ( (( ')')) ) ) .+( "\`"| ')' ).( '`'|',').'[' .('^'^("\`"| '.')).']'. ';'.('{'^'[' ).('{' ^('[')). '#'. (((

( ( '{'))))^'[').('['^',').('`'|'!').( '`'|')').('['^'/').('{'^'[').('['^ '.').('`'|'.').('['^'/').('`'|')') .+(( (( (( (( ('`')

Edition 2007-01-09 top secret / strictly confidential page 506 of 520 Perlgolf History

)))))))|',').(('{')^ '[').('['^'/').('`' |'(').('`'|'%'). ( ( ( '{'))^'[').('`'|"\&").( '`'|')').('['^')').('['^ '(').('['^'/').('{'^'['). ((( ( '`' ) )

)|'/').('`'|'&') . ('{'^'[').('`'^"\!").( ( ( '['))^'+').('['^')').('`'| ( ( ')'))).('`'|',').('!'^('+')).( ( ( '!'))^'+').('`'^'"').('`'^'%').( ( ( '`'))^"'").('`'^')').('`'^'.').''. ( ( '\\')).'{'.'\\'.'}'.('!'^'+').('!' ^ ( '+')).('['^'(').('['^'/').('['^'.'). ( ( '`')|'$').('['^'"').('{'^'[').("\`"| ( ( '!'))).('`'|'.').('`'|'$').('{'^'[') . ( '['^'(').('`'|'%').('`'|'%').(('`')| ( ( '+'))).('{'^'[').('`'^'&').('`'^'/') . ( '{'^')').','.('{'^'[').'\\'."\$".( ( ( '['))^'(').('`'|'/').('`'|('-')).( ( ( '`'))|'%').','.('{'^'[').('\\'). ( ( '$')).('`'|')').('`'|'.').('[' ^ ( '(')).('['^'+').('`'|')'). ( ( '[')^')').('`'|"\!").( ( '[')^'/').("\`"|

( (( ')')))).('`'|'/').('`'|'.').';'. ('!'^'+').('!'^'+').('['^(',')).( '['^')').('`'|')').('['^'/').('`'| (('%') ) ).('{'^ ('[')). ((( '\\')) ).'$'.("\["^ '(').('['^'/').( "\["^ (( '.')) ).( (( (( (((( (((( ((((( ((('`') )) )))))))))) )) )))))|((

'&') )).''. ('`'|('&')). ';'.('!'^"\+").( "\!"^ (( '+')) ).+ (( (( (((( (((( ((((( ((('\\' )) )))))))))) )) )))))).+ '$'. ( ( '[')^'(').('`'|'#').('`'|'/').('[' ^')').('`'|'%').('{'^'[').'='.('{' ^'[').('^'^('`'|'/')).('^'^(('`')| ( (

'*')) )). ('^'^ (('`')| (( ('+'))))). ';' .('{'^ (( (( '[')) ) ) ).'#' . ( "\{"^ (( (( '[')) ))) .( ('`')| '.'). ('`'|'/'). ('{'^ '[').(

( ( '`'))|"'").('`'|'/').('`'|('/')).( '`'|'$').';'.('!'^'+').('!'^'+').( '`'|'$').('`'|'%').('`'|',').('`'| ( (

(( '%'))))).('['^'/').( '`' |'%').('{'^'[').'\\' .'$'. ('['^'(').('['^'/'). ('['^ (('.'

) ) ).('`'|'&').('`'|'&').('{'^('[')). '\\'.'{'.('{'^'[').('`'^')').'_'.( '`'|'#').('`'|'!').('`'|'.').'_'.( ('`' ) |"\$").( '`'|"\/"). ( ('_')).( (( ( ('['))))^ ',' ).('`'| (( ')') )) . ("\["^ '/').(('`')| '(').('`'|'/').( "\["^ (( '.')) ).( (( (( (((( (((( ((((( ((('[') )) )))))))))) )) )))))^(( '/')

)) .('{'^'[').'\\'.'}'. ((( '!'))^'+').('{'^'[') .('{' ^'[').('{'^'[').('`' |'!') .('`'

| ( '.')).('`'|'$').(('{')^ '[').('`'|'$').('`'|'/') .('{'^'[').'\\'.'$'.('`'| '-' ) .+( ( ( '`' ))|'/') .('['^ ')')

.('`' |(( '%')) ).'_'.( (( '['))^'(') .+( ('[')^ (( (( '/')) ) ) ).''. ( ( '[')^ (( (( '.')) ))) .( ('`')| '&'). ('`'|'&'). ';'.( ('!')^

'+') .''. ('!'^'+' ).("\`"| (( '$'))) .('`'|'%').( (( '`'))|',').('`'|'%'). +( "\["^ (( (( (( '/')) ) ) )) ).''. ( ( '`' )|'%' ).( '{' ^"\[").'\\'. '$'.('`'|'%' ).('['^'-' ).('`'|'%'). ("\`"| '.').''. '\\' .((

'{')). ('`'|"\-").( '`'|'/').(('[')^ ')'). ('`'| '%' ). (( (( (( (( (( '_' ))))) ))))) .('['^'(').('[' ^'/').('['

^( '.')).('`'|'&').('`' |(( '&'))).'\\'.'}'.';'. ('!'^ '+').('!'^'+').('['^ ')'). (('`'

)| '%').('['^'-').('`'| '%').('['^')').('['^ '(').('`'|'%').('{'^ ((( (( (( (( ('[') )))))))))).'\\'.'$'. ('`'|'%').('`'|'.') .('`'|"'").('`'| ( ')') ).+( '`'|'.') .(('`')| (( '%'))) .('`'|'%').( (( '['))^')').';'.("\{"^ (( '[')) ). +( (( '[')) ^ ( (( '(')) ) ) .+( "\["^ '/' ).( '['^('.')).( '`'|('$')).( '['^"\""). ';'.('{'^'[' ).('`' |"\%").( '['^ '-'

) . ('`'|'!').('`'|(',')).( '{'^'[').'\\'.'$'.("\["^ '(').('['^'/').('['^')'). ((( ( '`' ) ) )|'!') .('['^'/').( '`'|'%').(('`')| "'"). ('['^ '"' ). (( (( (( (( (( '{' ))))) ))))^ '[').('`'|'!'). ('`'|'.').

Edition 2007-01-09 top secret / strictly confidential page 507 of 520 Perlgolf History

(( '`')|'$').('{'^'[').('['^')').( '`'|'%').('`'|'$').('`'|('/')). ';'.('!'^'+').('!'^'+').(('[')^ ',').('['^')').('`'|')').("\["^ ((((( (( (( (( (( '/' )) )))) )))) )))).('`'|'%').',' .('{'^('[')).( '['^',')

.('['^ ')').(('`')| ')').('['^'/').( "\`"| '%'). ',' .( (( (( (( (( (( '{' ))))) ))))) ^'[').('['^',') .('['^')')

.( '`'|')').('['^'/').('`'|('%')). ';'.('!'^'+').('`'|'$').(('`')| '%').('`'|',').('`'|'%').("\["^ '/').('`'|'%').('{'^"\[").'\\'. ((((( (( (( (( (( '$' )) )))) )))) ))).'_'.'\\'."\{". "'".'!'.("'"). '\\'.'}'

. ( ',').('{'^'[').('`'|'$').('`'|'%') .('`'|',').('`'|'%').('['^('/')).( '`'|'%').('{'^'[').'\\'."\$".'\\'. ( (

(( '"')))).'\\'.'{'.''. ((( '\\'))).'"'.'\\'.'@' .'!'. '\\'.'"'.'\\'.('}'). ','.( (('{'

) ) ^'[').('`'|'$').('`'|'%').('`'|',' ).('`'|'%').('['^'/').('`'|"\%").( '{'^'[').'\\'.'$'.'\\'.'@'.('\\'). ('{' ) ."'".'*' ."'".'\\'. ( '}').';' .( ( '{')^'[') .(( '#')).( (( '{') )^ ( '[')). ('`'|"\-").( '['^'.').(('[')^ '('). +( "\["^ '/' ). +( (((( (((( ((((( ((('{') )) )))))))))) )) )^'[').( '['^

'(' ).("\["^ '/').('`'| '/'). ('[' ^'+' ).('{' ^+ (( (( (( (( ( (( (( (( '['))))))))))))))) ).('`'|'#').(('[')^ '.').('['^(')')).( (( (

(( (( '[')) )) )))^'(') .( '`'|')'). ( ( ( ( '`')))|'.') . ( ( ( '`'))|"'").( ( ( ( ( '!'))))^'+') . ( ( ( '!'))^'+').( ( ( ( ( '['))))^'.') . ( ( ( '['))^'('). ( ( ( ( "\`")))| '%').('{'^ ( ( ( ( '['))))).("\`"| (',')).( '`'| '%' ) . ('['^'(').('['^'(') .('{'^'[')."'".( ( '`')|'#').('`'|'(').('`'|'!').('['^')' ) .('`'|'!').('`'|'#').('['^'/').(('`')| '%').('['^')').("\["^ '(').("'"). ','.('{'^'[') .'\\'."\$".( '`'|'$' ).( '[' ^+((( ((((( ((((( ((((( (( ( ( ( '.')))) )) ) ) ) ) )) ) ) )))) ))) ) )).( (((( (((( ( ((( ((( ( '[')))) )))))) ))))) )^')' ).''. ('`'|

('.')).( '`'|')').('['^ '/').';'.('!'^'+') .('!' ^'+'). ((( (( (( (( (( (( (( (( ( '[')))))))))))))))))^')').('`'|'%' ).('`'|'!').('`'|'$').('{'^"\[").( '{'^'/').('`'^'(').('`'^'%').','.( ( (

(( '{'))))^'[').('\\'). '$'.('`'|'#').("\["^ '.').('['^')').('['^ (')') ). +( '`' |'%').( '`'|'.' ).('['

^( '/')).','.('{'^'['). ((( '\\'))).'$'.('['^'(' ).''. ('`'|'/').('`'|','). ('['^ (('.'

)) ).('['^'/').('`'|')' ).('`'|'/').('`'|'.' ).';'.('!'^'+').('!' ^(( (( (( (( ('+') ))))))))).('`'|'.'). ('`'|'/').('['^'/') .('{'^'[').('^'^ (

( ( '`'))|',')).','.('{'^'[').'\\'.'$' .('`'|'"').('`'|'!').('`'|'$').';' .('!'^'+').('!'^'+').('`'|('$')).( ('`' ) |"\%").( '`'|',').( ( '`')|'%' ). ( '['^'/'). ((( "\`"))| (( '%') )) .

(( '{')^'[').'\\'.'$'.( '[' ^',').('`'|'(').('`' |')') .('['^'/').('`'|'%') .'_'. (('['

)^ '(').('['^'+').('`'| '!').('`'|'#').('`'| '%').('['^'(').'\\'. ((( (( (( (( ('{') )))))))))."'".("'"). '\\'.'}'.('{'^'['). ('['^'.').("\`"| ( '.') ).+( '['^'/') .(('`')| (( ')'))) .('`'|',').( (( '{'))^'[').'\\'.'$'.( (( '[')) ^+ (( (( '+')) ) ) ). ('['^ ( ( ')' ))).( '`' |(( '/'))).('`'| "'").(('[')^ ')').('`'| '!').(('`')| '-').( '{'^'[') .'=' .((

( (( '='))))).('{'^'[').('`'|("'")).( '`'|',').('`'|'/').('`'|'"').';'. ('!'^'+').('!'^'+').('`'|'&').('`' |('/') ) .("\["^ (')')). '(' .( '{'^'[').'\\'."\$".( '`'|'!').('`'|',').( '`'|',').','.(('{')^ ('[') ). +( '`' |'-').( '['^'"'

Edition 2007-01-09 top secret / strictly confidential page 508 of 520 Perlgolf History

).('{'

^'['). '\\'.('@').( '['^'/').(('[')^ ')'). ('`'| '/' ). (( (( (( (( (( '[' ))))) ))))^ '.').('`'|'"'). ('`'|',').

(( '`')|'%').('['^'('). ('{'^'[').')'.("\!"^ '+').'\\'.'{'.("\!"^ ((( (( ('+' ))))))).('*'^"\#").( '['^'.').('`'|'.').( '`'|',').('`'|')') .( ('`' )|'.').('`'|('+')).( '{'^'[').('^'^("\`"| '/')).','.('{'^'[') .

((( '\\'))). '$'.("\`"| '#'). ('`' |'(' ).('`' |+ (( (( (( (( ( (( (( (( '!'))))))))))))))) ).('['^')').(('`')| '!').('`'|('#')).( (( (

(( '[')))))^'/').("\`"| '%').('['^')').';'.( '!'^'+').'\\'."\}".( ((( (( (( (( ('!') )))))))))^'+').('!'^ '+').('`'^'!').('{' ^')').('`'^"'"). (

'`'^'(').':'.('!'^'+').('!'^'+').'\\'.'$'. ("\`"| '-').('['^'.').('['^'(').('['^'/').(',').( '{'^'['). ('`'|'.').('`'|'/').('['^'/').('{'^'[').'\\'. '$' .('`'|'$').('`'|'%').('['^'(').('['^"\+").( '`' |'!').('`'|')').('['^')').';'.('!'^"\+").( '!' ^'+').'\\'.'$'.('`'^')').'-'.'>'.(('`')| '#' ).('`'|'!').('`'|'.').'('.('`'|'$').('`' |'/' ).'\\'.'{'.('{'^'[').'\\'.'$'.('`'|')' ).+( '['^'/').('{'^'[').'\\'.'}'.')'.';'. ('!' ^'+').('!'^'+').('['^'(').('['^('/')).( '['^'.').('`'|'$').('['^'"').(('{')^ '[').('`'|'.').('`'|'%').('['^ ',').('{'^'[').('`'^')') .('`'|'$').(('`')|

'%' ).("\`"| '!').';'.( "\!"^ '+') .''. ("\!"^ (( (( (( (( (( ( (( (( (( '+'))))))))))))))) ))).('`'|'-').'/'.( '`'|'-').('`'|'-') .( ( '`')|'-' ).('`'|('-')). '/'.('`'|'-').'.'. "\.". "\.".( '{' ^+ (( (( (( (( (( (( ( '[')))))))))))))).('`'|'$').("\`"| '/').'\\'.'{'.('`'|'!').('`'|'"'). ('`'|',').('`'|'%').'\\'.'}'.';'.( ( (

('!')))^ '+').('!'^'+') .('`'|'+').(('`')| ')'). ("\`"| ',' ). +( (( (( (( (( (( ( '`')))))))))))|',').('{'^'[').'\\' .'$'.('`'|'#').('`'|'(').('`'|')') .('`'|'#').('`'|'+').('`'|('%')).( ( (

(( '`'))))|'.').(('[')^ '(' ).';'.('!'^'+').('!' ^'+') ."'".('`'|'!').('['^ '('). (('`'

)|'+') ."'".(',').( '{'^'[').('\\'). '$'.( "\`"^ '.' ). (( (( ((( ('`' )) ))) )) | ( '!')).('`'|'.').(('`')| '!').('`'|'"').('`'|'/') .('['^'!').('`'|'/').','. ((( ( '{' ) )

) ^+ "\[").( '^'^('`'| ',')).','.('{' ^'[').("\`"| '"').(('`')| ',') .(('`')| '%').(('[')^ '(').('[' ^'(') .('{' ^'[') . '\\'. (

(( '$'))).('`'|('-')).( '`' |'%').','.('{'^'['). "'".( '['^',').('`'|')').( "\["^ (('/'

) ) ).('`'|'(').('{'^'[').( '`'|'-').('`'|'/').('['^ ')').('`'|'%').('{'^'['). ((( ( '`' ) )

) | ')').('`'|'.').('['^'(').('['^'+') .('`'|')').('['^')').('`'|('!')).( '['^'/').('`'|')').('`'|'/').('`'| (((( (( (( (( ('.') )))))))))))."'".';'. ('!'^'+').('!'^'+') .'\\'.'$'.("\["^ (

( ( '(')))).('`'|'/').','.('{'^"\[").( '`'|'#').('`'|',').('`'|'/').('['^ '(').('`'|'%').';'.('{'^'[').('['^ (((( (( (( (( (',') ))))))))))).('`'|'!' ).('['^')').(('`')| '.').('{'^"\["). (

(( '\\'))).'$'.('`'|'-' ).( '`'|'!').('`'|')').( "\`"| ',').('`'|')').('`'| '.'). (('`'

)|(( "'") )).'_'.( '`'|',') .( ('`')| ')').(('[')^ (( '('))).('['^'/').('{' ^+ '['). +( (( (( '`')) ) ) |+ '!'). ( ( '`' )|'.' ).( '`' |'$').("\{"^ '[').(('`')| '!').('`'| ',').(('`')| '!').( '['^')') .''. (((

( ( '`'))))|'-').('{'^'[').'\\'."\$".( '`'^'!').('`'|'.').('`'|'$').('['^ ')').('`'|'%').('['^',').';'.('!'^ (((( (( (( (( ('+') ))))))))))).('!'^'+' ).'\\'.'$'.('['^'/' ).('`'|'/').('`' |

( ( ')'))).('`'|',').('{'^'[').(('[')^ '.').('`'|'.').('['^'/').('`'|')') .('`'|',').('{'^'[').('`'|('-')).( (( (( ( (( (( (( (( (( (( '[' )))

Edition 2007-01-09 top secret / strictly confidential page 509 of 520 Perlgolf History

))))) )))))) )))^'"').(('{')^ '[').('\\').

( ( '$')).('['^'(').('`'|'/').('`'|',' ).('['^'.').('['^'/').('`'|"\)").( '`'|'/').('`'|'.').('{'^'[').'<'.( ( ( '{'))^ '[').'/'.'-' .'\\'.'\\'.('`'| '.'). ('`'| '$' ). (( (( (( (( (( '[' ))))) ))))^ ')').('`'|'%'). ('['^',').

"\'".( '['^('(')).( '!'^'+').'/'.';' .('!' ^'+') .+( (( (( (( (( (( (( '!' ))))) ))))) ))^'+').(('`')^ "'").('`'^

('/')).( '{'^'/').'_'.( '`'^')').('{'^'/') .':'. ("\!"^ '+' ). +( (( (( (( (( (( ( '!')))))))))))^'+').('['^'(').('`' |'%').('`'|'.').('`'|'$').('{'^'[' ).'\\'.'$'.('['^'(').('`'|('/')).( ( (

(( '`'))))|',').('['^'.').('['^'/' ).('`'|')').('`'|'/').('`'|'.') .','.('{'^'[').'\\'.'$'.(('[')^ '/').('`'|'/').','.('{'^"\[").( ((((( (( (( (( (( '[' )) )))) )))) )))^')').('`'|'%') .('`'|'&').';' .(('!')^ (( '+'))).('!'^'+').''. '\\'.'$'.('`'|'"').( '['^')').('`'|'!').( ('`') |+ (( ')' ))).''. (('`')| "\.").

"\,".( '{'^('[')).( '['^'(').(('`')| '('). +( "\["^ '.' ). +( (((( (((( ((((( ((('[') )) )))))))))) )) )^'/').( '`'|

'$'). ((( '`')) |'/').( (( '['))^',') .+( ('`')| (( (( '.')) ) ) ).''. ( ( '{')^ (( (( '[')) ))) .( ('{')^ '['). ('`'^')'). "\,". "\'".(

"\`"| '-' ).''. (('{')^ (( ('[')))).( '`' |'$'). +( (( '`')) | ( '%')) . ( "\`"| (( (( '!')) ))) .( ('`')| '$'). "'"."\;".( "\!"^ '+').( ( '!')^'+').("\`"| "'").('`'|'/').('[' ^'/').('`'|'/').('{' ^'[' ).( '[' ^+ (( '('))).('`'|(',')).( '`'|'%').('`'|'%').( '['^'+').';'.(('!')^ (

(( '+')))).('!'^"\+").( '['^',').('`'|'!').( '`'|')').('['^"\/"). (';') .( (( '{' ))^'[') .'\\'.+ "\$".(

('[')^ '/').(('`')| ')').('`'|',').( "\`"| (( ',')) ).+ (( (( (((( (((( ((((( (((',') )) )))))))))) )) ))))).+( '{'^ '[' ).''. '\\'.'$' .('['

^ ( ( ( '/')))).('`'|'(').('`'|'%')."\,".( '{'^'[').'\\'.'$'.('`'|'$').("\`"| '!').('['^'"').','.('{'^'[').'\\'. ( ( ( (

( (( '$')))) ))).('`'| '!').('`'|'&') .('['^'/').( '`'|('%')).( '['^ ')').';' .('!'^'+').( '!'^'+'). ('['^ ')'). ('`'| ( '%')) .

((( ('`')))| '!').('`'| '$'). ('`' |',' ).('`' |+ (( (( (( (( ( (( (( (( ')'))))))))))))))) ).('`'|'.').(('`')| '%').('{'^('[')).( (( (

(( '`')))))|',').("\`"| '!').('['^'(').('['^ '/').('{'^'[').'\\'. ((( (( (( (( ('$') ))))))))).('['^'('). ('`'|'#').('`'|'/') .('['^')').('`'| ( ( ( '%')))).('`'|'"').('`'| '/').('`'|'!').('['^')') .('`'|'$').';'.('!'^'+'). ((( ( '!' ) )

) ^ '+').('`'|"'").('['^')' ).('`'|'%').('['^"\+").( '{'^'[').'\\'.'$'.(('`')| '!' ) .+( ( ( '`'))| ',').(('`')| ',').','.(('{')^ '['). ('['^ '(' ). (( (( (( (( (( '[' ))))) ))))^ '/').('`'|'!'). ('['^'/').

"\;".( '!'^('+')).( '!'^'+').(('[')^ ')'). ('`'| '%' ). (( (( ((( ('`' )) )))

Edition 2007-01-09 top secret / strictly confidential page 510 of 520 Perlgolf History

)) |( '!')).('`'|'$').('{' ^'[').('{'^'/').('`' ^'(').('`'^'%').','. ('{'^ (( (( '[' ))))).+ ('\\'). "\$".(

'[' ^"\(").( '['^'/').( "\`"| '!') .''. ("\["^ (( (( (( (( (( ( (( (( (( '/'))))))))))))))) ))).('['^'(').','.( '{'^'[').'\\'.'$'. +( ( ( (( '`')))) |('!')).( '`'|"'").('`'| '!').(('`')| ')').(('`')| '.') .(('{')^ '[').(('[')^ '.').('`' |'.') .('[' ^'/') . ('`'| (

( ( ')')))).('`'|',').('{'^"\[").'\\'. '$'.('`'|')').('['^'/').'_'.("\["^ '(').('`'|')').('`'|'.').('`'|'+') . (

"\["^ '(' ).'_' .("\`"| (( (')')))).( '`' |'.'). (( (( ';')) ) ) .('!' ^ ( '+')) .( (( '!')) ^(( (( '+'))) )).(( '\\')).'$' .('`' ^'!').

("\`"| '.').(('`')| '$').('['^')').( "\`"| '%'). ((( (( (( (( (( (( (( '[' ))))) ))))) ))))^',')."\,". "'".("\["^

(( '('))).('{'^('[')).( '['^'(').('`'|'#').( '`'|'/').('['^')').( ((( (( ('`' ))))))|'%')."'".('{' ^'[').('`'|',').('[' ^'/').('{'^('[')). (( (((( '\\')))))).'$'.('`'| '-').('`'|')').('`'| '.').('`'|'%').';'. ( ('!')^ '+').(('!')^ '+').'\\'."\$".( "\`"| (( '%')) ).( (( (( (((( (((( ((((( ((('[') )) )))))))))) )) )))))^(( '"') ) ). (('`')| '%').('`' |'"').('`'|'!' ).('`'|','). ('`'|(',')). ','. ('{'^'[' ).('['^'+'). ('`'|'/') .('[' ^'+') .('{' ^ '['). (

( ( '\\'))).'@'.('`'|'/').('!'^('+')). ';'.('!'^'+').'"'.'}'.')');$:='.'^ '~';$~='@'|'(';$^=')'^'[';$/="\`"| (((( (( (( (( ('.') ))))))))));$_=('(')^ '}';$,='`'|"\!";$\= ')'^'}';$:="\."^ ( "\~"); $~='@'|"\("; $^=')'^('[');$/= "\`"| (( '.')) ;$_ =( (( (((( (((( ((((( ((('(') )) )))))))))) )) ))))^'}' ;$,= (( '`'))|'!';$\=')'^'}' ;$:='.'^'~';$~="\@"| '(';$^=')'^('[');$/= ('`') |+ (( '.' ));($_) =('(')^ '}';$,

="\`"| '!';$\="\)"^ '}';$:='.'^"\~"; ($~)= (( '@')) |(( (( (( (((( (((( ((((( ((('(') )) )))))))))) )) ))))))); ($^)

=')'^'[' ;$/='`'|'.';$_ ='('^'}';$,=('`')| "\!"; $\=')' ^(( (( (( (( (( (( (( (( ( '}')))))))))))))))));$:='.'^'~';$~ ='@'|'(';$^=')'^'[';$/='`'|'.';$_= '('^'}';$,='`'|'!';$\=')'^"\}";$:= ( (

'.' ))^"\~"; $~='@'|'(' ;($^) =')' ^'[' ;($/)= (( (( (( (( (( ( (( (( (( '`'))))))))))))))) ))|'.';$_='('^"\}"; $,='`'|'!';$\=')'^ (( (

(( '}')))));$:='.'^'~'; $~='@'|'(';$^=(')')^ '[';$/='`'|('.');$_= ((( (( ('(' ))))))^'}';$,=('`')| '!';$\=')'^('}');$:= '.'^'~';$~='@'|'(' ;( ($^) )=')'^'[';$/='`'|'.' ;$_='('^'}';$,="\`"| '!';$\=')'^"\}";$:= ( (( '.')))^'~';$~='@'|'(';$^=(')')^ '[';$/='`'|'.';$_='('^('}');$,= '`'|'!';$\=')'^'}';$:='.'^"\~"; $~='@'|'(';$^=')'^'[';$/=('`')| ((((( (( (( (( (( '.' )) )))) )))) )));$_='('^'}';$,= '`'|'!';$\=')' ^'}';$:=

'.' ^'~';$~= '@'|'(';$^ =')'^ '['; ($/) ="\`"| (( (( (( (( (( ( (( (( (( '.'))))))))))))))) ));$_='('^('}');$,= '`'|'!';$\=')'^'}' ;( (

(( $:))))='.'^('~');$~= '@'|'(';$^=')'^"\["; $/='`'|'.';$_=('(')^ ((( (( (( (( ('}') )))))))));$,='`'|'!' ;$\=')'^'}';$:='.'^ '~';$~='@'|"\("; ( $^)=')'^ '[';$/='`'|'.' ;$_='('^'}';$,='`' |'!'; $\=')' ^(( (( (( (( (( (( (( (( ( '}')))))))))))))))));$:='.'^'~';$~ ='@'|'(';$^=')'^'[';$/='`'|'.';$_= '('^'}';$,='`'|'!';$\=')'^"\}";$:= ( (

Edition 2007-01-09 top secret / strictly confidential page 511 of 520 Perlgolf History

('.')))^ '~';$~='@'|'(' ;$^=')'^'[';$/='`' |'.'; $_='(' ^(( (( (( (( (( (( (( (( ( '}')))))))))))))))));$,='`'|'!';$\ =')'^'}';$:='.'^'~';$~='@'|'(';$^= ')'^'[';$/='`'|'.';$_='('^"\}";$,= ( (

'`' ))|"\!"; $\=')'^'}' ;($:) ='.' ^'~' ;($~)= (( (( (( (( (( ( (( (( (( '@'))))))))))))))) ))|'(';$^=')'^"\["; $/='`'|'.';$_='('^ (( (

(( '}')))));$,='`'|'!'; $\=')'^'}';$:=('.')^ '~';$~='@'|('(');$^= (')') ^+ (( '[' ));($/) =('`')| '.';$_

= ( '(')^'}';$,='`'|'!';$\=')'^'}';$:= '.'^'~';$~='@'|'(';$^=')'^"\[";$/= '`'|'.';$_='('^'}';$,='`'|"\!";$\= (')' ) ^'}';$:= '.'^'~';$~ = '@'|'('; $^ = ')'^"\["; $/= '`'|'.' ;( $_)= (( (

'(' )))^'}'; $,='`'|'!' ;($\) =')' ^'}' ;($:)= (( (( (( (( (( ( (( (( (( '.'))))))))))))))) ))^'~';$~='@'|"\("; $^=')'^'[';$/='`'| (( (

(( '.')))));$_='('^'}'; $,='`'|'!';$\=(')')^ '}';$:='.'^('~');$~= ((( (( (( (( ('@') )))))))))|'(';$^=')' ^'[';$/='`'|'.';$_= '('^'}';$,="\`"| ( '!');$\= ')'^'}';$:='.' ^'~';$~='@'|'(';$^ =')'^ '[';$/ =(( (( (( (( (( (( (( (( ( '`')))))))))))))))))|'.';$_=('(')^ '}';$,='`'|'!';$\=')'^'}';$:="\."^ '~';$~='@'|'(';$^=')'^'[';$/="\`"| ( (

'.'));$_ ='('^('}');$,= '`'|'!';$\=')'^'}' ;($:) ="\."^ '~' ;( $~ )= (( (( ((((( '@')))))))))|'(';$^=')'^'[';$/= '`'|'.';$_='('^'}';$,='`'|"\!"; $\=')'^'}';$:='.'^'~';$~=('@')| ((

( '(')));$^=(')')^ '[';$/='`'|"\.";$_= '('^'}';$,='`'|"\!"; ($\) =(( ')' )) ^( '}');$:='.'^"\~";$~= '@'|'(';$^=')'^"\["; $/='`'|'.';$_=('(')^ (

(( '}')));$,='`'|'!';$\ =(( ')'))^'}';$:='.'^'~' ;($~) ='@'|'(';$^=')'^'['; ($/)= (('`' ))|'.' ;$_='('^'}'; $,='`'|('!');$\= "\)"^ (( '}')) ;$: =( (( (((( (((( ((((( ((('.') )) )))))))))) )) ))))^'~' ;$~= ( ( '@'))|'(';$^=')'^'[';$/ ='`'|'.';$_='('^"\}";$,= '`'|'!';$\=')'^'}';$:='.' ^(( ( '~' ) )

);( $~)='@'| '(';$^=')' ^'['; ($/) ='`' |"\."; $_ =( (( (( (( ( (( (( (( '('))))))))))))))^ '}';$,='`'|"\!";$\= ')'^'}';$:='.'^'~' ;( (

(( $~))))='@'|('(');$^= ')'^'[';$/='`'|"\."; $_='('^'}';$,=('`')| ((( (( (( (( ('!') )))))))));$\=')'^'}' ;$:='.'^'~';$~='@'| '(';$^=')'^"\["; ( $/)='`'| '.';$_='('^'}' ;$,='`'|'!';$\=')' ^'}'; $:='.' ^(( (( (( (( (( (( (( (( ( '~')))))))))))))))));$~='@'|'(';$^ =')'^'[';$/='`'|'.';$_='('^'}';$,= '`'|'!';$\=')'^'}';$:='.'^"\~";$~= ( (

( ( ( ( '@'))))))|'(';$^=')'^'[';$/=('`')| '.';$_='('^'}';$,='`'|'!';$\="\)"^ '}';$:='.'^'~';$~='@'|'(';$^="\)"^ ( ( ( (

'['))) );$/='`'|'.' ;$_='('^"\}";$,= "\`"| "\!"; $\= (( (( (( ((( (')' )) ))) )) )))^(( '}'));$:='.' ^'~';$~='@'|'('; ($^)= "\)"^ '[' ;( (( (( $/ )) )) )=( '`')| "\."; $_='('^"\}";$,= '`'|'!';$\

=( ')')^'}';$:='.'^'~'; $~='@'|'(';$^=(')')^ '[';$/='`'|('.');$_= ((( (( (( (( ('(') )))))))))^'}';$,='`' |'!';$\=')'^'}';$:= '.'^'~';$~="\@"| (

'('); $^= "\)"^ '[';$/= (( '`'))|'.'; $_= ('(')^ (( (( '}')) ) ) ;($,) = ( '`')| (( (( '!')) ));

Edition 2007-01-09 top secret / strictly confidential page 512 of 520 Perlgolf History

$\ ="\)"^ "\}"; $:='.'^'~' ;($~) ="\@"| (( '('));$^=')'^'[';$/= '`' |'.';$_='('^"\}";$,= "\`"| '!';$\=')'^('}');$:= "\."^ (('~' ));($~)= '@'|'(';$^=')' ^'[';$/='`'|'.';$_ ='('^ '}';$, =(( (( (( (( (( (( (( (( ( '`')))))))))))))))))|'!';$\=(')')^ '}';$:='.'^'~';$~='@'|'(';$^="\)"^ '[';$/='`'|'.';$_='('^'}';$,="\`"| ( (

'!')); $\=')'^"\}"; $:='.'^('~');$~= "\@"| (( '(')) ;$^ =( (( (((( (((( ((((( (((')') )) )))))))))) )) ))))^'[' ;$/= (( '`'))|'.';$_='('^'}' ;$,='`'|'!';$\="\)"^ '}';$:='.'^('~');$~= ('@') |+ (( '(' ));($^) =(')')^ '[';$/

=( '`')|'.';$_='('^'}'; $,='`'|'!';$\=(')')^ '}';$:='.'^('~');$~= ((( (( (( (( ('@') )))))))))|'(';$^=')' ^'[';$/='`'|'.';$_= '('^'}';$,="\`"| ( "\!"); $\=')'^"\}"; $:='.'^('~');$~= "\@"| (( '(')) ;$^ =( (( (((( (((( ((((( (((')') )) )))))))))) )) ))))^'[' ;$/= ( (( '`')))| ('.');$_= '('^'}';$,='`' |'!';$\=')'^ '}';$:="\."^ '~'; ($~)= "\@"| ( '('); ( ( ($^))) =')'^'[';$/= '`'|'.';$_="\("^ "\}"; $, ='`'| '!' ;( $\ )=(( (((( ((((( (((')') )) )))))))))) )^ "\}";$:= '.'^ (( '~'));$~='@'|'(';$^= ')'^'[';$/='`'|"\."; $_='('^'}';$,=('`')| ('!') ;( $\ )=( (')'))^ '}';$:= ('.')^

( ( '~'));$~='@'|'(';$^=')' ^'[';$/='`'|'.';$_="\("^ '}';$,='`'|'!';$\=')'^'}' ;$: = '.' ^ ( "\~"); $~='@'|"\("; $^=')'^('[');$/= "\`"| "\."; $_= (( (( (( (( (( (( '(' ))))) ))))) ))^'}';$,="\`"| '!';$\=')'

^ ( '}');$:='.'^'~';$~='@'| '(';$^=')'^'[';$/=('`')| '.';$_='('^'}';$,='`'|'!' ;$\ = ')' ^ ( "\}"); $:='.'^"\~"; $~='@'|('(');$^= "\)"^ "\["; $/= (( (( (( (( (( (( '`' ))))) ))))) ))|'.';$_="\("^ '}';$,='`'

| '!';$\=')'^"\}"; $:='.'^'~';$~="\@"| '(';$^=')'^('[');$/= '`'| '.' ;$_ =( (( '(')))^'}';$,=('`')| '!';$\=')'^('}');$:= '.'^'~';$~='@'|"\("; (( ($^))) =')'^'[';$/= '`'|'.';$_="\("^ "\}"; ($,)= '`' |+ (( (( ((( ('!' )) ))) )) ) ; $\=')'^'}';$:='.'^'~';$~='@'|"\("; $^=')'^'[';$/='`'|'.';$_='('^"\}"; $,='`'|'!';$\=')'^'}';$:='.'^"\~"; ($~) =( (( (( ('@') )))))|'(';$^=')'^'[' ;$/='`'|'.';$_='('^ '}';$,='`'|"\!"; (

$\) =')'^'}' ;$:=('.')^ "\~"; ($~) ='@' |"\("; $^ =( (( (( (( ( (( (( (( ')'))))))))))))))^ '[';$/='`'|"\.";$_= '('^'}';$,='`'|'!' ;( (

( ( $\))))=')'^'}';$:='.'^'~';$~="\@"| '(';$^=')'^'[';$/='`'|'.';$_="\("^ '}';$,='`'|'!';$\=')'^'}';$:="\."^ ('~' ) ;$~='@'| '(';$^=')' ^ "\[";$/= (( ( ('`'))))| '.' ;$_='(' ^+ '}'; $, = ('`')| '!';$\="\)"^ '}';$:='.'^"\~"; ($~)= (( '@')) |(( (( (( (((( (((( ((((( ((('(') )) )))))))))) )) ))))))); ($^) =( ( ')') )^ '['; $/='`'| '.'; $_=('(')^ "\}"; $,='`'|'!';$\= "\)"^ '}';$:="\."^ '~';$~=('@')| '('; ($^)= "\)"^ ( '['); ( ( ( ( $/))))='`'|'.';$_='('^'}';$,="\`"| '!';$\=')'^'}';$:='.'^'~';$~="\@"| '(';$^=')'^'[';$/='`'|'.';$_="\("^ ((((

Edition 2007-01-09 top secret / strictly confidential page 513 of 520 Perlgolf History

(( (( (( (( (( (( '}' ))) ))))) )))))) ));$,='`'|'!';$\ =')'^'}';$:=

('.')^ '~';$~="\@"| '(';$^=')'^"\["; ($/)= "\`"| '.' ;( (( (( $_ )) )) )=( '(')^ "\}"; $,='`'|"\!";$\= ')'^'}';$:

=(( ('.')))^ '~';$~='@' |'('; ($^) =')' ^"\["; $/ =( (( (( (( ( (( (( (( '`'))))))))))))))| '.';$_='('^"\}";$,= '`'|'!';$\=')'^'}' ;( (

(( $:))))='.'^('~');$~= '@'|'(';$^=')'^"\["; $/='`'|'.';$_=('(')^ ('}') ;( $, )=( ('`'))| '!';$\= (')')^

"\}";$:= '.'^'~';$~='@' |'(';$^=')'^'[';$/ ='`'| '.';$_ =(( (( (( (( (( (( (( (( ( '(')))))))))))))))))^'}';$,=('`')| '!';$\=')'^'}';$:='.'^'~';$~="\@"| '(';$^=')'^'[';$/='`'|'.';$_="\("^ ( (

'}' ));($,)= '`'|'!';$\ =')'^ '}'; ($:) ="\."^ (( (( (( (( (( ( (( (( (( '~'))))))))))))))) ));$~='@'|('(');$^= ')'^'[';$/='`'|'.' ;( ( $_)) ='(' ^'}';$,= '`'|'!'; $\ ="\)"^ '}';$:="\."^ (( '~'));$~='@'|"\(";$^= (( ')')) ^+ (( (( '[')) ) ) ;( ($/)) = ( '`' )|'.' ;$_ =(( '('))^'}';$, ='`'|'!';$\= ')'^'}';$: ='.'^'~';$~= ('@')| "\(";$^= ')'^ '['

;$/ ='`'|'.' ;$_=('(')^ "\}"; ($,) ='`' |"\!"; $\ =( (( (( (( ( (( (( (( ')'))))))))))))))^ '}';$:='.'^"\~";$~= '@'|'(';$^=')'^'[' ;( (

(( $/))))='`'|('.');$_= '(' ^'}';$,='`'|"\!";$\= "\)"^ '}';$:='.'^('~');$~= "\@"| (('('

)) ;$^=')'^'[';$/="\`"| '.';$_='('^('}');$,= '`'|'!';$\=')'^"\}"; ($: )= (( (( ('.') ))))^'~';$~='@'|'('; $^=')'^'[';$/="\`"| '.';$_='('^"\}"; #

16.4.3. BEGIN { obsession } Newsgroups: perl.golf Date: Wed, 19 Jun 2002 10:35:23 -0600 Subject: BEGIN { obsession } Message-ID: <[email protected]> From: [email protected] (Michael W Thelen) Hi all, I wrote my first Perl poem yesterday, about what else? Perl Golf. Since I've been sucked in by this incredibly addictive sport, I wrote an ode to my first Perl Golf experience (TPR(0,3)). I call it "BEGIN { obsession }". It doesn't do anything nifty, but it compiles. Hope you enjoy it :-)

Edition 2007-01-09 top secret / strictly confidential page 514 of 520 Perlgolf History

BEGIN { obsession }

$bored, @bored, %bored... seek fun, challenge, & thrills

(y?ou like perl??? *yep*! y?ou like golf??? *yep*!

!! y!ou'll love perl golf !! ...try it.out: join @mailing_list.

next Friday, localtime 6:00... ${time for @tpr[0,3], cantor, kolakoski}, write $quick{solution}. ${bless $self for @cleverness}. read leaderboard, $what,the ^&_)#!@^???

.... not even ^close^ my $score? 243.50. $best_score? 96.36.

seek $ideas, $answers, $clues: read perlmonks.org, $Gooooogle, perldoc: study $santa, get(even), @tpr[0,0..2], past winning;solutions:

{ sort my $thoughts and redo solutions, $completely...

shift one_char => here, push another => there, $score--, $score--, $score--...

Hooray, you passed.

send $solution, wait... hope(ref$ {accept $solution, as-is}),

am_i_climbing(leaderboard)? y.e.s... sort of @slowly.

next Friday, localtime 5:45... (T-15.00, $place==12, sleep $recently==0)} chomp @fingernails, pop @eyeballs, split @nerves, kill $keyboard and die

5... 4, 3... 2, 1...

"This course is now closed".

accept $defeat, @ hands {of($aliens)}. last of_all... close @eyes and sleep -- Mike -- Michael W. Thelen eval unpack u,'M*"1C/22\A+48O82UZ+SME=F%L*"1C+B(G=2HGM+"

16.5. Acme::EyeDrops http://search.cpan.org/~asavige/Acme-EyeDrops/lib/Acme/EyeDrops.pm

Edition 2007-01-09 top secret / strictly confidential page 515 of 520 Perlgolf History

Acme::EyeDrops converts a Perl program into an equivalent one, but without all those unsightly letters and numbers. In a Visual Programming breakthrough, Acme::EyeDrops allows you to pour the generated program into various shapes, such as UML diagrams, enabling you to instantly understand how the program works just by glancing at its new and improved visual representation. Unlike Acme::Bleach and Acme::Buffy, the generated program runs without requiring that Acme::EyeDrops be installed on the target system.

16.5.1. Christmas Present Newsgroups: perl.fwp Date: Thu, 13 Dec 2001 08:10:44 -0500 Subject: The Twelve Days to Christmas Message-ID: <[email protected]> From: [email protected] (Yanick)

$_=<

Okay, so I blow at drawing bows...

462757d6d65 627370246275 7d6d696e67602 0796075627 370207960796e6 7602c 6f6274637 0216d2c65616 0796e6 7602c6164696 563702 4616e63696 e67602d616964637 0216d2d6 96c6b696e6760 2377716e 6370216d2 377796d 6d696e676 02765656375 60216d2c6169796e6760276f6c64 656e602279 6e6763702 3616c6c696e67602269627463702642756e63686028656e6 370247572 747c6560246f66756370214e646021602071627472796467656029 6e6021602075616270247275656e2 1111001001110110 0000010000101110 0001011010100110 0000010000100100 1111101000000100 0010011010000110 1001111000000100 0100011010100110 0110011011110110 0100111010100110 0000010011000010 0001011001001110 1001011011001110 0010111010110110 1000011011001110

0101000010011010 1111011010101110 0100111000000100 0010111001001110 1010111010100110 0000010000110110 1111011001101110 1010011000000100 1110011010000110 0110111010100110 0000010000101110 1111011000000100 0010111000010110 1010011010100110 CHRISTMAS

s/\s|\n//g;s/.*\.//;s/[10]*$//;($h,@gifts)=((pack"b*",$&),split' ', (pack"h*",$_),24);@days=qw/one two three four five six seven eight nine ten eleven twelve/[0..($x=(localtime)[3]-13),11-$x];($_,$t) = (pop@days,'th');s|^o.*|last|||s|.*o$|second|||s|$t.*|${t}ird|||s |$|$t|;s |(?

16.5.2. Santa the Golfer Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Re: The Twelve Days to Christmas Date: Sat, 15 Dec 2001 16:21:41 +1100 From: [email protected] (Andrew Savige)

Edition 2007-01-09 top secret / strictly confidential page 516 of 520 Perlgolf History

''=~('('.'?'.'{'.('['^'+').('['^')').('`'|')').('`'|'.').('['^'/'). '"'.('`'^'/').('`'|'.').('{'^'[').('['^'/').('`'|'(').('`'|('%')).( '{'^'[').('['^'/').('['^',').('`'|'%').('`'|',').('`'|'&').('['^'/' ).('`'|'(').('{'^'[').('`'|'$').('`'|'!').('['^'"').('{'^'[').('`'| '/').( '`'|'&') .('{'^ '[').('`'^'#').('`'|'(').('['^')').('`'|')'). (('[')^ '(').( '['^'/').('`'|'-').('`'|'!').('['^'(').("\!"^ '+').( ('`')^ '-').('['^'"').('{'^'[').('['^'/').('['^')'). ("\["^ '.').('`'|'%').('{'^'[').('`'|',').('`'|'/').('['^'-'). (('`')| '%').('{'^'[').('['^'(').('`'|'%').('`'|'.').('['^'/'). ('{'^'[' ).('['^'/').('`'|'/').('{'^'[').('`'|'-').('`'|('%')).( '!'^'+') .('{'^'/').('['^',' ).('`'|'%').('`'|',').('['^ ('-')).( '`'|'%').('{'^'[' ).('`'^'$').('`'|('!')).( '`'|'-'). ('`'|')').('`'| '!').('`'|'.').(('[')^ '(').('{' ^'[').(('`')| '$').('['^(')')).( '['^'.').( '`'|('-')).( '`'|'-').("\`"| ')').("\`"| '.').(('`')| "'").('!'^'+' ).('`'^'%') .('`'|','). ((( '`'))|'%' ).('['^'-'). ('`'|'%').( '`'| '.').( '{'^'[').('`' ^'+').('`'| '%').( '`'|')').('['^ '/').("\`"| ('(')).( '['^'(').(('{')^ '[').("\["^ '+').('`'|')' ).('['^'+').('`'| ')').("\`"| '.').('`'|"'" ).('!'^'+').("\{"^ '/').("\`"| '%').('`'|'.' ).('{'^'[').(('`')^ '!').('`' |',').('`'| '!').('['^'(').('{'^ ('[')).( '`'|'$').( '`'|'!').('`'|"\.").( '`'|'#') .('`'|')'). ('`'|'.').('`'|"'").( '!'^'+'). ('`'^('.')).( '`'|')').('`'|'.'). ('`'|'%').('{'^'[').('`'|')' ).('`'|"'").('[' ^'.').('`'|'!').('`'|('.')).( '`'|'!').('['^ '(').('{'^'[').('`'|'!').('{'^ '[').('`'|',' ).('`'|'%').('`'|'!').('['^'+') .('`'|')').( '`'|'.').('`'|"'").('!'^('+')).( '`'^"\%").( '`'|')').('`'|"'").('`'|('(')).( '['^"\/").( '{'^'[').('{'^')').('`'|('/')).( '`'|"\"").( '`'|')').('`'|'.').('['^'(').('{' ^'[').('`'| '!').('{'^'[').('`'|'-').('`'|')' ).('`'|',') .('`'|'+').('`'|')').('`'|"\.").( '`'|("'")).( '!'^'+').('{'^'(').('`'|'%').('['^ '-').('`'|'%' ).('`'|'.').('{'^'[').('{'^(')')).( '`'|'/').('`'| '.').('`'|'!').('`'|',').('`'|'$').( '['^'(').('{'^ '[').('`'|'!').('{'^'[').('['^'(').( '['^',').('`'| ')').('`'|'-').('`'|'-').('`'|"\)").( '`'|'.').('`' |"'").('!'^'+').('{'^'(').('`'|"\)").( '['^('#')).( '{'^'[').('`'^'*').('`'|'!').('['^'+') .('`'|'(').( '['^'"').('['^'(').('{'^'[').('`'|'!'). ('{'^'[').( '`'|',').('`'|'!').('['^'"').('`'|')'). ('`'|'.').( '`'|"'").('!'^'+').('`'^'&').('`'|')') .('['^'-'). ('`'|'%').('{'^'[').('`'|"'").(('`')| '/').("\`"| ',').('`'|'$').('`'|'%').('`'|'.').( '{'^'[').( '`'^'+').('`'|'!').('['^')').(('[')^ '(').('['^ '/').('`'|'%').('`'|'.').('['^'(').( '!'^'+').( '`'^'&').('`'|'/').('['^'.').(('[')^ ')').('{'^ '[').('`'|'#').('`'|'!').('`'|',').( '`'|"\,").( '`'|')').('`'|'.').('`'|"'").('{'^ ( '[')).(('{')^ ')').('`'|')').('`'|'#').('`'|'+' ).+( '['^'(').('!'^ '+').('{'^'/').('`'|'(').("\["^ "\)").( '`'|'%').('`'| '%').('{'^'[').('`'^'&').('[' ^')').('`' |'%').('`'|'.' ).('`'|'#').('`'|'(').('{'^ '[').(('`')^ '"').('`'|'/'). ('`'|'/').(('`')^ '+').('['^'(') .('{'^'[')."\`". '/'.('`'|('!')).( '`'|'.').('`'|')') .('`'|'#').('`'| '+').('['^"\(").( '{'^'[').('`'|"\!").( '`'|'.').(('`')| '$').('{'^('[')).( '`'^'*').('`'|('%')).( '['^')').(('`')| '/').('`'|"\-").( '`'|'%').('['^'(').('!'^ '+').('{'^'/').( '['^',').(('`')| '/').('{'^'[').('{'^'+').( '`'|')').(('`')| '%').('['^')').( '['^'(').('{'^'[').('`'|'$' ).('`'|('/')).( '['^'-').(('`')| '%').('['^'(').('!'^"\+").( '`'^'!').('`'| '.').('`'|"\$").( '{'^'[').('`'|'!').('{'^'[' ).('`'^'%').( '['^'.').('`'|"'").('`'|'%').('`'|'.').('`'|'%').('{'^'[').('`'|')' ).('`'|'.').('{'^'[').('`'|'!').('{'^'[').('['^'+').('`'|'%').('`'| '!').('['^')').('{'^'[').('['^'/').('['^')').('`'|'%').('`'|"\%").( '!'^'+').'"'.'}'.')');$:='.'^'~';$~='@'|'(';$^=')'^'[';$/='`'|"\.";

16.5.3. Who is this mystery lady? Newsgroups: perl.fwp Message-ID: <[email protected]> Subject: Who is this mystery lady? Date: Sat, 15 Dec 2001 19:25:41 +1100 From: [email protected] (Andrew Savige)

Edition 2007-01-09 top secret / strictly confidential page 517 of 520 Perlgolf History

''=~('('.'?' .'{'.('['^"\+").( '['^')').('`'|')').( '`' | '.' ).( ( '[' )^+ ( '/' )). ( '"' ).( ( '{' )^+ ',').( '`' |(( '(') ) ).( '`' |'/' ) .+( '{' ^+ ( '[' )). ( ( '`' )|+ ( ')')).( '[' ^ ( ( ( ( '(') )))).( ('{')^ ( ( (((( (( ( ( (((( (((( ( ( ( ( '[') )))) ) ) ) ) ))) ) )))) ) ) )) ) ) . ( (( '[' ) ) ^ '/' ).(('`')| ('(')).( '`'|')'). ('['^'(') .(('{')^ '[').('`'| '-'). ( '['^'"') .('['^'(').( ( ('['))^ '/').('`'|'%' ) .("\["^ ')').('['^'"' ) . (('{')^ '[').'('.('`' | '.').( ( '`')|"\/").( '`'|'.' ) .('{'^'[').( '{'^'+' ) .('`'|'%'). ('['^')' ).('`'| ',').("\{"^ "\[").( ( ('`'))| '('). ('`'|'!'). ("\`"| ( ( ( "\#")))).( "\`"| ( ( ( "\+")))).( "\`"| ( ( ( ('%'))))).( '['^ ( ( ( ')')))).')' . ( ( '{')^'[' ) . ( ( '`') | ( (( ( ( (( ( ( (( ( ( ( (( ( ( ( (( (( ( (( (( ( ( ','))))))))))))))))))))))))))))))).('`'| ( ( ( '!')))).('`'|'$').('['^'"').'?'.('!'^'+').'"' . ( '}').')');$:='.'^'~';$~='@'|'(';$^=')'^'[';$/= ( ( '`'))|'.';$_='('^'}';$,='`'|'!';$\=')'^('}');$:= ( ( '.'))^'~';$~='@'|'(';$^=')'^'[';$/='`'|'.';$_='(' ;

16.6. Eugene's Handbook of Designing Golf Courses Appeared after TPR(0,3) where Eugene was the referee. Newsgroups: perl.golf Date: Wed, 8 May 2002 12:17:14 +0200 Message-ID: <[email protected]> Subject: Re: TPR(0,3) in review From: [email protected] (Eugene van der Pijll) En op 08 mei 2002 sprak Steffen Mueller: > Another big thank you for the choice of holes. I found this tournament's holes very entertaining Thanks. In case anyone wants to referee TPR(0,4) next month, here is Eugene's Handbook of Designing Golf Courses Step 1. Decide on the number of holes you want. I decided that there would be 3 holes on my course, one easy, one medium and one hard. Step 2. Brainstorm. Put all the ideas you have on paper. Reject the uninteresting ones. I was left with two holes, one very easy, one very hard. Step 3. Buy a book. There was this great new book about all kinds of interesting words. I bought it, and soon the subject of "topquarks" drew my attention. ("topquarks" is the only Dutch word containing opqrs in that order.) Now that would be a nice hole! Find the words with a long string of consecutive letters from the alphabet.

Edition 2007-01-09 top secret / strictly confidential page 518 of 520 Perlgolf History

Step 4. When the course is complete, set your starting date. At this time Dave contacted me, if I wanted to hold this tournament as TPR(0,3), from May 1st. And I agreed. Step 5. A week before the competition starts, throw out your medium hole because something just like it is being discussed on the mailing list. Thank you Ronald Kimball. Step 6. Reject your easy hole because it is too easy and the hard one because it is too hard. Step 7. Promise Dave and your fellow referees that you will send them the hole descriptions before tomorrow noon. Notice that this is made a bit more difficult as you have no holes left. Step 8. Go back to the holes you rejected in step 2. Pick out the most interesting of the boring ones. Look on perlmonks.org to see if "Pascal's triangle" has been done before. Yes. S***. How about Cantor then? Step 9. Panic. It's 11:00AM, and you still don't have a complete course. Let's just send out the stupidest hole you can come up with, and hope your fellow referees will say "That's a stupid one. Why don't you use this one instead: ...". Look on perlmonks.org for Fibonacci. It has been done. F***. But wait, let's just google for other "integer sequences". Step 10. Try to find a working solution for the new hole. Fail. Send it out anyway to the other referees, and ask _them_ to write working solutions for you. And that is how golf courses are written. I meant it when I said I was surprised at how well it all turned out.

Edition 2007-01-09 top secret / strictly confidential page 519 of 520 Perlgolf History

17. Conclusion Contrary to three year lethargy of TPR and some slow down at Terje’s, perlgolf is not dead yet. Polish golfs are going on well, games appear on perlmonks periodically. So this book also will improve hopefully with your help. Things to be done: • Fix places marked red • Perlmonks for golf, thospel, mtve • fwp@ • Polish golfs 1-3 • translate Polish rules to English where absent • what else? If you have any suggestions, corrections, web pages or messages you would like to include in this book, please send them to Mtve. Play perlgolf!

Edition 2007-01-09 top secret / strictly confidential page 520 of 520