Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.43 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Polcode Code Contest PHP-2010.10
  4.  *
  5.  * Nick: NetCoder
  6.  */
  7.  
  8.  
  9. $str = $argv[1];
  10.  
  11. $a = $b = strlen($str) % 36;
  12. $i = 0;
  13. $lastIndex = 0;
  14. $k = 0;
  15.  
  16. $lt = array (
  17.   'A' => 1,
  18.   'B' => 2,
  19.   'C' => 3,
  20.   'D' => 4,
  21.   'E' => 5,
  22.   'F' => 6,
  23.   'G' => 7,
  24.   'H' => 8,
  25.   'I' => 9,
  26.   'J' => 10,
  27.   'K' => 11,
  28.   'L' => 12,
  29.   'M' => 13,
  30.   'N' => 14,
  31.   'O' => 15,
  32.   'P' => 16,
  33.   'Q' => 17,
  34.   'R' => 18,
  35.   'S' => 19,
  36.   'T' => 20,
  37.   'U' => 21,
  38.   'V' => 22,
  39.   'W' => 23,
  40.   'X' => 24,
  41.   'Y' => 25,
  42.   'Z' => 26,
  43.   'a' => 1,
  44.   'b' => 2,
  45.   'c' => 3,
  46.   'd' => 4,
  47.   'e' => 5,
  48.   'f' => 6,
  49.   'g' => 7,
  50.   'h' => 8,
  51.   'i' => 9,
  52.   'j' => 10,
  53.   'k' => 11,
  54.   'l' => 12,
  55.   'm' => 13,
  56.   'n' => 14,
  57.   'o' => 15,
  58.   'p' => 16,
  59.   'q' => 17,
  60.   'r' => 18,
  61.   's' => 19,
  62.   't' => 20,
  63.   'u' => 21,
  64.   'v' => 22,
  65.   'w' => 23,
  66.   'x' => 24,
  67.   'y' => 25,
  68.   'z' => 26,
  69.   0 => 27,
  70.   1 => 28,
  71.   2 => 29,
  72.   3 => 30,
  73.   4 => 31,
  74.   5 => 32,
  75.   6 => 33,
  76.   7 => 34,
  77.   8 => 35,
  78.   9 => 36,
  79. );
  80.  
  81. while (isset($str[$i])) {
  82.     $index = $lt[$str[$i]];
  83.  
  84.     $t = $b;
  85.     $b += $a;
  86.     if ($b >= 36) {
  87.         $b -= 36;
  88.     }
  89.     $a = $t;
  90.  
  91.     $index -= $a;
  92.     if ($index <= 0) {
  93.         $index += 36;
  94.     }
  95.  
  96.     if ($index > 26) {
  97.         if ($lastIndex === 11) {
  98.             $cols = $index - 27;
  99.             $ref =& $cols;
  100.             ++$k;
  101.         } elseif ($lastIndex === 23) {
  102.             $rows = $index - 27;
  103.             $ref =& $rows;
  104.             ++$k;
  105.         } elseif ($lastIndex === 1) {
  106.             $min = $index - 27;
  107.             ++$k;
  108.         } elseif ($lastIndex === 26) {
  109.             $max = $index - 27;
  110.             ++$k;
  111.         }
  112.  
  113.         if (isset($ref) && isset($str[$i + 1])) {
  114.             $next = $lt[$str[$i + 1]];
  115.             $next -= $b;
  116.             if ($next <= 0) {
  117.                 $next += 36;
  118.             }
  119.             if ($next > 26) {
  120.                 $ref = $ref * 10 + $next - 27;
  121.             }
  122.             unset($ref);
  123.         }
  124.  
  125.         if ($k === 4) {
  126.             break;
  127.         }
  128.     }
  129.  
  130.     $lastIndex = $index;
  131.  
  132.     ++$i;
  133. }
  134.  
  135. if ($min === $max) {
  136.     echo str_repeat(str_repeat(str_repeat($min, $cols) . "\n", $rows) . "\n", 3);
  137.     exit;
  138. }
  139.  
  140. // 1 kwadrat
  141. $width = $cols;
  142. $height = $rows;
  143.  
  144. $out = str_repeat(str_repeat(str_repeat(' ', $cols) . "\n", $rows) . "\n", 3);
  145. $x = -1;
  146. $y = 0;
  147. $current = $min - 1;
  148. $lineSize = $cols + 1;
  149. $oy = 0;
  150.  
  151. while ($height > 0 && $width > 0) {
  152.     if ($height > 0) {
  153.         $n = $width + 1;
  154.         while (--$n) {
  155.             $out[$oy + ++$x] = ++$current;
  156.             if ($current === $max) {
  157.                 $current = $min - 1;
  158.             }
  159.         }
  160.         --$height;
  161.     }
  162.  
  163.     if ($width > 0) {
  164.         $n = $height + 1;
  165.         while (--$n) {
  166.             $oy += $lineSize;
  167.             $out[$oy + $x] = ++$current;
  168.             if ($current === $max) {
  169.                 $current = $min - 1;
  170.             }
  171.         }
  172.         --$width;
  173.     }
  174.  
  175.     if ($height > 0) {
  176.         $n = $width + 1;
  177.         while (--$n) {
  178.             $out[$oy + --$x] = ++$current;
  179.             if ($current === $max) {
  180.                 $current = $min - 1;
  181.             }
  182.         }
  183.         --$height;
  184.     }
  185.  
  186.     if ($width > 0) {
  187.         $n = $height + 1;
  188.         while (--$n) {
  189.             $oy -= $lineSize;  
  190.             $out[$oy + $x] = ++$current;
  191.             if ($current === $max) {
  192.                 $current = $min - 1;
  193.             }
  194.         }
  195.         --$width;
  196.     }
  197. }
  198.  
  199. $ts = $lineSize * $rows;
  200. $in = $ts;
  201. ++$in;
  202.  
  203. // 2 kwadrat
  204. $off = $in - $lineSize;
  205. $current = $min - 1;
  206. $f = true;
  207. $x = $cols + 1;
  208.  
  209. while (--$x) {
  210.     if ($f) {
  211.         $c = $ts;
  212.         while ($c) {
  213.             $out[$c + $off] = ++$current;
  214.             if ($current === $max) {
  215.                 $current = $min - 1;
  216.             }
  217.             $c -= $lineSize;
  218.         }
  219.     } else {
  220.         $y = $rows + 1;
  221.         $c = $lineSize;
  222.         while (--$y) {
  223.             $out[$c + $off] = ++$current;
  224.             if ($current === $max) {
  225.                 $current = $min - 1;
  226.             }
  227.             $c += $lineSize;
  228.         }
  229.     }
  230.     $f = !$f;
  231.     ++$off;
  232. }
  233.  
  234. $in += $ts;
  235.  
  236. // 3 kwadrat
  237. $y = $rows + 1;
  238. $in += $ts;
  239.  
  240. $current = $min - 1;
  241.  
  242. while (--$y) {
  243.     $x = $cols + 1;
  244.     while (--$x) {
  245.         $out[--$in] = ++$current;
  246.         if ($current === $max) {
  247.             $current = $min - 1;
  248.         }
  249.     }
  250.     --$in;
  251. }
  252.  
  253. echo $out;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement