previndexinfo

code guessing, round #64, stage 2 (guessing)

started at ; stage 2 since . guess by

specification

peekaboo, I see you! let's list the look-and-say sequence. submissions can be written in any language.

the look-and-say sequence (OEIS A005150) is a sequence of integers (or of digit-strings, if you prefer) in which each number is the result of "describing" the groups of digits in the previous number, in a manner similar to run-length encoding.

here's how it starts:

note that the only digits that appear in this sequence are 1, 2, and 3.

your challenge is to compute this sequence, yielding arbitrarily many values as required by the user (within reason). as any language is allowed, there is no fixed API.

players

  1. Dolphy
  2. essaie
  3. japi
  4. kimapr
  5. LyricLy
  6. olive
  7. olus2000
  8. ponydork
  9. Proloy
  10. seshoumara

entries

you can download all the entries

entry #1

comments 0

post a comment


cg64_look-and-say.sed 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
#!/usr/bin/sed -nrf

:_Problem
    # look-and-say sequence
    # https://cg.esolangs.gay/64/
:_Restrictions
    # input N in unary, e.g. 000 instead of 3 (print all terms up to and including Nth)
    # very slow after the 54th term (regex slowed by increasing number of digits)

:main
	# error handling
	v
	/^0+$/! {
		s/.*/Error: please input N in unary! Use 000 instead of 3./p
		Q 1
	}
	# init
	s:^0::
	h
	s:.*:1:
b seq_loop

:seq_loop
	# print
	s:.*:> &:p
	s:^> ::
	# stop condition
	x
	/^$/Q 0
	s:^0::
	x
	# generate next term
	s:([123])\1*: &@\1:g
	s: [123]:a:g
	s:a[123]:b:g
	s:b[123]:c:g
	y:abc:123:
	s:@::g
b seq_loop

entry #2

comments 0

post a comment


the humble meee ASCII text, with no line terminators
1
1[&sJu52*ol[s>l<0s`[pl`sp=]p>l<]>r

entry #3

comments 0

post a comment


dir las
description.txt ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
syntactically minimal lambda calculus

` = application
\ = abstraction
a-z = variables

variables are single character, and do not appear near their lambdas. 
Instead, a variable's position in the alphabet determines which lambda it refers to, 
starting from the topmost lambda with a, the second topmost being b, and so on.
(basically a reverse De Bruijn indexing. or De Bruijn levels 
(according to https://en.wikipedia.org/wiki/De_Bruijn_index#Alternatives_to_de_Bruijn_indices))

That's enough info, good luck trying to implement it!
las.lc ASCII text
1
2
3
4
`\```````\\\\\\\``a`\`\`jj\`i\``jjk\\``j\\``l\\`````hkm\``n\\`````hmp\```gdk`iq\
```gck`ine```gcke\```gbk`ile```gbkee``fbe\\`bc\\`b`bc\\`b`b`bc\\c\\\\``dbc\\\\\`
`eb\\``gcd``\\\\``c``bde``bed``\\\\`c``bde`\\\``cbd\\\```b\\`f`ec\d\e\``b\\\e\\c
\\``bcb\\`a`a`a`a`a`ab

entry #4

comments 3
olus2000

Can we get an embed of this?


cdr sa

can we get an Imbed of thIs?


ponydork

Can we get an iFrame of this?


post a comment


index.html ASCII text, with very long lines (30323)

entry #5

comments 0

post a comment


looksi.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
-- local debug = function(msg, ...) print(msg, ...) return ... end
local debug = function(msg, ...) return ... end
-- local flip = function() io.write("...") io.read("*l") end
local flip = function() end

local function isnat(n) return ((n >= 0) and (n%1 == 0)) end

local function _reverse(xi, xo)
	debug("reverse", xi, xo)
	if xi == 0 then return xo end
	xo = xo * 10 + xi % 10
	xi = (xi - xi % 10) / 10
	return _reverse(xi, xo)
end

-- input must be reversed
local function _countup(xi, xo)
	debug("countup", xi, xo)
	if xi == 0 then return xo end
	if xi % 10 ~= xo % 10 then xo = xo * 100 + xi % 10 end
	xo = xo + 10 -- safe as seq only contains digits 1,2,3
	xi = (xi - xi % 10) / 10
	return _countup(xi, xo)
end

local function _looksi_iter(n, x)
	debug("iter", n, x)
	if n == 0 then return x end
	local nx = _countup(_reverse(x, 0), 0)
	return _looksi_iter(n-1, nx)
end

--- dom: nat >0
local function looksi(n)
	debug("looksi", n)
	assert(isnat(n))
	return _looksi_iter(n-1, 1)
end

local i = 0
while true do i=i+1 print(i,looksi(i)) flip() end

return looksi

entry #6

comments 0

post a comment


dir look-and-say
authors.txt ASCII text
1
Aleksander "olus2000" Sabak
look-and-say-docs.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
57
58
59
! Copyright (C) 2024 Aleksander Sabak.
! See https://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel lists sequences strings ;
IN: look-and-say

HELP: <look-and-say>
{ $values
    { "seed" string }
    { "list" list }
}
{ $description "Creates a lazy linked list representing a " { $link look-and-say } " sequence starting from a given seed to be used with the " { $vocab-link "lists" } " vocabulary." }
;

HELP: look-and-say
{ $class-description "An infinite linked list starting from " { $slot "car" } " an continuing in " { $slot "cdr" } " which is constructed lazily if not present." $nl
"Implements " { $link "lists-protocol" } "." }
;

HELP: next-look-and-say
{ $values
    { "string" string }
    { "string'" string }
}
{ $description "Calculates the next value in a look-and-say sequence: for each run of identical elements in " { $snippet "string" } " the resulting " { $snippet "string'" } " will contain the length of that run and that element." }
{ $examples
    { $example "USING: look-and-say prettyprint ;"
        "\"1\" next-look-and-say ."
        "11"
    }
    { $example "USING: look-and-say prettyprint ;"
        "\"11\" next-look-and-say ."
        "21"
    }
    { $example "USING: look-and-say prettyprint ;"
        "\"111221\" next-look-and-say ."
        "312211"
    }
    { $example "USING: look-and-say prettyprint ;"
        "\"AAAAAABBBCCCCCD\" next-look-and-say ."
        "6A3B5C1D"
    }
}
;

ARTICLE: "look-and-say" "The look-and-say sequence"
"The " { $vocab-link "look-and-say" } " vocabulary implements the " { $url "https://oeis.org/A005150" "look-and-say" } " sequence. Its first element is 1 (thought the vocabulary allows arbitrary strings as seeds) and generates following elements by \"describing\" previous elements:"
{ $list
  "1 is one 1, so the second element is 11"
  "11 is two 1s, so the third element is 21"
  "21 is one 2 and one 1, so the fourth element is 1211"
  "1211 is one 1, one 2, and two 1s, so the fifth element is 111221"
  "111221 is three 1s, two 2s and one 1, so the sixth element is 312211"
  "and so on..."
}
"The only digits that appear in the sequence seeded with 1 are 1, 2, and 3." $nl
"This vocabulary represents elements of the sequence as strings, since their string representations are what matters to the definition of the sequence."
;

ABOUT: "look-and-say"
look-and-say.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
! Copyright (C) 2024 Aleksander Sabak.
! See https://factorcode.org/license.txt for BSD license.
USING: accessors kernel lists make math math.parser sequences ;
IN: look-and-say


: next-look-and-say ( string -- string' )
  dup empty? [ [ unclip-slice 1 spin [
    2dup = [ drop [ 1 + ] dip ]
    [ spin number>string % , 1 swap ] if
  ] each swap number>string % , ] "" make ] unless ;


TUPLE: look-and-say car cdr ;

: <look-and-say> ( seed -- list ) f look-and-say boa ;


INSTANCE: look-and-say list

M: look-and-say nil? drop f ;

M: look-and-say car car>> ;

M: look-and-say cdr [ cdr>> ]
  [ dup car>> next-look-and-say
    <look-and-say> [ swap cdr<< ] keep ] ?unless ;

entry #7

comments 0

post a comment


hey.txt ASCII text
1
https://esolangs.org/wiki/Olus2000
olus2000.olus2000 ASCII text, with very long lines (490)
 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
                      "" olus2oOo OLUS2OOO "" ""                            olus2o0O olus2OoO                                     "ERROR" olus2o0o                  olus2OoO "3" olus2oO0          olus2oo0 olus2oOo OLUS2ooo olus2o0O 0lus2000!                    olus200O olus2000! olus20O0 OLUS2OOO olus2o0o olus2OoO "2"          olus2oO0 olus2oo0 olus2oOo OLUS2000 olus2o0O ""          0lus2000! olus200O olus2000! olus20O0 OLUS2ooo           olus2o0o olus2OoO "1" olus2oO0 olus2oo0 olus2oOo
                 OLUS200O 0lus2000! olus200O olus2000!                      olus20O0 OLUS2000                                     olus2oo0 olus2oOo                 OLUS20O0  "" olus2OOo          olus2Ooo olus2Oo0 olus2OOo olus2Ooo olus2O00                     olus2o0O olus2OoO 0lus2000! olus2000 olus2000! "" olus2ooO          0lus2000! olus200O olus2000! olus200o 0lus2000!          olus2000 olus2000! olus2Oo0  olus2ooo olus2OoO           "" olus2o0o olus2OoO olus2OOo 0lus2000! olus2000
            olus2000! olus2Oo0 olus2ooo 0lus2000! olus2000                  olus2000! 0lus2000!                                   olus200O olus2000!                olus2ooo olus2Oo0  ""          olus2OoO olus2oO0 olus2oo0 olus2oOo OLUS20OO                     olus2Oo0 olus2OOo 0lus2ooo! olus200O olus2000! olus2O0O ""          olus2oOO olus2OoO olus2Oo0 OLUS20O0 olus2Oo0 ""          olus2OOo 0lus2ooo! olus200O  olus2000! olus2O0O          olus2oO0 olus2OoO olus2Oo0 olus2OoO olus2OoO  ""
         olus2oo0 olus2oOo OLUS20Oo OLUS20OO olus2OOO olus2o00              olus2oOO olus2Oo0                                     olus2OOo OLUS200O                 "" 0lus2000! olus2000          olus2000! olus2Oo0 olus2ooo 0lus2000! olus200O                   olus2000! olus20O0 olus2oO0 "\n" olus2OoO "" "" 0lus2ooo!           olus200O olus2000! olus2OOO 0lus2000! olus2000           olus2000! olus2oo0 0lus2ooo! olus200O olus2000!          0lus2000! olus200O olus2000! 0lus2000! olus2000
       olus2000! "" 0lus2000!             olus200O olus2000! ""             OLUS200O " \n" ""                                     0lus2000! olus200O                olus2000! olus2oOO ""          olus2OoO OLUS20Oo                                                                                        0lus2000! olus200O          olus2000! olus2oO0          olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 " " olus2000                  olus2000 "" olus2000            olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000                                                                                        olus2000 olus2000           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "                                     olus2000 olus2000                     olus2000 olus2000                                                   olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "                                     olus2000 olus2000                     olus2000 olus2000                                                   olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "                                     olus2000 olus2000                     olus2000 olus2000                                                   olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "                                     olus2000 olus2000                     olus2000 olus2000                                                   olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 olus2000 ""                    olus2000 olus2000 ""           olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "                                     olus2000 olus2000                     olus2000 olus2000                                                   olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
     olus2000 " " olus2000                  olus2000 "" olus2000            olus2000 olus2000                                     olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
       Olus2000! "" 0lus2000!             olus200O Olus2000! ""             olus2000 olus2000 olus2000 olus2000 olus2000          olus2000 olus2000                 olus2000 olus2000 " "          olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000           olus2000 Olus2000!           olus2000 olus2000            olus2000 olus2000           olus2000 olus2000            olus2000 Olus2000!!
         olus2oo0 olus2oOo OLUS20Oo OLUS20OO olus2OOO olus2o00              olus2000 olus2000 olus2000 olus2000 olus2000           olus2000 olus2000               olus2000 olus2000 " "           olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000 Olus2000! olus2000 Olus2000!           olus2000 Olus2000! Olus2000! olus2000 olus2000           olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
            Olus2000! olus2Oo0 olus2ooo 0lus2000  olus2000                  olus2000 olus2000 olus2000 olus2000 olus2000             olus2000 olus2000 "" "" ""  olus2000 olus2000 " "             olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000 Olus2000! olus2000 Olus2000!           olus2000 Olus2000! Olus2000! olus2000 olus2000           olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
                 OLUS200O 0lus2000! olus200O Olus2000!                      olus2000 olus2000 olus2000 olus2000 olus2000                 olus2000 olus2000 "" olus2000 olus2000 " "                olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000 Olus2000! olus2000 Olus2000!           olus2000 Olus2000! Olus2000! olus2000 olus2000           olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
                      "" olus2oOo OLUS2OOO "" ""                            olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000                            olus2000 olus2000 olus2000 olus2000 olus2000                     olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " "           olus2000 olus2000 Olus2000! olus2000 Olus2000!           olus2000 Olus2000! Olus2000! olus2000 olus2000           olus2000 Olus2000! Olus2000! olus2000  olus2000!

entry #8

comments 0

post a comment


lookandsay.js ASCII text, with CRLF line terminators
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
let z = String.fromCharCode(49).split(''), f = +prompt(":3c nums of its: ")
while(f--){
    Array.isArray(z) ? alert(z.join('')) : alert(z)
    let f = z[0], k= 0, p = "", i=0
    while (i<z.length) {
        f != z[i] ? p += k+f : k
        f == z[i] ? k+= 1 : k= 1;
        f = z[i], i+=+1
    }
    z = p += k+ f
}

entry #9

comments 0

post a comment


lass.ysl ASCII text
1
2
3
4
(o&&,&)(p&&aah&)(suc&((n&&1&)ollyoop&)&)123&-/(&*)(s&&*)(c&
&&)|(*&pp&p)(&&&n)(&*&o)(*&o&cus)*((((&,&n&t))))(*&)/(((&,((&p&p))&tid)&.&mod))&
|((((dom&)1&(p&&(ame&p&1&)))(*1&p&)))((dit&(*)s&))/(**)(c&&(ame&c&1&))(yeetyi&)+
/(**)(n&n&(t&(c&c&)s&))(.&)+,|_
ysl.py 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
# two array, five and a half function defintions,
# a class definition, and a dream

primes = [2, 3, 5, 7, 11 ,13 ,17, 19]
pounce = ".,;:'" # supports up to 2^65536-1

def barker(numb):
  def r(n):
    if n < 2: return "0"[:n]
    return "0" + "0".join("".join(str(int(d) + 1)
                                  for d in r(e))
                          for e in bagties(n))
  return "".join(pounce[int(c)] for c in r(numb))

def parser(worb):
  if len(worb) < 2: return len(worb)
  p = 1
  worb = worb.split(worb[0])[1:]
  for i in range(len(worb)):
    try: # lazy
      p *= primes[i] ** parser(worb[i])
    except IndexError:
      p *= eratuto(primes[-1] * 2)[i] ** parser(worb[i])
  return p

read_value = lambda x: x if type(x) == int else parser(x)

def eratuto(n):
  global primes
  primes += [o + 1 for o in range(primes[-1], n)]
  i = 0
  while i < len(primes) and primes[i] < n ** .5:
    for n in primes[i + 1:]:
      if n % primes[i] == 0: primes.remove(n)
    i += 1
  return primes

def bagties(n):
  if n > primes[-1]: eratuto(n) # boooo
  out = []
  for p in primes:
    if p > n: return out
    c = 0
    while n % p == 0:
      n /= p
      c += 1
    out += [c]
  return out # booooooo

class YSL:
  def __init__(self, bod, gen=0, way=1, stk=[], dic={}, fed=""):
    self.bod = bod
    self.gen = gen
    self.way = way
    self.stk = stk.copy()
    self.dic = dic.copy()
    self.fed = fed

  def interpret(self):
    pon = -1 if self.way < 0 else 0
    going = True
    scream = ""
    while going:
      pon %= len(self.bod)
      match self.bod[pon]:
        case "+":
          if not self.stk: self.stk += [""]
          pon = (read_value(self.stk.pop()) - 1) % len(self.bod)
          if self.way < 0: pon = len(self.bod) - pon - 1
        case "-":
          self.way *= -1
          pon += self.way
        case "*":
          if not self.stk: self.stk += [""]
          b = self.stk.pop()
          if type(b) == int:
            raise TypeError(f"Cannot comprehend integer at {barker(
                              pon)}, level {self.gen}.")
          if self.gen:
            scream += b
          else:
            print(b, end="")
          pon += self.way
        case "/":
          b = 0
          if self.stk: b = read_value(self.stk[-1])
          pon += self.way
          if (self.way < 0 and b > 0) or (self.way > 0 and b < 1):
            while self.bod[pon % len(self.bod)] != "/":
              pon += self.way
            pon += self.way
        case "&":
          pon += self.way
        case "|":
          pon += self.way
          while self.bod[pon % len(self.bod)] != "|":
            pon += self.way
          pon += self.way
        case "=":
          going = False
        case "(":
          if self.way < 0:
            raise SyntaxError(f"Mismatched parenthesis at {barker(
                                pon)}, level {self.gen}.")
          pon = (pon + self.way) % len(self.bod)
          b, pon = self.find_paren(pon) # has side effects
          if b is None: going = False
        case ")":
          if self.way > 0:
            raise SyntaxError(f"Mismatched parenthesis at {barker(
                                pon)}, level {self.gen}.")
          pon = (pon + self.way) % len(self.bod)
          b, pon = self.find_paren(pon)
          if b is None: going = False
        case _:
          while self.bod[pon % len(self.bod)] != "&":
            pon += self.way
          pon += self.way

    if self.gen: return scream, self.stk
    else: return 0

  def find_paren(self, pon):
    pon = pon
    going = True
    inside = False
    params = []
    present = ""
    while going:
      pon %= len(self.bod)
      if inside:
        if self.bod[pon] == "&":
          inside = False
          params += [present]
          present = ""
        else:
          present += self.bod[pon]
        pon += self.way
      else:
        match self.bod[pon]:
          case "+":
            if not self.stk: self.stk += [""]
            b = self.stk.pop()
            params += [b]
            pon = (read_value(b) - 1) % len(self.bod)
            if self.way < 0: pon = len(self.bod) - pon - 1
          case "-":
            params += [""]
            self.way *= -1
            pon += self.way
          case "*":
            if not self.stk: self.stk += [""]
            params += [self.stk.pop()]
            pon += self.way
          case "/":
            b = ""
            if self.stk: b = self.stk[-1]
            params += [b]
            pon += self.way
            if ((self.way < 0 and read_value(b) > 0)
             or (self.way > 0 and read_value(b) < 1)):
              while self.bod[pon % len(self.bod)] != "/":
                pon += self.way
              pon += self.way
          case "&":
            params += [""]
            pon += self.way
          case "|":
            if self.way < 0:
              params += [len(self.bod) - pon]
            else:
              params += [pon + 1]
            pon += self.way
            while self.bod[pon % len(self.bod)] != "|":
              pon += self.way
            pon += self.way
          case "=":
            return None, 0
          case "(":
            pon += self.way
            if self.way > 0:
              b, pon = self.find_paren(pon)
              params += [b]
            else:
              going = False
          case ")":
            pon += self.way
            if self.way < 0:
              b, pon = self.find_paren(pon)
              params += [b]
            else:
              going = False
          case _:
            inside = True
    
    match params:
      case []:
        if self.gen:
          return self.fed, pon
        else:
          b = input() # unfortunate limitation of my means
          b = "\t".join(b.split("\\t"))
          b = "\n".join(b.split("\\n"))
          return b, pon
      case [one]:
        while one in self.dic:
          one = self.dic[one]
        self.stk += [one]
        return one, pon
      case [one, two]:
        while one in self.dic:
          one = self.dic[one]
        while two in self.dic:
          two = self.dic[two]
        s = read_value(one) - 1
        if s < 0: s += len(self.bod)
        e = read_value(two) - 1
        if e < 0: e += len(self.bod)
        suede = self.bod[::self.way]
        sxtra = 0
        extra = 0
        if s < e:
          while s < 0:
            sxtra += 1
            s += len(self.bod)
          while e > len(self.bod) - 1:
            extra += 1
            e -= len(self.bod)
          if sxtra or extra:
            b = suede[s:] + suede * (sxtra + extra - 1) + suede[:e + 1]
          else:
            b = suede[s:e + 1]
        if s > e:
          while s > len(self.bod) - 1:
            sxtra += 1
            s -= len(self.bod)
          while e < 0:
            extra += 1
            e += len(self.bod)
          if sxtra or extra:
            b = suede[e:] + suede * (sxtra + extra - 1) + suede[:s + 1]
          else:
            b = suede[e:s + 1]
          b = b[::-1]
        if s == e:
          b = suede[min(s, e)]
        return b, pon
      case [head, one, two]:
        while one in self.dic:
          one = self.dic[one]
        while two in self.dic:
          two = self.dic[two]
        match head:
          case "ame":
            return read_value(one) + read_value(two), pon
          case "dom":
            return read_value(one) - read_value(two), pon
          case "tim":
            return read_value(one) * read_value(two), pon
          case "spa":
            if read_value(two):
              return read_value(one) // read_value(two), pon
            else:
              return "", pon
          case "wal":
            if type(one) == int:
              raise TypeError(f"Cannot comprehend integer at {barker(
                                pon)}, level {self.gen}.")
            baby = YSL(one, self.gen + 1, self.way, self.stk, self.dic, two)
            b, t = baby.interpret()
            del baby
            self.stk = t
            return b, pon
          case "suc":
            # still a mess
            # does not cross program edge, so I.P. can be decided
            if type(one) == int or type(two) == int:
              raise TypeError(f"Cannot comprehend integer at {barker(
                                pon)}, level {self.gen}.")
            if one == two:
              return "", pon
            first = (self.bod[:pon + 1] if self.way < 0 
                     else self.bod[pon:])[::self.way]
            lirst = (self.bod[pon + 1:] if self.way < 0
                     else self.bod[:pon])[::self.way]
            suede = lirst + first
            if not one:
              self.bod = (lirst + two + first)[::self.way]
              if self.way < 0: pon += len(two)
              return "", pon
            if one in first:
              b = first.index(one)
              first = first[:b] + two + first[b + len(one):]
              self.bod = (lirst + first)[::self.way]
              if self.way < 0: pon += len(two) - len(one)
              return one, pon
            if one in suede:
              b = suede.index(one)
              suede = suede[:b] + two + suede[b + len(one):]
              self.bod = suede[::self.way]
              if self.way > 0: pon += len(two) - len(one)
              return one, pon
            return "", pon
          case "dit":
            return (two if one == two else ""), pon
          case _:
            if one == "":
              self.dic[head] = two
              return two, pon
            if two == "":
              self.dic[head] = one
              return one, pon
            if type(one) == int or type(two) == int:
              raise TypeError(f"Cannot comprehend integer at {barker(
                                pon)}, level {self.gen}.")
            self.dic[head] = one + two
            return one + two, pon
      case _:
        raise SyntaxError(f"Too many parameters at {barker(
                            pon)}, level {self.gen}.")

if __name__ == "__main__":
  with open("lass.ysl") as prog:
    lass = YSL(prog.read())
    lass.interpret()

entry #10

comments 0

post a comment


lookandsay.match ASCII text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
fst: a, b -> a;;
snd: a, b -> b;;

next:
	nil -> nil;
	ch, nil -> 1, ch, nil;
	ch, (sch, rest): ch = sch -> 2 + fst(count(ch, rest)), ch, next(snd(count(ch, rest)));
	ch, rest -> 1, ch, next(rest);;

count:
	ch, nil -> 0, nil;
	ch, (sch, rest): ch = sch -> 1 + fst(count(ch, rest)), snd(count(ch, rest));
	ch, (sch, rest) -> 0, sch, rest;;

iterate:
	0, _ -> nil;
	n, str -> println(str) then iterate(n - 1, next(str));;

main:
	_ -> print("How many iterations? > ") then iterate(parse(readln(nil)), 1, nil);;

# [https://github.com/japi012/match/]