aboutsummaryrefslogtreecommitdiffhomepage
path: root/2-the-false-awakens/remarks.markdown
blob: 7f072a9db932d3e660b5eafcb29f48355ea7e611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# Episode VII: The False Awakens

> A long time ago in a galaxy far,
> far away....




## Remarks

Just run it with:

```
$ ruby entry.rb
```

It will output "TRICK 2025".

It has been tested under the following environment:

```
$ ruby --version
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
```



## Description

The program consists of two parts:

* an interpreter of a subset of [FALSE esolang](https://esolangs.org/wiki/FALSE) and
* an obfuscated FALSE source code.

### FALSE interpreter

The interpreter part is embeeded into an ASCII art, "TRICK 2025" shaped like the Star Wars logo.
For more readable version, see `entry.clean.rb`.

### FALSE source code

The FALSE source code is encoded to the following expression:

```
  TrUE&FaLsE|TrUe&FaLse|TrUe&FAlSe|TrUE&FalSE|TrUe&FAlSe|TrUe&FaLse|TrUe&FaLse|TrUe&FaLse|TrUe&FaLse|TrUE&FAlsE|TrUe&FAlSE|TrUe&FALse|
  TrUE&FaLsE|TrUe&FAlSE|TrUe&FALse|TrUE&FalSe|TrUe&FALsE|TrUe&FALse|TrUE&FAlse|TrUe&FALsE|TrUe&FALse|TrUe&FALse|TrUE&FaLse|TrUE&FAlse|
  TrUe&FAlSe|TrUe&FALse|TrUE&FaLsE|TrUE&FalSe|TrUE&False|TrUE&FalSe|TrUe&FALSe|TrUe&FALSe|TrUe&FALSe|TrUe&FALSe|TrUE&FalSe|TrUE&FaLsE|
  TrUe&FAlSe|TrUe&FALse|false
```

Decoded version:

```
5$*3*$$$$9+,7+,2-,8-,,48*,5202....25*,
```

FALSE is a simple stack-based esolang. For instance,

* `5` pushes 5: `[5]`
* `$` duplicates the top: `[5 5]`
* `*` pushes the product: `[25]`
* `3` pushes 3: `[25 3]`
* `*` pushes the product: `[75]`
* `$$$$` duplicates the top 4 times: `[75 75 75 75 75]`
* `9` pushes 9: `[75 75 75 75 75 9]`
* `+` pushes the sum: `[75 75 75 75 84]`
* `,` writes the character: `[75 75 75 75]` (output `T`)
* `7` pushes 9: `[75 75 75 75 7]`
* `+` pushes the sum: `[75 75 75 82]`
* `,` writes the character: `[75 75 75]` (output `R`)
* ...


The source code is full of Star Wars references and homages.


```
# A long time ago in a galaxy far,
# far away....
```

This is the iconic Star Wars opening phrase.

```
# (inside the eval'ed code)

  while(c<p.size);
    if(!(i=p[c]));false;
    elsif"$"==i;s.push(s.last);
    elsif"%"==i;s.pop;
    ...
```

All comparison operations used in the program are written in the so-called "Yoda notation" (placing constants on the left hand side), referencing the Jedi Master Yoda.


```
     EPISODE_VII

  THE_FALSE_AWAKENS
```

This parodies the Star Wars Episode VII subtitle, "The Force Awakens."
"Force" refers to a supernatural power in Star Wars, but for our program, "false" has awakened instead because we used many `false`s.


```
  May.the.false.be.with.you;
```

This is a twist on one of the most famous Star Wars lines, "May the Force be with you."




## Internals

### FALSE interpreter

The interepreter is implemented as a method named `false`. In Ruby, you can use keywords as method names like this. It cannot be invoked directly, but you can call such a method via explicit receiver:`self.false()`


### Encoding the FALSE program

The FALSE program is obfuscated like this:

```
  TrUE&FaLsE|TrUe&FaLse|TrUe&FAlSe|TrUE&FalSE|TrUe&FAlSe|TrUe&FaLse|TrUe&FaLse|TrUe&FaLse|TrUe&FaLse|TrUE&FAlsE|TrUe&FAlSE|TrUe&FALse|
  TrUE&FaLsE|TrUe&FAlSE|TrUe&FALse|TrUE&FalSe|TrUe&FALsE|TrUe&FALse|TrUE&FAlse|TrUe&FALsE|TrUe&FALse|TrUe&FALse|TrUE&FaLse|TrUE&FAlse|
  TrUe&FAlSe|TrUe&FALse|TrUE&FaLsE|TrUE&FalSe|TrUE&False|TrUE&FalSe|TrUe&FALSe|TrUe&FALSe|TrUe&FALSe|TrUe&FALSe|TrUE&FalSe|TrUE&FaLsE|
  TrUe&FAlSe|TrUe&FALse|false
```

Each segment separated by `|` represents one instruction.

* `TrUE&FaLsE` => `5`
* `TrUe&FaLse` => `$`
* `TrUe&FAlSe` => `*`
* ...

This is achieved by defining `Object.const_missing`, `String#&`, and `String#|`.

First, our `const_missing `dynamically defines constants like `TrUE`:

```
# (inside the eval'ed code)

def Object.const_missing(n);
  const_set(n,n.to_s);
end;
```

With that, constant `TrUE` is resolved to string `"TrUE"`.

Second, such strings are concatenated with `&` with special decoding:

```
# (inside the eval'ed code)

class'String;
  def&(other);
    (self[1..]+other[1..])
      .chars
      .map{(_1.upcase==_1)??1:?0}
      .join
      .to_i(2)
      .chr;
  end;
end;
```

For `TrUE & FaLsE`,

```
    (self[1..]+other[1..])              # => "rUEaLsE"
      .chars                            # => ["r","U","E","a","L","s","E"]
      .map{(_1.upcase==_1)??1:?0}       # => ["0","1","1","0","1","0","1"]
      .join                             # => "0110101"
      .to_i(2)                          # => 53
      .chr;                             # => "5"
```

Finally, each FALSE instruction is concatenated by `|` operator:

```
# (inside the eval'ed code)

class'String;
  def|(other);
    (self||"")+(other||"");
  end;
end;
```


# Misc.

```
     EPISODE_VII

  THE_FALSE_AWAKENS
```

This code is equivalent to this:

```
     "EPISODE_VII"

  "THE_FALSE_AWAKENS"
```

It does nothing.

```
  May.the.false.be.with.you;
```

`May` is resolved to string `"May"` and the rest method chain is dispatched to `String#method_missing` defined here:

```
# (inside the eval'ed code)

class'String;
  def'method_missing(_);
    self;
  end;
end;
```

It does nothing too.





## Limitations

Our FALSE interpreter does not support the following instructions:

* `'c`: literal character "c"
* `ø`: pick
* `^`: input
* `"string"`: output "string"
* `ß`: flush the inout/output buffer.
* `{...}`: comments
* `\``: compile

Also, only one-digit numeric literals are supported, so `123` is interpreted as pushing `1`, `2` and `3` separately.