| 1 |
### Remarks |
| 2 |
|
| 3 |
Just run it with no argument: |
| 4 |
|
| 5 |
ruby entry.rb |
| 6 |
|
| 7 |
Or run it with one non-ascii half-width character argument: |
| 8 |
|
| 9 |
ruby entry.rb ⬮ |
| 10 |
ruby entry.rb 𓆡 |
| 11 |
|
| 12 |
I confirmed the following implementations/platforms: |
| 13 |
|
| 14 |
* ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19] |
| 15 |
* ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-darwin20] |
| 16 |
|
| 17 |
### Description |
| 18 |
|
| 19 |
This program is an aquatic quine. |
| 20 |
Some characters in the code are overwritten with `" "`, but this program can restore the missing parts. |
| 21 |
Every frame of this animation is an executable ruby program that let fishes start swimming again from their current position. |
| 22 |
|
| 23 |
### Internals |
| 24 |
|
| 25 |
#### Error Correction |
| 26 |
|
| 27 |
Error correction is performed for each block of length 135. |
| 28 |
It consists of 89 kinds of characters(`[*('!'..'W'), '[', *(']'..'}')]`) and satisfies the following constraint. |
| 29 |
|
| 30 |
``` |
| 31 |
matrix(size: 45x135) * block_vector(size: 135) % 89 == zero_vector(size: 45) |
| 32 |
``` |
| 33 |
|
| 34 |
To restore the missing characters in the block, we need to solve a linear equation problem in modulo 89. |
| 35 |
This can be achieved by using bundled gem 'matrix' and overwriting some methods. |
| 36 |
|
| 37 |
```ruby |
| 38 |
require 'matrix' |
| 39 |
matrix = Matrix[[3, 1, 4], [1, 5, 9], [2, 6, 5]] |
| 40 |
class Integer |
| 41 |
def quo(x) = self * x.pow(87, 89) % 89 # Fermat's little theorem. 89 is a prime number. |
| 42 |
def abs() = [self % 89, 89 - self % 89].min # To avoid division by multiple of 89. |
| 43 |
end |
| 44 |
answer = matrix.lup.solve([1, 2, 3]) #=> Vector[24, 42, 83] |
| 45 |
(matrix * answer).map { _1 % 89 } #=> Vector[1, 2, 3] |
| 46 |
``` |
| 47 |
|
| 48 |
#### Resuming Animation |
| 49 |
|
| 50 |
The entire animation of this fish tank is a loop of 960 frames. |
| 51 |
This program uses position of the floating bubbles to detect current frame number from the executed source code. |