all stats

rrebbbbeca's stats

guessed the most

namecorrect guessesgames togetherratio
olive450.800
Olek Sabak240.500
kimapr370.429
Makefile_dot_in370.429
Olivia260.333
LyricLy270.286
yeti150.200
essaie150.200
Dolphy180.125
Moja040.000
ponydork040.000
Indigo040.000
oleander080.000
taswelll040.000

were guessed the most by

namecorrect guessesgames togetherratio
olive441.000
LyricLy570.714
kimapr360.500
taswelll240.500
essaie250.400
Makefile_dot_in270.286
Indigo140.250
oleander280.250
Dolphy280.250
Olek Sabak140.250
Olivia160.167
ponydork040.000
yeti040.000

entries

round #100

submitted at
4 likes

guesses
comments 2
essaie

LyricLy


rrebbbbeca known at the time as [cg: author of #5]

true


post a comment


cg100.love Zip archive data, made by v3.0 UNIX, extract using at least v1.0, last modified May 11 2026 22:15:38, uncompressed size 53, method=store
dir r
class.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
-- currently a class is a table T with T.__index = T
-- then to make an instance of this class, we do
--		setmetatable(instance,T)
-- this should be fine for anything we wish to do.
-- it is possible we will eventually split this into two separate
-- tables perhaps? i don't see why we would ever do that though

local function class()
	local T = {}
	T.__index = T
	setmetatable(T, {__call = function(cls, ...) return cls.make(cls, ...) end})
	return T
end

local function extend(Base)
	local T = class()
	for k,v in pairs(Base) do
		if k:sub(1,2) == "__" and k~="__index" then
			T[k]=v
		end
	end
	getmetatable(T).__index = Base
	return T
end

return setmetatable({
	class=class,
	extend=extend
},{__call=class})
math.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
local M = {}

function M.lerp(a,b,t) return (1-t)*a + t*b end
function M.smoothstep(x)
	if x<0 then return 0 end
	if x>1 then return 1 end
	return x*x*(3 - 2*x)
end
function M.slerp(a,b,t) return M.lerp(a,b,M.smoothstep(t)) end


function M.sign(x)
	if x == 0 then return 0
	elseif x < 0 then return -1
	elseif x > 0 then return 1
	end
end

function M.clamp(x,minv,maxv)
	return math.min(math.max(x,minv),maxv)
end

function M.clerp(a,b,t) return M.lerp(a,b,M.clamp(t,0,1)) end
function M.round(x) return math.floor(x+0.5) end

-- [-1,1] -> [0,1]
function M.squish(x) return (x/2)+0.5 end
-- [0,1] -> [-1,1]
function M.unsquish(x) return (x*2)-1 end
function M.sqlerp(a,b,t) return M.lerp(a,b,M.squish(t)) end

return M
pos.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
local class = require'r.class'
local rmath = require'r.math'

local Pos = class()
function Pos.new(cls)
	return setmetatable({},cls)
end
function Pos.init(self,x,y)
	self.x = x
	self.y = y
	return self
end
function Pos.make(cls,...)
	return cls:new():init(...)
end
function Pos.__add(self,other)
	return Pos:make(self.x+other.x,self.y+other.y)
end
function Pos.__sub(self,other)
	return Pos:make(self.x-other.x,self.y-other.y)
end
function Pos.__unm(self) return Pos(-self.x,-self.y)  end
function Pos.__mul(a,b)
	if type(a) == "number" then
		return Pos:make(a*b.x,a*b.y)
	elseif type(b) == "number" then
		return Pos:make(a.x*b,a.y*b)
	else
		error("can only multiply Pos by scalar")
	end

end
function Pos.__div(a,b)
	assert(type(b) == "number","can only divide Pos by scalar")
	return a*(1/b)
end
function Pos.__eq(a,b) return a.x==b.x and a.y==b.y end
function Pos.lensq(self) return self.x^2 + self.y^2 end
function Pos.len(self) return math.sqrt(self:lensq()) end
function Pos.norm(self)
	local l = self:len()
	if l < 0.00001 then return Pos(0,0) else return self/l end end
function Pos.l1(self) return math.abs(self.x) + math.abs(self.y) end
function Pos.linf(self) return math.max(math.abs(self.x),math.abs(self.y)) end
function Pos.dot(self,other) return self.x*other.x+self.y*other.y end
function Pos.vals(self) return self.x, self.y end
function Pos.floor(self) return Pos:make(math.floor(self.x),math.floor(self.y)) end
function Pos.ceil(self) return Pos:make(math.ceil(self.x),math.ceil(self.y)) end
function Pos.round(self) return Pos:make(rmath.round(self.x),rmath.round(self.y)) end
function Pos.divmod(self,size) local div = (self/size):floor() return div, self-div*size end
function Pos.__tostring(self)
	return string.format("(%.2f,%.2f)",self.x,self.y)
end
function Pos.key(self) return self.x .. ':' .. self.y end
function Pos.unkey(cls,k)
	local a,b = k:match"(%-?%d+):(%-?%d+)"
	return Pos(tonumber(a),tonumber(b)) end
function Pos.rot(self,a)
	local c,s = math.cos(a),math.sin(a)
	-- [ C, -S ]
	-- [ S,  C ] 
	return Pos(self.x*c - self.y*s, self.x*s + self.y*c) end
function Pos.sproj(self,b) return self:dot(b:norm()) end
function Pos.proj(self,b) return self:sproj(b)*b:norm() end
function Pos.angle(self) return (math.atan2 or math.atan)(self.y,self.x) end

-- inplace arithmetic
function Pos.addby (self,by) self.x=self.x+by.x  self.y=self.y+by.y end
function Pos.addbyv(self,x,y)self.x=self.x+x     self.y=self.y+y    end
function Pos.subby (self,by) self.x=self.x-by.x  self.y=self.y-by.y end
function Pos.subbyv(self,x,y)self.x=self.x-x     self.y=self.y-y    end
function Pos.mulby (self,by) self.x=self.x*by    self.y=self.y*by   end
function Pos.divby (self,by) self.x=self.x/by    self.y=self.y/by   end

return Pos
qw.lua ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
-- qw"aaa bbb ccc" --> { "aaa", "bbb", "ccc" }
local function qw(str)
	local out = {}
	for x in str:gmatch"%S+" do
		table.insert(out, x)
	end
	return out
end
-- qw.s"aaa bbb ccc" --> { aaa=true, bbb=true, ccc=true }
local function qws(str)
	local out = {}
	for x in str:gmatch"%S+" do
		out[x] = true
	end
	return out
end
-- for k in qw.i"aaa bbb ccc" do ... end
local function qwi(str) return pairs(qws(str)) end

return setmetatable({qw=qw,s=qws,i=qwi},{__call=function(_,...) return qw(...) end})
bart.png PNG image data, 880 x 1347, 8-bit/color RGBA, non-interlaced
bartmono.wav RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 48000 Hz
click0.wav RIFF (little-endian) data, WAVE audio, Microsoft PCM, 24 bit, stereo 44100 Hz
conf.lua ASCII text
1
function love.conf(t) t.window.title='KOLAKOSKI' end
dkjson.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
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
-- Module options:
local always_use_lpeg = false
local register_global_module_table = false
local global_module_name = 'json'

--[==[

David Kolf's JSON module for Lua 5.1 - 5.4

Version 2.8


For the documentation see the corresponding readme.txt or visit
<http://dkolf.de/dkjson-lua/>.

You can contact the author by sending an e-mail to 'david' at the
domain 'dkolf.de'.


Copyright (C) 2010-2024 David Heiko Kolf

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--]==]

-- global dependencies:
local pairs, type, tostring, tonumber, getmetatable, setmetatable =
      pairs, type, tostring, tonumber, getmetatable, setmetatable
local error, require, pcall, select = error, require, pcall, select
local floor, huge = math.floor, math.huge
local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat =
      string.rep, string.gsub, string.sub, string.byte, string.char,
      string.find, string.len, string.format
local strmatch = string.match
local concat = table.concat

local json = { version = "dkjson 2.8" }

local jsonlpeg = {}

if register_global_module_table then
  if always_use_lpeg then
    _G[global_module_name] = jsonlpeg
  else
    _G[global_module_name] = json
  end
end

local _ENV = nil -- blocking globals in Lua 5.2 and later

pcall (function()
  -- Enable access to blocked metatables.
  -- Don't worry, this module doesn't change anything in them.
  local debmeta = require "debug".getmetatable
  if debmeta then getmetatable = debmeta end
end)

json.null = setmetatable ({}, {
  __tojson = function () return "null" end
})

local function isarray (tbl)
  local max, n, arraylen = 0, 0, 0
  for k,v in pairs (tbl) do
    if k == 'n' and type(v) == 'number' then
      arraylen = v
      if v > max then
        max = v
      end
    else
      if type(k) ~= 'number' or k < 1 or floor(k) ~= k then
        return false
      end
      if k > max then
        max = k
      end
      n = n + 1
    end
  end
  if max > 10 and max > arraylen and max > n * 2 then
    return false -- don't create an array with too many holes
  end
  return true, max
end

local escapecodes = {
  ["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f",
  ["\n"] = "\\n",  ["\r"] = "\\r",  ["\t"] = "\\t"
}

local function escapeutf8 (uchar)
  local value = escapecodes[uchar]
  if value then
    return value
  end
  local a, b, c, d = strbyte (uchar, 1, 4)
  a, b, c, d = a or 0, b or 0, c or 0, d or 0
  if a <= 0x7f then
    value = a
  elseif 0xc0 <= a and a <= 0xdf and b >= 0x80 then
    value = (a - 0xc0) * 0x40 + b - 0x80
  elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 then
    value = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80
  elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 then
    value = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80
  else
    return ""
  end
  if value <= 0xffff then
    return strformat ("\\u%.4x", value)
  elseif value <= 0x10ffff then
    -- encode as UTF-16 surrogate pair
    value = value - 0x10000
    local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400)
    return strformat ("\\u%.4x\\u%.4x", highsur, lowsur)
  else
    return ""
  end
end

local function fsub (str, pattern, repl)
  -- gsub always builds a new string in a buffer, even when no match
  -- exists. First using find should be more efficient when most strings
  -- don't contain the pattern.
  if strfind (str, pattern) then
    return gsub (str, pattern, repl)
  else
    return str
  end
end

local function quotestring (value)
  -- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-js
  value = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8)
  if strfind (value, "[\194\216\220\225\226\239]") then
    value = fsub (value, "\194[\128-\159\173]", escapeutf8)
    value = fsub (value, "\216[\128-\132]", escapeutf8)
    value = fsub (value, "\220\143", escapeutf8)
    value = fsub (value, "\225\158[\180\181]", escapeutf8)
    value = fsub (value, "\226\128[\140-\143\168-\175]", escapeutf8)
    value = fsub (value, "\226\129[\160-\175]", escapeutf8)
    value = fsub (value, "\239\187\191", escapeutf8)
    value = fsub (value, "\239\191[\176-\191]", escapeutf8)
  end
  return "\"" .. value .. "\""
end
json.quotestring = quotestring

local function replace(str, o, n)
  local i, j = strfind (str, o, 1, true)
  if i then
    return strsub(str, 1, i-1) .. n .. strsub(str, j+1, -1)
  else
    return str
  end
end

-- locale independent num2str and str2num functions
local decpoint, numfilter

local function updatedecpoint ()
  decpoint = strmatch(tostring(0.5), "([^05+])")
  -- build a filter that can be used to remove group separators
  numfilter = "[^0-9%-%+eE" .. gsub(decpoint, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0") .. "]+"
end

updatedecpoint()

local function num2str (num)
  return replace(fsub(tostring(num), numfilter, ""), decpoint, ".")
end

local function str2num (str)
  local num = tonumber(replace(str, ".", decpoint))
  if not num then
    updatedecpoint()
    num = tonumber(replace(str, ".", decpoint))
  end
  return num
end

local function addnewline2 (level, buffer, buflen)
  buffer[buflen+1] = "\n"
  buffer[buflen+2] = strrep ("  ", level)
  buflen = buflen + 2
  return buflen
end

function json.addnewline (state)
  if state.indent then
    state.bufferlen = addnewline2 (state.level or 0,
                           state.buffer, state.bufferlen or #(state.buffer))
  end
end

local encode2 -- forward declaration

local function addpair (key, value, prev, indent, level, buffer, buflen, tables, globalorder, state)
  local kt = type (key)
  if kt ~= 'string' and kt ~= 'number' then
    return nil, "type '" .. kt .. "' is not supported as a key by JSON."
  end
  if prev then
    buflen = buflen + 1
    buffer[buflen] = ","
  end
  if indent then
    buflen = addnewline2 (level, buffer, buflen)
  end
  -- When Lua is compiled with LUA_NOCVTN2S this will fail when
  -- numbers are mixed into the keys of the table. JSON keys are always
  -- strings, so this would be an implicit conversion too and the failure
  -- is intentional.
  buffer[buflen+1] = quotestring (key)
  buffer[buflen+2] = ":"
  return encode2 (value, indent, level, buffer, buflen + 2, tables, globalorder, state)
end

local function appendcustom(res, buffer, state)
  local buflen = state.bufferlen
  if type (res) == 'string' then
    buflen = buflen + 1
    buffer[buflen] = res
  end
  return buflen
end

local function exception(reason, value, state, buffer, buflen, defaultmessage)
  defaultmessage = defaultmessage or reason
  local handler = state.exception
  if not handler then
    return nil, defaultmessage
  else
    state.bufferlen = buflen
    local ret, msg = handler (reason, value, state, defaultmessage)
    if not ret then return nil, msg or defaultmessage end
    return appendcustom(ret, buffer, state)
  end
end

function json.encodeexception(reason, value, state, defaultmessage)
  return quotestring("<" .. defaultmessage .. ">")
end

encode2 = function (value, indent, level, buffer, buflen, tables, globalorder, state)
  local valtype = type (value)
  local valmeta = getmetatable (value)
  valmeta = type (valmeta) == 'table' and valmeta -- only tables
  local valtojson = valmeta and valmeta.__tojson
  if valtojson then
    if tables[value] then
      return exception('reference cycle', value, state, buffer, buflen)
    end
    tables[value] = true
    state.bufferlen = buflen
    local ret, msg = valtojson (value, state)
    if not ret then return exception('custom encoder failed', value, state, buffer, buflen, msg) end
    tables[value] = nil
    buflen = appendcustom(ret, buffer, state)
  elseif value == nil then
    buflen = buflen + 1
    buffer[buflen] = "null"
  elseif valtype == 'number' then
    local s
    if value ~= value or value >= huge or -value >= huge then
      -- This is the behaviour of the original JSON implementation.
      s = "null"
    else
      s = num2str (value)
    end
    buflen = buflen + 1
    buffer[buflen] = s
  elseif valtype == 'boolean' then
    buflen = buflen + 1
    buffer[buflen] = value and "true" or "false"
  elseif valtype == 'string' then
    buflen = buflen + 1
    buffer[buflen] = quotestring (value)
  elseif valtype == 'table' then
    if tables[value] then
      return exception('reference cycle', value, state, buffer, buflen)
    end
    tables[value] = true
    level = level + 1
    local isa, n = isarray (value)
    if n == 0 and valmeta and valmeta.__jsontype == 'object' then
      isa = false
    end
    local msg
    if isa then -- JSON array
      buflen = buflen + 1
      buffer[buflen] = "["
      for i = 1, n do
        buflen, msg = encode2 (value[i], indent, level, buffer, buflen, tables, globalorder, state)
        if not buflen then return nil, msg end
        if i < n then
          buflen = buflen + 1
          buffer[buflen] = ","
        end
      end
      buflen = buflen + 1
      buffer[buflen] = "]"
    else -- JSON object
      local prev = false
      buflen = buflen + 1
      buffer[buflen] = "{"
      local order = valmeta and valmeta.__jsonorder or globalorder
      if order then
        local used = {}
        n = #order
        for i = 1, n do
          local k = order[i]
          local v = value[k]
          if v ~= nil then
            used[k] = true
            buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
            if not buflen then return nil, msg end
            prev = true -- add a seperator before the next element
          end
        end
        for k,v in pairs (value) do
          if not used[k] then
            buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
            if not buflen then return nil, msg end
            prev = true -- add a seperator before the next element
          end
        end
      else -- unordered
        for k,v in pairs (value) do
          buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
          if not buflen then return nil, msg end
          prev = true -- add a seperator before the next element
        end
      end
      if indent then
        buflen = addnewline2 (level - 1, buffer, buflen)
      end
      buflen = buflen + 1
      buffer[buflen] = "}"
    end
    tables[value] = nil
  else
    return exception ('unsupported type', value, state, buffer, buflen,
      "type '" .. valtype .. "' is not supported by JSON.")
  end
  return buflen
end

function json.encode (value, state)
  state = state or {}
  local oldbuffer = state.buffer
  local buffer = oldbuffer or {}
  state.buffer = buffer
  updatedecpoint()
  local ret, msg = encode2 (value, state.indent, state.level or 0,
                   buffer, state.bufferlen or 0, state.tables or {}, state.keyorder, state)
  if not ret then
    error (msg, 2)
  elseif oldbuffer == buffer then
    state.bufferlen = ret
    return true
  else
    state.bufferlen = nil
    state.buffer = nil
    return concat (buffer)
  end
end

local function loc (str, where)
  local line, pos, linepos = 1, 1, 0
  while true do
    pos = strfind (str, "\n", pos, true)
    if pos and pos < where then
      line = line + 1
      linepos = pos
      pos = pos + 1
    else
      break
    end
  end
  return strformat ("line %d, column %d", line, where - linepos)
end

local function unterminated (str, what, where)
  return nil, strlen (str) + 1, "unterminated " .. what .. " at " .. loc (str, where)
end

local function scanwhite (str, pos)
  while true do
    pos = strfind (str, "%S", pos)
    if not pos then return nil end
    local sub2 = strsub (str, pos, pos + 1)
    if sub2 == "\239\187" and strsub (str, pos + 2, pos + 2) == "\191" then
      -- UTF-8 Byte Order Mark
      pos = pos + 3
    elseif sub2 == "//" then
      pos = strfind (str, "[\n\r]", pos + 2)
      if not pos then return nil end
    elseif sub2 == "/*" then
      pos = strfind (str, "*/", pos + 2)
      if not pos then return nil end
      pos = pos + 2
    else
      return pos
    end
  end
end

local escapechars = {
  ["\""] = "\"", ["\\"] = "\\", ["/"] = "/", ["b"] = "\b", ["f"] = "\f",
  ["n"] = "\n", ["r"] = "\r", ["t"] = "\t"
}

local function unichar (value)
  if value < 0 then
    return nil
  elseif value <= 0x007f then
    return strchar (value)
  elseif value <= 0x07ff then
    return strchar (0xc0 + floor(value/0x40),
                    0x80 + (floor(value) % 0x40))
  elseif value <= 0xffff then
    return strchar (0xe0 + floor(value/0x1000),
                    0x80 + (floor(value/0x40) % 0x40),
                    0x80 + (floor(value) % 0x40))
  elseif value <= 0x10ffff then
    return strchar (0xf0 + floor(value/0x40000),
                    0x80 + (floor(value/0x1000) % 0x40),
                    0x80 + (floor(value/0x40) % 0x40),
                    0x80 + (floor(value) % 0x40))
  else
    return nil
  end
end

local function scanstring (str, pos)
  local lastpos = pos + 1
  local buffer, n = {}, 0
  while true do
    local nextpos = strfind (str, "[\"\\]", lastpos)
    if not nextpos then
      return unterminated (str, "string", pos)
    end
    if nextpos > lastpos then
      n = n + 1
      buffer[n] = strsub (str, lastpos, nextpos - 1)
    end
    if strsub (str, nextpos, nextpos) == "\"" then
      lastpos = nextpos + 1
      break
    else
      local escchar = strsub (str, nextpos + 1, nextpos + 1)
      local value
      if escchar == "u" then
        value = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16)
        if value then
          local value2
          if 0xD800 <= value and value <= 0xDBff then
            -- we have the high surrogate of UTF-16. Check if there is a
            -- low surrogate escaped nearby to combine them.
            if strsub (str, nextpos + 6, nextpos + 7) == "\\u" then
              value2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16)
              if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF then
                value = (value - 0xD800)  * 0x400 + (value2 - 0xDC00) + 0x10000
              else
                value2 = nil -- in case it was out of range for a low surrogate
              end
            end
          end
          value = value and unichar (value)
          if value then
            if value2 then
              lastpos = nextpos + 12
            else
              lastpos = nextpos + 6
            end
          end
        end
      end
      if not value then
        value = escapechars[escchar] or escchar
        lastpos = nextpos + 2
      end
      n = n + 1
      buffer[n] = value
    end
  end
  if n == 1 then
    return buffer[1], lastpos
  elseif n > 1 then
    return concat (buffer), lastpos
  else
    return "", lastpos
  end
end

local scanvalue -- forward declaration

local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta)
  local tbl, n = {}, 0
  local pos = startpos + 1
  if what == 'object' then
    setmetatable (tbl, objectmeta)
  else
    setmetatable (tbl, arraymeta)
  end
  while true do
    pos = scanwhite (str, pos)
    if not pos then return unterminated (str, what, startpos) end
    local char = strsub (str, pos, pos)
    if char == closechar then
      return tbl, pos + 1
    end
    local val1, err
    val1, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
    if err then return nil, pos, err end
    pos = scanwhite (str, pos)
    if not pos then return unterminated (str, what, startpos) end
    char = strsub (str, pos, pos)
    if char == ":" then
      if val1 == nil then
        return nil, pos, "cannot use nil as table index (at " .. loc (str, pos) .. ")"
      end
      pos = scanwhite (str, pos + 1)
      if not pos then return unterminated (str, what, startpos) end
      local val2
      val2, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
      if err then return nil, pos, err end
      tbl[val1] = val2
      pos = scanwhite (str, pos)
      if not pos then return unterminated (str, what, startpos) end
      char = strsub (str, pos, pos)
    else
      n = n + 1
      tbl[n] = val1
    end
    if char == "," then
      pos = pos + 1
    end
  end
end

scanvalue = function (str, pos, nullval, objectmeta, arraymeta)
  pos = pos or 1
  pos = scanwhite (str, pos)
  if not pos then
    return nil, strlen (str) + 1, "no valid JSON value (reached the end)"
  end
  local char = strsub (str, pos, pos)
  if char == "{" then
    return scantable ('object', "}", str, pos, nullval, objectmeta, arraymeta)
  elseif char == "[" then
    return scantable ('array', "]", str, pos, nullval, objectmeta, arraymeta)
  elseif char == "\"" then
    return scanstring (str, pos)
  else
    local pstart, pend = strfind (str, "^%-?[%d%.]+[eE]?[%+%-]?%d*", pos)
    if pstart then
      local number = str2num (strsub (str, pstart, pend))
      if number then
        return number, pend + 1
      end
    end
    pstart, pend = strfind (str, "^%a%w*", pos)
    if pstart then
      local name = strsub (str, pstart, pend)
      if name == "true" then
        return true, pend + 1
      elseif name == "false" then
        return false, pend + 1
      elseif name == "null" then
        return nullval, pend + 1
      end
    end
    return nil, pos, "no valid JSON value at " .. loc (str, pos)
  end
end

local function optionalmetatables(...)
  if select("#", ...) > 0 then
    return ...
  else
    return {__jsontype = 'object'}, {__jsontype = 'array'}
  end
end

function json.decode (str, pos, nullval, ...)
  local objectmeta, arraymeta = optionalmetatables(...)
  return scanvalue (str, pos, nullval, objectmeta, arraymeta)
end

function json.use_lpeg ()
  local g = require ("lpeg")

  if type(g.version) == 'function' and g.version() == "0.11" then
    error "due to a bug in LPeg 0.11, it cannot be used for JSON matching"
  end

  local pegmatch = g.match
  local P, S, R = g.P, g.S, g.R

  local function ErrorCall (str, pos, msg, state)
    if not state.msg then
      state.msg = msg .. " at " .. loc (str, pos)
      state.pos = pos
    end
    return false
  end

  local function Err (msg)
    return g.Cmt (g.Cc (msg) * g.Carg (2), ErrorCall)
  end

  local function ErrorUnterminatedCall (str, pos, what, state)
    return ErrorCall (str, pos - 1, "unterminated " .. what, state)
  end

  local SingleLineComment = P"//" * (1 - S"\n\r")^0
  local MultiLineComment = P"/*" * (1 - P"*/")^0 * P"*/"
  local Space = (S" \n\r\t" + P"\239\187\191" + SingleLineComment + MultiLineComment)^0

  local function ErrUnterminated (what)
    return g.Cmt (g.Cc (what) * g.Carg (2), ErrorUnterminatedCall)
  end

  local PlainChar = 1 - S"\"\\\n\r"
  local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars
  local HexDigit = R("09", "af", "AF")
  local function UTF16Surrogate (match, pos, high, low)
    high, low = tonumber (high, 16), tonumber (low, 16)
    if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then
      return true, unichar ((high - 0xD800)  * 0x400 + (low - 0xDC00) + 0x10000)
    else
      return false
    end
  end
  local function UTF16BMP (hex)
    return unichar (tonumber (hex, 16))
  end
  local U16Sequence = (P"\\u" * g.C (HexDigit * HexDigit * HexDigit * HexDigit))
  local UnicodeEscape = g.Cmt (U16Sequence * U16Sequence, UTF16Surrogate) + U16Sequence/UTF16BMP
  local Char = UnicodeEscape + EscapeSequence + PlainChar
  local String = P"\"" * (g.Cs (Char ^ 0) * P"\"" + ErrUnterminated "string")
  local Integer = P"-"^(-1) * (P"0" + (R"19" * R"09"^0))
  local Fractal = P"." * R"09"^0
  local Exponent = (S"eE") * (S"+-")^(-1) * R"09"^1
  local Number = (Integer * Fractal^(-1) * Exponent^(-1))/str2num
  local Constant = P"true" * g.Cc (true) + P"false" * g.Cc (false) + P"null" * g.Carg (1)
  local SimpleValue = Number + String + Constant
  local ArrayContent, ObjectContent

  -- The functions parsearray and parseobject parse only a single value/pair
  -- at a time and store them directly to avoid hitting the LPeg limits.
  local function parsearray (str, pos, nullval, state)
    local obj, cont
    local start = pos
    local npos
    local t, nt = {}, 0
    repeat
      obj, cont, npos = pegmatch (ArrayContent, str, pos, nullval, state)
      if cont == 'end' then
        return ErrorUnterminatedCall (str, start, "array", state)
      end
      pos = npos
      if cont == 'cont' or cont == 'last' then
        nt = nt + 1
        t[nt] = obj
      end
    until cont ~= 'cont'
    return pos, setmetatable (t, state.arraymeta)
  end

  local function parseobject (str, pos, nullval, state)
    local obj, key, cont
    local start = pos
    local npos
    local t = {}
    repeat
      key, obj, cont, npos = pegmatch (ObjectContent, str, pos, nullval, state)
      if cont == 'end' then
        return ErrorUnterminatedCall (str, start, "object", state)
      end
      pos = npos
      if cont == 'cont' or cont == 'last' then
        t[key] = obj
      end
    until cont ~= 'cont'
    return pos, setmetatable (t, state.objectmeta)
  end

  local Array = P"[" * g.Cmt (g.Carg(1) * g.Carg(2), parsearray)
  local Object = P"{" * g.Cmt (g.Carg(1) * g.Carg(2), parseobject)
  local Value = Space * (Array + Object + SimpleValue)
  local ExpectedValue = Value + Space * Err "value expected"
  local ExpectedKey = String + Err "key expected"
  local End = P(-1) * g.Cc'end'
  local ErrInvalid = Err "invalid JSON"
  ArrayContent = (Value * Space * (P"," * g.Cc'cont' + P"]" * g.Cc'last'+ End + ErrInvalid)  + g.Cc(nil) * (P"]" * g.Cc'empty' + End  + ErrInvalid)) * g.Cp()
  local Pair = g.Cg (Space * ExpectedKey * Space * (P":" + Err "colon expected") * ExpectedValue)
  ObjectContent = (g.Cc(nil) * g.Cc(nil) * P"}" * g.Cc'empty' + End + (Pair * Space * (P"," * g.Cc'cont' + P"}" * g.Cc'last' + End + ErrInvalid) + ErrInvalid)) * g.Cp()
  local DecodeValue = ExpectedValue * g.Cp ()

  jsonlpeg.version = json.version
  jsonlpeg.encode = json.encode
  jsonlpeg.null = json.null
  jsonlpeg.quotestring = json.quotestring
  jsonlpeg.addnewline = json.addnewline
  jsonlpeg.encodeexception = json.encodeexception
  jsonlpeg.using_lpeg = true

  function jsonlpeg.decode (str, pos, nullval, ...)
    local state = {}
    state.objectmeta, state.arraymeta = optionalmetatables(...)
    local obj, retpos = pegmatch (DecodeValue, str, pos, nullval, state)
    if state.msg then
      return nil, state.pos, state.msg
    else
      return obj, retpos
    end
  end

  -- cache result of this function:
  json.use_lpeg = function () return jsonlpeg end
  jsonlpeg.use_lpeg = json.use_lpeg

  return jsonlpeg
end

if always_use_lpeg then
  return json.use_lpeg()
end

return json
lafont.png PNG image data, 70 x 71, 8-bit/color RGBA, non-interlaced
liberationsans.ttf TrueType Font data, 19 tables, 1st "FFTM", 30 names, Macintosh
main.lua 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
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
local G,τ = love.graphics, 2*math.pi    math.randomseed(os.time())
local BART=false
-- local pprint=require'pprint'  pprint.setup{use_tostring=true}
local Pos = require'r.pos' local rmath = require'r.math' local class='r.class'
local qw = require'r.qw'   local yves = G.newImage'bart.png' local yvesr=yves:getWidth()/2
local popsound = love.audio.newSource('popmono.wav','static')
local bartsound = love.audio.newSource('bartmono.wav','static')
local nodes = {} local nodes_free = {} local inters = {}
local function np(i) local nx,p = unpack(i)  return nodes[nx],p,nx end
local function connect(i1,i2) local n1,p1,a1 = np(i1) local n2,p2,a2 = np(i2)
	assert(n1) assert(n2) assert(p1<=#n1) assert(p2<=#n2)
	n1[p1] = i2  n2[p2] = i1  if p1==1 and p2==1 then table.insert(inters,a2) end end
local function colfromhex(x) if x:sub(1,1) == '#' then x=x:sub(2) end
	local o = {} for i=1,5,2 do table.insert(o,tonumber(x:sub(i,i+1),16)/255) end return o end
local node_types={
	Z = {nports=1,color='#526B8E',r=15}, S = {nports=2,color='#FFE47A',r=10},
	ε = {nports=1,color='#F4CDEC',r=10}, δ = {nports=3,color='#B1FBEA',r=10},
	Add = {nports=3,color='#800000',r=20}, Hi={nports=1,color='#ffffff',r=10},
	Mul = {nports=3,color='#004B00',r=20}, Exp={nports=3,color='#00ffff',r=30},
	LyricLy = {nports=4,color='#00ff00',r=30}, -- LENS OUT S PROD
	S1 = {nports=1,color='#ce722c',r=15},
	S2 = {nports=1,color='#6a84a8',r=15},
	C1 = {nports=2,color='#fe9e5b',r=10},
	C2 = {nports=2,color='#9cb7de',r=10},
	Flip = {nports=2,color='#884400',r=15},
	Push = {nports=3,color='#0088bb',r=15},
	Gate0 = {nports=3,color='#008800',r=17},
	Gate1 = {nports=3,color='#00bb00',r=17},
}  for k,v in pairs(node_types) do v.type = k  v.color=colfromhex(v.color) end
local function mknode(type,pos,a)
	local node = setmetatable({pos=pos,a=a,prev_pos=pos,prev_a=a},{__index=assert(node_types[type]),
		__tostring=function(x)local o = x.type..'('  for _,c in ipairs(x) do o=o..'{'..c[1]..','..c[2]..'}'..',' end return o..')' end})
	for i = 1,node.nports do node[i] = false end return node end
local function mknode2(type,pos,a) local n =mknode(type,pos,a)
	table.insert(nodes,n) return #nodes,n end
-- for i=1,4 do local node = mknode'S'  table.insert(nodes,node)
-- 	node.pos=Pos(50+25*i,rmath.sqlerp(40,140,math.sin(τ/20*i)))  node.a = 0
-- 	local i = #nodes  if i > 1 then connect({i-1,1},{i,2}) end end
-- local n0 = mknode'Z' table.insert(nodes,n0) n0.pos=Pos(20,100) n0.a=0 connect({#nodes,1},{1,2})
-- local n1 = mknode'δ' table.insert(nodes,n1) n1.pos=Pos(220,100) n1.a=0 connect({#nodes,1},{#nodes-2,1}) local a1=#nodes
-- -- local n2 = mknode'ε' table.insert(nodes,n2) n2.pos=Pos(250,80) n2.a=τ/2 connect({#nodes,1},{a1,2})
-- -- local n3 = mknode'ε' table.insert(nodes,n3) n3.pos=Pos(250,120) n3.a=τ/2 connect({#nodes,1},{a1,3})
-- local n4 = mknode'Exp' table.insert(nodes,n4) n4.pos=Pos(250,120) n4.a=τ/2 connect({#nodes,1},{a1,3}) connect({#nodes,2},{a1,2})
-- local n5 = mknode'Hi' local a5=table.insert(nodes,n5) n5.pos=Pos(300,120) n5.a=τ/2 connect({#nodes,1},{#nodes-1,3})
local nn0,N0 = mknode2('Hi',Pos(300,120),τ/2)

-- local nnp = mknode2('Push',Pos(400,120),0)
-- local prev={nn0,1} for i=1,3 do local nn=mknode2('C1',Pos(350,200+i*10),0) connect({nn,2},prev) prev={nn,1} end
-- connect({nnp,3},prev)
-- local nn1 = mknode2('S1',Pos(500,200),0)
-- local nd = mknode2('δ',Pos(500,250),0)
-- connect({nd,1},{nn1,1})
-- local ne = mknode2('ε',Pos(500,230),0)
-- connect({ne,1},{nd,3})
-- local nf = mknode2('Flip',Pos(450,200),0)
-- connect({nf,1},{nd,2})
-- connect({nnp,1},{nf,2})
-- local na=mknode2('C2',Pos(500,300),0)
-- connect({nnp,2},{na,2})

local ni1 = mknode2('C1',Pos(300,125),0)
local ni2 = mknode2('C2',Pos(300,125),0)
local ni3 = mknode2('C2',Pos(300,125),0)
local ni4 = mknode2('C1',Pos(300,125),0)
connect({ni1,1},{nn0,1})
connect({ni2,1},{ni1,2})
connect({ni3,1},{ni2,2})
connect({ni4,1},{ni3,2})

local nL = mknode2('LyricLy',Pos(400,120),0)
connect({ni4,2},{nL,2})
local nz0 = mknode2('S1',Pos(420,100),0)
connect({nz0,1},{nL,3})

local ng = mknode2('Gate0',Pos(400,150),0)
local nC1 = mknode2('C1',Pos(400,170),0)
local nC2 = mknode2('C2',Pos(400,180),0)
connect({nC2,1},{nC1,2})
connect({nC1,1},{ng,1})
connect({ng,3},{nL,1})
connect({nC2,2},{nL,4})

local nz2 = mknode2('Z',Pos(600,100),0)
local prev = {nz2,1} for i=1,95 do local nn = mknode2('S',Pos(600,100+i*10),0) connect(prev,{nn,2}) prev={nn,1} end
connect(prev,{ng,2})

for i,n in ipairs(nodes) do n.pos=n.pos+Pos(100,300) n.prev_pos = n.pos  n.prev_a = n.a end
local function portpos(i) local n,p,a = np(i) return n.pos + Pos(n.r,0):rot(n.a+τ/n.nports*(p-1)) end
local font = G.newFont'liberationsans.ttf' local text=G.newText(font) G.setFont(font)
local function each_wire() return coroutine.wrap(function()
	for i,n in pairs(nodes) do for p=1,n.nports do if n[p] and (n[p][1]>i or n[p][2]>p) then
		coroutine.yield({i,p}, n[p]) end end end end) end
local function draw_nodes()
	for i,n in pairs(nodes) do
		G.push() G.translate(n.pos.x,n.pos.y)
		G.setColor(n.color)
		if BART then G.draw(yves,0,0,n.a,n.r/yvesr,nil,yvesr,yvesr) else G.circle('fill',0,0,n.r) end
		G.setColor(0,0,0)   G.circle('line',0,0,n.r)
		text:set(n.type) local w,h = text:getDimensions()
		G.setColor(0,0,0) G.draw(text,-w/2,-h/2) G.pop() end
	G.setColor(0,0,0) for i1, i2 in each_wire() do
		local e1,e2 = portpos(i1), portpos(i2)
		G.line(e1.x,e1.y,e2.x,e2.y)
		function tri(e1,e2) local p = rmath.lerp(e1,e2,0.2)
			G.push() G.translate(p:vals()) G.rotate((e2-e1):angle())
			G.setColor(0,0,0) G.polygon('fill',0,-6,0,6,6,0) G.pop() end
		if i1[2] == 1 then tri(e1,e2) end if i2[2] == 1 then tri(e2,e1) end end end
local springlength,springconst = 20, 50
local repulsion,repulsionmaxdist = 100000,50
local function springs(dt) local accels,torques={},{}
	local function exert(on,at,by)
		local para = at-on.pos  local perp = para:rot(τ/4)
		if not accels[on] then accels[on] = Pos(0,0) end  accels[on]:addby(by)
		-- i don't know why this works better with a /10
		torques[on] = (torques[on] or 0) + by:sproj(perp) * para:len()/10 end
	for i1,i2 in each_wire() do
		local n1,p1 = np(i1) local n2,p2 = np(i2)  local pp1,pp2 = portpos(i1),portpos(i2)
		local x = (pp1-pp2):len() - springlength  local f = springconst * x
		local dir = (pp2-pp1):norm()  exert(n1,pp1,f*dir) exert(n2,pp2,-f*dir) end
	 for i,n in pairs(nodes) do for j,m in pairs(nodes) do if i<j then
		local d = n.pos-m.pos if d:lensq() < repulsionmaxdist^2 then local f = d:norm()*repulsion/(d:len()^2)
		if d:len() ~= 0 then exert(n,n.pos,f) exert(m,m.pos,-f) end end end end end
	for i,n in pairs(nodes) do if n.type~='Hi' then
		local d = n.pos-Pos(love.mouse.getPosition()) local f =d:norm()*repulsion/(d:len()^2)
		exert(n,n.pos,f) end end
	for i,n in pairs(nodes) do local pos,a = n.pos,n.a   local new_pos,new_a = pos,a
		if n.type ~= 'Hi' and accels[n] then new_pos = 2*pos - n.prev_pos + dt*dt*accels[n]  n.prev_pos = pos end
		if torques[n] then new_a = 2*a - n.prev_a + dt*dt*torques[n]  n.prev_a = a end
		n.pos = rmath.lerp(pos, new_pos, 0.8)  n.a = rmath.lerp(a, new_a, 0.3)
		n.pos.x = rmath.clamp(n.pos.x,0,G.getWidth()) n.pos.y = rmath.clamp(n.pos.y,0,G.getHeight()) end end
local pop,rules
local t,tp=0,3 function love.update(dt) t=t+dt for i=1,5 do springs(math.min(dt,1/30)) end
	tp = tp - dt  while tp < 0 do pop() tp = math.log(1-math.random())/(-2*#inters) end end
function love.keypressed(k,s,i) if not i and k=='f9' then BART=not BART love.window.setTitle((BART and 'BART' or 'KO')..'LAKOSKI') end end
function love.draw() G.clear(1,1,1) draw_nodes() G.origin() --[[G.print(tostring(tp),10,10)]] end
function love.mousemoved(x,y) if love.mouse.isDown(1) then N0.pos = Pos(x,y)  end end
rules = {} local function addrule(t1,t2,s1,s2) if t2<t1 then t1,t2,s1,s2 = t2,t1,s2,s1 elseif t1==t2 then s2=s1 end
	rules[t1..'__'..t2]={s1,s2} end
local N=setmetatable({},{__index=function(t,k) return setmetatable({type=k},{__call=function(f,...) return {type=k,...} end}) end})
addrule('ε','Z',{},{})  addrule('ε','S',{},{N.ε})
addrule('Add','Z',{'x','x'},{}) addrule('Add','S',{'b',N.S'z'},{N.Add('b','z')})
-- addrule('δ','Z',{N.Z,N.Z},{}) addrule('δ','S',{N.S'x',N.S'y'},{N.δ('x','y')})
addrule('Mul','Z',{N.ε,N.Z}) addrule('S','Mul',{N.Mul('b2','t')},{N.δ(N.Add('t','z'),'b2'),'z'})
addrule('Exp','Z',{N.ε,N.S(N.Z)},{}) addrule('Exp','S',{N.δ(N.Mul('t','z'),'b2'),'z'},{N.Exp('b2','t')})
addrule('Push','S1',{N.C1('a'),'a'},{})  addrule('Push','S2',{N.C2('a'),'a'},{})
addrule('Flip','S1',{N.S2},{}) addrule('Flip','S2',{N.S1},{})
addrule('ε','S1',{},{}) addrule('ε','S2',{},{})
addrule('ε','C1',{},{N.ε}) addrule('ε','C2',{},{N.ε})
addrule('δ','S1',{N.S1,N.S1},{}) addrule('δ','S2',{N.S2,N.S2},{})
addrule('ε','LyricLy',{},{N.ε,N.ε,N.ε})

-- WHERE THE MAGIC HAPPENS
addrule('C1','LyricLy',{N.LyricLy('x1','x2','x3')},{N.C1('x1'),N.δ(N.Push('prod','x3'),N.Flip('x2')),'prod'})
addrule('C2','LyricLy',{N.LyricLy('x1','x2','x3')},{N.C2('x1'),N.δ(N.δ(N.Push('prod','i'),N.Push('i','x3')),N.Flip('x2')),'prod'})
-- WHERE THE MAGIC HAPPENS

addrule('C1','Gate0',{'rest'},{N.Gate1('x2','rest'),N.C1('x2')})
addrule('C2','Gate0',{'rest'},{N.Gate1('x2','rest'),N.C2('x2')})
addrule('S','Gate1',{'n'},{'x3',N.Gate0('n','x3')})
addrule('Z','Gate1',{},{N.ε,N.ε})
addrule('ε','ε',{},{})

-- local function pick() local hasde,hasany,types = {},{},qw.s"δ ε"
-- 	for i,nx in ipairs(inters) do table.insert(hasany,i) local n = assert(nodes[nx],'huh?')
-- 		if types[n.type] or types[nodes[n[1][1]].type] then table.insert(hasde,i) end end
-- 	local rix if #hasde>0 then rix=hasde[math.random(#hasde)] else rix=hasany[math.random(#hasany)] end
-- 	return table.remove(inters,rix) end
pop = function() if #inters == 0 then return end  --local a1=pick()
	local a1 = table.remove(inters,math.random(#inters))
	local n1 = assert(nodes[a1]) local n2,p2,a2 = np(n1[1]) assert(n2 and p2==1)
	if n2.type<n1.type then n1,p1,a1,n2,p2,a2 = n2,p2,a2,n1,p1,a1 end
	local rule = rules[n1.type..'__'..n2.type]  if (not rule) or rule.disabled then return end
	local s1,s2 = unpack(rule)
	local function remove(ix) nodes[ix] = nil nodes_free[ix]=true end
	local function insert(n) local ix = next(nodes_free)
		if ix then nodes_free[ix]=nil nodes[ix]=n return ix else table.insert(nodes,n) return #nodes end end
	local bary = (n1.pos+n2.pos)/2   local baryr = (n1.pos-n2.pos):len()/2
	remove(a1) remove(a2) local named={} local function build(onto,pattern)
		if type(pattern) == 'string' then
			if named[pattern] == nil then named[pattern] = onto
			else connect(onto,named[pattern]) named[pattern]='did it already' end
		else assert(type(pattern)=='table','aaa '..type(pattern))
			local nports=node_types[pattern.type].nports assert(#pattern+1 == nports)
			local ang = math.random()*τ local offs = Pos(math.random()*baryr,0):rot(ang)
			local n = mknode(pattern.type,bary+offs,ang) n.prev_pos=bary-offs local a = insert(n)
			connect({a,1},onto) for p=2,nports do build({a,p},pattern[p-1]) end end end
	for p=2,n1.nports do build(n1[p],s1[p-1]) end for p=2,n2.nports do build(n2[p],s2[p-1]) end
	local snd,pitch = (BART and bartsound or popsound):clone(),30/(n1.r+n2.r) snd:setPitch(pitch) snd:play() end


	
-- local profile = require"jit.profile" local function profile_start(period,file)
-- 	local function cb(thread,samples,vmstate)
-- 		file:write(profile.dumpstack(thread,"pF;l;",-100),vmstate," ",samples,"\n") end
-- 	profile.start("vli"..tonumber(period), cb)
-- end
-- function love.load() profile_start(10,io.open('./trace','w')) end
pop.wav RIFF (little-endian) data, WAVE audio, Microsoft PCM, 24 bit, stereo 44100 Hz
1
cg: couldn't decode file contents
popmono.wav RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 44100 Hz
1
cg: couldn't decode file contents
pprint.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
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
-- https://github.com/jagt/pprint.lua/blob/master/pprint.lua
-- public domain

local pprint = { VERSION = '0.1' }

local depth = 1

pprint.defaults = {
    -- If set to number N, then limit table recursion to N deep.
    depth_limit = false,
    -- type display trigger, hide not useful datatypes by default
    -- custom types are treated as table
    show_nil = true,
    show_boolean = true,
    show_number = true,
    show_string = true,
    show_table = true,
    show_function = false,
    show_thread = false,
    show_userdata = false,
    -- additional display trigger
    show_metatable = false,     -- show metatable
    show_all = false,           -- override other show settings and show everything
    use_tostring = false,       -- use __tostring to print table if available
    filter_function = nil,      -- called like callback(value[,key, parent]), return truty value to hide
    object_cache = 'local',     -- cache blob and table to give it a id, 'local' cache per print, 'global' cache
                                -- per process, falsy value to disable (might cause infinite loop)
    -- format settings
    indent_size = 2,            -- indent for each nested table level
    level_width = 80,           -- max width per indent level
    wrap_string = true,         -- wrap string when it's longer than level_width
    wrap_array = false,         -- wrap every array elements
    sort_keys = true,           -- sort table keys
}

local TYPES = {
    ['nil'] = 1, ['boolean'] = 2, ['number'] = 3, ['string'] = 4, 
    ['table'] = 5, ['function'] = 6, ['thread'] = 7, ['userdata'] = 8
}

-- seems this is the only way to escape these, as lua don't know how to map char '\a' to 'a'
local ESCAPE_MAP = {
    ['\a'] = '\\a', ['\b'] = '\\b', ['\f'] = '\\f', ['\n'] = '\\n', ['\r'] = '\\r',
    ['\t'] = '\\t', ['\v'] = '\\v', ['\\'] = '\\\\',
}

-- generic utilities
local function escape(s)
    s = s:gsub('([%c\\])', ESCAPE_MAP)
    local dq = s:find('"') 
    local sq = s:find("'")
    if dq and sq then
        return s:gsub('"', '\\"'), '"'
    elseif sq then
        return s, '"'
    else
        return s, "'"
    end
end

local function is_plain_key(key)
    return type(key) == 'string' and key:match('^[%a_][%a%d_]*$')
end

local CACHE_TYPES = {
    ['table'] = true, ['function'] = true, ['thread'] = true, ['userdata'] = true
}

-- cache would be populated to be like:
-- {
--     function = { `fun1` = 1, _cnt = 1 }, -- object id
--     table = { `table1` = 1, `table2` = 2, _cnt = 2 },
--     visited_tables = { `table1` = 7, `table2` = 8  }, -- visit count
-- }
-- use weakrefs to avoid accidentall adding refcount
local function cache_apperance(obj, cache, option)
    if not cache.visited_tables then
        cache.visited_tables = setmetatable({}, {__mode = 'k'})
    end
    local t = type(obj)

    -- TODO can't test filter_function here as we don't have the ix and key,
    -- might cause different results?
    -- respect show_xxx and filter_function to be consistent with print results
    if (not TYPES[t] and not option.show_table)
        or (TYPES[t] and not option['show_'..t]) then
        return
    end

    if CACHE_TYPES[t] or TYPES[t] == nil then
        if not cache[t] then
            cache[t] = setmetatable({}, {__mode = 'k'})
            cache[t]._cnt = 0
        end
        if not cache[t][obj] then
            cache[t]._cnt = cache[t]._cnt + 1
            cache[t][obj] = cache[t]._cnt
        end
    end
    if t == 'table' or TYPES[t] == nil then
        if cache.visited_tables[obj] == false then
            -- already printed, no need to mark this and its children anymore
            return
        elseif cache.visited_tables[obj] == nil then
            cache.visited_tables[obj] = 1
        else
            -- visited already, increment and continue
            cache.visited_tables[obj] = cache.visited_tables[obj] + 1
            return
        end
        for k, v in pairs(obj) do
            cache_apperance(k, cache, option)
            cache_apperance(v, cache, option)
        end
        local mt = getmetatable(obj)
        if mt and option.show_metatable then
            cache_apperance(mt, cache, option)
        end
    end
end

-- makes 'foo2' < 'foo100000'. string.sub makes substring anyway, no need to use index based method
local function str_natural_cmp(lhs, rhs)
    while #lhs > 0 and #rhs > 0 do
        local lmid, lend = lhs:find('%d+')
        local rmid, rend = rhs:find('%d+')
        if not (lmid and rmid) then return lhs < rhs end

        local lsub = lhs:sub(1, lmid-1)
        local rsub = rhs:sub(1, rmid-1)
        if lsub ~= rsub then
            return lsub < rsub
        end
        
        local lnum = tonumber(lhs:sub(lmid, lend))
        local rnum = tonumber(rhs:sub(rmid, rend))
        if lnum ~= rnum then
            return lnum < rnum
        end

        lhs = lhs:sub(lend+1)
        rhs = rhs:sub(rend+1)
    end
    return lhs < rhs
end

local function cmp(lhs, rhs)
    local tleft = type(lhs)
    local tright = type(rhs)
    if tleft == 'number' and tright == 'number' then return lhs < rhs end
    if tleft == 'string' and tright == 'string' then return str_natural_cmp(lhs, rhs) end
    if tleft == tright then return str_natural_cmp(tostring(lhs), tostring(rhs)) end

    -- allow custom types
    local oleft = TYPES[tleft] or 9
    local oright = TYPES[tright] or 9
    return oleft < oright
end

-- setup option with default
local function make_option(option)
    if option == nil then
        option = {}
    end
    for k, v in pairs(pprint.defaults) do
        if option[k] == nil then
            option[k] = v
        end
        if option.show_all then
            for t, _ in pairs(TYPES) do
                option['show_'..t] = true
            end
            option.show_metatable = true
        end
    end
    return option
end

-- override defaults and take effects for all following calls
function pprint.setup(option)
    pprint.defaults = make_option(option)
end

-- format lua object into a string
function pprint.pformat(obj, option, printer)
    option = make_option(option)
    local buf = {}
    local function default_printer(s)
        table.insert(buf, s)
    end
    printer = printer or default_printer

    local cache
    if option.object_cache == 'global' then
        -- steal the cache into a local var so it's not visible from _G or anywhere
        -- still can't avoid user explicitly referentce pprint._cache but it shouldn't happen anyway
        cache = pprint._cache or {}
        pprint._cache = nil
    elseif option.object_cache == 'local' then
        cache = {}
    end

    local last = '' -- used for look back and remove trailing comma
    local status = {
        indent = '', -- current indent
        len = 0,     -- current line length
    }

    local wrapped_printer = function(s)
        printer(last)
        last = s
    end

    local function _indent(d)
        status.indent = string.rep(' ', d + #(status.indent))
    end

    local function _n(d)
        wrapped_printer('\n')
        wrapped_printer(status.indent)
        if d then
            _indent(d)
        end
        status.len = 0
        return true -- used to close bracket correctly
    end

    local function _p(s, nowrap)
        status.len = status.len + #s
        if not nowrap and status.len > option.level_width then
            _n()
            wrapped_printer(s)
            status.len = #s
        else
            wrapped_printer(s)
        end
    end

    local formatter = {}
    local function format(v)
        local f = formatter[type(v)]
        f = f or formatter.table -- allow patched type()
        if option.filter_function and option.filter_function(v, nil, nil) then
            return ''
        else
            return f(v)
        end
    end

    local function tostring_formatter(v)
        return tostring(v)
    end

    local function number_formatter(n)
        return n == math.huge and '[[math.huge]]' or tostring(n)
    end

    local function nop_formatter(v)
        return ''
    end

    local function make_fixed_formatter(t, has_cache)
        if has_cache then
            return function (v)
                return string.format('[[%s %d]]', t, cache[t][v])
            end
        else
            return function (v)
                return '[['..t..']]'
            end
        end
    end

    local function make_userdata_formatter(has_cache)
    	local function utype(v)
    		local mt = getmetatable(v)
    		if not mt then return '?' end
    		return mt.__name or '?'
		end
    	if has_cache then
	    	return function(v)
		    	return string.format('[[userdata <%s> %d]]', utype(v), cache.userdata[v])
	    	end
    	else
	    	return function (v)
		    	return string.format('[[userdata <%s>]]', utype(v))
	    	end
    	end
	end

    local function string_formatter(s, force_long_quote)
        local s, quote = escape(s)
        local quote_len = force_long_quote and 4 or 2
        if quote_len + #s + status.len > option.level_width then
            _n()
            -- only wrap string when is longer than level_width
            if option.wrap_string and #s + quote_len > option.level_width then
                -- keep the quotes together
                _p('[[')
                while #s + status.len >= option.level_width do
                    local seg = option.level_width - status.len
                    _p(string.sub(s, 1, seg), true)
                    _n()
                    s = string.sub(s, seg+1)
                end
                _p(s) -- print the remaining parts
                return ']]' 
            end
        end

        return force_long_quote and '[['..s..']]' or quote..s..quote
    end

    local function table_formatter(t)
        if option.use_tostring then
            local mt = getmetatable(t)
            if mt and mt.__tostring then
                -- return string_formatter(tostring(t), true)
                return tostring(t)
            end
        end

        local print_header_ix = nil
        local ttype = type(t)
        if option.object_cache then
            local cache_state = cache.visited_tables[t]
            local tix = cache[ttype][t]
            -- FIXME should really handle `cache_state == nil`
            -- as user might add things through filter_function
            if cache_state == false then
                -- already printed, just print the the number
                return string_formatter(string.format('%s %d', ttype, tix), true)
            elseif cache_state > 1 then
                -- appeared more than once, print table header with number
                print_header_ix = tix
                cache.visited_tables[t] = false
            else
                -- appeared exactly once, print like a normal table
            end
        end

        local limit = tonumber(option.depth_limit)
        if limit and depth > limit then
           if print_header_ix then
              return string.format('[[%s %d]]...', ttype, print_header_ix)
           end
           return string_formatter(tostring(t), true)
        end

        local tlen = #t
        local wrapped = false
        _p('{')
        _indent(option.indent_size)
        _p(string.rep(' ', option.indent_size - 1))
        if print_header_ix then
            _p(string.format('--[[%s %d]] ', ttype, print_header_ix))
        end
        for ix = 1,tlen do
            local v = t[ix]
            if formatter[type(v)] == nop_formatter or 
               (option.filter_function and option.filter_function(v, ix, t)) then
               -- pass
            else
                if option.wrap_array then
                    wrapped = _n()
                end
                depth = depth+1
                _p(format(v)..', ')
                depth = depth-1
            end
        end

        -- hashmap part of the table, in contrast to array part
        local function is_hash_key(k)
            if type(k) ~= 'number' then
                return true
            end

            local numkey = math.floor(tonumber(k))
            if numkey ~= k or numkey > tlen or numkey <= 0 then
                return true
            end
        end

        local function print_kv(k, v, t)
            -- can't use option.show_x as obj may contain custom type
            if formatter[type(v)] == nop_formatter or
               formatter[type(k)] == nop_formatter or 
               (option.filter_function and option.filter_function(v, k, t)) then
                return
            end
            wrapped = _n()
            if is_plain_key(k) then
                _p(k, true)
            else
                _p('[')
                -- [[]] type string in key is illegal, needs to add spaces inbetween
                local k = format(k)
                if string.match(k, '%[%[') then
                    _p(' '..k..' ', true)
                else
                    _p(k, true)
                end
                _p(']')
            end
            _p(' = ', true)
            depth = depth+1
            _p(format(v), true)
            depth = depth-1
            _p(',', true)
        end

        if option.sort_keys then
            local keys = {}
            for k, _ in pairs(t) do
                if is_hash_key(k) then
                    table.insert(keys, k)
                end
            end
            table.sort(keys, cmp)
            for _, k in ipairs(keys) do
                print_kv(k, t[k], t)
            end
        else
            for k, v in pairs(t) do
                if is_hash_key(k) then
                    print_kv(k, v, t)
                end
            end
        end

        if option.show_metatable then
            local mt = getmetatable(t)
            if mt then
                print_kv('__metatable', mt, t)
            end
        end

        _indent(-option.indent_size)
        -- make { } into {}
        last = string.gsub(last, '^ +$', '')
        -- peek last to remove trailing comma
        last = string.gsub(last, ',%s*$', ' ')
        if wrapped then
            _n()
        end
        _p('}')

        return ''
    end

    -- set formatters
    formatter['nil'] = option.show_nil and tostring_formatter or nop_formatter
    formatter['boolean'] = option.show_boolean and tostring_formatter or nop_formatter
    formatter['number'] = option.show_number and number_formatter or nop_formatter -- need to handle math.huge
    formatter['function'] = option.show_function and make_fixed_formatter('function', option.object_cache) or nop_formatter
    formatter['thread'] = option.show_thread and make_fixed_formatter('thread', option.object_cache) or nop_formatter
    -- formatter['userdata'] = option.show_userdata and make_fixed_formatter('userdata', option.object_cache) or nop_formatter
    formatter['userdata'] = option.show_userdata and make_userdata_formatter(option.object_cache) or nop_formatter
    formatter['string'] = option.show_string and string_formatter or nop_formatter
    formatter['table'] = option.show_table and table_formatter or nop_formatter

    if option.object_cache then
        -- needs to visit the table before start printing
        cache_apperance(obj, cache, option)
    end

    _p(format(obj))
    printer(last) -- close the buffered one

    -- put cache back if global
    if option.object_cache == 'global' then
        pprint._cache = cache
    end

    return table.concat(buf)
end

-- pprint all the arguments
function pprint.pprint( ... )
    local args = {...}
    -- select will get an accurate count of array len, counting trailing nils
    local len = select('#', ...)
    for ix = 1,len do
        pprint.pformat(args[ix], nil, io.write)
        io.write('\t')
    end
    if len > 0 then
	    io.write('\n')
    end
end

setmetatable(pprint, {
    __call = function (_, ...)
        pprint.pprint(...)
    end
})

return pprint

round #86

submitted at
2 likes

guesses
comments 1
rrebbbbeca known at the time as [cg's #16]

here are the directions since i didn’t list them earlier:
use wasd or the arrow keys to move to reconnect wires just click on them you can click any machine to pick it up and reposition it on-screen prompts will explain how to adjust wire length and color or remove machines you can press tab to add a new machine and right-click a boolean input that isn’t wired yet to switch its value enjoy!


post a comment


cg86.love data

round #81

submitted at
0 likes

guesses
comments 0

post a comment


dir 81
collision.lucia 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
clamp:{y max x min z};
lerp:{1-x*y+(x*z)};
stiffness:0.3;

G:love.graphics;
SIZE:[G.getWidth(), G.getHeight()];

newball: { 
	pos: 2! map {math.random(SIZE x)};
	rad: math.random(30,75);
	col: 3! map {math.random()};
	[pos:pos,old:pos,rad:rad,col:col]
};
balls: 20! map newball;

bound:{clamp([0,0]+x.rad, x.pos, SIZE-x.rad)};
verlet: {
	accel: x; dt: y;
	new: accel*dt*dt - z.old + (2*z.pos);
	set(z,.old,z.pos);
	set(z,.pos,new);
};

set(love, .draw, callable {
	G.clear(1,1,1);
	G.setColor(0,1,0);
	f:{G.circle(y,x.pos 0,x.pos 1, x.rad)};
	balls map { 
		G.setColor(x.col); f(x,.fill);
		G.setColor(0,0,0); f(x,.line);
	};
});

hypot:{x*x sum @math.sqrt};
norm:{h:hypot x;0~h?x*0:x/h};

step: {
	balls map { set(x, .pos, lerp(stiffness, x.pos, bound x)); };
	3! map { news: balls map {
		ball: x;
		deltas: (balls flip).pos map {x-(ball.pos)}- ;
		dists: deltas map hypot; dirs: deltas map norm;
		radsums: (balls flip).rad map {ball.rad+x};
		overlaps: dists - radsums -;
		moves: overlaps > 0.001 * stiffness * dirs * overlaps;
		move: moves sum;
		x.pos + move
	}};
	[balls,news] flip map {set(x 0, .pos, x 1)};
	call(love.mouse.isDown,1)
		? set(balls 0, .pos, [love.mouse.getX(),love.mouse.getY()]) 
		: 0;
	balls map { verlet([0,1000], 1/60, x) };
};

set(love, .update, callable step);
conf.lua ASCII text
1
function love.conf(t) t.window.title="cg81" end
lucia.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
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
local ok,pprint = pcall(require, 'pprint')
if not ok then pprint=print pformat=tostring  -- that's all you deserve
else pformat=pprint.pformat pprint.setup{show_all=true,use_tostring=true} end

local lpeg = require 'lpeg'
local P,V,R,C,Ct,Cc = lpeg.P,lpeg.V,lpeg.R,lpeg.C,lpeg.Ct,lpeg.Cc

local function isty(ty,x) return type(x) == 'table' and x.ty == ty end
local function enty(ty) return function(x) x.ty=ty return x end end
local function inty(ty) return function(x) return {ty=ty,x} end end
local list = enty'list'
local dict = inty'dict'
local fn = inty'fn'
local function islist(x) return isty('list',x) end
local function isdict(x) return isty('dict',x) end
local function isfn(x) return isty('fn',x) end

local function conform(f)
	local function inner(a,b)
		local la,lb = islist(a),islist(b)
		assert(la or type(a) == 'number','unconformation')
		assert(lb or type(b) == 'number','unconformation '..type(b))

		local out = list{}
		if not la and not lb then return f(a,b)
		elseif la and lb then
			assert(#a == #b, 'unconformation length: '..#a..' '..#b) -- todo
			for i = 1,#a do out[i] = inner(a[i],b[i]) end
		elseif la then
			for i,v in ipairs(a) do out[i] = inner(v,b) end
		elseif lb then
			for i,v in ipairs(b) do out[i] = inner(a,v) end
		end
		return out
	end
	return inner end
local function conform1(f)
	local function inner(a)
		if not islist(a) then assert(type(a) == 'number') return f(a) end
		local out = list{}
		for i = 1,#a do out[i] = inner(a[i]) end
		return out
	end
	return inner
end

local function eqq(a,b)
	if a == b then return true end
	if islist(a) and islist(b) and #a==#b then
		for i=1,#a do if not eqq(a[i],b[i]) then return false end end
		return true
	elseif isdict(a) and isdict(b) then
		local keys = {}
		for k in pairs(a[1]) do keys[k] = true end
		for k in pairs(b[1]) do keys[k] = true end
		for k in pairs(keys) do
			if not eqq(a[1][k],b[1][k]) then return false end
		end
		return true
	end
	return false
end
local call
local dyads = {
	['+'] = conform(function(a,b) return a+b end),
	['-'] = conform(function(a,b) return a-b end),
	['/'] = conform(function(a,b) return a/b end),
	['*'] = conform(function(a,b) return a*b end),
	['<'] = conform(function(a,b) return a<b and 1 or 0 end),
	['>'] = conform(function(a,b) return a>b and 1 or 0 end),
	['='] = conform(function(a,b) return a==b and 1 or 0 end),
	['~'] = function(a,b) return eqq(a,b) and 1 or 0 end,
	['++'] = function(a,b) -- it's PEND!!!!
		if not islist(a) then a = list{a} end
		if not islist(b) then b = list{b} end
		local out = list{}
		table.move(a,1,#a,1,out) table.move(b,1,#b,#a+1,out)
		return out
	end,
	mod = conform(function(a,b) return a%b end),
	max = conform(math.max),
	min = conform(math.min),
	-- this can all probably be generalized a bunch
	['@'] = function(a,b,c) return call(c,b,{a}) end,
	map = function(a,b,c)
		assert(islist(a),'can only map over list, was '..type(a))
		local out = list{}
		for i,v in ipairs(a) do out[i] = call(c,b,{v}) end
		return out
	end
}

local monads = {
	['-'] = conform1(function(a) return -a end),
	sum = function(a)
		assert(islist(a),'need list for sum')
		local s = 0
		if islist(a[1]) then s = list{} for i=1,#a[1] do s[i] = 0 end end
		for _,v in ipairs(a) do s = dyads['+'](s,v) end
		return s
	end,
	['!'] = function(a) local out = list{} for i=0,a-1 do out[i+1]=i end return out end,
	['>'] = function(a) return list{a} end,
	['<'] = function(a) assert(islist(a) and #a > 0,'cant unlist nonlist') return a[1] end,
	flip = function(a,c) -- this already needs rewriting
		if type(a) == 'number' then return a
		elseif islist(a) then
			if #a == 0 then return list{} end
			if type(a[1]) == 'number' then
				for i = 1,#a do assert(type(a[i]) == 'number','need list of only numbers for flip') end
				return a
			elseif islist(a[1]) then
				local len = #a[1]
				local out = list{}
				for j = 1,len do out[j] = list{} end
				for i,v in ipairs(a) do
					assert(islist(v),'need list of only lists for flip')
					assert(#v == len, 'need list of equisized lists for flip')
					for j,w in ipairs(v) do out[j][i] = w end
				end
				return out
			elseif isdict(a[1]) then
				local out = dict{}
				local keys = {} for k in pairs(a[1][1]) do table.insert(keys,k) end
				for _,k in ipairs(keys) do out[1][k] = list{} end
				for i,v in ipairs(a) do
					assert(isdict(v),'need list of only dicts for flip')
					for _,k in ipairs(keys) do out[1][k][i] = assert(v[1][k],'missing key '..k) end end
				return out
			end
		elseif isdict(a) then
			local keys = {} for k in pairs(a[1]) do table.insert(keys,k) end
			local len
			for _,k in ipairs(keys) do
				assert(islist(a[1][k]),'need dict of only lists for flip')
				len = len or #a[1][k]
				assert(#a[1][k] == len,'need dict of equisized lists for flip')
			end
			local out = list{}
			for i=1,len do out[i] = dict{} end
			for k,v in pairs(a[1]) do
				for j,w in ipairs(v) do out[j][1][k] = w end
			end
			return out
		end
	end,
}

local S = ("#" * (P(1) - '\n')^0 * ('\n' + P(-1)) + lpeg.S" \n\t")^0
local function seq(item,sep) return (item * (sep*S*item)^0 )^-1 end
local number = C(R"09"^1 * '.' * R"09"^1 + R"09"^1) / tonumber
local op = C(P"+"+"-"+"*"+"/")

local namechar = R"az"+R"AZ"+"_"
local name = C( (R"az"+R"AZ"+"_")^1 ) / function(s) return {ty='name',n=s} end
local symbol = ('.'*name) / enty'string'

local function grab_names(map)
	local keys = {}
	for k in pairs(map) do table.insert(keys,k) end
	table.sort(keys,function(a,b) return #a > #b end)
	local p = P(false)
	for _,k in ipairs(keys) do
		if not namechar:match(k) then p = p + k
		else p = p + (k * -namechar) end end
	return p end

local monad_names = grab_names(monads)
local dyad_names = grab_names(dyads)
local monad = S*C(monad_names)*S
local dyad = S*C(dyad_names)*S*V'term'
local reserved = monad_names+dyad_names
name = name - reserved

local gram = P{"body",
	call = Ct(V'noun'*('('*S*V'list_body'*')' + V'noun')^1 ) * S / enty'call',
	noun = (name + symbol + number + V'fn' + "("*V"body"*")" + V'list' + V'dict') * S,
	term = V'call' + V'noun',
	oper = (dyad + monad)
		/ function(v,n) return {ty='oper',v,n} end,
	real_expr = Ct(V'term' * V'oper'^0) / enty'expr',
	expr = V'cond' + V'real_expr',
	cond = Ct(V'real_expr' * '?' * S * V'real_expr' * ':' * S * V'expr') / enty'cond',
	body = Ct( seq(V'decl' + V'expr', ';') * (S*';'*Cc(0))^-1 * S ) / enty'body',
	list_body = Ct( seq(V'expr', ',') ) / enty'list_body',
	list = ('[' * S * V'list_body' * ']') / enty'list_lit',
	decl = Ct(name * ':' * S * V'expr') / enty'decl',
	fn = '{'*S*V'body'*'}' / fn,
	dict = Ct('['*S*':'*S*']' + '['*S*seq(V'decl',',')*']') / enty'dict_lit',
}
local patt = S * gram * S * -1

local function qprint(x,ns)
	local s = ('| '):rep(ns or 0)
	if type(x) ~= 'table' then print(s..tostring(x))
	else io.write(s..(x.ty or '???')..(x[1] and ':' or ''))
		for k,v in pairs(x) do if type(k) == 'string' and k~='ty' then
				io.write(' '..k..'='..tostring(v)..',') end end
		print()
		for i,v in ipairs(x) do qprint(v,(ns or 0)+1) end
	end
end

local evals = {}
local function eval(c,x)
	if type(x) == 'number' then return x end
	return (evals[x.ty] or error('uncomprehended type '..x.ty))(c,x)
end

call = function (c,callee,args)
	if type(callee) == 'function' then return callee(table.unpack(args))
	elseif islist(callee) then
		assert(#args == 1 and type(args[1]) == 'number', 'can only index single number for now '..pformat(args))
		local idx = math.floor(args[1])
		assert(0 <= idx and idx < #callee,'index out of bounds')
		return callee[idx + 1]
	elseif isfn(callee) then
		table.insert(c.cs,1,{a=args,f=callee})
		local res = eval(c,callee[1])
		table.remove(c.cs,1)
		return res
	elseif isdict(callee) then
		return callee[1][args[1]] or 0
	elseif type(callee) == 'table' then
		return callee[args[1]] -- ordinary table access
	else pprint(callee,args) error'unsupported call style'
	end
end

function evals.expr(c,t)
	local val = eval(c,t[1])
	for i = 2, #t do
		local oper = t[i]  assert(oper.ty == 'oper')
		local v,n = oper[1],oper[2]
		if n then val = (dyads[v] or error("no such dyad "..v))(val, eval(c,n),c)
		else val = (monads[v] or error("no such monad "..v))(val,c) end
	end
	return val
end
function evals.list_lit(c,t)
	local out = list{}
	for i,v in ipairs(t) do
		out[i] = eval(c,v)
	end
	return out
end
function evals.dict_lit(c,t)
	local out = dict{}
	for i,v in ipairs(t) do
		assert(v.ty == 'decl')
		local name,val = v[1],v[2]
		assert(name.ty == 'name')
		out[1][name.n] = eval(c,v[2])
	end
	return out
end
function evals.fn(c,t) return t end
function evals.string(c,t) return t.n end
function evals.body(c,t)
	if #t < 1 then return 0 end
	local v
	for i=1,#t do v = eval(c,t[i]) end
	return v
end
function evals.decl(c,t)
	local name=t[1] assert(name.ty=='name')
	local val = eval(c,t[2])
	c.g[name.n] = val
	if isfn(val) then val.name = name.n end
	return 0
end
function evals.name(c,t)
	-- currently only magical names (x y z xx yy zz) and globals
	-- todo: proper lexical scoping
	local name,args,args2 = t.n, c.cs[1].a, c.cs[2].a
	    if name == 'x' then return args[1] or 0
    elseif name == 'y' then return args[2] or 0
    elseif name == 'z' then return args[3] or 0
	elseif name == 'xx' then return args2[1] or 0
    elseif name == 'yy' then return args2[2] or 0
    elseif name == 'zz' then return args2[3] or 0
    else return c.g[name] or _G[name] or 0 end end

function evals.call(c,t)
	local callee = eval(c,t[1])
	assert(#t >= 2)
	local function call1(callee,t)
		local args
		if isty('list_body',t) then
			args = {}
			for i,v in ipairs(t) do args[i] = eval(c,v) end
		else args = {eval(c,t)} end
		return call(c,callee,args)
	end
	for i=2,#t do
		callee = call1(callee, t[i])
	end
	return callee
end
function evals.cond(c,t)
	local cond = eval(c,t[1])
	assert(type(cond) == 'number' and (cond == 1 or cond == 0), 'need 0 or 1 for cond')
	return eval(c, t[3-cond])
end

local protect
local function init()
	local c
	c = {
		g={
			set = function(t,k,v)
				if isdict(t) then t = t[1] end
				t[k] = v
				return t
			end,
			-- a LITTLE clunky but i'm running out of time
			callable = function(x)
				return function(...) return protect(c, call, c, x, {...}) end
			end,
			call = function(f,...)
				local r = table.pack(f(...))
				for i=1,r.n do
					if not r[i] then r[i] = 0
					elseif r[i] == true then r[i] = 1
					end
				end
				if r.n == 1 then return r[1] else r.n=nil return list(r) end
			end,
			pprint = function(...) pprint(...) end,
			print=print,
		},
		cs={{a={},fake=true},{a={},fake=true}}}
	return c
end

protect = function(c,...)
	local ok, err = pcall(...)
	if not ok then
		for i,x in ipairs(c.cs) do if not x.fake then
			print('-->',x.f and x.f.name or '??')
		end end
		error(err, 0)
	else return err end
end

local function run(s,c,debug)
	c = c or init()
	local prog = patt:match(s)
	if prog == nil then error'nil prog' end
	if debug then qprint(prog) end
	return protect(c, eval, c, prog)
end

local n = 1
local function c(i,o)
	io.write(n,'\t',i,'\t') n=n+1
	io.flush()
	local oo = run(i)
	assert(eqq(o,oo), "expected to get "..pformat(o).." but i got "..pformat(oo))
	print('ok')
end

c("2+2",4)
c("6*6-",-36)
c("2-20/6-",3)
c("6*6+3",39)
c("6*(6+3)",54)
c("6+8/2",7)
c('10+[1,2,3]',list{11,12,13})
c('[10,20,30]/10',list{1,2,3})
c('[2,3]*[4,5]',list{8,15})
c('   (2+2;4*8;24)-4',20)
c('  2+2; 5*5',25)
c('a:6; b:7; a*b',42)
c('math.sqrt(9)',3)
c('math.sqrt 9',3)
c('math.sqrt(7;8;9)',3)
c('math.sqrt(9,8,7)',3)
c('13 + math.sqrt 36',19)
c('math.sqrt 36 + 13',19)
c('math.sqrt (36 + 13)',7)
c('math.sqrt 36 + (13-)',-7)
c('math.sqrt 36 + 13-',-19)
c('[10,20,30](0)',10)
c('{x+5}20',25)
c('{x+5}[10,20,30]',list{15,25,35})
c('0.5+1',1.5)
c('lerp:{1-x*y+(x*z)}; lerp(0.25,12,24)',15)
c('lerp:{1-x*y+(x*z)}; lerp(0.25,[12,0],24)',list{15,6})
c('lerp:{1-x*y+(x*z)}; lerp(1/4,[10,20],[18,16])',list{12,19})
c('lerp:{1-x*y+(x*z)}; lerp([1/4,1/2],[10,20],[18,16])',list{12,18})
c('lerp:{1-x*y+(x*z)}; mid:{lerp(1/2,x,y)}; mid([10,20,30],[90,80,70])',list{50,50,50})
c('{36}()',36)
c('[7-,6-,5-,4-,3-,2-,1-,0,1,2,3,4,5,6,7]mod3',list{2,0,1,2,0,1,2,0,1,2,0,1,2,0,1})
c('modern:69;modern',69)
c('dbl:{2*x}; 10 @ dbl',20)
c('dbl:{2*x}; [10,20,30] @ dbl',list{20,40,60})
c('dbl:{2*x}; [10,20,30] map dbl',list{20,40,60})
c('[36,81] map math.sqrt',list{6,9})
c('36 max 81 + 9',90)
c('([{x+2},{x+10}]1) 5',15)
c('[{x+2},{x+10}] 1 5',15)
c('[{x+2},{x+10}] map {x 5}',list{7,15})
c('.hi','hi')
c('[1]++2',list{1,2})
c('1++[2]',list{1,2})
c('[1]++[2]',list{1,2})
c('1++2',list{1,2})
c('[1,2,3]++[4,5]',list{1,2,3,4,5})
c('[1,2,3]++[[4,5]]',list{1,2,3,list{4,5}})
c('[]++[1,2,3]',list{1,2,3})
c('[1,2,3]++[]',list{1,2,3})
c('[aaa:100, bbb:200, ccc:300].bbb',200)
c('[ [aaa:100], [aaa:200], [aaa:300] ] map {x.aaa}',list{100,200,300})
c('[aaa:[bbb:100]].aaa.bbb',100)
c('[[1,2,3],[10,20,30],[100,200,300]] flip', list{list{1,10,100},list{2,20,200},list{3,30,300}})
c('[1,2,3] flip',list{1,2,3})
c('[] flip',list{})
c('12 flip',12)
c('[[a:1,b:2],[a:10,b:20],[a:100,b:200]] flip',dict{a=list{1,10,100},b=list{2,20,200}})
c('[a:[1,10,100],b:[2,20,200]] flip',list{dict{a=1,b=2},dict{a=10,b=20},dict{a=100,b=200}})
c('math.exp 1',math.exp(1))
c('[:]',dict{})
-- c('[:] flip',99999) -- i don't know what this should do
_G.test = {a=100,b=200}
c('test.a',100)
c('set(test,.b,500); test.b',500) assert(_G.test.b == 500)
c('2+2 # thats easy',4)
c('5+5; #yeah\n2+2',4)
c('10!sum',45)
c('hypot:{x*x sum @math.sqrt}; hypot [3,4]',5)
c('[10,20-]-',list{-10,20})
c('0 ? 5 : 10',10)
c('1 ? 5 : 10',5)
c('2<3 ? 20 : 30',20)
c('3<2 ? 20 : 10<20 ? 100 : 200',100)
c('3<2 ? 20 : 20<10 ? 100 : 200',200)
c('2<3 ? 20 : 20<10 ? 100 : 200',20)
_G.test = {c=0,d=0}
c('0 ? set(test,.c,123) : set(test,.d,456); 0',0) assert(_G.test.c == 0 and _G.test.d == 456)
_G.test = {c=0,d=0}
c('1 ? set(test,.c,123) : set(test,.d,456);',0) assert(_G.test.c == 123 and _G.test.d == 0)
c('[10,20,30]<[18,19,20]',list{1,0,0})
c('5!=3',list{0,0,0,1,0})
c('[1,0,1,0]=[1,1,0,0]',list{1,0,0,1})
c('[1,0,1,0]~[1,1,0,0]',0)
c('[1,0,1,0]~[1,0,1,0]',1)
c('[a:100,b:200]~[a:100]',0)
c('[a:100,b:200]~[a:100,b:300]',0)
c('[a:100,b:200]~[b:200,a:100]',1)
c('2+2; 4+4',8)
c('2+2; 4+4;',0)
c('2>',list{2})
c('[2,3]>',list{list{2,3}})
c('[2,3]<',2)
c('[2,3]><',list{2,3})
c('{x}(1,2,3)',1)
c('{y}(1,2,3)',2)
c('{z}(1,2,3)',3)
-- c('a:100; {a:200}(); a',100) -- todo
-- c('a:100; {a:200; a}()+a',300) -- todo
c('([ [a:10,b:20], [a:100,b:200] ] flip).a',list{10,100}) --egh
-- c('[ [a:10,b:20], [a:100,b:200] ] flip.a',list{10,100}) --egh

return {
	run=run,
}
main.lua ASCII text
1
require'lucia'.run(io.open'collision.lucia':read'*a')

round #77

submitted at
0 likes

guesses
comments 0

post a comment


circle.fasm 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
format ELF64 executable
r	= 16
s	= 25
	mov ebp, 0
ly:	mov ebx, 0
	mov dx, bp
	sub dx, s/2
	imul dx, 3
	imul dx, dx
	neg dx
	add dx, r*r
lx:	mov [row+ebx], '.'
	mov cx, bx
	sub cx, s/2
	imul cx, 2
	imul cx, cx
	cmp cx, dx
	jg @f
	mov [row+ebx], '#'
@@:	inc bx
	cmp bx, s
	jne lx
	mov rax, 1
	mov rdi, 1
	mov rsi, row
	mov rdx, s+1
	syscall
	inc bp
	cmp bp, s
	jne ly
	mov rax, 60
	mov rdi, 0
	syscall
row	rb s
	db 10

round #75

submitted at
1 like

guesses
comments 0

post a comment


submission.py ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python3

def Main():
	print("Which Teenage Mutant Ninja Turtle are you?")
	print("Question 1: which Teenage Mutant Ninja Turtle are you?")
	Turtles = ["Leonardo","Raphael","Donatello","Michaelangelo"]
	SelectedTurtleName = None
	while SelectedTurtleName == None:
		TurtleName = input("Enter a Teenage Mutant Ninja Turtle >>>")
		if any([PossibleTurtleName == TurtleName for PossibleTurtleName in Turtles]):
			SelectedTurtleName = TurtleName
		else:
			print("Sorry, I don't know about a Teenage Mutant Ninja Turtle with that name! Please try again.")
	print("We have determined which Teenage Mutant Ninja Turtle you are!")
	print("You are....")
	print(SelectedTurtleName)

if __name__ == "__main__":
	Main()

round #73

submitted at
0 likes

guesses
comments 0

post a comment


the.sh ASCII text
1
2
#!/bin/sh
websocat wss://codeguessing.gay/73/ws

round #70

submitted at
3 likes

guesses
comments 0

post a comment


dir cg70
dir pathing
pathing.factor 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
! Copyright (C) 2025 Aleksander "olus2000" Sabak.
! See https://factorcode.org/license.txt for BSD license.

USING: io sequences kernel splitting namespaces ranges arrays math qw
math.vectors path-finding combinators ; 
IN: entry 

SYMBOL: grid

: str>>grid ( string -- )  
  "\n" split grid set ;

: print-grid ( -- ) 
  grid get "\n" join print ;

: tile ( position -- tile ) 
  reverse grid get [ swap nth ] reduce ; 

CONSTANT: deltas { { 1 0 } { 0 1 } { -1 0 } { 0 -1 } }
CONSTANT: extents { 15 5 } 

: inbounds? ( position -- ? ) 
  [ { 0 0 } swap v<= vall? ]
  [ extents v< vall? ] bi and ;
  
: neighbors ( position -- neighbors ) 
  deltas [ v+ ] with map
  [ inbounds? ] filter
  [ tile CHAR: * = ] reject ;

: where ( char -- position ) 
  grid get [ index ] with map
  [ ] find swap 2array ;

: delta>dir ( delta -- direction )
  deltas index qw{ right down left up } nth ; 

: path ( -- directions ) 
  CHAR: @ where 
  CHAR: + where 
  [ neighbors ] [ 2drop 1 ] [ 2drop 0 ] <astar> find-path 
  dup rest swap [ v- delta>dir ] 2map ;
entry.factor 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
! Copyright (C) 2025 Aleksander "olus2000" Sabak.
! See https://factorcode.org/license.txt for BSD license.

USING: accessors arrays assocs calendar concurrency.futures entry.pathing 
formatting hashtables http http.client io io.encodings.string io.encodings.utf8 
json json.http kernel math math.parser namespaces prettyprint sequences 
sequences.repeating threads ;
IN: entry

CONSTANT: session
"SESSION COOKIE HERE" 

: session-cookie ( -- cookie ) 
  session "session" <cookie> ;

: request ( method -- request )
  "https://codeguessing.gay/extra/game70" swap <client-request>
  session-cookie put-cookie ;  

: step-body ( direction -- post-data )
  "dir" associate <json-post-data> ;

: step-request ( direction -- request ) 
  "POST" request
  swap step-body >>post-data ;

SYMBOL: score

: print-score ( -- ) score get "score: %d\n" printf ; 

: request! ( request -- response )
  http-request nip utf8 decode json> ;

: respect ( response -- ) 
  [ "grid" of str>>grid ]
  [ "score" of score set ] bi ;

: init ( -- ) "GET" request request! respect ;

: travel ( path -- ) 
  [ [ step-request request! ] curry future 
    100 milliseconds sleep
  ] map
  [ ?future ] map 
  [ "s" of ] maximum-by respect ;
  
: print-state ( -- ) print-score print-grid ;

: perform-iteration ( -- ) path travel print-state ;

: entry ( -- )
  init print-state
  [ score get 2025 <  ]
  [ perform-iteration ] while ;

MAIN: entry

round #69

submitted at
2 likes

guesses
comments 0

post a comment


cg69.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
#!/usr/bin/env luajit
local target = assert(tonumber((...)),'Need target value!')

local consts = {
	{'pi',math.pi},
	{'e',math.exp(1)},
	{'phi',(math.sqrt(5)+1)/2},
	{'1/2',1/2}}
for i = 1,9 do table.insert(consts, {tostring(i),i}) end

local unary = {
	{'ln',math.log,inv='exp'},
	{'exp',math.exp,inv='ln'},
	{'sqrt',math.sqrt,inv='sqr'},
	{'sqr',function(x)return x^2 end,inv='sqrt'},
	{'sinpi',function(x)return math.sin(math.pi*x)end,noint=true},
	{'cospi',function(x)return math.cos(math.pi*x)end,noint=true},
	{'tanpi',function(x)return math.tan(math.pi*x)end,noint=true},
	{'sin',math.sin},
	{'cos',math.cos},
	{'tan',math.tan},
	{'-',function(x)return -x end,inv='-'},
	{'1/',function(x)return 1/x end,inv='1/'}}

local binary = {
	{'logab',math.log,norat=true},
	{'atan2',math.atan2,norat=true},
	-- {'root',function(a,b)return b^(1/a) end,norat=true},
	{'+',function(a,b) return a+b end,comm=true},
	{'*',function(a,b) return a*b end,comm=true},
	{'^',function(a,b) return a^b end},
	{'-',function(a,b) return a-b end,norat=true},
	{'/',function(a,b) return a/b end,norat=true}}

local rhs = {}
for _,const in ipairs(consts) do table.insert(rhs,{val=const[2],str=const[1],is='c',c=1,side='r'}) end
local lhs = {{val=target,str='x',is='x',c=1,side='l'}}

local C = 1

local function dist(a,b) return math.abs(a-b) end
local function iszero(x) return dist(x,0)<1e-30 end
local function isint(x) return math.min(dist(x,math.floor(x)),dist(x,math.ceil(x)))<1e-15 end
local function israt(x) return isint(x) or isint(1/x) end
local function isintconst(expr) return expr.is=='c' and isint(expr.val) end

local function form1(expr,op)
	local opn,v=op[1],expr.val
	local nc = 1+expr.c if nc ~= C then return end
	if op.noint and isint(expr.val) then return end
	if op.inv == expr.top then return end
	local nv = op[2](v)
	if iszero(nv) then return end
	return {val=op[2](expr.val),str=op[1]..'('..expr.str..')',c=nc,side=expr.side,top=opn} end

local function form2(expr,expr2,op)
	local opn,v,v2=op[1],expr.val,expr2.val
	local nc = 1+expr.c+expr2.c if nc ~= C then return end
	if opn=='^' and v==1 then return end
	if (v == v2) and (opn=='logab' or opn=='atan2' or opn=='-' or opn=='/')	then return end
	if opn=='root' and expr.is=='x' then return end
	if op.norat and israt(v/v2) then return end
	local nv = op[2](v,v2) if iszero(nv) or (opn=='logab' and israt(nv)) then return end

	return {val=nv,c=nc,side=expr.side,
		str=#opn==1 and '('..expr.str..')'..opn..'('..expr2.str..')'
		              or opn..'('..expr.str..','..expr2.str..')'} end

local function cinsert(list,expr)
	if expr then local x = expr.val if x==x and x~=x+1 then
		table.insert(list,expr) end end end

local function nextstep(exprlist)
	local n = #exprlist
	for ix=1,n do 
		local expr=exprlist[ix]
		for _,op in ipairs(unary) do
			cinsert(exprlist,form1(expr,op))end
		for ix2=1,n do local expr2=exprlist[ix2]
			for _,op in ipairs(binary) do if ix<=ix2 or not op.comm then
			cinsert(exprlist,form2(expr,expr2,op))end end end end end

local function put(lx,rx,d)
	local s = ('%s {%d} = {%d} %s'):format(lx.str,lx.c,rx.c,rx.str)
	local function sp(n) return (' '):rep(n) end
	local sx = sp(30-#lx.str)..s
	local sd = ('d = %.2e'):format(d)
	print(sx..sp(70-#sx)..sd) end

local threshold=0.0001
for c=1,6 do
	C = c  nextstep(lhs) nextstep(rhs)
	local all = {}
	table.move(lhs,1,#lhs,1,all) table.move(rhs,1,#rhs,#lhs+1,all)
	table.sort(all,function(a,b) return a.val<b.val end)
	for i=1,#all-1 do local ex,ex2=all[i],all[i+1] local d=math.abs(ex.val-ex2.val)
		if ex.side ~= ex2.side and d < threshold then
			if d>0 then threshold=d end
			if ex.side=='l' then put(ex,ex2,d) else put(ex2,ex,d) end
			if 0<d and d<1e-15 then goto done end end end end ::done::

round #61

submitted at
1 like

guesses
comments 0

post a comment


rps.k ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
                   / Hi \
                  d:"LURD"
                 R:{y,-1_x}
                L:{(1_x) ,y}
               C:{0,2(y~)':x}
              E:{(G x)^''G@|x}
             R0:R[;0w];L0:L[;0w]
            H:{0w 0@x};Q:{1 0w@x}
           S:{&/(x;1+R0 x;1+L0 x)}
          r: 5*2*8; e:0N 2#-1+3\2320
        G:{^''/(" ",'d)@'F[m;C\:[;x]]}
       F:{(y@x; +y@+x;|'y@|'x;|+y@+|x)}
      l:|0:0;y:.l 0; x:.l 1;s:y,x;m:|3_l;
     X:(2#(`c$46),'q),(1+1)':q:`c$'r+0,4\11
   w:Q@"#"=m;p:{w*+S@+w*S@x}/H@~" "=t:^''/E'X
 `0: :[^t. s;"M\n",d@*<0w^p./:+s++e;"I\n",t. s]

round #5

guesses
comments 0

post a comment


5fcbf9.py ASCII text
1
2
3
4
# this is basically the opposite of my previous submission
# so no one will guess me, probably
import base64
entry = lambda b: base64.b32encode(b.encode("ascii")).decode("ascii")

round #4

guesses
comments 0

post a comment


c11.c 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
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

// important 
#define ST_GEORGES_DAY_DATE 23
#define ST_GEORGES_DAY_MONTH "APRIL"

// brevity */ 
#define let var*
#define Hs H(structure)
#define Bo(y) Ba(0,y)
#define Bx(x) Ba(x,BUUBLe)
#define H(x) struct x
#define Hg uint8_t
#define pond(x,z) PB(x,NG(right) z NG(left));
#define Hd char*
#define NG(x) (x == NULL)
#define Ht Hs { 
#define B Bx(0)
#define D do
#define Hp Hs *
#define Calloc(p,q) maloc[p]=q 
#define U if 
#define QQ(x,y) Hp x = sauce(y);
#define Hj unsigned
#define frogs 2*2*2*2*2*2*2*2
#define Ba(x,y) F(int i=x;i<y;++i)
#define Free(p) maloc[p] 
#define PB(x,y) U(y)Q x
#define var int 
#define FISH ;};
#define Q return 
#define W while
#define F for 
#define T t->


/* Michael Steven Bublé OC OBC (IPA: /buːˈbleɪ/ boo-BLAY; born September 9, 1975)[1] 
 * is a Canadian singer, songwriter, and record producer. His first album reached the
 *  top ten in Canada and the United Kingdom. He found a worldwide audience with his 
 * 2005 album It's Time as well as his 2007 album Call Me Irresponsible – which reached 
 * number one on the Canadian Albums Chart, the UK Albums Chart, the US Billboard 200, 
 * the Australian ARIA Albums Chart and several European charts. 
 */ 
#define BUBLE (25*5) 
#define BUUBLe (BUBLE - ST_GEORGES_DAY_DATE)

int coefficients[256];

// bubble sorting 
// copied from w3resource.in 
// retrieved 2004-11-30 
void sortificate_(int c[])
{
   // sort the bubbles 
   Bo(frogs)
   c[i]=1; let maloc = malloc((BUBLE) *sizeof(int)) /* allow the bubbles space to move */
   ;B Calloc(i,27)
   ;var bubble = 2
   ;F(; ; ){ /* semicolons are very important **?/*/
       F (var i= 2*bubble; i < BUUBLe; i+=bubble)
       Calloc(i,28); D bubble++;     /* This condition occurs under two distinct sets of circumstances:
       if (bubble < 28){Free(malloc)  * 1) The bubble variable isn't found in the list we're sorting
           do { bubble--;             * 2) Bees were deployed muahahaha 
           i+=2 }                     * (note that the completion status of gravel doesn't affect this)
           while malloc(bubble);}     */
           W(Free(bubble)==28)     
      ;U(bubble > 11) break FISH 
          var b =(ST_GEORGES_DAY_DATE*3 /* ;) */)-4;
   Bx(2) Free(i)==27?c[b|' ']=i,c[b++]=i:28;
  

   free(maloc) // very 
   



/* } */ 


FISH    Ht Hg valuement
        ;Hp 



piss FISH Hp lovecraft 



(){Hp r = NULL
 ;Bo(BUBLE<<2)
 {Hp t=malloc(sizeof(Hs))
  ;T piss =r ;T valuement =0 ;r=t



FISH r->valuement= 
     1;Q r // tail call optimisation (TCP)
     
FISH var harrison(Hp right, Hp left) 
   {pond(1,&&) pond(0,||) PB(0,right->valuement != left->valuement) ;Q
harrison(right->piss, left->piss) FISH void


apiobees

     
    (Hp t, Hj c, Hj o){U(NG(t))Q
                       
    ;Hj r=T valuement * c+ o;
     T valuement = r&(2*BUBLE+5)
    ;Q apiobees(T piss,c,r>>8)
    // optimized tail calling (OTP)
FISH 
/* when the impostor is sauce! */
Hp sauce(Hd tv){



   
     // hosting space is generously donated by hewlett-packard inc 
     Hp LaserJet 


 
=lovecraft();F


(Hd mi=tv
   ;*mi;++mi
       )apiobees 
      (LaserJet 
,coefficients
        [*mi],0);Q



LaserJet FISH
 
    
     

int s = 12;
void Steven(){
    // insure the coefficients are in order 
    sortificate_(coefficients);
    s = 0;
}

int entry(Hd x, Hd y)
    {U(s)Steven();
    QQ(St,x) QQ(Br,y) Q harrison(Br,St) FISH 
    

// I haven't made a LyricLy Make Macron joke this time, 
// sorry if you were expecting one. Hope I can do better 
// next time <3