Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Polcode Code Contest PHP-2010.10
- *
- * Nick: NetCoder
- */
- $str = $argv[1];
- $a = $b = strlen($str) % 36;
- $i = 0;
- $lastIndex = 0;
- $k = 0;
- $lt = array (
- 'A' => 1,
- 'B' => 2,
- 'C' => 3,
- 'D' => 4,
- 'E' => 5,
- 'F' => 6,
- 'G' => 7,
- 'H' => 8,
- 'I' => 9,
- 'J' => 10,
- 'K' => 11,
- 'L' => 12,
- 'M' => 13,
- 'N' => 14,
- 'O' => 15,
- 'P' => 16,
- 'Q' => 17,
- 'R' => 18,
- 'S' => 19,
- 'T' => 20,
- 'U' => 21,
- 'V' => 22,
- 'W' => 23,
- 'X' => 24,
- 'Y' => 25,
- 'Z' => 26,
- 'a' => 1,
- 'b' => 2,
- 'c' => 3,
- 'd' => 4,
- 'e' => 5,
- 'f' => 6,
- 'g' => 7,
- 'h' => 8,
- 'i' => 9,
- 'j' => 10,
- 'k' => 11,
- 'l' => 12,
- 'm' => 13,
- 'n' => 14,
- 'o' => 15,
- 'p' => 16,
- 'q' => 17,
- 'r' => 18,
- 's' => 19,
- 't' => 20,
- 'u' => 21,
- 'v' => 22,
- 'w' => 23,
- 'x' => 24,
- 'y' => 25,
- 'z' => 26,
- 0 => 27,
- 1 => 28,
- 2 => 29,
- 3 => 30,
- 4 => 31,
- 5 => 32,
- 6 => 33,
- 7 => 34,
- 8 => 35,
- 9 => 36,
- );
- while (isset($str[$i])) {
- $index = $lt[$str[$i]];
- $t = $b;
- $b += $a;
- if ($b >= 36) {
- $b -= 36;
- }
- $a = $t;
- $index -= $a;
- if ($index <= 0) {
- $index += 36;
- }
- if ($index > 26) {
- if ($lastIndex === 11) {
- $cols = $index - 27;
- $ref =& $cols;
- ++$k;
- } elseif ($lastIndex === 23) {
- $rows = $index - 27;
- $ref =& $rows;
- ++$k;
- } elseif ($lastIndex === 1) {
- $min = $index - 27;
- ++$k;
- } elseif ($lastIndex === 26) {
- $max = $index - 27;
- ++$k;
- }
- if (isset($ref) && isset($str[$i + 1])) {
- $next = $lt[$str[$i + 1]];
- $next -= $b;
- if ($next <= 0) {
- $next += 36;
- }
- if ($next > 26) {
- $ref = $ref * 10 + $next - 27;
- }
- unset($ref);
- }
- if ($k === 4) {
- break;
- }
- }
- $lastIndex = $index;
- ++$i;
- }
- if ($min === $max) {
- echo str_repeat(str_repeat(str_repeat($min, $cols) . "\n", $rows) . "\n", 3);
- exit;
- }
- // 1 kwadrat
- $width = $cols;
- $height = $rows;
- $out = str_repeat(str_repeat(str_repeat(' ', $cols) . "\n", $rows) . "\n", 3);
- $x = -1;
- $y = 0;
- $current = $min - 1;
- $lineSize = $cols + 1;
- $oy = 0;
- while ($height > 0 && $width > 0) {
- if ($height > 0) {
- $n = $width + 1;
- while (--$n) {
- $out[$oy + ++$x] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- }
- --$height;
- }
- if ($width > 0) {
- $n = $height + 1;
- while (--$n) {
- $oy += $lineSize;
- $out[$oy + $x] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- }
- --$width;
- }
- if ($height > 0) {
- $n = $width + 1;
- while (--$n) {
- $out[$oy + --$x] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- }
- --$height;
- }
- if ($width > 0) {
- $n = $height + 1;
- while (--$n) {
- $oy -= $lineSize;
- $out[$oy + $x] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- }
- --$width;
- }
- }
- $ts = $lineSize * $rows;
- $in = $ts;
- ++$in;
- // 2 kwadrat
- $off = $in - $lineSize;
- $current = $min - 1;
- $f = true;
- $x = $cols + 1;
- while (--$x) {
- if ($f) {
- $c = $ts;
- while ($c) {
- $out[$c + $off] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- $c -= $lineSize;
- }
- } else {
- $y = $rows + 1;
- $c = $lineSize;
- while (--$y) {
- $out[$c + $off] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- $c += $lineSize;
- }
- }
- $f = !$f;
- ++$off;
- }
- $in += $ts;
- // 3 kwadrat
- $y = $rows + 1;
- $in += $ts;
- $current = $min - 1;
- while (--$y) {
- $x = $cols + 1;
- while (--$x) {
- $out[--$in] = ++$current;
- if ($current === $max) {
- $current = $min - 1;
- }
- }
- --$in;
- }
- echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement