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. Perl Versions ...... 16 2.4.2. Some Assumptions ...... 16 2.5. Open Source Tournament Engines...... 17 2.5.1. PGAS...... 17 2.5.2. JAGGS ...... 17 3. Games – Pretournaments ...... 18 3.1. Andrew’s Santa Claus Golf 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 "Labyrinth" ...... 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 SOLITAIRE ...... 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 Maze”...... 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. Acme::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 ) • Audrey Tang ( 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
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 following 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: 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( 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) 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^' #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^' #define ord #include $ 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 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 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 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 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: 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 precedence 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 frustration, 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 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 Edition 2007-01-09 top secret / strictly confidential page 111 of 520 Perlgolf History #include 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 Perl module. 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 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 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 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 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 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) 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 = 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: 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: 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: 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)-#$1g;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} $_= 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/2 2\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 $_= 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: 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)=( 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] 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 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!.* 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 clock. 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.$_, 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]) $1<#/||s/ (.{$l}) (.{$ l})n/ $1n$2#/||(s/>(.{$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 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= 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$- 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/ //~1 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 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: 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< 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 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= 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: 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<(.*)
.*!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