need to go to bed let's get this over with. decompose a numberoid. submissions may be written in any language.
you can break numbers, or things like numbers such as matrices, into other numbers. like when you factor an integer, which is a kind of decomposition into prime factors. or breaking an integer into sums of powers (301.5 = 3⋅10² + 0⋅10¹ + 1⋅10⁰ + 5⋅10⁻¹). what makes it decomposition is that at the end you get an equality, and you can compute the original number from the decomposition. I feel like the point is normally to represent the value in terms of a simpler, smaller set, like how you decompose all integers into only primes, or all numbers into only powers of a given base. I guess that's the point behind this problem.
anything invertible is permitted, though, so you could submit an identity function for all I care. that doesn't really feel like decomposition, though. it feels like you left it just as composed as it was... so maybe it's not in the spirit of things.
your challenge, given a number or whatever you want really, is to decompose it such that the original value can be reconstructed from the result. as any language is allowed, there is no fixed API.
it's 40 minutes past my bedtime man never procrastinate
# puppydog does group decomposition!r''' ############# ,------------------------.# __~~~~~__ # | i wruff group theory ! |# \_ O O _/ # <_________________________/# \ ' / ## ===== # ##/~%~%~%~\## '''(source):"https://www.tumblr.com/shiftythrifting/\823683395572858880/goodwill-grand-junction-colorado"# =============== How To Use! ===============# 1. Input the name of a finite group, such as# "C15" for the cyclic group of order 15.# 2. Wait a little while for the number to get# decomposed by the puppydog.# 3. Watch as the precise decomposition gets# printed to your terminal!# ===========================================defentry():numberoid=parse(input("Group please: "))print("Here you go!",classify_group(numberoid),"=",end=" ",flush=True)forQ,extindecompose(numberoid):print(Q+ext,end="",flush=True)print(__doc__)# puppydog says: here's the main algorithm! it's pretty pawsome!defdecompose(G):whileTrue:try:Hs=G.unique_proper_subgroups()N=max(filter(G.is_normal,Hs),key=lambdaH:H.order)Q=G/Nyieldclassify_group(Q),classify_extension(N,G,Q)G=NexceptValueError:yieldclassify_group(G),""break# puppydog says: this only supports cyclic groups for now :3defparse(s):ifs.startswith("C"):importsyssys.path.append([pforpinsys.pathifp.endswith("site-packages")][0]+"/src")fromfinite_algebrasimportgenerate_cyclic_groupreturngenerate_cyclic_group(int(s[1:]))# puppydog says: this only supports cyclic groups for now :3defclassify_group(G):ifG.is_cyclic():returnf"C{G.order}"# puppydog says: this only supports direct products for now :3defclassify_extension(N,G,Q):Q=Q.copy_algebra([e[1:]foreinQ.elements])# puppydog reminds you of the schur-zassenhaus theoremfrommathimportgcdifgcd(N.order,Q.order)==1:ifG.is_normal(Q):return"×"else:return"⋊"elifset(N.elements)<=set(G.center()):return"×ᶜ"# puppydog doesn't know how solve the extension problem :(return"?"# puppydog is excited to play with you !entry()# puppydog says good bye... i love you <3
usingSystem;usingSystem.Linq;usingSystem.Collections.Generic;namespaceIloNanpa.Soko{publicclassSoko{constbyteAla=0;constbyteWan=1;constbyteTu=Wan+Wan;constbyteLuka=Tu+Tu+Wan;constbyteMute=Luka+Luka+Luka+Luka;constbyteAle=Mute+Mute+Mute+Mute+Mute;/** * soko kasi li ko pakala e ma la, ilo ni li soko e nanpa tawa toki pona */publicstaticvoidMain(string[]pana){Console.WriteLine("o pana e nanpa:");ulongnanpa;stringlinja=Console.ReadLine();// toki tawa jan kepekenConsole.WriteLine("kili ona li ni:");if(ulong.TryParse(linja,outnanpa)){List<byte>kulupu=OSokoENanpaKepekenNasinNanpaPona(nanpa);Console.Write(string.Join(" ",kulupu.Select(n=>Nanpa.NanpaTawaSitelen(n))));if(kulupu.SequenceEqual(newbyte[]{5,2,1}))// o kute a e kalama pi jan UsawiConsole.Write(" 💃");Console.WriteLine();}else{Console.WriteLine(OKasiTawaNanpaTanSitelen(linja));}}/// <lili>/// o ante e nanpa tawa sitelen kepeken nasin pu pona/// </lili>/// <poka>/// ni li toki pona sama pu.////// pana ona li sitelen ala li nanpa tawa sitelen./// </poka>/// <pana nimi="nanpa">ni li nanpa li wan anu tu anu mute anu ala</pana>/// <kili>kulupu nanpa li nanpa e ijo la kulupu li jo e nanpa</kili>staticList<byte>OSokoPuENanpa(ulongnanpa){List<byte>kulupu=newList<byte>();// tenpo open la mi kama lili e nanpa lon tenpo sike// mi kepeken nanpa sitelen ale// te "wile nanpa en wan li ale" to li sama toki pona a a awhile(nanpa+1>Ale){nanpa-=Ale;kulupu.Add(Ale);}while(nanpa+1>Mute){nanpa-=Mute;kulupu.Add(Mute);}while(nanpa+1>Luka){nanpa-=Luka;kulupu.Add(Luka);}while(nanpa+1>Tu){nanpa-=Tu;kulupu.Add(Tu);}while(nanpa+1>Wan){nanpa-=Wan;kulupu.Add(Wan);}// tenpo pini la mi lukin e ni: nanpa li lon ala lonif(Ala>=kulupu.Count){returnnewList<byte>{Ala};}returnkulupu;}/// <lili>/// o ante e nanpa tawa sitelen kepeken nasin pi nasin nanpa pona/// </lili>/// <poka>/// nasin ni li kepeken nimi ale la nanpa open li mute ale e nanpa pini.////// pana ona li sitelen ala li nanpa tawa sitelen./// </poka>/// <pana nimi="nanpa">ni li nanpa li wan anu tu anu mute anu ala</pana>/// <kili>kulupu nanpa li nanpa e ijo la kulupu ni li jo e nanpa</kili>staticList<byte>OSokoENanpaKepekenNasinNanpaPona(ulongnanpa){// ni la nanpa li mute: nanpa pi nimi ale li lili, nanpa ni li suliulongnanpaMute=nanpa/Ale;if(nanpaMute>Ala){List<byte>tuLili;bytenanpaLili=(byte)(nanpa%Ale);// nimi "kipisi" anu nimi "%" li pona ala tawa mi// taso, nimi "tu" li pana e sona pi nasin nanpa, sona li tu ante a!if(Ala>=nanpaLili)tuLili=newList<byte>();elsetuLili=OSokoPuENanpa(nanpaLili);List<byte>tuSuli=OSokoENanpaKepekenNasinNanpaPona(nanpaMute);tuSuli.Add(Ale);tuSuli.AddRange(tuLili);returntuSuli;}returnOSokoPuENanpa(nanpa);}/// <lili>/// o ante e sitelen tawa nanpa kepeken nasin nanpa pona/// </lili>/// <poka>/// kasi li kama sitelen lipu li kepeken ma la, kasi li nasin soko ala/// </poka>/// <pana nimi="ona">ni li sitelen. kon li insa li sama sona tan sitelen la sitelen ni li kon sama nanpa lon</pana>/// <kili>nanpa li tan sitelen ona</kili>staticulongOKasiTawaNanpaTanSitelen(stringona){ulongaleWan=Ala;bytenanpaTan=Ale;foreach(stringsiteleninona.Trim().Split((char[])null)){if(string.IsNullOrEmpty(sitelen))continue;stringsitelenPona=sitelen.ToLower();if(sitelenPona.Any(sitelenLili=>sitelenLiliisnot((>='a')and(<='z'))))continue;bytenanpa=Nanpa.SitelenTawaNanpa(sitelenPona);if(nanpa==Ale&&nanpaTan<Ale){aleWan*=Ale;}else{aleWan+=nanpa;nanpaTan=nanpa;}}returnaleWan;}/** * ilo ni li ante e nanpa e sitelen */classNanpa{internalstaticstringNanpaTawaSitelen(bytenanpa)=>nanpaswitch{Ala=>"ala",Wan=>"wan",Tu=>"tu",Luka=>"luka",Mute=>"mute",Ale=>"ale",_=>thrownewArgumentOutOfRangeException("nanpa",nanpa,$"nanpa {nanpa} li ken ala sitelen la, mi li alasa ala e ni"),};internalstaticbyteSitelenTawaNanpa(stringsitelen)=>sitelenswitch{"ala"=>Ala,"wan"=>Wan,"tu"=>Tu,"luka"=>Luka,"mute"=>Mute,"ale"=>Ale,"ali"=>Ale,// toki ante_=>thrownewArgumentOutOfRangeException("sitelen",sitelen,$"mi alasa ala e sitelen nanpa ala ni: {sitelen}"),};}}}
fromfunctoolsimportcacheLIMIT=20000# <- keep low (just don't ask for the decomposition of a big number and you'll be fine :3)OP=3# <- raise this to make it funnier# ^ the bigger the less interesting@cachedefhyperop(n:int,a:int,b:int)->int:"""i stole this but idk where"""ifn==0:returnb+1ifn==1:returna+bifn==2:returna*bifn==3:returna**bresult:int=1for_inrange(b):result=hyperop(n-1,a,result)ifresult>LIMIT:# if it's too big we need to discard it asapreturnLIMIT+1returnresultprimerer:list[int]=[]no:dict[int,list[list[int]]]={}defcheck(v:int=1,chain:list[int]|None=None):"""it's a bit slow but it works"""ifchainisNone:chain=[v]forninprimerer:# print(f"{n} {'*' * (OP - 1)} {v}")t=hyperop(OP,n,v)new_chain=[n]+chainift<=LIMIT:iftinno:ifnew_chainnotinno[t]:no[t].append(new_chain)print("Duplicate!!")print(f"{v=}{n=}{t=}{chain=}{no[t]=}")else:no[t]=[new_chain]check(t,new_chain)else:break# primerer is sorted, no need to raise it to even greater powers if it already failsforiinrange(2,LIMIT+1):ifi%100==0:print(i)ifinotinno:primerer.append(i)ifhyperop(OP,2,i)<=LIMITorhyperop(OP,i,2)<=LIMIT:# HYPEROPTIMIZER2000check()defdecompose(x):assertx<=LIMITifxinno:returnno[x][0]ifxinprimerer:return[x,1]raiseKeyError("?")defrecompose(x:list[int],y:int=1):ifnotx:returnyreturnrecompose(x[:-1],x[-1]**y)# Usage: decompose(<your number>) gives a list, recompose(<list>) gives your number back# keep your number below LIMIT# Example: decompose(1331) >>> [11, 3, 1] ; recompose([11, 3, 1]) >>> 1331# Since 11 ** 3 ** 1 = 1331# list(filter(lambda x: x not in primerer, range(LIMIT))) is fun
post a comment