we made it! let's celebrate: give me 100 terms of the kolakoski sequence. submissions may be written in any language.
ever dipped your toes in the field of compression? there's a basic concept there known as run-length encoding. you've probably heard of it. it makes it more efficient to store repeated symbols: to store "aaaaa", instead of keeping 5 copies of the character 'a', you can just remember "there are 5 'a's here", right? so instead of just storing each character, you store them along with a "run length" that tells you how many times it's repeated. "apple" becomes "1a2p1l1e". simple, right?
let's forget about strings for a second. in fact, let's forget about what the runs consist of at all. let's remember "apple" as "1211", just the length of the runs. we'll define a function f that turns a string into a series of run lengths, so that f("apple") = "1211". I could repeat the operation to get f("1211") = "112"... this iteration reminds me of the look-and-say sequence, but it's a little different. because we don't keep the content of the runs, only their lengths, the string doesn't grow infinitely. if I keep going, I get "21", then "11", then "2". unlike look and say, it isn't growing to infinity. it in fact turns out that this operation has fixed points: infinite sequences x such that f(x) = x. the sequence is equal to its own sequence of run lengths!
the Kolakoski sequence is the unique such sequence that consists of only 1 and 2 and starts with 1. let's look at it:
above are the terms of the sequence and below the runs and their lengths are shown. for the infinite Kolakoski sequence, these two sequences are one and the same.
ordinarily, I'd let you generate as many terms of this sequence as you liked in any way that you liked. but this is round 100, so your challenge is to give me exactly 100 terms of the kolakoski sequence. as any language is allowed, there is no fixed API.
hello my name is essaie and this is my submission to code guessing (gay)
you can tell i am essaie as my spelling is purrfect (i discovered grammar checkers)
Kind Regards,
lychee
-- 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 thoughlocalfunctionclass()localT={}T.__index=Tsetmetatable(T,{__call=function(cls,...)returncls.make(cls,...)end})returnTendlocalfunctionextend(Base)localT=class()fork,vinpairs(Base)doifk:sub(1,2)=="__"andk~="__index"thenT[k]=vendendgetmetatable(T).__index=BasereturnTendreturnsetmetatable({class=class,extend=extend},{__call=class})
localclass=require'r.class'localrmath=require'r.math'localPos=class()functionPos.new(cls)returnsetmetatable({},cls)endfunctionPos.init(self,x,y)self.x=xself.y=yreturnselfendfunctionPos.make(cls,...)returncls:new():init(...)endfunctionPos.__add(self,other)returnPos:make(self.x+other.x,self.y+other.y)endfunctionPos.__sub(self,other)returnPos:make(self.x-other.x,self.y-other.y)endfunctionPos.__unm(self)returnPos(-self.x,-self.y)endfunctionPos.__mul(a,b)iftype(a)=="number"thenreturnPos:make(a*b.x,a*b.y)elseiftype(b)=="number"thenreturnPos:make(a.x*b,a.y*b)elseerror("can only multiply Pos by scalar")endendfunctionPos.__div(a,b)assert(type(b)=="number","can only divide Pos by scalar")returna*(1/b)endfunctionPos.__eq(a,b)returna.x==b.xanda.y==b.yendfunctionPos.lensq(self)returnself.x^2+self.y^2endfunctionPos.len(self)returnmath.sqrt(self:lensq())endfunctionPos.norm(self)locall=self:len()ifl<0.00001thenreturnPos(0,0)elsereturnself/lendendfunctionPos.l1(self)returnmath.abs(self.x)+math.abs(self.y)endfunctionPos.linf(self)returnmath.max(math.abs(self.x),math.abs(self.y))endfunctionPos.dot(self,other)returnself.x*other.x+self.y*other.yendfunctionPos.vals(self)returnself.x,self.yendfunctionPos.floor(self)returnPos:make(math.floor(self.x),math.floor(self.y))endfunctionPos.ceil(self)returnPos:make(math.ceil(self.x),math.ceil(self.y))endfunctionPos.round(self)returnPos:make(rmath.round(self.x),rmath.round(self.y))endfunctionPos.divmod(self,size)localdiv=(self/size):floor()returndiv,self-div*sizeendfunctionPos.__tostring(self)returnstring.format("(%.2f,%.2f)",self.x,self.y)endfunctionPos.key(self)returnself.x..':'..self.yendfunctionPos.unkey(cls,k)locala,b=k:match"(%-?%d+):(%-?%d+)"returnPos(tonumber(a),tonumber(b))endfunctionPos.rot(self,a)localc,s=math.cos(a),math.sin(a)-- [ C, -S ]-- [ S, C ] returnPos(self.x*c-self.y*s,self.x*s+self.y*c)endfunctionPos.sproj(self,b)returnself:dot(b:norm())endfunctionPos.proj(self,b)returnself:sproj(b)*b:norm()endfunctionPos.angle(self)return(math.atan2ormath.atan)(self.y,self.x)end-- inplace arithmeticfunctionPos.addby(self,by)self.x=self.x+by.xself.y=self.y+by.yendfunctionPos.addbyv(self,x,y)self.x=self.x+xself.y=self.y+yendfunctionPos.subby(self,by)self.x=self.x-by.xself.y=self.y-by.yendfunctionPos.subbyv(self,x,y)self.x=self.x-xself.y=self.y-yendfunctionPos.mulby(self,by)self.x=self.x*byself.y=self.y*byendfunctionPos.divby(self,by)self.x=self.x/byself.y=self.y/byendreturnPos
qw.lua ASCII text
1 2 3 4 5 6 7 8 91011121314151617181920
-- qw"aaa bbb ccc" --> { "aaa", "bbb", "ccc" }localfunctionqw(str)localout={}forxinstr:gmatch"%S+"dotable.insert(out,x)endreturnoutend-- qw.s"aaa bbb ccc" --> { aaa=true, bbb=true, ccc=true }localfunctionqws(str)localout={}forxinstr:gmatch"%S+"doout[x]=trueendreturnoutend-- for k in qw.i"aaa bbb ccc" do ... endlocalfunctionqwi(str)returnpairs(qws(str))endreturnsetmetatable({qw=qw,s=qws,i=qwi},{__call=function(_,...)returnqw(...)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
-- Module options:localalways_use_lpeg=falselocalregister_global_module_table=falselocalglobal_module_name='json'--[==[David Kolf's JSON module for Lua 5.1 - 5.4Version 2.8For 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 thedomain 'dkolf.de'.Copyright (C) 2010-2024 David Heiko KolfPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall beincluded 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 OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE ANDNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERSBE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN ANACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.--]==]-- global dependencies:localpairs,type,tostring,tonumber,getmetatable,setmetatable=pairs,type,tostring,tonumber,getmetatable,setmetatablelocalerror,require,pcall,select=error,require,pcall,selectlocalfloor,huge=math.floor,math.hugelocalstrrep,gsub,strsub,strbyte,strchar,strfind,strlen,strformat=string.rep,string.gsub,string.sub,string.byte,string.char,string.find,string.len,string.formatlocalstrmatch=string.matchlocalconcat=table.concatlocaljson={version="dkjson 2.8"}localjsonlpeg={}ifregister_global_module_tablethenifalways_use_lpegthen_G[global_module_name]=jsonlpegelse_G[global_module_name]=jsonendendlocal_ENV=nil-- blocking globals in Lua 5.2 and laterpcall(function()-- Enable access to blocked metatables.-- Don't worry, this module doesn't change anything in them.localdebmeta=require"debug".getmetatableifdebmetathengetmetatable=debmetaendend)json.null=setmetatable({},{__tojson=function()return"null"end})localfunctionisarray(tbl)localmax,n,arraylen=0,0,0fork,vinpairs(tbl)doifk=='n'andtype(v)=='number'thenarraylen=vifv>maxthenmax=vendelseiftype(k)~='number'ork<1orfloor(k)~=kthenreturnfalseendifk>maxthenmax=kendn=n+1endendifmax>10andmax>arraylenandmax>n*2thenreturnfalse-- don't create an array with too many holesendreturntrue,maxendlocalescapecodes={["\""]="\\\"",["\\"]="\\\\",["\b"]="\\b",["\f"]="\\f",["\n"]="\\n",["\r"]="\\r",["\t"]="\\t"}localfunctionescapeutf8(uchar)localvalue=escapecodes[uchar]ifvaluethenreturnvalueendlocala,b,c,d=strbyte(uchar,1,4)a,b,c,d=aor0,bor0,cor0,dor0ifa<=0x7fthenvalue=aelseif0xc0<=aanda<=0xdfandb>=0x80thenvalue=(a-0xc0)*0x40+b-0x80elseif0xe0<=aanda<=0xefandb>=0x80andc>=0x80thenvalue=((a-0xe0)*0x40+b-0x80)*0x40+c-0x80elseif0xf0<=aanda<=0xf7andb>=0x80andc>=0x80andd>=0x80thenvalue=(((a-0xf0)*0x40+b-0x80)*0x40+c-0x80)*0x40+d-0x80elsereturn""endifvalue<=0xffffthenreturnstrformat("\\u%.4x",value)elseifvalue<=0x10ffffthen-- encode as UTF-16 surrogate pairvalue=value-0x10000localhighsur,lowsur=0xD800+floor(value/0x400),0xDC00+(value%0x400)returnstrformat("\\u%.4x\\u%.4x",highsur,lowsur)elsereturn""endendlocalfunctionfsub(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.ifstrfind(str,pattern)thenreturngsub(str,pattern,repl)elsereturnstrendendlocalfunctionquotestring(value)-- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-jsvalue=fsub(value,"[%z\1-\31\"\\\127]",escapeutf8)ifstrfind(value,"[\194\216\220\225\226\239]")thenvalue=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)endreturn"\""..value.."\""endjson.quotestring=quotestringlocalfunctionreplace(str,o,n)locali,j=strfind(str,o,1,true)ifithenreturnstrsub(str,1,i-1)..n..strsub(str,j+1,-1)elsereturnstrendend-- locale independent num2str and str2num functionslocaldecpoint,numfilterlocalfunctionupdatedecpoint()decpoint=strmatch(tostring(0.5),"([^05+])")-- build a filter that can be used to remove group separatorsnumfilter="[^0-9%-%+eE"..gsub(decpoint,"[%^%$%(%)%%%.%[%]%*%+%-%?]","%%%0").."]+"endupdatedecpoint()localfunctionnum2str(num)returnreplace(fsub(tostring(num),numfilter,""),decpoint,".")endlocalfunctionstr2num(str)localnum=tonumber(replace(str,".",decpoint))ifnotnumthenupdatedecpoint()num=tonumber(replace(str,".",decpoint))endreturnnumendlocalfunctionaddnewline2(level,buffer,buflen)buffer[buflen+1]="\n"buffer[buflen+2]=strrep(" ",level)buflen=buflen+2returnbuflenendfunctionjson.addnewline(state)ifstate.indentthenstate.bufferlen=addnewline2(state.levelor0,state.buffer,state.bufferlenor#(state.buffer))endendlocalencode2-- forward declarationlocalfunctionaddpair(key,value,prev,indent,level,buffer,buflen,tables,globalorder,state)localkt=type(key)ifkt~='string'andkt~='number'thenreturnnil,"type '"..kt.."' is not supported as a key by JSON."endifprevthenbuflen=buflen+1buffer[buflen]=","endifindentthenbuflen=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]=":"returnencode2(value,indent,level,buffer,buflen+2,tables,globalorder,state)endlocalfunctionappendcustom(res,buffer,state)localbuflen=state.bufferleniftype(res)=='string'thenbuflen=buflen+1buffer[buflen]=resendreturnbuflenendlocalfunctionexception(reason,value,state,buffer,buflen,defaultmessage)defaultmessage=defaultmessageorreasonlocalhandler=state.exceptionifnothandlerthenreturnnil,defaultmessageelsestate.bufferlen=buflenlocalret,msg=handler(reason,value,state,defaultmessage)ifnotretthenreturnnil,msgordefaultmessageendreturnappendcustom(ret,buffer,state)endendfunctionjson.encodeexception(reason,value,state,defaultmessage)returnquotestring("<"..defaultmessage..">")endencode2=function(value,indent,level,buffer,buflen,tables,globalorder,state)localvaltype=type(value)localvalmeta=getmetatable(value)valmeta=type(valmeta)=='table'andvalmeta-- only tableslocalvaltojson=valmetaandvalmeta.__tojsonifvaltojsontheniftables[value]thenreturnexception('reference cycle',value,state,buffer,buflen)endtables[value]=truestate.bufferlen=buflenlocalret,msg=valtojson(value,state)ifnotretthenreturnexception('custom encoder failed',value,state,buffer,buflen,msg)endtables[value]=nilbuflen=appendcustom(ret,buffer,state)elseifvalue==nilthenbuflen=buflen+1buffer[buflen]="null"elseifvaltype=='number'thenlocalsifvalue~=valueorvalue>=hugeor-value>=hugethen-- This is the behaviour of the original JSON implementation.s="null"elses=num2str(value)endbuflen=buflen+1buffer[buflen]=selseifvaltype=='boolean'thenbuflen=buflen+1buffer[buflen]=valueand"true"or"false"elseifvaltype=='string'thenbuflen=buflen+1buffer[buflen]=quotestring(value)elseifvaltype=='table'theniftables[value]thenreturnexception('reference cycle',value,state,buffer,buflen)endtables[value]=truelevel=level+1localisa,n=isarray(value)ifn==0andvalmetaandvalmeta.__jsontype=='object'thenisa=falseendlocalmsgifisathen-- JSON arraybuflen=buflen+1buffer[buflen]="["fori=1,ndobuflen,msg=encode2(value[i],indent,level,buffer,buflen,tables,globalorder,state)ifnotbuflenthenreturnnil,msgendifi<nthenbuflen=buflen+1buffer[buflen]=","endendbuflen=buflen+1buffer[buflen]="]"else-- JSON objectlocalprev=falsebuflen=buflen+1buffer[buflen]="{"localorder=valmetaandvalmeta.__jsonorderorglobalorderiforderthenlocalused={}n=#orderfori=1,ndolocalk=order[i]localv=value[k]ifv~=nilthenused[k]=truebuflen,msg=addpair(k,v,prev,indent,level,buffer,buflen,tables,globalorder,state)ifnotbuflenthenreturnnil,msgendprev=true-- add a seperator before the next elementendendfork,vinpairs(value)doifnotused[k]thenbuflen,msg=addpair(k,v,prev,indent,level,buffer,buflen,tables,globalorder,state)ifnotbuflenthenreturnnil,msgendprev=true-- add a seperator before the next elementendendelse-- unorderedfork,vinpairs(value)dobuflen,msg=addpair(k,v,prev,indent,level,buffer,buflen,tables,globalorder,state)ifnotbuflenthenreturnnil,msgendprev=true-- add a seperator before the next elementendendifindentthenbuflen=addnewline2(level-1,buffer,buflen)endbuflen=buflen+1buffer[buflen]="}"endtables[value]=nilelsereturnexception('unsupported type',value,state,buffer,buflen,"type '"..valtype.."' is not supported by JSON.")endreturnbuflenendfunctionjson.encode(value,state)state=stateor{}localoldbuffer=state.bufferlocalbuffer=oldbufferor{}state.buffer=bufferupdatedecpoint()localret,msg=encode2(value,state.indent,state.levelor0,buffer,state.bufferlenor0,state.tablesor{},state.keyorder,state)ifnotretthenerror(msg,2)elseifoldbuffer==bufferthenstate.bufferlen=retreturntrueelsestate.bufferlen=nilstate.buffer=nilreturnconcat(buffer)endendlocalfunctionloc(str,where)localline,pos,linepos=1,1,0whiletruedopos=strfind(str,"\n",pos,true)ifposandpos<wherethenline=line+1linepos=pospos=pos+1elsebreakendendreturnstrformat("line %d, column %d",line,where-linepos)endlocalfunctionunterminated(str,what,where)returnnil,strlen(str)+1,"unterminated "..what.." at "..loc(str,where)endlocalfunctionscanwhite(str,pos)whiletruedopos=strfind(str,"%S",pos)ifnotposthenreturnnilendlocalsub2=strsub(str,pos,pos+1)ifsub2=="\239\187"andstrsub(str,pos+2,pos+2)=="\191"then-- UTF-8 Byte Order Markpos=pos+3elseifsub2=="//"thenpos=strfind(str,"[\n\r]",pos+2)ifnotposthenreturnnilendelseifsub2=="/*"thenpos=strfind(str,"*/",pos+2)ifnotposthenreturnnilendpos=pos+2elsereturnposendendendlocalescapechars={["\""]="\"",["\\"]="\\",["/"]="/",["b"]="\b",["f"]="\f",["n"]="\n",["r"]="\r",["t"]="\t"}localfunctionunichar(value)ifvalue<0thenreturnnilelseifvalue<=0x007fthenreturnstrchar(value)elseifvalue<=0x07ffthenreturnstrchar(0xc0+floor(value/0x40),0x80+(floor(value)%0x40))elseifvalue<=0xffffthenreturnstrchar(0xe0+floor(value/0x1000),0x80+(floor(value/0x40)%0x40),0x80+(floor(value)%0x40))elseifvalue<=0x10ffffthenreturnstrchar(0xf0+floor(value/0x40000),0x80+(floor(value/0x1000)%0x40),0x80+(floor(value/0x40)%0x40),0x80+(floor(value)%0x40))elsereturnnilendendlocalfunctionscanstring(str,pos)locallastpos=pos+1localbuffer,n={},0whiletruedolocalnextpos=strfind(str,"[\"\\]",lastpos)ifnotnextposthenreturnunterminated(str,"string",pos)endifnextpos>lastposthenn=n+1buffer[n]=strsub(str,lastpos,nextpos-1)endifstrsub(str,nextpos,nextpos)=="\""thenlastpos=nextpos+1breakelselocalescchar=strsub(str,nextpos+1,nextpos+1)localvalueifescchar=="u"thenvalue=tonumber(strsub(str,nextpos+2,nextpos+5),16)ifvaluethenlocalvalue2if0xD800<=valueandvalue<=0xDBffthen-- we have the high surrogate of UTF-16. Check if there is a-- low surrogate escaped nearby to combine them.ifstrsub(str,nextpos+6,nextpos+7)=="\\u"thenvalue2=tonumber(strsub(str,nextpos+8,nextpos+11),16)ifvalue2and0xDC00<=value2andvalue2<=0xDFFFthenvalue=(value-0xD800)*0x400+(value2-0xDC00)+0x10000elsevalue2=nil-- in case it was out of range for a low surrogateendendendvalue=valueandunichar(value)ifvaluethenifvalue2thenlastpos=nextpos+12elselastpos=nextpos+6endendendendifnotvaluethenvalue=escapechars[escchar]oresccharlastpos=nextpos+2endn=n+1buffer[n]=valueendendifn==1thenreturnbuffer[1],lastposelseifn>1thenreturnconcat(buffer),lastposelsereturn"",lastposendendlocalscanvalue-- forward declarationlocalfunctionscantable(what,closechar,str,startpos,nullval,objectmeta,arraymeta)localtbl,n={},0localpos=startpos+1ifwhat=='object'thensetmetatable(tbl,objectmeta)elsesetmetatable(tbl,arraymeta)endwhiletruedopos=scanwhite(str,pos)ifnotposthenreturnunterminated(str,what,startpos)endlocalchar=strsub(str,pos,pos)ifchar==closecharthenreturntbl,pos+1endlocalval1,errval1,pos,err=scanvalue(str,pos,nullval,objectmeta,arraymeta)iferrthenreturnnil,pos,errendpos=scanwhite(str,pos)ifnotposthenreturnunterminated(str,what,startpos)endchar=strsub(str,pos,pos)ifchar==":"thenifval1==nilthenreturnnil,pos,"cannot use nil as table index (at "..loc(str,pos)..")"endpos=scanwhite(str,pos+1)ifnotposthenreturnunterminated(str,what,startpos)endlocalval2val2,pos,err=scanvalue(str,pos,nullval,objectmeta,arraymeta)iferrthenreturnnil,pos,errendtbl[val1]=val2pos=scanwhite(str,pos)ifnotposthenreturnunterminated(str,what,startpos)endchar=strsub(str,pos,pos)elsen=n+1tbl[n]=val1endifchar==","thenpos=pos+1endendendscanvalue=function(str,pos,nullval,objectmeta,arraymeta)pos=posor1pos=scanwhite(str,pos)ifnotposthenreturnnil,strlen(str)+1,"no valid JSON value (reached the end)"endlocalchar=strsub(str,pos,pos)ifchar=="{"thenreturnscantable('object',"}",str,pos,nullval,objectmeta,arraymeta)elseifchar=="["thenreturnscantable('array',"]",str,pos,nullval,objectmeta,arraymeta)elseifchar=="\""thenreturnscanstring(str,pos)elselocalpstart,pend=strfind(str,"^%-?[%d%.]+[eE]?[%+%-]?%d*",pos)ifpstartthenlocalnumber=str2num(strsub(str,pstart,pend))ifnumberthenreturnnumber,pend+1endendpstart,pend=strfind(str,"^%a%w*",pos)ifpstartthenlocalname=strsub(str,pstart,pend)ifname=="true"thenreturntrue,pend+1elseifname=="false"thenreturnfalse,pend+1elseifname=="null"thenreturnnullval,pend+1endendreturnnil,pos,"no valid JSON value at "..loc(str,pos)endendlocalfunctionoptionalmetatables(...)ifselect("#",...)>0thenreturn...elsereturn{__jsontype='object'},{__jsontype='array'}endendfunctionjson.decode(str,pos,nullval,...)localobjectmeta,arraymeta=optionalmetatables(...)returnscanvalue(str,pos,nullval,objectmeta,arraymeta)endfunctionjson.use_lpeg()localg=require("lpeg")iftype(g.version)=='function'andg.version()=="0.11"thenerror"due to a bug in LPeg 0.11, it cannot be used for JSON matching"endlocalpegmatch=g.matchlocalP,S,R=g.P,g.S,g.RlocalfunctionErrorCall(str,pos,msg,state)ifnotstate.msgthenstate.msg=msg.." at "..loc(str,pos)state.pos=posendreturnfalseendlocalfunctionErr(msg)returng.Cmt(g.Cc(msg)*g.Carg(2),ErrorCall)endlocalfunctionErrorUnterminatedCall(str,pos,what,state)returnErrorCall(str,pos-1,"unterminated "..what,state)endlocalSingleLineComment=P"//"*(1-S"\n\r")^0localMultiLineComment=P"/*"*(1-P"*/")^0*P"*/"localSpace=(S" \n\r\t"+P"\239\187\191"+SingleLineComment+MultiLineComment)^0localfunctionErrUnterminated(what)returng.Cmt(g.Cc(what)*g.Carg(2),ErrorUnterminatedCall)endlocalPlainChar=1-S"\"\\\n\r"localEscapeSequence=(P"\\"*g.C(S"\"\\/bfnrt"+Err"unsupported escape sequence"))/escapecharslocalHexDigit=R("09","af","AF")localfunctionUTF16Surrogate(match,pos,high,low)high,low=tonumber(high,16),tonumber(low,16)if0xD800<=highandhigh<=0xDBffand0xDC00<=lowandlow<=0xDFFFthenreturntrue,unichar((high-0xD800)*0x400+(low-0xDC00)+0x10000)elsereturnfalseendendlocalfunctionUTF16BMP(hex)returnunichar(tonumber(hex,16))endlocalU16Sequence=(P"\\u"*g.C(HexDigit*HexDigit*HexDigit*HexDigit))localUnicodeEscape=g.Cmt(U16Sequence*U16Sequence,UTF16Surrogate)+U16Sequence/UTF16BMPlocalChar=UnicodeEscape+EscapeSequence+PlainCharlocalString=P"\""*(g.Cs(Char^0)*P"\""+ErrUnterminated"string")localInteger=P"-"^(-1)*(P"0"+(R"19"*R"09"^0))localFractal=P"."*R"09"^0localExponent=(S"eE")*(S"+-")^(-1)*R"09"^1localNumber=(Integer*Fractal^(-1)*Exponent^(-1))/str2numlocalConstant=P"true"*g.Cc(true)+P"false"*g.Cc(false)+P"null"*g.Carg(1)localSimpleValue=Number+String+ConstantlocalArrayContent,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.localfunctionparsearray(str,pos,nullval,state)localobj,contlocalstart=poslocalnposlocalt,nt={},0repeatobj,cont,npos=pegmatch(ArrayContent,str,pos,nullval,state)ifcont=='end'thenreturnErrorUnterminatedCall(str,start,"array",state)endpos=nposifcont=='cont'orcont=='last'thennt=nt+1t[nt]=objenduntilcont~='cont'returnpos,setmetatable(t,state.arraymeta)endlocalfunctionparseobject(str,pos,nullval,state)localobj,key,contlocalstart=poslocalnposlocalt={}repeatkey,obj,cont,npos=pegmatch(ObjectContent,str,pos,nullval,state)ifcont=='end'thenreturnErrorUnterminatedCall(str,start,"object",state)endpos=nposifcont=='cont'orcont=='last'thent[key]=objenduntilcont~='cont'returnpos,setmetatable(t,state.objectmeta)endlocalArray=P"["*g.Cmt(g.Carg(1)*g.Carg(2),parsearray)localObject=P"{"*g.Cmt(g.Carg(1)*g.Carg(2),parseobject)localValue=Space*(Array+Object+SimpleValue)localExpectedValue=Value+Space*Err"value expected"localExpectedKey=String+Err"key expected"localEnd=P(-1)*g.Cc'end'localErrInvalid=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()localPair=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()localDecodeValue=ExpectedValue*g.Cp()jsonlpeg.version=json.versionjsonlpeg.encode=json.encodejsonlpeg.null=json.nulljsonlpeg.quotestring=json.quotestringjsonlpeg.addnewline=json.addnewlinejsonlpeg.encodeexception=json.encodeexceptionjsonlpeg.using_lpeg=truefunctionjsonlpeg.decode(str,pos,nullval,...)localstate={}state.objectmeta,state.arraymeta=optionalmetatables(...)localobj,retpos=pegmatch(DecodeValue,str,pos,nullval,state)ifstate.msgthenreturnnil,state.pos,state.msgelsereturnobj,retposendend-- cache result of this function:json.use_lpeg=function()returnjsonlpegendjsonlpeg.use_lpeg=json.use_lpegreturnjsonlpegendifalways_use_lpegthenreturnjson.use_lpeg()endreturnjson
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
localG,τ=love.graphics,2*math.pimath.randomseed(os.time())localBART=false-- local pprint=require'pprint' pprint.setup{use_tostring=true}localPos=require'r.pos'localrmath=require'r.math'localclass='r.class'localqw=require'r.qw'localyves=G.newImage'bart.png'localyvesr=yves:getWidth()/2localpopsound=love.audio.newSource('popmono.wav','static')localbartsound=love.audio.newSource('bartmono.wav','static')localnodes={}localnodes_free={}localinters={}localfunctionnp(i)localnx,p=unpack(i)returnnodes[nx],p,nxendlocalfunctionconnect(i1,i2)localn1,p1,a1=np(i1)localn2,p2,a2=np(i2)assert(n1)assert(n2)assert(p1<=#n1)assert(p2<=#n2)n1[p1]=i2n2[p2]=i1ifp1==1andp2==1thentable.insert(inters,a2)endendlocalfunctioncolfromhex(x)ifx:sub(1,1)=='#'thenx=x:sub(2)endlocalo={}fori=1,5,2dotable.insert(o,tonumber(x:sub(i,i+1),16)/255)endreturnoendlocalnode_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 PRODS1={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},}fork,vinpairs(node_types)dov.type=kv.color=colfromhex(v.color)endlocalfunctionmknode(type,pos,a)localnode=setmetatable({pos=pos,a=a,prev_pos=pos,prev_a=a},{__index=assert(node_types[type]),__tostring=function(x)localo=x.type..'('for_,cinipairs(x)doo=o..'{'..c[1]..','..c[2]..'}'..','endreturno..')'end})fori=1,node.nportsdonode[i]=falseendreturnnodeendlocalfunctionmknode2(type,pos,a)localn=mknode(type,pos,a)table.insert(nodes,n)return#nodes,nend-- 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})localnn0,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})localni1=mknode2('C1',Pos(300,125),0)localni2=mknode2('C2',Pos(300,125),0)localni3=mknode2('C2',Pos(300,125),0)localni4=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})localnL=mknode2('LyricLy',Pos(400,120),0)connect({ni4,2},{nL,2})localnz0=mknode2('S1',Pos(420,100),0)connect({nz0,1},{nL,3})localng=mknode2('Gate0',Pos(400,150),0)localnC1=mknode2('C1',Pos(400,170),0)localnC2=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})localnz2=mknode2('Z',Pos(600,100),0)localprev={nz2,1}fori=1,95dolocalnn=mknode2('S',Pos(600,100+i*10),0)connect(prev,{nn,2})prev={nn,1}endconnect(prev,{ng,2})fori,ninipairs(nodes)don.pos=n.pos+Pos(100,300)n.prev_pos=n.posn.prev_a=n.aendlocalfunctionportpos(i)localn,p,a=np(i)returnn.pos+Pos(n.r,0):rot(n.a+τ/n.nports*(p-1))endlocalfont=G.newFont'liberationsans.ttf'localtext=G.newText(font)G.setFont(font)localfunctioneach_wire()returncoroutine.wrap(function()fori,ninpairs(nodes)doforp=1,n.nportsdoifn[p]and(n[p][1]>iorn[p][2]>p)thencoroutine.yield({i,p},n[p])endendendend)endlocalfunctiondraw_nodes()fori,ninpairs(nodes)doG.push()G.translate(n.pos.x,n.pos.y)G.setColor(n.color)ifBARTthenG.draw(yves,0,0,n.a,n.r/yvesr,nil,yvesr,yvesr)elseG.circle('fill',0,0,n.r)endG.setColor(0,0,0)G.circle('line',0,0,n.r)text:set(n.type)localw,h=text:getDimensions()G.setColor(0,0,0)G.draw(text,-w/2,-h/2)G.pop()endG.setColor(0,0,0)fori1,i2ineach_wire()dolocale1,e2=portpos(i1),portpos(i2)G.line(e1.x,e1.y,e2.x,e2.y)functiontri(e1,e2)localp=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()endifi1[2]==1thentri(e1,e2)endifi2[2]==1thentri(e2,e1)endendendlocalspringlength,springconst=20,50localrepulsion,repulsionmaxdist=100000,50localfunctionsprings(dt)localaccels,torques={},{}localfunctionexert(on,at,by)localpara=at-on.poslocalperp=para:rot(τ/4)ifnotaccels[on]thenaccels[on]=Pos(0,0)endaccels[on]:addby(by)-- i don't know why this works better with a /10torques[on]=(torques[on]or0)+by:sproj(perp)*para:len()/10endfori1,i2ineach_wire()dolocaln1,p1=np(i1)localn2,p2=np(i2)localpp1,pp2=portpos(i1),portpos(i2)localx=(pp1-pp2):len()-springlengthlocalf=springconst*xlocaldir=(pp2-pp1):norm()exert(n1,pp1,f*dir)exert(n2,pp2,-f*dir)endfori,ninpairs(nodes)doforj,minpairs(nodes)doifi<jthenlocald=n.pos-m.posifd:lensq()<repulsionmaxdist^2thenlocalf=d:norm()*repulsion/(d:len()^2)ifd:len()~=0thenexert(n,n.pos,f)exert(m,m.pos,-f)endendendendendfori,ninpairs(nodes)doifn.type~='Hi'thenlocald=n.pos-Pos(love.mouse.getPosition())localf=d:norm()*repulsion/(d:len()^2)exert(n,n.pos,f)endendfori,ninpairs(nodes)dolocalpos,a=n.pos,n.alocalnew_pos,new_a=pos,aifn.type~='Hi'andaccels[n]thennew_pos=2*pos-n.prev_pos+dt*dt*accels[n]n.prev_pos=posendiftorques[n]thennew_a=2*a-n.prev_a+dt*dt*torques[n]n.prev_a=aendn.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())endendlocalpop,ruleslocalt,tp=0,3functionlove.update(dt)t=t+dtfori=1,5dosprings(math.min(dt,1/30))endtp=tp-dtwhiletp<0dopop()tp=math.log(1-math.random())/(-2*#inters)endendfunctionlove.keypressed(k,s,i)ifnotiandk=='f9'thenBART=notBARTlove.window.setTitle((BARTand'BART'or'KO')..'LAKOSKI')endendfunctionlove.draw()G.clear(1,1,1)draw_nodes()G.origin()--[[G.print(tostring(tp),10,10)]]endfunctionlove.mousemoved(x,y)iflove.mouse.isDown(1)thenN0.pos=Pos(x,y)endendrules={}localfunctionaddrule(t1,t2,s1,s2)ift2<t1thent1,t2,s1,s2=t2,t1,s2,s1elseift1==t2thens2=s1endrules[t1..'__'..t2]={s1,s2}endlocalN=setmetatable({},{__index=function(t,k)returnsetmetatable({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 HAPPENSaddrule('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 HAPPENSaddrule('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) endpop=function()if#inters==0thenreturnend--local a1=pick()locala1=table.remove(inters,math.random(#inters))localn1=assert(nodes[a1])localn2,p2,a2=np(n1[1])assert(n2andp2==1)ifn2.type<n1.typethenn1,p1,a1,n2,p2,a2=n2,p2,a2,n1,p1,a1endlocalrule=rules[n1.type..'__'..n2.type]if(notrule)orrule.disabledthenreturnendlocals1,s2=unpack(rule)localfunctionremove(ix)nodes[ix]=nilnodes_free[ix]=trueendlocalfunctioninsert(n)localix=next(nodes_free)ifixthennodes_free[ix]=nilnodes[ix]=nreturnixelsetable.insert(nodes,n)return#nodesendendlocalbary=(n1.pos+n2.pos)/2localbaryr=(n1.pos-n2.pos):len()/2remove(a1)remove(a2)localnamed={}localfunctionbuild(onto,pattern)iftype(pattern)=='string'thenifnamed[pattern]==nilthennamed[pattern]=ontoelseconnect(onto,named[pattern])named[pattern]='did it already'endelseassert(type(pattern)=='table','aaa '..type(pattern))localnports=node_types[pattern.type].nportsassert(#pattern+1==nports)localang=math.random()*τlocaloffs=Pos(math.random()*baryr,0):rot(ang)localn=mknode(pattern.type,bary+offs,ang)n.prev_pos=bary-offslocala=insert(n)connect({a,1},onto)forp=2,nportsdobuild({a,p},pattern[p-1])endendendforp=2,n1.nportsdobuild(n1[p],s1[p-1])endforp=2,n2.nportsdobuild(n2[p],s2[p-1])endlocalsnd,pitch=(BARTandbartsoundorpopsound):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
-- https://github.com/jagt/pprint.lua/blob/master/pprint.lua-- public domainlocalpprint={VERSION='0.1'}localdepth=1pprint.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 tableshow_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 triggershow_metatable=false,-- show metatableshow_all=false,-- override other show settings and show everythinguse_tostring=false,-- use __tostring to print table if availablefilter_function=nil,-- called like callback(value[,key, parent]), return truty value to hideobject_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 settingsindent_size=2,-- indent for each nested table levellevel_width=80,-- max width per indent levelwrap_string=true,-- wrap string when it's longer than level_widthwrap_array=false,-- wrap every array elementssort_keys=true,-- sort table keys}localTYPES={['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'localESCAPE_MAP={['\a']='\\a',['\b']='\\b',['\f']='\\f',['\n']='\\n',['\r']='\\r',['\t']='\\t',['\v']='\\v',['\\']='\\\\',}-- generic utilitieslocalfunctionescape(s)s=s:gsub('([%c\\])',ESCAPE_MAP)localdq=s:find('"')localsq=s:find("'")ifdqandsqthenreturns:gsub('"','\\"'),'"'elseifsqthenreturns,'"'elsereturns,"'"endendlocalfunctionis_plain_key(key)returntype(key)=='string'andkey:match('^[%a_][%a%d_]*$')endlocalCACHE_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 refcountlocalfunctioncache_apperance(obj,cache,option)ifnotcache.visited_tablesthencache.visited_tables=setmetatable({},{__mode='k'})endlocalt=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 resultsif(notTYPES[t]andnotoption.show_table)or(TYPES[t]andnotoption['show_'..t])thenreturnendifCACHE_TYPES[t]orTYPES[t]==nilthenifnotcache[t]thencache[t]=setmetatable({},{__mode='k'})cache[t]._cnt=0endifnotcache[t][obj]thencache[t]._cnt=cache[t]._cnt+1cache[t][obj]=cache[t]._cntendendift=='table'orTYPES[t]==nilthenifcache.visited_tables[obj]==falsethen-- already printed, no need to mark this and its children anymorereturnelseifcache.visited_tables[obj]==nilthencache.visited_tables[obj]=1else-- visited already, increment and continuecache.visited_tables[obj]=cache.visited_tables[obj]+1returnendfork,vinpairs(obj)docache_apperance(k,cache,option)cache_apperance(v,cache,option)endlocalmt=getmetatable(obj)ifmtandoption.show_metatablethencache_apperance(mt,cache,option)endendend-- makes 'foo2' < 'foo100000'. string.sub makes substring anyway, no need to use index based methodlocalfunctionstr_natural_cmp(lhs,rhs)while#lhs>0and#rhs>0dolocallmid,lend=lhs:find('%d+')localrmid,rend=rhs:find('%d+')ifnot(lmidandrmid)thenreturnlhs<rhsendlocallsub=lhs:sub(1,lmid-1)localrsub=rhs:sub(1,rmid-1)iflsub~=rsubthenreturnlsub<rsubendlocallnum=tonumber(lhs:sub(lmid,lend))localrnum=tonumber(rhs:sub(rmid,rend))iflnum~=rnumthenreturnlnum<rnumendlhs=lhs:sub(lend+1)rhs=rhs:sub(rend+1)endreturnlhs<rhsendlocalfunctioncmp(lhs,rhs)localtleft=type(lhs)localtright=type(rhs)iftleft=='number'andtright=='number'thenreturnlhs<rhsendiftleft=='string'andtright=='string'thenreturnstr_natural_cmp(lhs,rhs)endiftleft==trightthenreturnstr_natural_cmp(tostring(lhs),tostring(rhs))end-- allow custom typeslocaloleft=TYPES[tleft]or9localoright=TYPES[tright]or9returnoleft<orightend-- setup option with defaultlocalfunctionmake_option(option)ifoption==nilthenoption={}endfork,vinpairs(pprint.defaults)doifoption[k]==nilthenoption[k]=vendifoption.show_allthenfort,_inpairs(TYPES)dooption['show_'..t]=trueendoption.show_metatable=trueendendreturnoptionend-- override defaults and take effects for all following callsfunctionpprint.setup(option)pprint.defaults=make_option(option)end-- format lua object into a stringfunctionpprint.pformat(obj,option,printer)option=make_option(option)localbuf={}localfunctiondefault_printer(s)table.insert(buf,s)endprinter=printerordefault_printerlocalcacheifoption.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 anywaycache=pprint._cacheor{}pprint._cache=nilelseifoption.object_cache=='local'thencache={}endlocallast=''-- used for look back and remove trailing commalocalstatus={indent='',-- current indentlen=0,-- current line length}localwrapped_printer=function(s)printer(last)last=sendlocalfunction_indent(d)status.indent=string.rep(' ',d+#(status.indent))endlocalfunction_n(d)wrapped_printer('\n')wrapped_printer(status.indent)ifdthen_indent(d)endstatus.len=0returntrue-- used to close bracket correctlyendlocalfunction_p(s,nowrap)status.len=status.len+#sifnotnowrapandstatus.len>option.level_widththen_n()wrapped_printer(s)status.len=#selsewrapped_printer(s)endendlocalformatter={}localfunctionformat(v)localf=formatter[type(v)]f=forformatter.table-- allow patched type()ifoption.filter_functionandoption.filter_function(v,nil,nil)thenreturn''elsereturnf(v)endendlocalfunctiontostring_formatter(v)returntostring(v)endlocalfunctionnumber_formatter(n)returnn==math.hugeand'[[math.huge]]'ortostring(n)endlocalfunctionnop_formatter(v)return''endlocalfunctionmake_fixed_formatter(t,has_cache)ifhas_cachethenreturnfunction(v)returnstring.format('[[%s %d]]',t,cache[t][v])endelsereturnfunction(v)return'[['..t..']]'endendendlocalfunctionmake_userdata_formatter(has_cache)localfunctionutype(v)localmt=getmetatable(v)ifnotmtthenreturn'?'endreturnmt.__nameor'?'endifhas_cachethenreturnfunction(v)returnstring.format('[[userdata <%s> %d]]',utype(v),cache.userdata[v])endelsereturnfunction(v)returnstring.format('[[userdata <%s>]]',utype(v))endendendlocalfunctionstring_formatter(s,force_long_quote)locals,quote=escape(s)localquote_len=force_long_quoteand4or2ifquote_len+#s+status.len>option.level_widththen_n()-- only wrap string when is longer than level_widthifoption.wrap_stringand#s+quote_len>option.level_widththen-- keep the quotes together_p('[[')while#s+status.len>=option.level_widthdolocalseg=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 partsreturn']]'endendreturnforce_long_quoteand'[['..s..']]'orquote..s..quoteendlocalfunctiontable_formatter(t)ifoption.use_tostringthenlocalmt=getmetatable(t)ifmtandmt.__tostringthen-- return string_formatter(tostring(t), true)returntostring(t)endendlocalprint_header_ix=nillocalttype=type(t)ifoption.object_cachethenlocalcache_state=cache.visited_tables[t]localtix=cache[ttype][t]-- FIXME should really handle `cache_state == nil`-- as user might add things through filter_functionifcache_state==falsethen-- already printed, just print the the numberreturnstring_formatter(string.format('%s %d',ttype,tix),true)elseifcache_state>1then-- appeared more than once, print table header with numberprint_header_ix=tixcache.visited_tables[t]=falseelse-- appeared exactly once, print like a normal tableendendlocallimit=tonumber(option.depth_limit)iflimitanddepth>limitthenifprint_header_ixthenreturnstring.format('[[%s %d]]...',ttype,print_header_ix)endreturnstring_formatter(tostring(t),true)endlocaltlen=#tlocalwrapped=false_p('{')_indent(option.indent_size)_p(string.rep(' ',option.indent_size-1))ifprint_header_ixthen_p(string.format('--[[%s %d]] ',ttype,print_header_ix))endforix=1,tlendolocalv=t[ix]ifformatter[type(v)]==nop_formatteror(option.filter_functionandoption.filter_function(v,ix,t))then-- passelseifoption.wrap_arraythenwrapped=_n()enddepth=depth+1_p(format(v)..', ')depth=depth-1endend-- hashmap part of the table, in contrast to array partlocalfunctionis_hash_key(k)iftype(k)~='number'thenreturntrueendlocalnumkey=math.floor(tonumber(k))ifnumkey~=kornumkey>tlenornumkey<=0thenreturntrueendendlocalfunctionprint_kv(k,v,t)-- can't use option.show_x as obj may contain custom typeifformatter[type(v)]==nop_formatterorformatter[type(k)]==nop_formatteror(option.filter_functionandoption.filter_function(v,k,t))thenreturnendwrapped=_n()ifis_plain_key(k)then_p(k,true)else_p('[')-- [[]] type string in key is illegal, needs to add spaces inbetweenlocalk=format(k)ifstring.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)endifoption.sort_keysthenlocalkeys={}fork,_inpairs(t)doifis_hash_key(k)thentable.insert(keys,k)endendtable.sort(keys,cmp)for_,kinipairs(keys)doprint_kv(k,t[k],t)endelsefork,vinpairs(t)doifis_hash_key(k)thenprint_kv(k,v,t)endendendifoption.show_metatablethenlocalmt=getmetatable(t)ifmtthenprint_kv('__metatable',mt,t)endend_indent(-option.indent_size)-- make { } into {}last=string.gsub(last,'^ +$','')-- peek last to remove trailing commalast=string.gsub(last,',%s*$',' ')ifwrappedthen_n()end_p('}')return''end-- set formattersformatter['nil']=option.show_nilandtostring_formatterornop_formatterformatter['boolean']=option.show_booleanandtostring_formatterornop_formatterformatter['number']=option.show_numberandnumber_formatterornop_formatter-- need to handle math.hugeformatter['function']=option.show_functionandmake_fixed_formatter('function',option.object_cache)ornop_formatterformatter['thread']=option.show_threadandmake_fixed_formatter('thread',option.object_cache)ornop_formatter-- formatter['userdata'] = option.show_userdata and make_fixed_formatter('userdata', option.object_cache) or nop_formatterformatter['userdata']=option.show_userdataandmake_userdata_formatter(option.object_cache)ornop_formatterformatter['string']=option.show_stringandstring_formatterornop_formatterformatter['table']=option.show_tableandtable_formatterornop_formatterifoption.object_cachethen-- needs to visit the table before start printingcache_apperance(obj,cache,option)end_p(format(obj))printer(last)-- close the buffered one-- put cache back if globalifoption.object_cache=='global'thenpprint._cache=cacheendreturntable.concat(buf)end-- pprint all the argumentsfunctionpprint.pprint(...)localargs={...}-- select will get an accurate count of array len, counting trailing nilslocallen=select('#',...)forix=1,lendopprint.pformat(args[ix],nil,io.write)io.write('\t')endiflen>0thenio.write('\n')endendsetmetatable(pprint,{__call=function(_,...)pprint.pprint(...)end})returnpprint
entry #7
comments 0
post a comment
oldbnengb.ypASCII text, with very long lines (466)
# kolkaoksit is defined as the run legnths encoding of the kokkalsoi sequnece# we need to omcpute one hundred terms of hte kolksaoksi systme# secuqnece# so we need one hundred runs lenghts of the kolakoasi sequcense to liost at# ksfkoklklk=[1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,2,2,1,1,2,1,1,2,1,2,2,1,2,2,1,1,2,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,1,2,2,1,2,1,1,2,2,1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,1,2,2,1,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,1,2,1,2,2,1,2,1,1,2,2,1]koklslk=[]# too kkkkkeep track of whk where' lookingslookins=1# tmeporaorylookings=0# i forgotr why ityped this#ok#OH IForgot# ocuntcount=0foriinkoklklk:tmeproary=iiftmeproary==lookins:count+=1else:koklslk.append(count)count=1lookins=tmeproaryprint(koklslk)
0 [1]
pop do (
fork pick below (last pop)
-1
switch(
fix +3 neg
| coupon (+3 neg)
)
fork (+1 gi|back join dgi)
| <100 len gi
)
take 100
# I'm a bit snick and snired
# What's the point of typoes
# and comma splices and fake
# signatures if you shrimply
# do the right thing instead
# I should just have fun and
# have the wombats ride free
# That's snailsick and snail
# tired if you're new around
# here i am just using slang
fromcopyimportcopyfromtimeimportsleep#for suspenseful purposesfromitertoolsimportzip_longest,starmap#gotta have long enough zippers and locatory mechanisms when your robes are as spacefaring as thesestrist=lambdacol=0:lambdal:'['+''.join(map(('░▒▓█'ifcolelse'░█').__getitem__,l))+']'#string-list portcreateaure(portmanteau-creature)dbg=lambdax,*a:(x,print('\n'.join(map(strist(),a+(x,)))))[0]X=lambdaf:(lambdag:g(g))(lambdag:f(lambda:g(g)))#much better than the Y combinator whatever that thing iswatch=lambdax:bool(xandx[0])#they watchbite=lambdax:bool(xandx.pop(0))#bites you tee hee"""help me i have forgotten how to counti am trying to count in binary but all i get is this weird sequencemy binary counter is developing dendritic tendrils everywherewhy are the least-place-value bits beckoning to me so ominously... whatever could be their significance"""deffeast(eu,cond,old,meal,other,val):new=[]whilecond():new.append(meal())ifeu==2:print(strist(1)(weave(*(new+old(),other)[::(-1)**val])),end='\r');sleep(1/2**5)returnnewweave=lambdax,y:starmap(lambdai,j:i|j<<1,zip_longest(x,y,fillvalue=0))defkolakoski(eu=0):#you see i ran out of letters and had to use the vowels in debugyield1x=[];y=[1]while1:ifeu:print(strist(1)(weave(y,x)),2-watch(x));sleep(1/2**4)yield2-watch(x)z=copy(y)ifeu:z=feast(eu,lambda:notbite(z),lambda:x,lambda:notbite(x),y,1)+xx=[bite(z)]+zyy=feast(eu,munch:=lambda:bite(y)|bite(z),lambda:y,lambda:0,x,0)+[1]whiley:yy.append(munch())y=yyelse:#i think this way is much more elegant and neatly tessellated together#but unfortunately humans appear to have eyes instead of brains that can execute and appreciate Python rapidly in their mind#sigh my art form shall forever remain beyond your speciesx,y=[bite(z:=X(lambdaf:xifbite(z)else[notbite(x)]+f()))]+z),X(lambdaf:[0]+f()if(munch:=lambda:bite(y)|bite(z))()else[1]+X(lambdag:yand[munch()]+g())K=kolakoski(2)#2 to watch it traverse turingfully in real time, 1 to just see the states, 0 if it's okay because you can already taste RAMprint([next(K)for_inrange(100)])'''btw (highly spoilerful; i recommend you dedicate yourself wholly to deciphering my pythology first)this is just doing https://11011110.github.io/blog/2016/10/14/kolakoski-sequence-via.html if you are wondering'''
#include<stdio.h>#include<stdlib.h>#define LEFT 1#define RIGHT 2typedefstructitem{intvalue;structitem*left;structitem*right;}Item;typedefstructqueue{Item**queue;intstart;intend;}Queue;voiddequeue(Queue*queue){if(queue->start!=queue->end){// not working, seems to be coming from this functionprintf("%d\n",(queue->queue)[queue->start]->value);queue->start++;}}Item*peek(Queue*queue){returnqueue->queue[queue->start];}voidenqueue(Queue*queue,Item*item){(queue->queue)[queue->end]=item;queue->end+=1;}inthasLeft(Item*item){if(item->value>=LEFT){return1;}return0;}inthasRight(Item*item){if(item->value>=RIGHT){return1;}return0;}voidtraversal(Item*tree){intdepth=0;Item*queueArr[1000];Queuequeue;queue.queue=queueArr;queue.start=0;queue.end=0;Item*node=tree;while(depth<10000){if(depth==99){printf("2\n");// can't figure out the crash :(}dequeue(&queue);if(hasLeft(node)){node->left->value=depth%2+1;enqueue(&queue,node->left);}node=peek(&queue);if(hasRight(node)){node->right->value=depth%2+1;enqueue(&queue,node->right);}node=peek(&queue);depth++;}}Item*genTree(intdepth){if(depth==0){return0;}Item*parent=malloc(sizeof(Item));parent->left=genTree(depth-1);parent->right=genTree(depth-1);parent->value=1;returnparent;}intmain(){Item*tree=genTree(12);traversal(tree);free(tree);}
-- Output TableCREATETABLEsequence(iINTEGERPRIMARYKEY,valueINTEGER);-- Range TableCREATETABLEranges(valueINTEGER,iterationINTEGER);CREATEVIEWoutputASSELECTgroup_concat(value)FROMsequenceWHEREi<100ORDERBYi;-- Generate new number batchCREATETRIGGERgenINSTEADOFINSERTONoutputFOREACHROWBEGININSERTORIGNOREINTOsequenceSELECTcount(value)OVER(ORDERBYiROWSUNBOUNDEDPRECEDINGEXCLUDECURRENTROW),i%2+1FROMsequenceNATURALJOINranges;END;INSERTINTOrangesVALUES(1,0),(2,0),(2,1);INSERTINTOsequenceVALUES(0,1),(1,2);-- Trigger 10 timesINSERTINTOoutputVALUES('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');SELECT*FROMoutput;
# it's the 100th anniversary of Code Guessing!!!# how the years fly by so fast...# # thank you so much for all the amazing rounds,# for all the mind-blowing entries,# for all the clever social deductions,# for all the silly gimmick rounds,# for all the really cool challenges and also the boring ones,# for all the features on the website, and how they've grown over time,# for all the annoying language restrictions,# for all the anonymous chatters that decided to join #announcements,# for all the cool games everyone has made,# for all the languages made for the purpose of CG,# for all the entries attributed to SoundOfSpouting#6980 (UID: 151149148639330304),# for all the times boris johnson had to step in to break a tie,# for all the malware entries that leak your submission,# for all the statistical analysis of player patterns,# for all the shufflers that don't even try to guess,# for all the oldies that have stuck with CG since single-digit rounds,# for all the players that burnt out and quit,# for all the newbies that started after joining the code guessing server,# for razetime, how we miss you always,# for LyricLy for all the work you've done over the years to grow Code Guessing into something beautiful.## but reminiscing aside. it's time for me to submit my code# i hope you like it :) i have a suspicion you might# scroll all the way to the bottom if you want to just see the kolakoski implementation!# # below is the obligatory suspicious first line of code# you've learned to skip past these by now, right? ^-^with(lambdag={},src="":exec(b"".join([bytes([int(src[i:i+8].replace("\u200b","0").replace("\u200c","1"),2)])foriinrange(0,len(src),8)]),g)org)()["poy"]:# =============================================# = =# = [[[[]]]][[ ]][[[[]]] ][[[] ]] =# = [[[[] ]] ][[[] ]] [[[[] ]] =# = ][[[] ]] [[[[] ]] ][[[] ]] =# = [[[[]]]][[ ]][[[ [] ]]][[[] =# = ]][[[ []]]] [[ []]][ =# = [[[]] ]][[[ ]] ][[[[ =# = ]]]][ [[]]][[[[ ]]]][ =# = =# = [[]]] [[[[]]]] =# = [[[[[[[ []]] ]] =# = ]]][[[[]] ]][[ [ ]] =# = ][[[[] ]]][ [ [] =# = ]][[[[ ]]]] [ [] =# = ][[[[] ]]][[ []]] [[ =# = [[]]]] [[[]] ][[[[]]] =# = =# = =# = ][[[ ]]][ =# = [[ [] ]] ][ =# = [[ ]] ][ [[ =# = =# = []]] ][[[ =# = ]]][ [[[] =# = ]]][ [[]]][ [[[] =# = ]]][ [[]] ][[[ []]] =# = ][[[[[[[ [[]]]] =# = ]]] ]] =# = =# =============================================# # POY (short for Python cOncatenative programmYng) is a concatenative# programming language that uses [] characters for its source code.# It's somewhat Factor-flavored, despite rhyming with Joy.# The language is implemented, as you'd expect, as a DSL within Python :3# # POY is stack-based, and its source code is a sequence of concatenated and nested quotations.# These are written in syntax as one would expect: [], [[]], [][[]], etc.# However, an empty quotation is not allowed to be on the right side of a concatenation.# Any whitespace in the source code is ignored.# # Certain kinds of concatenated quotations in POY have special meaning.# In particular, a sequence of three quotations in a row is defined as a word call.# Example: [] [[[]]] [[]]# The leftmost quotation is pushed onto the stack. The middle quotation defines# the namespace of the word being called; this determines how the rightmost# quotation is interpreted. The middle and right quotations are a (possibly revursively nested) quotation# without any concatenations, and the depth of its nesting is used as an index.# The first index is called the namespace index, and the second index is called the word index.# Together, these are used to execute a given piece of functionality within the runtime.# # As a special case, if the namespace index is 1, i.e. the middle quotation is [[]],# the right quotation is instead called against the current stack. In this special case,# the right quotation is allowed to contain concatenations in its subtree as well.# # The set of words included in the POY 1.0 runtime are included below.# Each line begins with the namespace and word index, and ends with a namespaced word.# These words are not documented, but you should be able to understand their behavior# from their names alone.# 2, 1: base/swap# 2, 2: base/dup# 2, 3: base/drop# 2, 4: base/call# 2, 5: base/quote# 2, 6: base/over# 2, 7: base/swapd# 2, 8: base/dupd# 2, 9: base/nip# 2, 10: base/rot# 2, 11: base/-rot# 3, 1: number/0# 3, 2: number/++# 3, 3: number/--# 3, 4: number/+# 3, 5: number/-# 3, 6: number/neg# 3, 7: number/*# 3, 8: number/div# 3, 9: number/floordiv# 3, 10: number/%# 3, 11: number/pow# 3, 12: number/round# 4, 1: array/new# 4, 2: array/push# 4, 3: array/get# 4, 4: array/iota# 4, 5: array/map# 5, 1: combinator/2dup# 5, 2: combinator/dip# 5, 3: combinator/keep# 5, 4: combinator/times# 6, 1: boolean/t# 6, 2: boolean/f# 6, 3: boolean/if# 7, 1: io/.# # # # Now: time for sans undertale[[][[[]]][[[[]]]][[[[[]]]]][[]][[[[]]]][[]][[[[]]]][[[]]][[[[[]]]]][[[]]][[[[]]]][[]][[[[]]]][[]][[]][[[][[[]]][[[[]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[]]]]][[]][[[][[[]]][[[[]]]][[[]]][[[]]][[]][[[][[[]]][[[[]]]][[[[[]]]]][[[[]]]]]][[[[[[]]]]]][[[]]]]][[[[[[]]]]]][[[]]][[[]]][[[[[[[[[[[]]]]]]]]]]][[[[]]]][[[[[[]]]]]][[[]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[[[]]]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[[]]]]]]]]][[[]]][[[[[[[]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[[[]]]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[[]]]]]]]]][[[[]]]][[[[[[]]]]]][[[]]][[[[[[[]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[[[]]]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[]]]][[[[]]]][[[[]]]][[[[]]]][[[[]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[[]]]]]]]]][[[[]]]][[[[[]]]]][[[]]][[[[[[[]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[[[]]]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[[]]]]]]]]][[[[]]]][[[[[[]]]]]][[[]]][[]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[[[[[[]]]]]]]]][[[[]]]][[[[[]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[]]]]][[[[]]]][[[[[[[[[[[[[]]]]]]]]]]]]][[]][[[][[[]]][[[[]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[[]]]]]]]]]]][[[[]]]][[[[[]]]]]]][[[[[[]]]]]][[[[]]]][[]][[[][[[]]][[[[]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[[[]]]]][[[]]][[[[[[[[]]]]]]]][[[[[]]]]][[[]]][[[]]][[]]]][[[[[[]]]]]][[[[]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[[[]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[[[]]]][[[[]]]][[[[[[]]]]]][[[[[]]]]][[[]]][[[[]]]][[[]]][[[[]]]][[[[[[[[]]]]]]]][[]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]][[]][[]][[[]]][[[[]]]]][[[]]][[[[[]]]]]
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Created with JFLAP 7.1.--><structure><type>turing</type><automaton><!--The list of states.--><stateid="0"name="q0"><x>99.0</x><y>45.0</y><initial/></state><stateid="1"name="q1"><x>276.0</x><y>129.0</y></state><stateid="2"name="q2"><x>436.0</x><y>221.0</y></state><stateid="3"name="q3"><x>268.0</x><y>223.0</y></state><stateid="4"name="q4"><x>352.0</x><y>325.0</y></state><stateid="5"name="q5"><x>82.0</x><y>238.0</y></state><stateid="6"name="q6"><x>200.0</x><y>428.0</y></state><stateid="7"name="q7"><x>334.0</x><y>521.0</y></state><stateid="8"name="q8"><x>469.0</x><y>322.0</y></state><stateid="9"name="q9"><x>659.0</x><y>265.0</y></state><stateid="10"name="q10"><x>664.0</x><y>374.0</y></state><stateid="12"name="q12"><x>369.0</x><y>741.0</y></state><stateid="13"name="q13"><x>466.0</x><y>524.0</y></state><stateid="14"name="q14"><x>561.0</x><y>461.0</y></state><stateid="15"name="q15"><x>569.0</x><y>585.0</y></state><stateid="16"name="q16"><x>698.0</x><y>458.0</y></state><stateid="17"name="q17"><x>705.0</x><y>590.0</y></state><stateid="19"name="q19"><x>987.0</x><y>597.0</y></state><!--The list of transitions.--><transition><from>6</from><to>4</to><read>¹</read><write>¹</write><move>R</move></transition><transition><from>17</from><to>19</to><read/><write>1</write><move>R</move></transition><transition><from>0</from><to>1</to><read/><write>1</write><move>R</move></transition><transition><from>14</from><to>16</to><read/><write>2</write><move>R</move></transition><transition><from>13</from><to>15</to><read>2</read><write>2</write><move>R</move></transition><transition><from>3</from><to>5</to><read/><write>¹</write><move>R</move></transition><transition><from>12</from><to>6</to><read>2</read><write>²</write><move>S</move></transition><transition><from>19</from><to>12</to><read>¹</read><write>1</write><move>R</move></transition><transition><from>2</from><to>3</to><read/><write>2</write><move>R</move></transition><transition><from>12</from><to>6</to><read>1</read><write>¹</write><move>S</move></transition><transition><from>16</from><to>19</to><read/><write>2</write><move>R</move></transition><transition><from>9</from><to>19</to><read/><write>2</write><move>R</move></transition><transition><from>19</from><to>12</to><read>²</read><write>2</write><move>R</move></transition><transition><from>10</from><to>19</to><read/><write>1</write><move>R</move></transition><transition><from>4</from><to>8</to><read/><write/><move>L</move></transition><transition><from>7</from><to>13</to><read/><write/><move>L</move></transition><transition><from>6</from><to>7</to><read>²</read><write>²</write><move>R</move></transition><transition><from>6</from><to>6</to><read>1</read><write>1</write><move>L</move></transition><transition><from>6</from><to>6</to><read/><write/><move>L</move></transition><transition><from>6</from><to>6</to><read>2</read><write>2</write><move>L</move></transition><transition><from>19</from><to>19</to><read/><write/><move>L</move></transition><transition><from>19</from><to>19</to><read>1</read><write>1</write><move>L</move></transition><transition><from>19</from><to>19</to><read>2</read><write>2</write><move>L</move></transition><transition><from>15</from><to>17</to><read/><write>1</write><move>R</move></transition><transition><from>4</from><to>4</to><read>1</read><write>1</write><move>R</move></transition><transition><from>4</from><to>4</to><read>2</read><write>2</write><move>R</move></transition><transition><from>7</from><to>7</to><read>1</read><write>1</write><move>R</move></transition><transition><from>7</from><to>7</to><read>2</read><write>2</write><move>R</move></transition><transition><from>1</from><to>2</to><read/><write>2</write><move>R</move></transition><transition><from>8</from><to>10</to><read>2</read><write>2</write><move>R</move></transition><transition><from>13</from><to>14</to><read>1</read><write>1</write><move>R</move></transition><transition><from>5</from><to>6</to><read/><write>1</write><move>R</move></transition><transition><from>8</from><to>9</to><read>1</read><write>1</write><move>R</move></transition></automaton></structure>
cg100.pngPNG image data, 1335 x 761, 8-bit/color RGB, non-interlaced
-module(cogging).-export([koalakoskie/1]).%% Returns a koalakosksokigei sequence with length at least N.koalakoskie(0)->[];koalakoskie(1)->[1];koalakoskie(2)->[1,2];koalakoskie(N)->expand_until_length(N,[1,2]).expand_until_length(N,L)whenis_integer(N),length(L)>=N->L;expand_until_length(N,L)whenis_integer(N),N>=0->expand_until_length(N,expand(L)).flip(1)->2;flip(2)->1.expand(L)->expand_with(1,L).expand_with(X,[1|T])->[X|expand_with(flip(X),T)];expand_with(X,[2|T])->[X,X|expand_with(flip(X),T)];expand_with(_,[])->[].main(_)->{L,_}=lists:split(100,koalakoskie(100)),io:format("one hundered values of it:~n~p~n",[L]).
Kolakoski's World.zipZip archive data, made by v2.0 UNIX, extract using at least v2.0, last modified May 11 2026 22:05:50, uncompressed size 0, method=store
dir Kolakoski's World v3
dir data
dir minecraft
custom_boss_events.dat gzip compressed data, original size modulo 2^32 30
1
cg: couldn't decode file contents
game_rules.dat gzip compressed data, original size modulo 2^32 1966
1
cg: couldn't decode file contents
random_sequences.dat gzip compressed data, original size modulo 2^32 2791
1
cg: couldn't decode file contents
scheduled_events.dat gzip compressed data, original size modulo 2^32 44
1
cg: couldn't decode file contents
scoreboard.dat gzip compressed data, original size modulo 2^32 30
1
cg: couldn't decode file contents
stopwatches.dat gzip compressed data, original size modulo 2^32 45
1
cg: couldn't decode file contents
wandering_trader.dat gzip compressed data, original size modulo 2^32 67
1
cg: couldn't decode file contents
weather.dat gzip compressed data, original size modulo 2^32 115
1
cg: couldn't decode file contents
world_clocks.dat gzip compressed data, original size modulo 2^32 118
1
cg: couldn't decode file contents
world_gen_settings.dat gzip compressed data, original size modulo 2^32 637
1
cg: couldn't decode file contents
dir dimensions
dir minecraft
dir overworld
dir data
dir minecraft
chunk_tickets.dat gzip compressed data, original size modulo 2^32 30
1
cg: couldn't decode file contents
raids.dat gzip compressed data, original size modulo 2^32 55
1
cg: couldn't decode file contents
world_border.dat gzip compressed data, original size modulo 2^32 212
1
cg: couldn't decode file contents
dir entities
r.-1.-1.mca data r.0.-1.mca data
1
cg: couldn't decode file contents
dir region
r.-1.-1.mca data r.0.-1.mca data
dir the_end
dir data
dir minecraft
chunk_tickets.dat gzip compressed data, original size modulo 2^32 30
1
cg: couldn't decode file contents
ender_dragon_fight.dat gzip compressed data, original size modulo 2^32 207
1
cg: couldn't decode file contents
raids.dat gzip compressed data, original size modulo 2^32 55
1
cg: couldn't decode file contents
world_border.dat gzip compressed data, original size modulo 2^32 212
1
cg: couldn't decode file contents
dir the_nether
dir data
dir minecraft
chunk_tickets.dat gzip compressed data, original size modulo 2^32 30
1
cg: couldn't decode file contents
raids.dat gzip compressed data, original size modulo 2^32 55
1
cg: couldn't decode file contents
world_border.dat gzip compressed data, original size modulo 2^32 212
1
cg: couldn't decode file contents
icon.png PNG image data, 64 x 64, 8-bit/color RGBA, non-interlaced level.dat gzip compressed data, from TOPS/20, original size modulo 2^32 569
1
cg: couldn't decode file contents
session.lock Unicode text, UTF-8 text, with no line terminators
post a comment