all stats

Makefile_dot_in's stats

guessed the most

namecorrect guessesgames togetherratio
essaie370.429
yeti270.286
kimapr270.286
rrebbbbeca150.200
ponydork160.167
Moja040.000
oleander0110.000
Dolphy070.000
LyricLy050.000

were guessed the most by

namecorrect guessesgames togetherratio
LyricLy450.800
Dolphy370.429
rrebbbbeca250.400
yeti260.333
essaie270.286
oleander3110.273
ponydork060.000
kimapr060.000

entries

round #82

submitted at
0 likes

guesses
comments 0

post a comment


gdc.ml ASCII text
 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
#!/usr/bin/env utop
(* horrible music follows sorry *)

(* github ver *)
let () = Topfind.load_deeply ["llama"]

open StdLabels
open Llama
open Dsl

let gate = periodic_gate
    ~frequency_hz:(const 2.0)
    ~duty_01:(const 0.05)

let envelope =
    ar_linear ~gate ~attack_s:(const 0.1) ~release_s:(const 0.01)

let click =
    (* _not_ synced up with the moog module *)
    oscillator (const Pulse) (const 100.0)
    |> scale 500.0
    |> chebyshev_low_pass_filter
        ~resonance:(const 1.0)
        ~cutoff_hz:(envelope |> scale 500.0 |> offset 200.0)
    |> ( *.. ) envelope

let sgn =
    let lst = [ `E; `C; `D; `B; `D; `E; `F; `E ]
        |> List.map ~f:(fun note -> (note, match note with `A | `B -> 3 | _ -> 4))
        |> List.map ~f:Music.Note.frequency_hz
        |> List.map ~f:(Fun.compose (oscillator (const Pulse)) const)
        |> List.map ~f:(fun value -> { value; period_s = const 1.0 })
    in
    let { value; gate } = generic_step_sequencer lst (Gate.to_trigger gate) in
    ar_linear ~gate ~attack_s:(const 0.01) ~release_s:(const 0.1) *.. value

let mel =
    let meltrig = clock_of_period_s (const 4.0) in
    let chords =
        [
            [ `C, 3 ];
            [ `E, 3 ];
            [ `G, 3 ];
        ]
        |> List.map ~f:begin fun notes ->
            sum @@ List.map notes ~f:begin fun note -> note
                |> Music.Note.frequency_hz
                |> const
                |> oscillator (const Pulse)
            end
        end
    in
    let { value; gate } = random_sequencer chords (const 4.0) meltrig in
    ar_linear ~gate ~attack_s:(const 0.01) ~release_s:(const 0.1) *.. value
    |> delay ~time_s:(const 16.0) ~fill:0.0


let () = play_signal @@ sum [click; sgn; mel]

round #80

submitted at
1 like

guesses
comments 0

post a comment


sdl-ext.vapi ASCII text
1
2
3
4
5
[CCode(cname = "SDL_RenderSetClipRect")]
static int set_clip_rect(SDL.Video.Renderer renderer, SDL.Video.Rect? rect);

[CCode(cname = "SDL_OpenAudioDevice")]
static SDL.Audio.AudioDevice open_audio_device(string? device, bool iscapture, ref SDL.Audio.AudioSpec desired, out SDL.Audio.AudioSpec obtained, int allowed_changes);
sitelen-Mosu.vala ASCII text
  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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
#!/usr/bin/env -S vala --pkg sdl2 --pkg json-glib-1.0 --pkg posix sdl-ext.vapi
// valac --pkg sdl2 --pkg json-glib-1.0 --pkg posix sitelen-Mosu.vala sdl-ext.vapi --Xcc=-lm

using SDL;
using SDL.Video;

struct Glyph {
    uint16 x;
    uint16 y;
    uint8 width;
    uint8 height;
    uint8 baseline;
    bool extant;
    unichar c;

    Glyph(Json.Array data, uint8 baseline, Surface surf, int x, int y, unichar c) {
        this.x = (uint16) x;
        this.y = (uint16) y;
        this.c = c;
        this.baseline = baseline;
        this.width = 0;
        this.height = (uint8) data.get_length();
        this.extant = true;
        for (int dy = 0; dy < data.get_length(); dy++) {
            string row = data.get_string_element(dy);
            this.width = uint8.max(this.width, (uint8) row.length);
            for (int dx = 0; dx < row.length; ++dx) {
                uint8* ptr = surf.pixels;
                int rx = x + dx;
                int ry = y + dy;
                ptr[ry * surf.pitch + rx / 8] |= (uint8) (row[dx] == '#') << (uint8) (rx % 8);
            }
        }
    }

    public Rect get_rect() {
        return Rect() {
            x = x,
            y = y,
            w = width,
            h = height
        };
    }
}

struct Block {
    Glyph[] characters;
}

struct Plane {
    Block[] blocks;
}

class Morse {
    uint8[] long_beep;
    uint8[] short_beep;
    Audio.AudioDevice audio_device;
    Audio.AudioSpec spec;

    // generates earrape
    int16[] synthesize_sine(double frequency, double seconds, double amplitude) {
        uint buf_length = (uint) (seconds * (double) spec.freq);
        int16[] res = new int16[buf_length];
        for (uint i = 0; i < buf_length; i++) {
            double t = (double) i / (double) spec.freq;
            res[i] = (int16) ((double) int16.MAX * Math.sin(2 * Math.PI * frequency * t) * amplitude);
            print("res[%u]: %d t: %f\n", i, res[i], t);
        }

        return res;
    }

    public Morse() {
        spec = Audio.AudioSpec() {
            freq = 44100,
            format = Audio.AudioFormat.S16,
            channels = 1,
            samples = 1024,
            callback = null
        };
        uint32 len;
        Audio.AudioSpec? x = Audio.load("short.wav", ref spec, out short_beep, out len);
        if (x == null)
            error("short load: %s", SDL.get_error());
        x = Audio.load("long.wav", ref spec, out long_beep, out len);
        if (x == null)
            error("long load: %s", SDL.get_error());
        audio_device = open_audio_device(null, false, ref spec, null, 0);
        if (audio_device == 0)
            error("%s", SDL.get_error());

    }
}

class TextEditor {
    private const int MAX_CODEPOINT = 0x10ffff;
    private Plane characters[(MAX_CODEPOINT >> 16) + 1];
    private int line_height;
    private Surface surface;
    public Texture texture;
    public Texture itexture;
    private unowned Renderer renderer;
    private StringBuilder[] lines;
    private int maxcharh;
    private int max_baseline;
    private Color fg;
    private Color bg;
    public Rect bounds { get; set; }
    public int scale { get; set; }
    public int cursor_line { get; set; default = 0; }
    public int cursor_column { get; set; default = 0; }

    public Glyph? lookup(unichar codepoint) {
        unowned Plane? p = characters[codepoint >> 16];
        if (p.blocks == null) return null;
        unowned Block? b = p.blocks[codepoint >> 8 & 0xff];
        if (b.characters == null) return null;
        unowned Glyph? g = b.characters[codepoint & 0xff];
        if (!g.extant) return null;
        return g;
    }

    void insert(unichar codepoint, Glyph c) {
        Plane* p = &characters[codepoint >> 16];
        if (p->blocks == null)
            p->blocks = new Block[(MAX_CODEPOINT >> 8 & 0xff) + 1];

        Block* b = &p->blocks[codepoint >> 8 & 0xff];
        if (b->characters == null)
            b->characters = new Glyph[(MAX_CODEPOINT & 0xff) + 1];

        b->characters[codepoint & 0xff] = c;
    }

    public int line_width(string s, bool selected) {
        int result = 0;
        int index = 0;
        unichar codepoint;
        bool selected_passed = false;
        bool invert;
        while (next_char(s, selected, ref index, ref selected_passed, out codepoint, out invert)) {
            Glyph? g = lookup(codepoint);
            if (g == null) continue;
            result += (g.width + 2) * scale;
        }

        return result;
    }

    private bool next_char(string s, bool selected, ref int index, ref bool selected_passed, out unichar codepoint, out bool invert) {
        int oldindex = index;
        bool res = s.get_next_char(ref index, out codepoint);
        invert = false;
        if (selected && !selected_passed && oldindex == cursor_column) {
            selected_passed = true;
            invert = true;
            if (!res) {
                codepoint = ' ';
                return true;
            }
        }

        return res;
    }

    public void render_line(int x, int y, string s, bool selected) {
        int index = 0;

        unichar codepoint = 0;
        bool selected_passed = false;
        bool invert;
        while (next_char(s, selected, ref index, ref selected_passed, out codepoint, out invert)) {
            Glyph? g = lookup(codepoint);
            if (g == null) continue;

            var outline_rect = Rect() {
                x = x,
                y = y - g.baseline * scale,
                w = (g.width + 2) * scale,
                h = (g.height + 2) * scale
            };

            var target_rect = Rect() {
                x = outline_rect.x + scale,
                y = outline_rect.y + scale,
                w = outline_rect.w - 2 * scale,
                h = outline_rect.h - 2 * scale
            };

            int res;
            if (invert) {
                renderer.set_draw_color(fg.r, fg.g, fg.b, fg.a);
                renderer.fill_rect(outline_rect);
                res = renderer.copy(itexture, g.get_rect(), target_rect);
            } else {
                renderer.set_draw_color(bg.r, bg.g, bg.b, bg.a);
                renderer.fill_rect(outline_rect);
                res = renderer.copy(texture, g.get_rect(), target_rect);
            }
            if (res != 0) error("%s", SDL.get_error());

            x += (int) outline_rect.w;
        }
    }

    public void render() {
        int scaled_line_diff = scale * (line_height + 2);
        clear_error();
        int e = set_clip_rect(renderer, bounds);
        if (e != 0) error("%s", SDL.get_error());

        int nlines = int.min((int) bounds.h / scaled_line_diff + 1, lines.length);
        int y = bounds.y + (int) bounds.h - scale * maxcharh + scale * max_baseline - 50; // mystery factor
        print(@"bounds.y: $(bounds.y) bounds.h: $(bounds.h) maxcharh: $maxcharh max_baseline: $max_baseline ystart: $y\n");
        for (int i = lines.length - 1; i >= lines.length - nlines; i--) {
            int linew = line_width(lines[i].str, i == cursor_line);
            int x;
            if (linew < bounds.w)
                x = bounds.x;
            else
                x = bounds.x + (int) bounds.w - linew;

            render_line(x, y, lines[i].str, i == cursor_line);
            y -= scaled_line_diff;
        }

        e = set_clip_rect(renderer, null);
        if (e != 0) error("%s", SDL.get_error());
    }

    public void set_colors(Color fg, Color bg) {
        print("%d\n", surface.format.palette.colors.length);

        // int status = surface.format.palette.set_colors({bg, fg}, 0); compiler bug?
        surface.format.palette.colors[0] = bg;
        surface.format.palette.colors[1] = fg;
        texture = Texture.create_from_surface(renderer, surface);
        surface.format.palette.colors[0] = fg;
        surface.format.palette.colors[1] = bg;
        itexture = Texture.create_from_surface(renderer, surface);

        this.fg = fg;
        this.bg = bg;
    }

    public void on_key(Input.Keycode keycode, out string? line) {
        line = null;
        switch (keycode) {
            case Input.Keycode.BACKSPACE:
                if (lines.length > 1 && lines[cursor_line].len == 0) {
                    lines.move(cursor_line+1, cursor_line, lines.length - cursor_line - 1);
                    lines.resize(lines.length - 1);
                    --cursor_line;
                    cursor_column = (int) lines[cursor_line].len;
                } else if (cursor_column != 0) {
                    lines[cursor_line].erase(cursor_column - 1, 1);
                    --cursor_column;
                }
                break;

            case Input.Keycode.RETURN:
                int oldlen = lines.length;
                lines.resize(lines.length + 1);
                lines.move(cursor_line+1, cursor_line+2, oldlen - (cursor_line + 1));
                lines[cursor_line + 1] = new StringBuilder(lines[cursor_line].str[cursor_column:]);
                lines[cursor_line].truncate(cursor_column);
                line = lines[cursor_line].str;
                cursor_line++;
                cursor_column = 0;
                break;
        }
    }

    public void handle(SDL.Event ev, out string? line) {
        line = null;
        switch (ev.type) {
            case EventType.TEXTINPUT:
                print("line_text %s\n", ev.text.text);
                lines[cursor_line].insert(cursor_column, ev.text.text);
                cursor_column += ev.text.text.length;
                break;
            case EventType.KEYDOWN:
                on_key(ev.key.keysym.sym, out line);
                break;
            default:
                break;
        }
    }

    public TextEditor(Renderer r) throws GLib.Error {
        renderer = r;
        max_baseline = 0;
        lines = { new StringBuilder() };

        var p = new Json.Parser();
        p.load_from_file("ultlf/ultlf-data/trimmed.json");
        Json.Array data = p.get_root().get_array();
        p.load_from_file("ultlf/ultlf-data/codepoints.json");
        Json.Array codepoints = p.get_root().get_array();
        p.load_from_file("ultlf/ultlf-data/trimmed_baselines.json");
        Json.Array baselines = p.get_root().get_array();

        int maxcharw = 0;
        maxcharh = 0;
        for (int i = 0; i < data.get_length(); i++) {
            Json.Array a = data.get_array_element(i);
            maxcharh = int.max(maxcharh, (int)a.get_length());
            for (int y = 0; y < a.get_length(); y++) {
                string row = a.get_string_element(y);
                maxcharw = int.max(maxcharw, row.length);
            }
        }
        print("len: %u, maxcharh: %d\n", codepoints.get_length(), maxcharh);

        surface = new Surface.rgb_with_format(
            (int)(maxcharw * 32),
            (int)(maxcharh * (codepoints.get_length() / 32)),
            1,
            PixelRAWFormat.INDEX1LSB
        );

        Posix.memset(surface.pixels, surface.pitch * surface.h, 0);

        print("surfw: %d, surfh: %d\n", surface.w, surface.h);

        for (int i = 0; i < codepoints.get_length(); i++) {
            Glyph c = Glyph(
                data.get_array_element(i),
                (uint8) baselines.get_int_element(i),
                surface,
                (i % 32) * maxcharw,
                (i / 32) * maxcharh,
                (unichar)codepoints.get_int_element(i)
            );
            insert((unichar) codepoints.get_int_element(i), c);
            max_baseline = int.max(max_baseline, c.baseline);
        }

        line_height = maxcharh + 2;
    }
}

public string[] morse_alphabet() {
    string[] retval = new string[256];
    retval['A'] = ".-";
    retval['B'] = "-...";
    retval['C'] = "-.-.";
    retval['D'] = "-..";
    retval['E'] = ".";
    retval['F'] = "..-.";
    retval['G'] = "--.";
    retval['H'] = "....";
    retval['I'] = "..";
    retval['J'] = ".---";
    retval['K'] = "-.-";
    retval['L'] = ".-..";
    retval['M'] = "--";
    retval['N'] = "-.";
    retval['O'] = "...";
    retval['P'] = ".--.";
    retval['Q'] = "--.-";
    retval['R'] = ".-.";
    retval['S'] = "...";
    retval['T'] = ".";
    retval['U'] = "..-";
    retval['V'] = "...-";
    retval['W'] = ".--";
    retval['X'] = "-..-";
    retval['Y'] = "-.--";
    retval['Z'] = "--..";
    retval['1'] = ".----";
    retval['2'] = "..---";
    retval['3'] = "...--";
    retval['4'] = "....-";
    retval['5'] = ".....";
    retval['6'] = "-....";
    retval['7'] = "--...";
    retval['8'] = "---..";
    retval['9'] = "----.";
    retval['0'] = "-----";
    return retval;
}

class MorseShow {
    public unowned Renderer r;
    public unowned MyRenderer myR; // just as about I was about to take my shoes
    public Rect bound;

    public void on(int delay) {
        myR.render_normal();
        r.set_draw_color(255, 255, 255, 255);
        r.fill_rect(bound);
        r.present();
        SDL.Timer.delay(100 * delay);
    }

    public void off(int delay) {
        myR.render_normal();
        r.set_draw_color(0, 0, 0, 255);
        r.fill_rect(bound);
        r.present();
        SDL.Timer.delay(100 * delay);
    }
}

class MyRenderer {
    private TextEditor tr;
    private MorseShow morseShow;
    private unowned Renderer renderer;
    private unowned Window window;
    private string morse_line;
    private string[] alphabet;

    public MyRenderer(Window w, Renderer r) throws GLib.Error {
        alphabet = morse_alphabet();
        window = w;
        renderer = r;
        morseShow = new MorseShow();
        morseShow.r = r;
        morseShow.myR = this;
        tr = new TextEditor(r);
        tr.set_colors(
            Color() { r = 255, g = 255, b = 255, a = 255 },
            Color() { r = 0, g = 0, b = 0, a = 0 }
        );
        tr.scale = 10;
    }

    public void on_event(Event ev) {
        morse_line = null;
        tr.handle(ev, out morse_line);
        render();
    }

    public void render_normal() {
        int winw, winh;
        window.get_size(out winw, out winh);
        renderer.set_draw_color(0, 0, 0, 255);
        renderer.clear();
        tr.bounds = Rect() { x = 0, y = 0, w = winw, h = winh - 100 };
        tr.render();
    }

    public void render() {
        render_normal();
        renderer.present();
        if (morse_line != null) {
            int winw, winh;
            window.get_size(out winw, out winh);
            morseShow.bound = Rect() { x = 0, y = winh - 100, w = 100, h = 100 };
            int index = 0;
            unichar codepoint;
            while (morse_line.get_next_char(ref index, out codepoint)) {
                if (codepoint == ' ') {
                    morseShow.off(7);
                    continue;
                }
                string? a = alphabet[codepoint.toupper()];
                if (a == null) continue;

                for (int i = 0; i < a.length; i++) {
                    switch (a[i]) {
                        case '.':
                            morseShow.on(1);
                            break;
                        case '-':
                            morseShow.on(3);
                            break;
                    }
                    morseShow.off(3);
                }
            }
        }
    }
}

void main() {
    SDL.init();
    var win = new Window("sitelen Mosu", 0, 0, 400, 400, WindowFlags.RESIZABLE);
    GL.set_attribute(GL.Attributes.CONTEXT_MAJOR_VERSION, 3);
    GL.set_attribute(GL.Attributes.CONTEXT_MINOR_VERSION, 2);
    GL.set_attribute(GL.Attributes.CONTEXT_PROFILE_MASK, GL.ProfileType.CORE);
    var renderer = Renderer.create(win, -1, RendererFlags.ACCELERATED);
    if (renderer == null) {
        printerr("Error initializing SDL renderer");
        return;
    }

    MyRenderer myRenderer;
    try {
        myRenderer = new MyRenderer(win, renderer);
    } catch (GLib.Error e) {
        printerr(e.message);
        return;
    }

    Event ev;
    while (Event.wait(out ev) != 0 && ev.type != QUIT) {
        myRenderer.on_event(ev);
        // Rect r = g.get_rect();
        // print(@"x: $(r.x) y: $(r.y) w: $(r.w) h: $(r.h) gx: $(g.x) rcp: $(g.c)\n");
        // Glyph? g = tr.lookup(codepoint);
        // renderer.copy(tr.texture, g.get_rect(), null);
    }
    SDL.quit();
}

round #78

submitted at
0 likes

guesses
comments 0

post a comment


cg17710.py ASCII text, with CRLF line terminators
 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
from operator import *
from functools import reduce, partial
import random

# @author SoundOfSpouting
# @template T
# @param {Iterable<T>} it
# @param {T -> void} callback
foreach = (lambda it, callback:
  (foreach_(iter(it), callback)))

foreach_ = (lambda it, callback:
  (el := next(it, None),
   el and (callback(el), foreach(it, callback))))

# @author SoundOfSpouting
# @param {number} x
# @param {number} y
Coordinate = type("Coordinate", (), dict(
  __init__ = (lambda self, x, y:
    (setattr(self, "x", x),                                                                                                                                                         (
     setattr(self, "y", y)))                                                                                                                                                        and None)
  ,
  # @author SoundOfSpouting
  # @returns {string}
  __str__ = (lambda self: 
    ("%X%d" % (self.y + 10, self.x))),

  # @author SoundOfSpouting
  # @returns {number}
  getX = (lambda self: 
    (self.x)),

  # @author SoundOfSpouting
  # @returns {number}
  getY = (lambda self: 
    (self.y)),

  add = (lambda self, other:
    (Coordinate(add(self.x, other.x),
                add(self.y, other.y))))
));

# @author SoundOfSpouting
Board = type("Board", (), dict(
  HEIGHT = 10,
  WIDTH = 10,

  # @author SoundOfSpouting
  __init__ = (lambda self:
    (setattr(self, "b", 0))),

  # @author SoundOfSpouting
  # @param {Coordinate} coord
  # @returns {boolean}
  at = (lambda self, coord:
    (eq(and_(rshift(self.b, add(mul(coord.getY(), Board.WIDTH), coord.getX())), 1), 1))),

  # @author SoundOfSpouting
  # @param {Coordinate} coord
  # @param {boolean} newVal
  # @returns {void}
  set = (lambda self, coord, newVal:
    (pos := coord.getY() * Board.WIDTH + coord.getX(),
     setattr(self, "b", or_(and_(self.b, invert(lshift(1, pos))), lshift(+newVal, pos))))),

  # @author SoundOfSpouting
  # @returns {bool}
  place = (lambda self, coord, num, dx = 0, dy = 0:
    (any(map((lambda i: self.at(coord.add(Coordinate(mul(i, dx), mul(i, dy))))),
             range(num))))
    or foreach(range(num), lambda i: self.set(Coordinate(mul(i, dx), mul(i, dy)), True))
    and None)
));

# @author SoundOfSpouting
# @returns {Coordinate[]}
place = (lambda:
  next(filter((lambda x: is_not(x, None)), iter(
    (lambda:
     (b := Board(),
      l := list(map((lambda num: (num, Coordinate(random.randint(0, 10), random.randint(0, 10)), random.choice([(0, 1), (1, 0)]))), range(5, 0, -1))),                     (
      None if not any(map((lambda t: b.place(t[1], t[0], *t[2])), l)) else list(map((lambda x: (x[0], x[2])), l))))                                                                              [-1]),
    0))));


# @author SoundOfSpouting
# @returns {string}
boom = (lambda:
  "\n".join(map((lambda x: Coordinate(*x)), product(range(Board.WIDTH), range(Board.HEIGHT)))));

main = (lambda:
  print("\n".join(map((lambda t: "%c%s" % ({(0, 1): "|", (1, 0): "-"}[t[1]], t[0])), place())),
        boom()))

main()

round #77

submitted at
0 likes

guesses
comments 0

post a comment


luacontroller.lua ASCII text
  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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
-- by hatsune miku
notes = {
  {delta = 0, duration = 0.1919355958333333, pitch = 0.7399888454232688},
  {delta = 0.3870969999999999, duration = 0.1919355958333333, pitch = 0.9877666025122482},
  {delta = 0.3870969999999999, duration = 0.1919355958333333, pitch = 0.6592551138257399},
  {delta = 0.387097, duration = 0.1919355958333333, pitch = 0.7399888454232688},
  {delta = 0.387097, duration = 0.1919355958333333, pitch = 0.9877666025122482},
  {delta = 0.387097, duration = 0.1919355958333333, pitch = 0.6592551138257399},
  {delta = 0.3870969999999998, duration = 0.1919355958333333, pitch = 0.7399888454232688},
  {delta = 0.3870969999999998, duration = 0.1919355958333333, pitch = 0.9877666025122482},
  {delta = 0.3870969999999998, duration = 0.1919355958333333, pitch = 0.6592551138257399},
  {delta = 0.3870969999999998, duration = 0.1919355958333333, pitch = 0.6592551138257399},
  {delta = 0.3870969999999998, duration = 0.19193559583333286, pitch = 0.7399888454232688},
  {delta = 0.3870969999999998, duration = 0.19193559583333375, pitch = 0.4938833012561241},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333286, pitch = 0.24694165062806206},
  {delta = 0.3870969999999998, duration = 0.3661292458333332, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333286, pitch = 0.16481377845643497},
  {delta = 0.3870969999999998, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333286, pitch = 0.24694165062806206},
  {delta = 0.3870969999999998, duration = 0.3661292458333332, pitch = 0.39199543598174924},
  {delta = 0.0, duration = 0.19193559583333286, pitch = 0.16481377845643497},
  {delta = 0.3870969999999998, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333286, pitch = 0.24694165062806206},
  {delta = 0.3870969999999998, duration = 0.19193559583333286, pitch = 0.16481377845643497},
  {delta = 0.3870969999999998, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333332, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333332, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333332, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333332, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.16481377845643497},
  {delta = 0.3870970000000007, duration = 0.5161293333333337, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333375, pitch = 0.1849972113558172},
  {delta = 0.3870970000000007, duration = 0.19193559583333375, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.39199543598174924},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.24694165062806206},
  {delta = 0.38709699999999714, duration = 0.3661292458333314, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.27718263097687207},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.7338713958333294, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.24694165062806206},
  {delta = 0.38709699999999714, duration = 0.3661292458333314, pitch = 0.39199543598174924},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.204839995833325, pitch = 0.12347082531403103},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.39199543598174924},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.7758069041666609, pitch = 0.44},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.204839995833318, pitch = 0.09799885899543734},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.24694165062806206},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.3661292458333314, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.24694165062806206},
  {delta = 0.38709699999999714, duration = 0.3661292458333314, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.204839995833325, pitch = 0.1468323839587038},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.5161293333333319, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.3661292458333314, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.06129035833333418, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333285, pitch = 0.11},
  {delta = 0.06290326250000078, duration = 0.4725809208333338, pitch = 0.27718263097687207},
  {delta = 0.3241937374999999, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.19193559583333197, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.19193559583333197, pitch = 0.1849972113558172},
  {delta = 0.38709699999999714, duration = 0.3661292458333314, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333197, pitch = 0.24694165062806206},
  {delta = 0.3870970000000007, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.516129333333339, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.12347082531403103},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.516129333333339, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.39199543598174924},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.516129333333339, pitch = 0.44},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.09799885899543734},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 1.1016135458333451, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 1.101613545833338, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 1.1016135458333451, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.11},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 1.101613545833338, pitch = 0.27718263097687207},
  {delta = 0.0, duration = 0.19193559583333553, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.19193559583333553, pitch = 0.16481377845643497},
  {delta = 0.38709699999999714, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.1468323839587038},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.12347082531403103},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.12347082531403103},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.09799885899543734},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.12347082531403103},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.1849972113558172},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.27718263097687207},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.13859131548843603},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.11},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.27718263097687207},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.24694165062806206},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.13859131548843603},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.1468323839587038},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.12347082531403103},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1849972113558172},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.32962755691286993},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.3699944227116344},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.6592551138257399},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.24694165062806206},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.5873295358348152},
  {delta = 0.0, duration = 0.73387139583334, pitch = 0.7839908719634985},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.12347082531403103},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.09799885899543734},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1468323839587038},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.7399888454232688},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.73387139583334, pitch = 0.5873295358348152},
  {delta = 0.0, duration = 0.73387139583334, pitch = 0.7399888454232688},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.12347082531403103},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.7399888454232688},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.19599771799087462},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.44},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.6592551138257399},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.16481377845643497},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.1468323839587038},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.5873295358348152},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.5543652619537441},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.44},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.6592551138257399},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.5873295358348152},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.5543652619537441},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.2936647679174076},
  {delta = 0.38709700000000424, duration = 0.516129333333339, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 1.1016135458333451, pitch = 0.13859131548843603},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.11},
  {delta = 0.0, duration = 2.2048399958333533, pitch = 0.16481377845643497},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.44},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.516129333333339, pitch = 0.4938833012561241},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.0, duration = 0.550000320833341, pitch = 0.13859131548843603},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.36612924583333495, pitch = 0.44},
  {delta = 0.0, duration = 0.36612924583333495, pitch = 0.22},
  {delta = 0.38709700000000424, duration = 0.5161293333333319, pitch = 0.4938833012561241},
}

function run_nilable(f, ...) if f ~= nil then return f(...) end end

F = {}

function F.program()
  mem.note_idx = 1
end

function play_note()
  local note = notes[mem.note_idx]
  digiline_send("digistuff_noteblock", {sound = "sine", pitch = note.pitch, cut = note.duration})
  mem.note_idx = mem.note_idx + 1
end

function F.interrupt()
  play_note()
  while notes[mem.note_idx] do
    local note = notes[mem.note_idx]
    if note.delta > 0 then
      interrupt(note.delta)
      return
    end
    play_note()
  end
end

F.on = F.interrupt

run_nilable(F[event.type])

round #76

submitted at
0 likes

guesses
comments 0

post a comment


dir interpreter
dir js
interpreter.js ASCII text
  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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
function display(s) {
	document.getElementById("output").innerHTML += s;
}

// A limited stack.
function Stack(array) {
	this.array = array;
	this.as_html = () => this.array.map(el => `<td><pre>${JSON.stringify(el)}</pre></td>`).join(""); 
	this.update_debug_table = function() {
		let row = document.getElementById("current-stack");
		row.innerHTML = `<td>current</td>${this.as_html()}`
	}
	function update_on_call(f) {
		return function(...a) {
			let retval = f(...a);
			this.update_debug_table();
			return retval;
		}
	}
	this.push = update_on_call((...x) => this.array.push(...x));
	this.pop  = update_on_call(() => this.array.pop());
	this.dump = function() {
		display(this.array.join(", "));
	}
}

function add_call_info(token, state) {
	let table = document.getElementById("debug");
	let row = table.insertRow();
	row.innerHTML = `<td><pre>${token.type}(${token.payload})</pre></td>${state.stack.as_html()}`;
}

function Settings(debug, nya_delay) {
	this.debug = debug;
	this.nya_delay = nya_delay;
}

function State(stack, settings, builtins) {
	this.settings = settings;
	this.stack = stack;
	this.functions = {};
	Object.assign(this.functions, builtins);
}

function Token(type, payload) {
	this.type    = type    || "";
	this.payload = payload || "";
}

function Error(code) {
	this.code = code;
}

const errors = {
	type: () => debug(new Error(1))
};

function asyncsleep(t) {
	return new Promise(resolve => setInterval(resolve, t));
}


function nyaypeof(x) {
	switch (typeof(x)) {
	case "number": return "num";
	case "string": return "str";
	case "boolean": return "bool";
	case "undefined": return "void";
	case "object":
		if (x instanceof Error)
			return "err";
	default:
		display(`Error: Cannot determine the type of ${x}\n`);
	}
}


function nyaize(types, f) {
	types.reverse();
	return async function(s) {
		let invalid = false;
		let args = types.map(type => {
			switch (type) {
			case "stack": return s.stack;
			case "any":   return s.stack.pop();
			case "state": return s;
			default:
				let arg = s.stack.pop();
				let argtype = nyaypeof(arg);

				if (argtype !== type) {
					invalid = true;
				}
				return arg;
			}
		});
		if (invalid) {
			s.stack.push(errors.type());
			return;
		}
		let retval = f(...args.reverse());
		if (retval instanceof Promise)
			retval = await retval;

		if (retval instanceof Array)
			s.stack.push(...retval);
		else if (retval !== undefined)
			s.stack.push(retval);
	}
}

const binnum = ["num", "num"];
const binstr = ["str", "str"];
const binbool = ["bool", "bool"]
const builtins = {
	"+":  nyaize(binnum, (a, b) => a + b),
	"-":  nyaize(binnum, (a, b) => a - b),
	"*":  nyaize(binnum, (a, b) => a * b),
	"/":  nyaize(binnum, (a, b) => a / b),
	"%":  nyaize(binnum, (a, b) => a % b),
	">":  nyaize(binnum, (a, b) => a > b),
	"<":  nyaize(binnum, (a, b) => a < b),
	"=":  nyaize(binnum, (a, b) => a == b),
	">=": nyaize(binnum, (a, b) => a >= b),
	"<=": nyaize(binnum, (a, b) => a <= b),
	".":  nyaize(binstr, (a, b) => a + b),
	"&":  nyaize(binbool,(a, b) => a && b),
	"|":  nyaize(binbool,(a, b) => a || b),
	"AwA":nyaize(["bool"], a => !a),
	"Nya":nyaize(["state", "str", "bool"], async function(s, code, cond) {
		while (cond) {
			if (nyaypeof(cond) !== "bool") {
				s.stack.push(errors.type());
				break;
			}
			await execute(code, s);
			await asyncsleep(s.settings.nya_delay);
			cond = s.stack.pop();
		}
	}),
	"Nom":nyaize(["stack", "num"], function(s, n) {
		for (let i = 0; i < n + 1; i++)
			s.pop();
	}),
	"Meow": nyaize(["str"], display),
	"Myaff": nyaize(["num"], num => num.toString()),
	"Dup" :nyaize(["any"], x => [x, x]),
	"ayN": nyaize(["stack", "num"], (s, a) => Array(a).fill(null).map(_ => s.pop())),
	"Nyurr": nyaize(["state", "str", "str"], function(state, code, name) {
		state.functions[name] = async (s) => {
			await execute(code, s);
		};
	}),
	"Nyaypeof": nyaize(["any"], nyaypeof)
};

// for debugging the interpreter (place your breakpoints here)
function debug(payload) {
	return;
}

async function run_token(token, s) {
	switch (token.type) {
	case 'n': s.stack.push(parseFloat(token.payload));                    break;
	case 's': s.stack.push(token.payload);                                break;
	case 'b': s.stack.push({"Purr": true, "HISS": false}[token.payload]); break;
	case 'f': await s.functions[token.payload](s);                          break;
	case 'd':
		if (s.settings.debug) {
			display(`Breakpoint ${token.payload}\nStack dump:`);
			s.stack.dump();
			display(`\n`);
		}
		break;
	case 'e': if (s.settings.debug)
		debug(token.payload);
		break;
	case 'c': break; // comment
	default: return false;
	}
	return true;

}

function tokenize(code) {
	code += " ";
	let tokens = [];
	let paren_depth = 0;
	let current_token = new Token();
	let current_mode = null;
	let whitespace = /\s/;
	/* two types of mode switching:
	   current_mode = modes.x // switches the mode to x with the next iteration
	   modes.x()              // switches the mode to x in this iteration

	   three modes:
	   none: parses types and consumes whitespace
	   simple: parses simple payloads
	   paren: parses parenthetical payloads
	*/
	let modes = {
		simple: function(c) {
			current_mode = modes.simple;
			if (whitespace.test(c)) {
				modes.none(c);
				return;
			} else if (c == "(") {
				modes.paren(c);
				return;
			}
			current_token.payload += c;
		},
		none: function(c) {
			current_mode = modes.none;
			if (whitespace.test(c)) {
				if (current_token.type != "") {
					tokens.push(current_token);
					current_token = new Token();
				}
				return;
			}
			current_token.type = c;
			current_mode = modes.simple;
		},
		paren: function(c) {
			current_mode = modes.paren;
			let internal_paren_depth = null;
			switch (c) {
			case '(':
				paren_depth++;
				if (paren_depth == 1)
					return;
				break;
			case ')':
				paren_depth--;
				if (paren_depth == 0) {
					current_mode = modes.none;
					return;
				}
				break;
			}
			current_token.payload += c;
		}


	};
	current_mode = modes.none;

	for (const c of code) {
		current_mode(c);
	}
	
	return tokens;
}

async function execute(code, state) {
	let tokens = tokenize(code);
	for (const token of tokens) {
		add_call_info(token, state);
		let valid = await run_token(token, state);
		if (!valid) {
			display(`Syntax error: Invalid type: ${token.type}\n`);
			break;
		}
	}
}
async function run() {
	let run_button = document.getElementById("run-button");
	run_button.disabled = true;
	run_button.innerHTML = "Running...";
	let stack = new Stack([]);
	let debug = document.getElementById("debug-mode").checked;
	let nya_delay = parseInt(document.getElementById("nya-delay").value);
	let settings = new Settings(debug, nya_delay);
	let state = new State(stack, settings, builtins);
	document.getElementById("output").innerHTML = "";
	await execute(document.getElementById("code").value, state);
	//	state.stack.dump();
	run_button.disabled = false;
	run_button.innerHTML = "Nya it out!";
}

function toggle_debug() {
	document.getElementById("demeow").classList.toggle("hidden");
}

function reset_table() {
	document.getElementById("debug").innerHTML = `<tr id="current-stack"></tr>`;
}
LICENSE ASCII text
1
2
3
The Nya General Public License.
THIS PROGRAM IS PROVIDED WITH NO WARRANTY, EXPRESS OR IMPLIED- and all that stuff.
Otherwise, you may use this program however you want, provided you agree to put on a cat ear headband upon the author's request.
fizzbuzz.txt ASCII text
 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
s(f% n0 f=) sDivides fNyurr c(creates a function named `divides' that cheks if the last element on the stack divides the second top element.)
s(fDup n100 f<) sNotReached100 fNyurr c(creates a function that returns whether 100 is the last element of the stack)

n0 c(starting value)
s(
	n1 f+ c(increment)
	s(
		sFizz fMeow bHISS
	)
        c(before reversal)
        n2 fayN c(first reversal)
        fDup    c(first duplication)
        n3 fayN c(second reversal)
        n2 fayN c(third reversal)
        n3 fDivides dCondition
        fDup    c(second suplication)
        n3 fayN c(fourth reversal)
        n2 fayN c(fifth reversal)
        fNya
	s(
		sBuzz fMeow bHISS
	) 
        n3 fayN c(first reversal #2)
        fDup    c(first duplication #2)
        n4 fayN c(second reversal #2)
        n2 fayN c(third reversal #2)
        n3 fayN c(fourth reversal #2)
        n5 fDivides dCondition
        fDup    c(second duplication #2)
        n3 fayN c(fifth reversal #2)
        n2 fayN c(sixth reversal #2)
        fNya
	s(
		fDup fMyaff fMeow bHISS e(exiting the loop)
	)
        c(before reversal #3)
        n3 fayN f| fAwA cCondition
        fNya
        cNumber
        s(
) fMeow
	fNotReached100 cCondition
) bPurr fNya
index.html ASCII text, with very long lines (588)
 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
<!DOCTYPE html>
<html>
  <head>
    <title>StackNya</title>
    <meta charset="utf-8">
    <style>
	.monospace {
		font-family: monospace;
	}
	td {
	    border: 1px solid black;
	}
	table {
	    max-width: 100vw;
	}
	pre {
	    text-overflow: ellipsis;
	    max-width: 20vw;
	    word-break: break-all;
	}
	.hidden {
	    display: none;
	}
    </style>
    <script src="js/interpreter.js"></script> 
  </head>
  <body>
    <h1>StackNya</h1>
    <h3>Description</h3>
    <p>StackNya is a stack-based language. This means that there's a single array (called a stack) around which all calculations are based. When a function is called, it receives its arguments by removing them from the stack.</p>
    <h3>Syntax</h3>
    <p>A StackNya program consists of one or mowe tokens. A token consists of a type (single letter) followed by a payload, optionally in parentheses, in which case it goes on as long as the initial parentheses are closed. Currently, these types exist: </p>
    <ul>
      <li><code>n</code> - pushes a number on the stack</li>
      <li><code>s</code> - pushes a string on the stack</li>
      <li><code>b</code> - pushes a boolean - <code>Purr</code> or <code>HISS</code></li>
      <li><code>f</code> - calls a function</li>
      <li><code>d</code> - dumps the stack to output - mostly obsolete due to the demeowing table</li>
      <li><code>e</code> - calls a function that does nothing but can be used to debug the interpreter at specific points by placing a breakpoint on that function.</li>
      <li><code>c</code> - no-op. Useful for comments and annotations for the demeowing table.</li>
    </ul>
    <h3>Functions</h3>
    <p>Functions that correspond to binary operators work mostly as you'd expect, taking the second-to-top element on the stack as their first argument, and the top element as their second argument. These include <p><code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>, <code>&gt;</code>, <code>&lt;</code>, <code>=</code> (like C <code>==</code>), <code>&gt;=</code>, <code>&lt;=</code>, <code>.</code> (used for concatenation - <code>+</code> works for integers only), <code>&amp;</code>, <code>|</code> (like C <code>&amp;&amp;</code> and <code>||</code>)</p>
    </p>
    <p>The others are:</p>
    <ul>
      <li><code>AwA</code> - negates the top of s.</li>
      <li><code>Nya</code> - takes 2 arguments: a string containing code and a boolean, then, if the boolean is true, runs the code as long as the top of the stack is <code>bPurr</code></li>
      <li><code>Nom</code> - takes a single numeric argument and consumes that many + 1 (because it also has to consume its argument) elements from the stack</li>
      <li><code>Meow</code> - takes a string and outputs it</li>
      <li><code>Myaff</code> - converts a number to a string</li>
      <li><code>Dup</code> - duplicates the top of stack.</li>
      <li><code>ayN</code> - takes a numeric argument n, then reverses the last <em>n</em> elements of stack.</li>
      <li><code>Nyurr</code> - takes a string containing NyaStack code, another string containing a function name, and creates a function with that name</li>
      <li><code>Nyaypeof</code> - returns the type of the top element of the stack, consuming it in the process. Current types are <code>num</code>, <code>str</code>, <code>bool</code>, <code>void</code> and <code>err</code></li>
    </ul>
    <h3>Examples</h3>
    <h4>Hello, World!</h4>
    <code>
      s(Hello, World!) fMeow
    </code>
    <h4><code>yes</code></h4>
    <pre>
s(s(y
) fMeow bPurr) bPurr fNya
    </pre>
    <h4>FizzBuzz</h4>
    <iframe src="fizzbuzz.txt"></iframe>
    <h2>Interpreter</h2>
    <div><textarea cols="40" rows="5" type="text" class="monospace" id="code"></textarea></div>
    <button onclick="toggle_debug();">Toggle demeow tools</button>
    <button id="run-button" onclick="run();">Nya it out!</button><br>
    <label for="nya-delay">The delay between consecutive iterations as done by <code>Nya</code> (ms) (smaller is faster):</label>
    <input type="number" id="nya-delay" name="nya-delay" value="50">
    <div class="hidden" id="demeow">
    <h2>Demeowing</h2>
    <input type="checkbox" id="debug-mode" name="debug-mode">
    <label for="debug-mode">Demeowing mode (enables commands <code>d</code> un <code>e</code>)</label>
    <p>(Warning: the table is a little broken but CSS is hard-)</p>
    <button onclick="reset_table();">Reset table</button>
    <table id="debug">
      <tr id="current-stack"></tr>
    </table>
    </div>
    <pre id="output"></pre>
    </div>
  </body>
</html>
a.stacknya ASCII text
 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
s(
	c(a b)
	n2 fayN fDup
	c(b a a)
	n3 fayN
	c(a a b)
	n2 fayN
	c(a b a)
) c(a b -- a b a) sOver fNyurr

s(
	c(a b c)
	n3 fayN fDup
	c(c b a a)
	n4 fayN
	c(a a b c)
	n2 fayN
	c(a a c b)
	n3 fayN
	c(a b c a)
) c(a b c -- a b c a) sPick fNyurr

s(fOver fOver) c(a b -- a b a b) sDup2 fNyurr
s(fPick fPick fPick) c(a b c -- a b c a b c) sDup3 fNyurr

s(s__InternalDip fNyurr n2 fayN f__InternalDip n2 fayN) c(a b code -- a' b) sDip fNyurr

s(bPurr fNya) c(code --) sDoWhile fNyurr
s(s(s( bHISS) f.) fDip fNya) c(code --) sIf fNyurr

c(An array is a pair (len data) on the stack.)

s(n0 s()) c(-- len data) sEmptyArray fNyurr
s(fMyaff s( n) n2 fayN f. f. s(n1 f+) fDip) c(len data el -- len' data') sAppend fNyurr
s(
	c(ex: 1 2 3 4 5 6 7 8 9 10)
	n2 fayN s__InternalIdxA fNyurr
	c(len idx)
	n2 fayN fOver f-
	c(idx len-idx)
	s(f__InternalIdxA n0 n) n2 fayN fMyaff f.
	s( fNom fDup n) f. fOver n1 f+ fMyaff f.
	s( fayN n0 n) f. n2 fayN fMyaff f.
	s( fNom) f.
	s__InternalIdxB fNyurr
	f__InternalIdxB
) c(len data idx[1..] -- elem) sIdx fNyurr

s(1 2 ) fMeow

c(len data num uses)
n2 s(n1 n2) n2 n1
s(
	fDup n0 f<=
	s(
		n0 fNom
		c(len data num)
		n1 f+
		fDup3 fIdx
	) n2 fayN fIf

	n4 fayN n3 fayN
	c(uses len data num)
	fDup fMyaff s( ) f. fMeow
	fDup
	c(uses len data num num)
	n4 fayN n3 fayN fAppend
	c(uses num len' data')
	n2 fayN n4 fayN
	n1 f-
	bPurr
) fDoWhile

round #75

submitted at
1 like

guesses
comments 0

post a comment


75cg.janet ASCII text, with very long lines (2278), with CRLF line terminators
 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
# You need janet spork mpv yt-dlp
(import spork/base64)
(import spork/rawterm)
(import spork/utf8)
(import spork/sh)

# Spoilers!
(def questions "ICBbQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PTdKTkZiTG1sU1VZIiA6YW5zd2VyICJMYWd0cmFpbiIgOmNvbW1lbnQgImhpIDozIn0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PXNiS1hpemo1V1U4IiA6YW5zd2VyICJUd28gWWVhcnMifQogICBAezp1cmwgImh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZGxBZUVjVm5udm8iIDphbnN3ZXIgIll1a2FpIFlvdW5nIn0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWhsZ2MzXzRXTDBNIiA6YW5zd2VyICJNb25vcmFsIn0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PWRQNHRfR0dsM0VzIiA6YW5zd2VyICJpbm5lciB1bml2ZXJzZSJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj16aGwtQ3MxLXNHNCIgOmFuc3dlciAiR2lvcmdpbyBieSBNb3JvZGVyIn0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PXRueVJCdVNzSXAwIiA6YW5zd2VyICJCYWthIG1pdGFpIGJ1dCBpdCdzIGluIHRva2kgcG9uYSJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1QUmhqcVBDUEF0cyIgOmFuc3dlciAiWWFlZ2FraSJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1hMERielVlLXI0USIgOmFuc3dlciAiSGVsaWtvcHRlciJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1hNXVRTXdSTUhjcyIgOmFuc3dlciAiSW5zdGFudCBDcnVzaCJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1sdXRxSnpHZlFNQSIgOmFuc3dlciAiZmVtaW5pbmUgYWRvcm5tZW50cyJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1jUG5URmRNcFZzOCIgOmFuc3dlciAiSSBIYXZlbid0IEdvdCBBbnkgTGVncyJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj0tMXRYSlc5Q01aMCIgOmFuc3dlciAiVGhlcmUgSXMgQSBMaWdodCBUaGF0IE5ldmVyIEdvZXMgT3V0In0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PTFHYjJFVDk5TTNrIiA6YW5zd2VyICJrYWxhIGxpbGkgbGkga2FtYSB0YW4gbWEifQogICBAezp1cmwgImh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9RVdITU5JQ3JDZjgiIDphbnN3ZXIgInN1c3N5IG1hY2hpbmUifQogICBAezp1cmwgImh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9T3VpVEhNdXZxVDQiIDphbnN3ZXIgIkNhbmNpb24gZGVsIG1hcmlhY2hpIn0KICAgQHs6dXJsICJodHRwczovL3d3dy55b3V0dWJlLmNvbS93YXRjaD92PVlub3BIQ0wxSms4IiA6YW5zd2VyICJEcmFnb3N0ZWEgRGluIFRlaSJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1IaFphSGY4UlA2ZyIgOmFuc3dlciAiVmVyaWRpcyBRdW8ifQogICBAezp1cmwgImh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9aHF0aHNwU0taVjgiIDphbnN3ZXIgIklldmFuIHBvbGtrYSJ9CiAgIEB7OnVybCAiaHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1LNUtBYzVDb0N1ayIgOmFuc3dlciAiRGVybmllcmUgRGFuc2UifV0=")
(def questions (parse (base64/decode questions)))

(def man0 "_________")
(def man
  ["   |\n   |\n   |"
   "\n _____\n|     |\n|     |\n|     |\n-----"
   "\n   |\n   |"
   "\n  /"
   " \\"
   "\n /"
   "   \\"])


(def mpv (os/spawn ["mpv"
  "--input-ipc-server=/tmp/mpv-quiz.socket"
  "--keep-open=always"
  "--no-video"
  "--no-terminal"
  ;(map |(get $ :url) questions)] :p))

(rawterm/begin)
(print "In this quiz you will hear songs and have to guess their names hangman-style.")
(print "Please wait a bit for the playback to start.")
(print "If the program crashes, you may need to use pkill mpv and tput reset.")
(print "During the quiz, press ^C to exit.")
(prin "Press any key to continue: ")
(flush)
(rawterm/getch)
(def sock (net/connect :unix "/tmp/mpv-quiz.socket"))
(var points 0)
(var prevanswer "")
(each q questions
  (def {:url url :answer answer} q)
  (var wrong @"")
  (var correct @" '")
  (def testanswer (string/ascii-upper answer))
  (while (and (< (length wrong) (length man)) (not (string/check-set correct testanswer)))
    (prin "\x1b[2J\x1b[H")
    (printf "Previous answer: %s\n" prevanswer)
    (print man0)
    (print (string/join (slice man 0 (length wrong))))
    (prin "\n\n")
    (each char testanswer
      (cond
        (has-value? correct char) (prinf "%c" char)
        (= char 32) (prin " ")
        (= char 39) (prin "'")
        (prin "_"))
      (prin " "))
    (prin "\n\n")
    (prin "Guessed: ")
    (each char wrong (prinf "%c " char))
    (prin "\n\nEnter a character: ")
    (flush)
    (def char (get (string/ascii-upper (rawterm/getch)) 0))
    (when (= char 3)
      (rawterm/end)
      (os/proc-kill mpv)
      (os/exit))
    (when (and char
            (not= char 10)
            (not (has-value? correct char))
            (not (has-value? wrong char)))
      (if (has-value? testanswer char)
        (buffer/push correct char)
        (buffer/push wrong char))))
  (set (q :points) (- (length man) (length wrong)))
  (set prevanswer answer)
  (net/write sock "playlist-next force\nset pause no\n"))

(prin "\x1b[2J\x1b[H")
(printf "%-43s %-36s %-5s" "URL" "Answer" "Points")
(var total 0)
(each {:url url :answer answer :points points} questions
  (printf "%-43s %-36s %-5d" url answer points)
  (+= total points))

(printf "Total points: %d/%d. Goodbye." total (* (length questions) 7))
(rawterm/end)

(net/close sock)
(os/proc-wait mpv)

round #74

submitted at
1 like

guesses
comments 0

post a comment


cg73.tcl ASCII text
 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
package require http
package require tls

http::register https 443 ::tls::socket
http::config -useragent {DiscordBot (https://codeguessing.gay, 1.0.0) songebot/1.0 (zzz)}

set song_list {
    https://www.youtube.com/watch?v=T5Cp55MvX54
    https://www.youtube.com/watch?v=eA2kiCScnI8&t=56s
    https://www.youtube.com/watch?v=vW9_5giCK1I
    https://www.youtube.com/watch?v=nXZuv1T8bfg
    https://www.youtube.com/watch?v=Lt-EbHhHD5Q
}

proc send {token channel_id} {
    set song [lindex $::song_list [expr {round(floor([llength $::song_list] * rand()))}]]
    set token [http::geturl https://discord.com/api/v10/channels/$channel_id/messages \
        -method POST \
        -query [subst {{"content": "$song"}}] \
        -headers [dict create \
                      content-type application/json \
                      authorization "Bot $token"
                 ]]

    set ret [http::data $token]
    http::cleanup $token
    set ret
}

array set arguments $argv
puts [send $arguments(-token) $arguments(-channel-id)]

# Then it waddled away...
# Waddle waddle

round #73

submitted at
0 likes

guesses
comments 0

post a comment


Roboto-Regular.ttf TrueType Font data, 18 tables, 1st "GDEF", 13 names, Microsoft, language 0x409, Copyright 2011 Google Inc. All Rights Reserved.RobotoRegularVersion 2.001101; 2014Roboto-Regular
cat.png PNG image data, 48 x 48, 8-bit/color RGBA, non-interlaced
cg73.hs ASCII text
  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
{- cabal:
build-depends: base, wuss, websockets, aeson, lens, text, monomer, text-show, stm
-}

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE NamedFieldPuns #-}

module Main where

import Wuss
import Network.WebSockets (receiveData, sendTextData)
import Data.Aeson
import Control.Lens hiding ((.=))
import Data.Text (Text)
import Monomer
import Control.Concurrent.STM.TChan

import Control.Monad (forever)
import Data.Functor (void)
import Control.Concurrent (forkIO)
import Control.Concurrent.STM (atomically)
import qualified Monomer.Lens as L

data R
  = Connect { name :: Text }
  | Disconnect { name :: Text }
  | MessageR { name :: Text, content :: Text }
  deriving (Eq, Show)

instance FromJSON R where
  parseJSON = withObject "R" $ \o -> do
    reason <- o .: "reason"
    case reason :: Text of
      "connect" -> Connect <$> o .: "name"
      "disconnect" -> Disconnect <$> o .: "name"
      "message" -> MessageR <$> o .: "name" <*> o .: "content"
      _ -> fail $ "Unknown reason: " <> show reason

newtype S = S Text

instance ToJSON S where
  toJSON (S content) = object ["content" .= content]

data AppModel =
  AppModel
    { _messages :: [(Text, Text)]
    , _message :: Text
    , _users :: [Text]
    }
  deriving (Eq, Show)

data AppEvent
  = AppInit
  | AppWsEvent R
  | AppSendMessage
  | AppMessageSent
  | AppScrollUpdate ScrollStatus
  deriving (Eq, Show)


makeLenses 'AppModel

connectWs :: TChan S -> (AppEvent -> IO ()) -> IO ()
connectWs chan sendMessage =
  runSecureClient "codeguessing.gay" 443 "/73/ws" $ \con -> do
    void $ forkIO $ forever $ atomically (readTChan chan) >>= sendTextData con . encode
    forever $ receiveData con >>= mapM_ (sendMessage . AppWsEvent) . decode

buildUI
  :: WidgetEnv AppModel AppEvent
  -> AppModel
  -> WidgetNode AppModel AppEvent
buildUI _wenv model = widgetTree where
  widgetTree = hsplit_ [splitHandlePosV 0.9] (messageView, userlst)
  userlst = vscroll $ vstack $ map (`label_` [ellipsis]) $ model ^. users
  messageView = vstack_ [childSpacing]
    [ flip styleBasic [expandHeight 1]
      $ flip nodeKey "scroll"
      $ vscroll_
        [onChange AppScrollUpdate]
          $ vstack_ [childSpacing] $ reverse $
              map
                (\(sender, content) -> hstack_ [childSpacing]
                  [ label sender
                  , if content == ":cat_with_gua_pi_mao_hat_tone5:" then
                      image "cat.png" `styleBasic` [width 48, height 48]
                    else
                      label_ content [multiline]
                  ])
                (model ^. messages)
              & ix 0 %~ (`nodeKey` "first")
    , keystroke [("Enter", AppSendMessage)] $ textField message
    ] `styleBasic` [padding 10]

handleEvent
  :: TChan S
  -> WidgetEnv AppModel AppEvent
  -> WidgetNode AppModel AppEvent
  -> AppModel
  -> AppEvent
  -> [AppEventResponse AppModel AppEvent]
handleEvent chan wenv _node model evt = case evt of
  AppInit ->
    [Producer $ connectWs chan]
  AppWsEvent (MessageR {name, content}) ->
    [ Model (model & messages %~ ((name, content):))
    , responseMaybe $
        Message (WidgetKey "scroll") . ScrollTo . view L.viewport <$>
          nodeInfoFromKey wenv (WidgetKey "first")
    ]
  AppWsEvent (Connect {name}) ->
    [ Model (model & users %~ (name:)) ]
  AppWsEvent (Disconnect {name}) ->
    [ Model (model & users %~ filter (/=name)) ]
  AppSendMessage ->
    [ Task $ fmap (const AppMessageSent) $ atomically $ writeTChan chan $ S $ model ^. message
    , Model $ model & message .~ ""
    ]
  AppMessageSent ->
    []
  AppScrollUpdate (ScrollStatus {scrollRect = Rect x _ w h}) ->
    [Message (WidgetKey "scroll") $ Rect x (h+10) w (h+10)]


main :: IO ()
main = do
  chan <- atomically newTChan
  startApp model (handleEvent chan) buildUI config
  where
    config =
      [ appWindowTitle "Code Guessing"
      , appTheme darkTheme
      , appFontDef "Regular" "./Roboto-Regular.ttf"
      , appInitEvent AppInit
      ]
    model = AppModel
      { _messages = []
      , _message = ""
      , _users = []
      }

round #70

submitted at
0 likes

guesses
comments 0

post a comment


shipshipshitship.js ASCII text
 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
async function sendmoves(...lst) {
  const l = [];
  for (let { x = 0, y = 0, delay } of lst) {
    if (delay) await Promise.race([new Promise(resolve => setTimeout(() => resolve(), delay)), Promise.all(l)]);
    const xaxis = (x > 0) ? ["right", x] : ["left", -x];
    const yaxis = (y > 0) ? ["down",  y] : ["up",   -y];
    for (let [dir, length] of [xaxis, yaxis])
      for (let i = 0; i < length; ++i)
        l.push(fetch("/extra/game70", {method: "POST", body: JSON.stringify({dir}), headers}).then(r => r.json()));
  }

  let newState = await Promise.all(l)
    .then(rs => rs.reduce((a, b) => a.s > b.s ? a : b));
    
  if (newState !== undefined)
    renderGame(newState);
  return newState;
}

function findLocations(arr) {
  let plus, at, star;
  for (let y = 0; y < arr.length; ++y) {
    for (let x = 0; x < arr[y].length; ++x) {
     switch (arr[y][x]) {
        case "+": plus = [x, y]; break;
        case "@": at = [x, y]; break;
        case "*": star = [x, y]; break;
     }
    }
  }
  return {plus, at, star};
}

function vminus([x1, y1], [x2, y2]) { return [x1 - x2, y1 - y2]; }
function veq([x1, y1], [x2, y2]) { return x1 == x2 && y1 == y2; }

let x = false;

async function play() {
  while (!x) {
    const { plus, at: sat, star } = findLocations(screen.innerText.split("\n"));
    const at = [sat[0], sat[1]];
    const moves = [];
    const log = [];
    let n = 0;
    const x = x => { at[0] += x; n += Math.abs(x); moves.push({x}); };
    const y = y => { at[1] += y; n += Math.abs(y); moves.push({y}); };
    const delay = delay => { moves.push({delay: n * delay}); n = 0; };
    while (!veq(at, plus)) {
      const movevec = vminus(plus, at);
      if (star !== undefined) {
        const comet = vminus(star, at);
        const shenan = Math.sign(comet[0]) == Math.sign(movevec[0]) && Math.abs(comet[0]) <= Math.abs(movevec[0])
                    || Math.sign(comet[1]) == Math.sign(movevec[1]) && Math.abs(comet[1]) <= Math.abs(movevec[1]);
        const sxaxis = shenan && plus[0] == at[0] && at[0] == star[0];
        const syaxis = shenan && plus[1] == at[1] && at[1] == star[1];
        const interf = shenan && (plus[0] == star[0] || at[1] == star[1]);
        log.push({comet, shenan, sxaxis, syaxis, interf});
        if      (sxaxis) { x(plus[0] < 14 ? 1 : -1); delay(250);     }
        else if (syaxis) { y(plus[1] < 4  ? 1 : -1); delay(250);     }
        else if (interf) { y(movevec[1]); delay(150); x(movevec[0]); }
        else if (shenan) { x(movevec[0]); delay(150); y(movevec[1]); }
        else             { x(movevec[0]); y(movevec[1]);             }
      } else             { x(movevec[0]); y(movevec[1]);             }
    }
    const newstate = await sendmoves(...moves);
    console.log({plus, at, sat, star, moves, newstate, log, n});
    console.log(newstate.grid);
    await new Promise(resolve => setTimeout(() => resolve(), 10));
  }
}

round #69

submitted at
2 likes

guesses
comments 0

post a comment


cg69.el Unicode text, UTF-8 text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
(defun shitty-ries (n)
  (interactive "nThose who know: ")
  (with-temp-buffer
    (rename-buffer "Knowledge")
    (print `(= (- x ,n) 0) (current-buffer))
    (print `(= (- x (/ π ,(/ float-pi n))) 0) (current-buffer))
    (dotimes (i 10)
      (let ((r (+ n (random 0.01))) ; for increased fun
            (a (random))
            (y (random)))
        (print `(= (+ (* ,a (^ x 2)) (* ,(- (+ y r)) x) ,(* y r)) 0) (current-buffer))))
    (print-buffer)))
        
    

round #68

submitted at
0 likes

guesses
comments 0

post a comment


c.st Unicode text, UTF-8 text
  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
#!/home/olus2000/programy/smalltalk-3.2/gst

Object subclass: CipherCracker [
    | corpusBag inputBag count tbl |
    <comment: 'I crack subtitution ciphers ^_^'>

    CipherCracker class >> new [
        | r |
        r := super new.
        r init.
        ^r
    ]
    
    init [
        <category: 'initialization'>
        corpusBag := Bag new.
        inputBag := Bag new.
        count := 0.
    ]

    learn: corpus [
        <category: 'processing'>
        <comment: 'I update the cracker to expect text similar to the one provided.'>
        corpus do: [:c | c isLetter ifTrue: [corpusBag add: c asLowercase]].
    ]

    prescan: input [
        <category: 'processing'>
        <comment: 'I learn the frequency of letters in the input.'>
        input do: [:c | c isLetter ifTrue: [inputBag add: c asLowercase]].
    ]

    beforeCrack [
        <category: 'processing'>
        tbl := LookupTable new.
        inputBag sortedByCount
            with: corpusBag sortedByCount
            do: [:i :c | tbl at: i value put: c value].
    ]

    crack: string [
        <category: 'processing'>
        <comment: 'I cracka da string.'>
        count := count + 1.
        ^(string collect: [:c | c isUppercase
                              ifTrue: [(tbl at: c asLowercase ifAbsent: [c asLowercase]) asUppercase]
                              ifFalse: [tbl at: c ifAbsent: [c]]
                          ]) asString
    ]

    stats [
        <category: 'statistics'>
        ^'BORN TO SPAM
WORLD IS A MJAU
鬼神 Love Em All %1
I am l​ouna ^_^
' % { count }
    ]    
]

Dictionary extend [
    at: key ifAbsent: absent ifPresent: present [
        present value: (self at: key ifAbsent: [^absent value])
    ]
]
FileStream class extend [
    withOpen: fn mode: m do: block [
        | f |
        f := self open: fn mode: m.
        [block value: f] ensure: [f close].
    ]

    withOpen: fn1 mode: m1 and: fn2 mode: m2 do: block [
        | f1 f2 |
        f1 := self open: fn1 mode: m1.
        f2 := self open: fn2 mode: m2.
        [block value: f1 value: f2] ensure: [f1 close. f2 close].
    ]
]

Object subclass: Program [
    | input output corpus |

    arguments := LookupTable new
                 at: $c put: #corpus:;
                 at: $i put: #input:;
                 at: $o put: #output:;
                 yourself.
   
    corpus: filename [corpus := filename]
    input:  filename [input  := filename]
    output: filename [output := filename]

    run [
        | err cracker |
        err := false.
        Smalltalk arguments: '-c: -i: -o:'
                  do: [:name :arg | arguments
                                  at: name
                                  ifAbsent: [err := true]
                                  ifPresent: [:sel | self perform: sel with: arg].
                      ]
                  ifError: [^self usage].
        err ifTrue: [^self usage].
        corpus ifNil: [^self usage].
        input ifNil: [^self usage].
        output ifNil: [^self usage].
        
        cracker := CipherCracker new.
        FileStream withOpen: corpus
                   mode: FileStream read
                   do: [:f | f linesDo: [:l | cracker learn: l]].

        FileStream withOpen: input
                   mode: FileStream read
                   and: output
                   mode: FileStream write
                   do: [:in :out |
                        in linesDo: [:line | cracker prescan: line].
                        cracker beforeCrack.
                        in reset.
                        in linesDo: [:line | out << (cracker crack: line); nl]
                       ].
        cracker stats displayNl.
    ]

    usage [
        FileStream stderr << 'cracker.st -c CORPUS -i INPUT -o OUTPUT'; nl.
        ObjectMemory quit: 2
    ]
]

Program new run