Link.FYI

Pastebin

Create New My Pastes

Code (PHP) pasted on 2019-01-31, 22:21 Raw Source

  1. <?php
  2. function getTetrominos(int $count): string {
  3.    $bag = [];
  4.    $tetrominos = [];
  5.    while (count($tetrominos) < 50) {
  6.       if (empty($bag)) {
  7.         $bag = initTetrominoBag();
  8.       }
  9.       $tetrominos[] = array_pop($bag);
  10.    }
  11.    return join('', $tetrominos);
  12. }
  13.  
  14. function initTetrominoBag(): array {
  15.    $bag = ['I', 'O', 'L', 'J', 'T', 'S', 'Z'];
  16.    shuffle($bag);
  17.    return $bag;
  18. }
  19.  
  20. echo getTetrominos(50);