Imprima infinitamente o paradoxo da dicotomia de Zenão (1 / (2 ^ n))


31

Wikipedia: Paradoxo da dicotomia de Zenão

Um número infinito de matemáticos entra em um bar. O primeiro pede uma cerveja. O segundo pede meia cerveja. O terceiro pede um quarto de cerveja. O barman os para, bebe duas cervejas e diz: "Vocês são todos um bando de idiotas".

Reddit

Imprima a série a seguir enquanto o programa for executado, com o denominador de cada item multiplicado por dois a cada vez:

1 + 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + ...

À medida que se naproxima do infinito, a soma dessa sequência se aproxima 2.

Regras

Não, você não pode imprimir 2.

Você não pode imprimir 1/1como o primeiro item.

Você pode remover espaços 1+1/2+...ou adicionar espaços 1 + 1 / 2 + ...conforme necessário.

Você pode usar novas linhas em vez de espaços como um delimitador devido à demanda popular.

Você pode acrescentar um .número constante de 0s ao denominador, se necessário.

"Infinitamente" significa que não há atrasos desnecessários, e pelo maior tempo possível limitado pelas especificações do sistema atual (variável), mas não limitado pelo idioma atual.

Aplicam-se brechas padrão .

Isso é , então a resposta mais curta em bytes vence.


41
Quanto à piada, eu gosto mais da versão "Vocês devem conhecer seus limites".
Ho

14
Sou só eu ou isso é uma parábola ?
Adám 16/05/19

1
@StephenS Sim, eu também os vi, mas este é muito mais claro e maior.
Adám 16/05/19

10
@ Adám: sim! Se os comprimentos dos denominadores não estivessem mudando, o padrão visual de +1/s formaria apenas uma linha diagonal. No entanto, os comprimentos dos denominadores estão mudando linearmente (até o arredondamento): o número de dígitos de 2^né aproximadamente n log(2)/log(10). Essa mudança linear se traduz em uma mudança linear na posição relativa de cada uma +1/em relação à anterior, que é igual a uma mudança quadrática na posição absoluta .
Greg Martin

3
@QPaysTaxes então você não concorrentes - mas se várias pessoas querem postar respostas C competindo, você pode competir uns contra os outros :)
Stephen

Respostas:


14

05AB1E , 10 9 bytes

Guardado 1 byte graças a Erik the Outgolfer

[No…+1/J?

Experimente online!

Explicação

[           # loop over N infinitely [0 ...]
 No         # calculate 2^N
   …+1/J    # join with the string "+1/"
        ?   # print without newline

Você pode jogar isto:[No?…+1/?
Erik the Outgolfer

@EriktheOutgolfer: True! Eu sabia que a interpolação parecia um desperdício: P
Emigna

1
Tecnicamente, você deve usar em «vez de, Jmas isso também funciona.
Erik the Outgolfer

13
@EriktheOutgolfer 'deveria usar' não está no dicionário de golfistas.
Okx 16/05




6

APL (Dyalog Unicode) , 15 bytes

Mais divertido se ⎕FR( M ponto-loating R ePresentation) é 1287(de 128 bits decimal) e ⎕PP( P rint P recision) é de 34.

{∇2×⊃⎕←⍵'+1/'}1

Experimente online!

{}1 Aplique a seguinte função no número 1:

⎕←⍵'+1/' imprime o argumento e a string

 escolha o primeiro (ou seja, o argumento)

 dobrar isso

 recursão de chamada final (otimizada, para que possa ser repetida infinitamente)


6

C (gcc) , 60 bytes

f(){for(long long n=1;n;n*=2)printf(&"+1/%llu"[n^1?0:3],n);}

Aumenta o limite de 64 bits não assinado.

Experimente online!

Este continua para sempre; (é o menor possível)

C (TCC) , 312 264 255 251 233 231 208 204 195 190 188 170 bytes

l=4;c;main(i){for(char*t="*\b1+";puts(i=t),*++t=48;l=asprintf(&t,"1/%s",t+=*++t<49))for(t+=l-2;--t>i;)*t>52?*t=*t*2%58+c,c=*--t>52,*t=*t%48*2%10+49:(*t=*t*2-48+c+(c=0));}

Experimente online!

Aqui está a versão não tão golfe;

c;l=4;main(i){
    for(char*t="*\b1+";puts(i=t),*++t=48;l=asprintf(&t,"1/%s",t+=*++t<49))
        for(t+=l-2;--t>i;)
            *t>52?*t=*t*2%58+c,c=*--t>52,*t=*t%48*2%10+49:(*t=*t*2-48+c+(c=0));
}

5

Bash , 33 bytes

echo 1;yes|awk '{print"+1/"2^NR}'

Experimente online!

Alterar printpara printfe echopara printfevitar nova linha


1
printf 1também evita a nova linha, não?
Neil

No meu Awk (GNU Awk 4.2.1), sou repetido a +1/infpartir do 1024º período. :-(
Toby Speight

5

dc, 19 18 bytes

1[rdp+[+1/]Prdx]dx

Explicação

Nós empurrar 1e [rdp+[+1/]Prdx]na pilha. Em seguida, duplicamos e executamos [rdp+[+1/]Prdx]. A primeira coisa que faz é girar a pilha ( r) para que o valor fique no topo. dp+imprime o valor e se adiciona (para multiplicar por 2). [+1/]Pimprime o invariante e +1/, em seguida, rotacionamos os argumentos para que a definição da macro salva fique no topo, duplique e inicie novamente.

Notas

O GNU dcnormalmente quebra em 70 colunas. Para substituir isso e obter uma linha infinita, adicioneDC_LINE_LENGTH=0 às suas variáveis ​​de ambiente.

Saída (parcial)

1
+1/2
+1/4
+1/8
+1/16
+1/32
+1/64
+1/128
+1/256
+1/512
+1/1024
+1/2048
+1/4096
+1/8192
+1/16384
+1/32768
+1/65536
+1/131072
+1/262144
+1/524288
+1/1048576
+1/2097152
+1/4194304
+1/8388608

...

+1/1042962419883256876169444192465601618458351817556959360325703910069443225478828393565899456512
+1/2085924839766513752338888384931203236916703635113918720651407820138886450957656787131798913024
+1/4171849679533027504677776769862406473833407270227837441302815640277772901915313574263597826048
+1/8343699359066055009355553539724812947666814540455674882605631280555545803830627148527195652096
+1/16687398718132110018711107079449625895333629080911349765211262561111091607661254297054391304192
+1/33374797436264220037422214158899251790667258161822699530422525122222183215322508594108782608384

...

+1/395087429607039737016990582493211473623084548479366958355967894445617992237751193831383393115316177621785336292974757702861456280882511441699391271295733513512496264566385933380947965261723454959331220707759295808360415615991592990777778282040705827434949633856633176265789944580636935948031966453153742439217291986581128250733429493898120451931770274751229567569237843273729615827100381825373339221412595529512989073039623048380802736380367607801160720048450955272332555885534822792967746973597821924656959979423188656952212441297346660701518718326620774081406711639289159232374325676221430645461061339419517215005226454502285089841722594900476336947000733101279737598704985318796279216595068894677898277722179745279389210632125609476578229717704884251829483656808483833708957351468743071618868390065369478551657766868765417931368111672635805713040939576059856661966901849284974427853607640934780174510177467344954981530954324587346785943498033783853652888777144814836577685249298036748395273293867889213776236596621464513866240966454560881624123468744072759399999977952917047275150817022801141959157607304299710040536803961941539248511838228140896285208917844516516354328828341895189859625184919137459427696083645173496443173168837863941880276763158758023006149415211675330687766377148229974279566049003264864600191840267483777843342674487811516073311635515312490178552895957423373899881643180029114753167161849015185102165069678102141792645820016416047568386145306495107877487105159701033434133879076295235543592729076137504220533421618969333525966517622043110194920864084904515587227955524573123041514933277200135397957913967801292194452638091786561237904399020102666362253691989299390107684868894715745836877407032377238840608843413131092703960427769853699078374834491936996044463254349297156213103279673169178505184701872144900045771102435610296184197209227529288007415067046022722582981596269522005749627981773526366438220575437177263889604130699335432595226257543492333263422050922067270179224260275144056594379835114406083447004727056013389366056869669871721247387721885160070482303207498193981625368149767105925975387341377059500273590145880590627076202552189658057673577965137474478445230279151378408213456608653443746420052642315479741917201353741316367530727339674720984684319607014456047714106368632178729336223365487529774958557802515621876807522117219692963254636001726226095376131918803784811313633676500693288681886899229878108736316145573597053282102794465392580102681361770473681924380592794825281026389925319284295575976905371805098869309557779427667880257736023553969079065990247752442478709560271890544575319753044785213713815214853531493050977096589318122209182622944866896029727456835427297057238010067400316328458733735151924868494740318125717480345439976856588095695103557933254518724035147790867900860802490856266882895272405233909349503100342835778128113450704055933916580251051242513114247923234285375218348330984968499261151666279876934252251642210658880406798177100551493117002184732295738827350073267361848262282761987958004309963517948938698786164969644086580797555934352507402669257430636696930339621666387272089588481086182797065416819524024244039514527278555283258634786254208521110348742241263325816002709937195402337679130173170319173019473143013813053957781486624112400998612123509635383191611221055251405429574982431605111210811909998737934637009821942743916100790356493781569074043021092914565490511459722069379412568362070588905824887062692251966557571063144913628359617852782242850667347243493635423170856735991445443417871593754841930126545261100978250334790401134417708085254996280546469054953434698740338004535923304134925010294666195488077033498408573400230908456372758784275514839518209197168385986800728708864486555574751038959875865944573232904382772174165469240721191260083414343513721167588202103644839217795869540476457367497547061295275817063645407861999254441068513089288941238387198872484274061935238732418142521129602424711571463536885701004481109813887972526424268833936301999940489737888191570936888484964073548401260573294755586807219169314540668429632835157545851763722427756273879072731431505757610169922077517245770967529970605394054778171352769192297060429577138791870011615935227225671201093581479973265123899759178588060627003483624484718952553536175080141557411018195112843918387330586945434704681386712037849132186150132261042825792865372648754304087311364485783913995232206503295131703588146450037893765442335625163597434960232164031867939806213034434955304659392517248083742743104580255027984810817258473711668510466293353159230682507713356536346933373222621074069493621551732890007902642898203729353535541505055230646447927335528957518174124051240324790069803454443268705032437412987085956986231654396653945449361791419385673388462153863206838157383577706049673416137197255949136605805960826652037358130882947815724836422987739828579124410515444240566417712451706437934444715054112852437374620837818318965333233036720725057182268814289785426876890730560232557019341916693475054757150722335726164285001394620207185098209060247075408696040161086332399037926647184391403995691066367778171562567400295434214765373073532471221761418214238803246752363904522571261072568011082281025572468893579252790734242527127778212414258417151636760753113090140644900683087184729743937692882688781682528416310850143754232086010450547458252820624921499276046395019090380887163852054555145431526258731837552253081278815739277412689465695941457195947520449547528479195654921291630947757961099209920460560771007698446991318388178005121886864829789281989687868033416542896922010329803510712241486910230176578077334774066133073728498756538589509813926190053693968878600638282582915610844019713891397117761984470765139228094313389312619025293455644485019485659751869296503689550132880058360683768191850360853185346730443998577670217447676572006007846832281428067265029500735963006405097225737892017644266262369462412574469988693558883982457143609025342185734610083070158152370952984896142295431884162794373897052159892645389273308325006511838982963210612512322440419463781685703879460818754246754737940067675306280339905099665753185624213049959974358988865877958103529903146946530778345631329029194118707823987745182366133711832776917746326752560414432248765580001690261776455186768733481157296158946100861665048300648945542904325905584298490513362292415753190834332376223017933102895303381625772236869056493905619864331052324553111223626084907937012036147356323467349271564345943614252673724659330963224126235367389507942684619417763187571792457049977423564605600407492739749810469638764253641886550627347410736476168235036323056296424076410773881349066193975356477998788704088168252906853359434516247984743194831348262718121306661583008435884810496549588343058262321647390735264606206072011103907091768882769468469548172289382501112430456154299134997391379920716169599617338345446024206416533732905022779643316661925667780044405263747380549446190984315096751598520871084659561682150880941631909886116710336501837005063103142970019870229280161913535898896273821723701749825424198801867406788183134913924263719112061721504776882103064064359808662664627132885266814050508776452910137134270723647297071012906850061114810029573681278211481183908305090518470607821191868530182355469879320671285317749034490711147615749836523756450457907560809808180752736277635732973149879636046843370244031978388137905356568834841691405960511052920098099303117458443459752992376005588918461949244074455720525010639887497443006893435915417651916819463649597517491710312592729976616519543890099530933526832155577274386878813332226092536388499227272797049735342204092718218399418943214483876032335170210620818582577397681191807311146697580973912033655792648256970866595194893815163653986467309514803085649995372052311880524198806710857097759813038371950266290297264677343705141037392715602877631695706464175624716337179764939952510203992806290410817066938678282725721991737936771618886658531530432671336707243253399686635114284033467196647570867723924592346710336310499837157847001000657477981583545401290986926236963825871995956812647720239548464931532537453731179201219809243551668681899320550475784370849798950308066492614030400947685348077036376906960967572117048503094709377111019534286030732015239027627742931733097540469889785438409079499563218182778062136770448874634337602252200785481498083800414471627026908575019040813241133085007748236210770824190826032543188084102056377610344497047314070899072279218186771810995166773473114538521089207373662535516843804894247865222415416567979253467876905240369631759382670743540819101472322524971913190038014207087495403005280426785325932475391049960936934038679922250485974423425021273852536322945163397389403648570637150505325367515540775710473683840127830499238530870104153509651904712990936272485771980487060597330426352158711289651715205689049260499430924095066894960045670014855252638636173892541721664064657257545484662281992727145339820179787932300136239018814532042680306206506846252926868289215506270940648380151080863903543873800421024947008029227493253733743659931460789009603522492213592492048391771760673166705432907234322574655099086321398830175703899404965151123193886696442296349071654094637032308306856955288952171834242794325316103826542731616585851913306273167685606136686470354702529673355285989172690078260014657789396032732932707667614838197171927208752920806753147947753042162645589267309328014049843059474903297455903512702132260588248559475081881636853227563097955967083889828222963665998878755153458074282990405836509465604418489946220280072051695243646682126417012619626420434704676470720900405053137991022528724677776185782640188543273087475178910478479476375475107166115050700098469965773154824987334911488998504643031126617426087742334881528986730831286510376127857270260065953591254351135389978509155685077650175013516418689843888963267814029997035174397017156131402312672241612206597456154522391107951335408620230202536389665726663417780482765640799333938105922754878613702760187032743689376707408517940178159467558086798870508509302008010853150053660329410964652409126276870654180681874881929746118180582577305743743952810779398262012426174907734327106136327201729744548683488487099663898103452434942210300833833130143850134675972327857405316343100019819653706594138235142730877703690741728508059492138642914276288984044042099728558960754700526065507631173050607164329771213342522618716881636690451903407693545135452815509580836160948812037959966193150381363591325661363476282370880535386441056486977358792737573438415565582362150808790336607040072093996865509619115356670599413230372818843108462117192738018820456322869946146303496007938903379241735817413492283835977534999446414774242209937016102619721220743544264050400097257089329412409254182040067187294506795767071674839385327568309523275288224086341778500123181829914635212704885959073672849205647176312287693211208290617090697646296209359258826200442497277991265116001163923419756327042484575648575021801534747270301153864412881912695313170393490767798464601324811063517942109518188821662675241828342647930010935849739305511205479557635171775009458846115428296418509860882903797249010462815241310630703763917719343099389989212618131651857779639943520010464854895769226125734400676226305595574413150903275614989606378324476097633897174939587875967658516048531378475872344597620732910259889372637316612851578821200108167426224067862632022377346659611324512681594932786190395749866081212126765942648631311170725777632375318331458676692976060778353923365207931601783140329977239640697677390642952067751304225189275891914656263416947084450120234441671746028997201191323195215386733714871687707800672016820227681962426204834017171078741804363016905452036367437049026691141558129758797699640194324162736418976728910597423824473007553073364103514575141561781882871644975070955229562369626756867869338986838760342284146441315204683418587181558372435743877156433485354976428152730039744389279516110761771426764201299330794471271711515888964165405659366091810847151036007173905114063582213623053963744257889874028150526901847782612540828524150747603549047215293759454581158155329597162690004775971455898321404025294368662413692106436456898487879798453482089212957398027468299542185050952024424434257748368440629523534889927058704389099405555033480560657504105905182439365431354241976084762913941805532894762520886571190102966212136887152569491150928851182909057450691899990027643415972827215164457661126843197212359209124565023629842753704005053902959730902144697324536284243222516487451881162143985260026576702277354398701943268311327348278723577644934801132856940314800246225039733533484807420506534462368695104335500466194188432862110475125223174190441086648726124829278566262264102582145477455790001229962128988151514777487437037270487153943987721550211938223551105161674656128149829492208549801379399145307479176248550539143187103073739912305990874163539516471346476299608693068764303029104908023285789101921870714244184682024700760361462663101570206457539892273492121502188312469283565918477771845191345920751263742268857954344987825767697329023593992910217713704972512065484949552264125935161622986929633713130569797577128578214458329586269690647799782014649930675405127944876912350950231416318397349447230393724491695757547080501396519382299957816346147421987910768628451509475789472047213399478200233594932011006341697414362898632815522642132016614650400350428923555620918057200926864089035767073332791867816685434096971239607592477801325642486235952866653992824568229542798606247131414859323219085694179902810098535657962013883197934894815206949876469106535355971101217848490155179261164663801145917802217034896618411596621165894170862154553621702226207363854759575529806758207708865406552630203012980490505941247406029120385466493805043607084819136763318505396587786149987409414795363172301089051894908740418011869835127044174788340738050919777596148274325858751879060573875387047962263073964078212858407556731801896720172173402451609345514653369843948925865731285026645995919856979876708543976520293377113985661155885697067770340963454255462317778374708234636608739119582761909701893485235072604937207880557091958509260575756938640165512270322212561952906328322017549014849215824787611893951617083671247652355225313571195438343636594795213938009780362376632674524801606712889751259220696409500370952911456813275349818073892021046409289255786132787385187019129176514080173483822613572793996361788110041096484931301484233630238022334653847275796035554791678720054505018864099939754669651544296841730613206450101627744726143047203934946454579761956034246397049238954525292315292293731998279977819953334814618383443186382455045395596531660361384999262672019010927022846744105110180629489154477796693814515782860555654300726449058256946453431271071240673715129993027272108615147743053163012016539090192335094681890199309163850322423174196757401200305496025245970076637786182016385654479388672
+1/790174859214079474033981164986422947246169096958733916711935788891235984475502387662766786230632355243570672585949515405722912561765022883398782542591467027024992529132771866761895930523446909918662441415518591616720831231983185981555556564081411654869899267713266352531579889161273871896063932906307484878434583973162256501466858987796240903863540549502459135138475686547459231654200763650746678442825191059025978146079246096761605472760735215602321440096901910544665111771069645585935493947195643849313919958846377313904424882594693321403037436653241548162813423278578318464748651352442861290922122678839034430010452909004570179683445189800952673894001466202559475197409970637592558433190137789355796555444359490558778421264251218953156459435409768503658967313616967667417914702937486143237736780130738957103315533737530835862736223345271611426081879152119713323933803698569948855707215281869560349020354934689909963061908649174693571886996067567707305777554289629673155370498596073496790546587735778427552473193242929027732481932909121763248246937488145518799999955905834094550301634045602283918315214608599420081073607923883078497023676456281792570417835689033032708657656683790379719250369838274918855392167290346992886346337675727883760553526317516046012298830423350661375532754296459948559132098006529729200383680534967555686685348975623032146623271030624980357105791914846747799763286360058229506334323698030370204330139356204283585291640032832095136772290612990215754974210319402066868267758152590471087185458152275008441066843237938667051933035244086220389841728169809031174455911049146246083029866554400270795915827935602584388905276183573122475808798040205332724507383978598780215369737789431491673754814064754477681217686826262185407920855539707398156749668983873992088926508698594312426206559346338357010369403744289800091542204871220592368394418455058576014830134092045445165963192539044011499255963547052732876441150874354527779208261398670865190452515086984666526844101844134540358448520550288113188759670228812166894009454112026778732113739339743442494775443770320140964606414996387963250736299534211851950774682754119000547180291761181254152405104379316115347155930274948956890460558302756816426913217306887492840105284630959483834402707482632735061454679349441969368639214028912095428212737264357458672446730975059549917115605031243753615044234439385926509272003452452190752263837607569622627267353001386577363773798459756217472632291147194106564205588930785160205362723540947363848761185589650562052779850638568591151953810743610197738619115558855335760515472047107938158131980495504884957419120543781089150639506089570427427630429707062986101954193178636244418365245889733792059454913670854594114476020134800632656917467470303849736989480636251434960690879953713176191390207115866509037448070295581735801721604981712533765790544810467818699006200685671556256226901408111867833160502102485026228495846468570750436696661969936998522303332559753868504503284421317760813596354201102986234004369464591477654700146534723696524565523975916008619927035897877397572329939288173161595111868705014805338514861273393860679243332774544179176962172365594130833639048048488079029054557110566517269572508417042220697484482526651632005419874390804675358260346340638346038946286027626107915562973248224801997224247019270766383222442110502810859149964863210222421623819997475869274019643885487832201580712987563138148086042185829130981022919444138758825136724141177811649774125384503933115142126289827256719235705564485701334694486987270846341713471982890886835743187509683860253090522201956500669580802268835416170509992561092938109906869397480676009071846608269850020589332390976154066996817146800461816912745517568551029679036418394336771973601457417728973111149502077919751731889146465808765544348330938481442382520166828687027442335176404207289678435591739080952914734995094122590551634127290815723998508882137026178577882476774397744968548123870477464836285042259204849423142927073771402008962219627775945052848537667872603999880979475776383141873776969928147096802521146589511173614438338629081336859265670315091703527444855512547758145462863011515220339844155034491541935059941210788109556342705538384594120859154277583740023231870454451342402187162959946530247799518357176121254006967248969437905107072350160283114822036390225687836774661173890869409362773424075698264372300264522085651585730745297508608174622728971567827990464413006590263407176292900075787530884671250327194869920464328063735879612426068869910609318785034496167485486209160510055969621634516947423337020932586706318461365015426713072693866746445242148138987243103465780015805285796407458707071083010110461292895854671057915036348248102480649580139606908886537410064874825974171913972463308793307890898723582838771346776924307726413676314767155412099346832274394511898273211611921653304074716261765895631449672845975479657158248821030888481132835424903412875868889430108225704874749241675636637930666466073441450114364537628579570853753781461120465114038683833386950109514301444671452328570002789240414370196418120494150817392080322172664798075853294368782807991382132735556343125134800590868429530746147064942443522836428477606493504727809045142522145136022164562051144937787158505581468485054255556424828516834303273521506226180281289801366174369459487875385765377563365056832621700287508464172020901094916505641249842998552092790038180761774327704109110290863052517463675104506162557631478554825378931391882914391895040899095056958391309842583261895515922198419840921121542015396893982636776356010243773729659578563979375736066833085793844020659607021424482973820460353156154669548132266147456997513077179019627852380107387937757201276565165831221688039427782794235523968941530278456188626778625238050586911288970038971319503738593007379100265760116721367536383700721706370693460887997155340434895353144012015693664562856134530059001471926012810194451475784035288532524738924825148939977387117767964914287218050684371469220166140316304741905969792284590863768325588747794104319785290778546616650013023677965926421225024644880838927563371407758921637508493509475880135350612560679810199331506371248426099919948717977731755916207059806293893061556691262658058388237415647975490364732267423665553835492653505120828864497531160003380523552910373537466962314592317892201723330096601297891085808651811168596981026724584831506381668664752446035866205790606763251544473738112987811239728662104649106222447252169815874024072294712646934698543128691887228505347449318661926448252470734779015885369238835526375143584914099954847129211200814985479499620939277528507283773101254694821472952336470072646112592848152821547762698132387950712955997577408176336505813706718869032495969486389662696525436242613323166016871769620993099176686116524643294781470529212412144022207814183537765538936939096344578765002224860912308598269994782759841432339199234676690892048412833067465810045559286633323851335560088810527494761098892381968630193503197041742169319123364301761883263819772233420673003674010126206285940039740458560323827071797792547643447403499650848397603734813576366269827848527438224123443009553764206128128719617325329254265770533628101017552905820274268541447294594142025813700122229620059147362556422962367816610181036941215642383737060364710939758641342570635498068981422295231499673047512900915815121619616361505472555271465946299759272093686740488063956776275810713137669683382811921022105840196198606234916886919505984752011177836923898488148911441050021279774994886013786871830835303833638927299195034983420625185459953233039087780199061867053664311154548773757626664452185072776998454545594099470684408185436436798837886428967752064670340421241637165154795362383614622293395161947824067311585296513941733190389787630327307972934619029606171299990744104623761048397613421714195519626076743900532580594529354687410282074785431205755263391412928351249432674359529879905020407985612580821634133877356565451443983475873543237773317063060865342673414486506799373270228568066934393295141735447849184693420672620999674315694002001314955963167090802581973852473927651743991913625295440479096929863065074907462358402439618487103337363798641100951568741699597900616132985228060801895370696154072753813921935144234097006189418754222039068572061464030478055255485863466195080939779570876818158999126436365556124273540897749268675204504401570962996167600828943254053817150038081626482266170015496472421541648381652065086376168204112755220688994094628141798144558436373543621990333546946229077042178414747325071033687609788495730444830833135958506935753810480739263518765341487081638202944645049943826380076028414174990806010560853570651864950782099921873868077359844500971948846850042547705072645890326794778807297141274301010650735031081551420947367680255660998477061740208307019303809425981872544971543960974121194660852704317422579303430411378098520998861848190133789920091340029710505277272347785083443328129314515090969324563985454290679640359575864600272478037629064085360612413013692505853736578431012541881296760302161727807087747600842049894016058454986507467487319862921578019207044984427184984096783543521346333410865814468645149310198172642797660351407798809930302246387773392884592698143308189274064616613713910577904343668485588650632207653085463233171703826612546335371212273372940709405059346710571978345380156520029315578792065465865415335229676394343854417505841613506295895506084325291178534618656028099686118949806594911807025404264521176497118950163763273706455126195911934167779656445927331997757510306916148565980811673018931208836979892440560144103390487293364252834025239252840869409352941441800810106275982045057449355552371565280377086546174950357820956958952750950214332230101400196939931546309649974669822977997009286062253234852175484669763057973461662573020752255714540520131907182508702270779957018311370155300350027032837379687777926535628059994070348794034312262804625344483224413194912309044782215902670817240460405072779331453326835560965531281598667876211845509757227405520374065487378753414817035880356318935116173597741017018604016021706300107320658821929304818252553741308361363749763859492236361165154611487487905621558796524024852349815468654212272654403459489097366976974199327796206904869884420601667666260287700269351944655714810632686200039639307413188276470285461755407381483457016118984277285828552577968088084199457117921509401052131015262346101214328659542426685045237433763273380903806815387090270905631019161672321897624075919932386300762727182651322726952564741761070772882112973954717585475146876831131164724301617580673214080144187993731019238230713341198826460745637686216924234385476037640912645739892292606992015877806758483471634826984567671955069998892829548484419874032205239442441487088528100800194514178658824818508364080134374589013591534143349678770655136619046550576448172683557000246363659829270425409771918147345698411294352624575386422416581234181395292592418718517652400884994555982530232002327846839512654084969151297150043603069494540602307728825763825390626340786981535596929202649622127035884219036377643325350483656685295860021871699478611022410959115270343550018917692230856592837019721765807594498020925630482621261407527835438686198779978425236263303715559279887040020929709791538452251468801352452611191148826301806551229979212756648952195267794349879175751935317032097062756951744689195241465820519778745274633225703157642400216334852448135725264044754693319222649025363189865572380791499732162424253531885297262622341451555264750636662917353385952121556707846730415863203566280659954479281395354781285904135502608450378551783829312526833894168900240468883343492057994402382646390430773467429743375415601344033640455363924852409668034342157483608726033810904072734874098053382283116259517595399280388648325472837953457821194847648946015106146728207029150283123563765743289950141910459124739253513735738677973677520684568292882630409366837174363116744871487754312866970709952856305460079488778559032221523542853528402598661588942543423031777928330811318732183621694302072014347810228127164427246107927488515779748056301053803695565225081657048301495207098094430587518909162316310659194325380009551942911796642808050588737324827384212872913796975759596906964178425914796054936599084370101904048848868515496736881259047069779854117408778198811110066961121315008211810364878730862708483952169525827883611065789525041773142380205932424273774305138982301857702365818114901383799980055286831945654430328915322253686394424718418249130047259685507408010107805919461804289394649072568486445032974903762324287970520053153404554708797403886536622654696557447155289869602265713880629600492450079467066969614841013068924737390208671000932388376865724220950250446348380882173297452249658557132524528205164290954911580002459924257976303029554974874074540974307887975443100423876447102210323349312256299658984417099602758798290614958352497101078286374206147479824611981748327079032942692952599217386137528606058209816046571578203843741428488369364049401520722925326203140412915079784546984243004376624938567131836955543690382691841502527484537715908689975651535394658047187985820435427409945024130969899104528251870323245973859267426261139595154257156428916659172539381295599564029299861350810255889753824701900462832636794698894460787448983391515094161002793038764599915632692294843975821537256903018951578944094426798956400467189864022012683394828725797265631045284264033229300800700857847111241836114401853728178071534146665583735633370868193942479215184955602651284972471905733307985649136459085597212494262829718646438171388359805620197071315924027766395869789630413899752938213070711942202435696980310358522329327602291835604434069793236823193242331788341724309107243404452414727709519151059613516415417730813105260406025960981011882494812058240770932987610087214169638273526637010793175572299974818829590726344602178103789817480836023739670254088349576681476101839555192296548651717503758121147750774095924526147928156425716815113463603793440344346804903218691029306739687897851731462570053291991839713959753417087953040586754227971322311771394135540681926908510924635556749416469273217478239165523819403786970470145209874415761114183917018521151513877280331024540644425123905812656644035098029698431649575223787903234167342495304710450627142390876687273189590427876019560724753265349049603213425779502518441392819000741905822913626550699636147784042092818578511572265574770374038258353028160346967645227145587992723576220082192969862602968467260476044669307694551592071109583357440109010037728199879509339303088593683461226412900203255489452286094407869892909159523912068492794098477909050584630584587463996559955639906669629236766886372764910090791193063320722769998525344038021854045693488210220361258978308955593387629031565721111308601452898116513892906862542142481347430259986054544217230295486106326024033078180384670189363780398618327700644846348393514802400610992050491940153275572364032771308958777344
+1/1580349718428158948067962329972845894492338193917467833423871577782471968951004775325533572461264710487141345171899030811445825123530045766797565085182934054049985058265543733523791861046893819837324882831037183233441662463966371963111113128162823309739798535426532705063159778322547743792127865812614969756869167946324513002933717975592481807727081099004918270276951373094918463308401527301493356885650382118051956292158492193523210945521470431204642880193803821089330223542139291171870987894391287698627839917692754627808849765189386642806074873306483096325626846557156636929497302704885722581844245357678068860020905818009140359366890379601905347788002932405118950394819941275185116866380275578711593110888718981117556842528502437906312918870819537007317934627233935334835829405874972286475473560261477914206631067475061671725472446690543222852163758304239426647867607397139897711414430563739120698040709869379819926123817298349387143773992135135414611555108579259346310740997192146993581093175471556855104946386485858055464963865818243526496493874976291037599999911811668189100603268091204567836630429217198840162147215847766156994047352912563585140835671378066065417315313367580759438500739676549837710784334580693985772692675351455767521107052635032092024597660846701322751065508592919897118264196013059458400767361069935111373370697951246064293246542061249960714211583829693495599526572720116459012668647396060740408660278712408567170583280065664190273544581225980431509948420638804133736535516305180942174370916304550016882133686475877334103866070488172440779683456339618062348911822098292492166059733108800541591831655871205168777810552367146244951617596080410665449014767957197560430739475578862983347509628129508955362435373652524370815841711079414796313499337967747984177853017397188624852413118692676714020738807488579600183084409742441184736788836910117152029660268184090890331926385078088022998511927094105465752882301748709055558416522797341730380905030173969333053688203688269080716897041100576226377519340457624333788018908224053557464227478679486884989550887540640281929212829992775926501472599068423703901549365508238001094360583522362508304810208758632230694311860549897913780921116605513632853826434613774985680210569261918967668805414965265470122909358698883938737278428057824190856425474528714917344893461950119099834231210062487507230088468878771853018544006904904381504527675215139245254534706002773154727547596919512434945264582294388213128411177861570320410725447081894727697522371179301124105559701277137182303907621487220395477238231117710671521030944094215876316263960991009769914838241087562178301279012179140854855260859414125972203908386357272488836730491779467584118909827341709188228952040269601265313834934940607699473978961272502869921381759907426352382780414231733018074896140591163471603443209963425067531581089620935637398012401371343112512453802816223735666321004204970052456991692937141500873393323939873997044606665119507737009006568842635521627192708402205972468008738929182955309400293069447393049131047951832017239854071795754795144659878576346323190223737410029610677029722546787721358486665549088358353924344731188261667278096096976158058109114221133034539145016834084441394968965053303264010839748781609350716520692681276692077892572055252215831125946496449603994448494038541532766444884221005621718299929726420444843247639994951738548039287770975664403161425975126276296172084371658261962045838888277517650273448282355623299548250769007866230284252579654513438471411128971402669388973974541692683426943965781773671486375019367720506181044403913001339161604537670832341019985122185876219813738794961352018143693216539700041178664781952308133993634293600923633825491035137102059358072836788673543947202914835457946222299004155839503463778292931617531088696661876962884765040333657374054884670352808414579356871183478161905829469990188245181103268254581631447997017764274052357155764953548795489937096247740954929672570084518409698846285854147542804017924439255551890105697075335745207999761958951552766283747553939856294193605042293179022347228876677258162673718531340630183407054889711025095516290925726023030440679688310068983083870119882421576219112685411076769188241718308555167480046463740908902684804374325919893060495599036714352242508013934497938875810214144700320566229644072780451375673549322347781738818725546848151396528744600529044171303171461490595017216349245457943135655980928826013180526814352585800151575061769342500654389739840928656127471759224852137739821218637570068992334970972418321020111939243269033894846674041865173412636922730030853426145387733492890484296277974486206931560031610571592814917414142166020220922585791709342115830072696496204961299160279213817773074820129749651948343827944926617586615781797447165677542693553848615452827352629534310824198693664548789023796546423223843306608149432523531791262899345691950959314316497642061776962265670849806825751737778860216451409749498483351273275861332932146882900228729075257159141707507562922240930228077367666773900219028602889342904657140005578480828740392836240988301634784160644345329596151706588737565615982764265471112686250269601181736859061492294129884887045672856955212987009455618090285044290272044329124102289875574317011162936970108511112849657033668606547043012452360562579602732348738918975750771530755126730113665243400575016928344041802189833011282499685997104185580076361523548655408218220581726105034927350209012325115262957109650757862783765828783790081798190113916782619685166523791031844396839681842243084030793787965273552712020487547459319157127958751472133666171587688041319214042848965947640920706312309339096264532294913995026154358039255704760214775875514402553130331662443376078855565588471047937883060556912377253557250476101173822577940077942639007477186014758200531520233442735072767401443412741386921775994310680869790706288024031387329125712269060118002943852025620388902951568070577065049477849650297879954774235535929828574436101368742938440332280632609483811939584569181727536651177495588208639570581557093233300026047355931852842450049289761677855126742815517843275016987018951760270701225121359620398663012742496852199839897435955463511832414119612587786123113382525316116776474831295950980729464534847331107670985307010241657728995062320006761047105820747074933924629184635784403446660193202595782171617303622337193962053449169663012763337329504892071732411581213526503088947476225975622479457324209298212444894504339631748048144589425293869397086257383774457010694898637323852896504941469558031770738477671052750287169828199909694258422401629970958999241878555057014567546202509389642945904672940145292225185696305643095525396264775901425911995154816352673011627413437738064991938972779325393050872485226646332033743539241986198353372233049286589562941058424824288044415628367075531077873878192689157530004449721824617196539989565519682864678398469353381784096825666134931620091118573266647702671120177621054989522197784763937260387006394083484338638246728603523766527639544466841346007348020252412571880079480917120647654143595585095286894806999301696795207469627152732539655697054876448246886019107528412256257439234650658508531541067256202035105811640548537082894589188284051627400244459240118294725112845924735633220362073882431284767474120729421879517282685141270996137962844590462999346095025801831630243239232723010945110542931892599518544187373480976127913552551621426275339366765623842044211680392397212469833773839011969504022355673847796976297822882100042559549989772027573743661670607667277854598390069966841250370919906466078175560398123734107328622309097547515253328904370145553996909091188198941368816370872873597675772857935504129340680842483274330309590724767229244586790323895648134623170593027883466380779575260654615945869238059212342599981488209247522096795226843428391039252153487801065161189058709374820564149570862411510526782825856702498865348719059759810040815971225161643268267754713130902887966951747086475546634126121730685346828973013598746540457136133868786590283470895698369386841345241999348631388004002629911926334181605163947704947855303487983827250590880958193859726130149814924716804879236974206674727597282201903137483399195801232265970456121603790741392308145507627843870288468194012378837508444078137144122928060956110510971726932390161879559141753636317998252872731112248547081795498537350409008803141925992335201657886508107634300076163252964532340030992944843083296763304130172752336408225510441377988189256283596289116872747087243980667093892458154084356829494650142067375219576991460889661666271917013871507620961478527037530682974163276405889290099887652760152056828349981612021121707141303729901564199843747736154719689001943897693700085095410145291780653589557614594282548602021301470062163102841894735360511321996954123480416614038607618851963745089943087921948242389321705408634845158606860822756197041997723696380267579840182680059421010554544695570166886656258629030181938649127970908581359280719151729200544956075258128170721224826027385011707473156862025083762593520604323455614175495201684099788032116909973014934974639725843156038414089968854369968193567087042692666821731628937290298620396345285595320702815597619860604492775546785769185396286616378548129233227427821155808687336971177301264415306170926466343407653225092670742424546745881418810118693421143956690760313040058631157584130931730830670459352788687708835011683227012591791012168650582357069237312056199372237899613189823614050808529042352994237900327526547412910252391823868335559312891854663995515020613832297131961623346037862417673959784881120288206780974586728505668050478505681738818705882883601620212551964090114898711104743130560754173092349900715641913917905501900428664460202800393879863092619299949339645955994018572124506469704350969339526115946923325146041504511429081040263814365017404541559914036622740310600700054065674759375555853071256119988140697588068624525609250688966448826389824618089564431805341634480920810145558662906653671121931062563197335752423691019514454811040748130974757506829634071760712637870232347195482034037208032043412600214641317643858609636505107482616722727499527718984472722330309222974975811243117593048049704699630937308424545308806918978194733953948398655592413809739768841203335332520575400538703889311429621265372400079278614826376552940570923510814762966914032237968554571657105155936176168398914235843018802104262030524692202428657319084853370090474867526546761807613630774180541811262038323344643795248151839864772601525454365302645453905129483522141545764225947909435170950293753662262329448603235161346428160288375987462038476461426682397652921491275372433848468770952075281825291479784585213984031755613516966943269653969135343910139997785659096968839748064410478884882974177056201600389028357317649637016728160268749178027183068286699357541310273238093101152896345367114000492727319658540850819543836294691396822588705249150772844833162468362790585184837437035304801769989111965060464004655693679025308169938302594300087206138989081204615457651527650781252681573963071193858405299244254071768438072755286650700967313370591720043743398957222044821918230540687100037835384461713185674039443531615188996041851260965242522815055670877372397559956850472526607431118559774080041859419583076904502937602704905222382297652603613102459958425513297904390535588699758351503870634064194125513903489378390482931641039557490549266451406315284800432669704896271450528089509386638445298050726379731144761582999464324848507063770594525244682903110529501273325834706771904243113415693460831726407132561319908958562790709562571808271005216900757103567658625053667788337800480937766686984115988804765292780861546934859486750831202688067280910727849704819336068684314967217452067621808145469748196106764566232519035190798560777296650945675906915642389695297892030212293456414058300566247127531486579900283820918249478507027471477355947355041369136585765260818733674348726233489742975508625733941419905712610920158977557118064443047085707056805197323177885086846063555856661622637464367243388604144028695620456254328854492215854977031559496112602107607391130450163314096602990414196188861175037818324632621318388650760019103885823593285616101177474649654768425745827593951519193813928356851829592109873198168740203808097697737030993473762518094139559708234817556397622220133922242630016423620729757461725416967904339051655767222131579050083546284760411864848547548610277964603715404731636229802767599960110573663891308860657830644507372788849436836498260094519371014816020215611838923608578789298145136972890065949807524648575941040106306809109417594807773073245309393114894310579739204531427761259200984900158934133939229682026137849474780417342001864776753731448441900500892696761764346594904499317114265049056410328581909823160004919848515952606059109949748149081948615775950886200847752894204420646698624512599317968834199205517596581229916704994202156572748412294959649223963496654158065885385905198434772275057212116419632093143156407687482856976738728098803041445850652406280825830159569093968486008753249877134263673911087380765383683005054969075431817379951303070789316094375971640870854819890048261939798209056503740646491947718534852522279190308514312857833318345078762591199128058599722701620511779507649403800925665273589397788921574897966783030188322005586077529199831265384589687951643074513806037903157888188853597912800934379728044025366789657451594531262090568528066458601601401715694222483672228803707456356143068293331167471266741736387884958430369911205302569944943811466615971298272918171194424988525659437292876342776719611240394142631848055532791739579260827799505876426141423884404871393960620717044658655204583671208868139586473646386484663576683448618214486808904829455419038302119227032830835461626210520812051921962023764989624116481541865975220174428339276547053274021586351144599949637659181452689204356207579634961672047479340508176699153362952203679110384593097303435007516242295501548191849052295856312851433630226927207586880688693609806437382058613479375795703462925140106583983679427919506834175906081173508455942644623542788271081363853817021849271113498832938546434956478331047638807573940940290419748831522228367834037042303027754560662049081288850247811625313288070196059396863299150447575806468334684990609420901254284781753374546379180855752039121449506530698099206426851559005036882785638001483811645827253101399272295568084185637157023144531149540748076516706056320693935290454291175985447152440164385939725205936934520952089338615389103184142219166714880218020075456399759018678606177187366922452825800406510978904572188815739785818319047824136985588196955818101169261169174927993119911279813339258473533772745529820181582386126641445539997050688076043708091386976420440722517956617911186775258063131442222617202905796233027785813725084284962694860519972109088434460590972212652048066156360769340378727560797236655401289692696787029604801221984100983880306551144728065542617917554688

...


i foi de 15 minutos T_T tarde, usam dpem vez de ddnpara salvar um byte
Felipe Nardi Batista

Eu costumava dnevitar a introdução de uma nova linha, mas considerei p(ao custo da produção mais feia). Na verdade, pensando bem, não é tão feio, afinal.
Toby Speight




4

Pitão, 10 bytes

#h~hyZ"+1/

Zcomeça como zero. ~hyZpost atribui o valor de 2*Z+1a Z. Assim, Ztorna 0, 1, 3, 7, 15, ...- se repetidas iterações sucessivas. hdepois imprime o valor um maior. #executa o loop infinito e "+1/obtém a formatação correta.


4

JavaScript (ES6) , 36 34 bytes

for(a=1;;a*=2)console.log(a+'+1/')

Experimente online!

Inspirado pela resposta de Jake Taylor .

Observe que isso é limitado pelo idioma, pois aé uma variável de ponto flutuante, não um número inteiro.

-2 bytes graças a @Stefnotch .


1
Você pode salvar 2 bytes, deixando de fora os colchetes depois do console.log. for(a=.5;;)console.log`${a*=2}+1/` Porém, sua solução é limitada pelo idioma, porque a é um flutuador, não um número inteiro grande. (O desafio diz que não deve ser limitada pela linguagem, mas sim por especificações do sistema.)
Stefnotch

1
Infelizmente, isso não funciona , porque os modelos marcados com interpolação passam mais do que um único argumento. Eu adicionei a nota sobre limitação, obrigado.
Eush77

1
Oh, sorry for not testing my code. Well, this code does shave off 2 bytes: for(a=1;;a*=2)console.log(a+"+1/")
Stefnotch

@Stefnotch Oh, and it's a lot simpler, too :) Thank you.
eush77


3

Java, 107 102 bytes

()->{for(java.math.BigInteger z=null,o=z.ONE,n=o;;n=n.add(n))System.out.print(n.max(o)==o?1:"+1/"+n);}

z=null exists to shorten the o=java.math.BigInteger.ONE into z=null,o=z.ONE, saving 12 bytes. z.ONE will not throw a NullPointerException because we access a static member and not an instance one.

Using int shortens the code, but fails to comply after 32 iterations.

Saves

  • 107 -> 102 bytes: n.compareTo(o)>0 turned into n.max(o)==o, thanks to an idea given by @Shufflepants

This looks like one of the only entries that attempts to meet the rule: ""Infinitely" means no unnecessary delays, and for as long as possible limited by the current (variable) system's specs, but not limited by your current language." but it still doesn't do that because BigInteger still has a max value of 2^(Integer.MAX_VALUE).
Shufflepants

@Shufflepants Where is that limit written? Nowhere ("may support values outside of that range"), so it's not a limitation of the language, but a limitation of the JVM, which then is the system. Also, "works on my computer", so good enough for codegolf ;)
Olivier Grégoire

If the implementation of a language or the JVM is considered part of the system and not the language, then you might as well use int instead of BigInteger.
Shufflepants

No, because int and all other primitive types are limited at the language level. Also, the BigInteger doc explicitly says that a limit is optional, not mandatory (and that the default JVM implementation uses that limit).
Olivier Grégoire

This function "BigInteger max(BigInteger val)" exists in the specification too, which implies, that while the limit need not be what the current implementation limit is, it implies in the specification that there must be some finite limit.
Shufflepants

3

Vim, 22, 21 bytes/keystrokes

qqyiwA+1/<esc>p@"<C-a>@qqxX@q

While testing this, you might run into issues with the current register values. To fix this, run

:let @q=''
:let @"=''

before running this, or by launching vim with

vim -u NONE -i NONE

1
absolutely beautiful.
Tyrannosaur

3

R, 35 34 bytes

cat(i<-1);repeat cat("+1/",i<-i*2)

Spacing is a bit werid but I understand that's ok.


1
You can use repeat instead of while(T): cat(i<-1);repeat cat("+1/",i<-i*2) for 1 byte less.
plannapus

3

Befunge 93: 14 bytes

1:.2*"/1+",,,#

Doesn't seem to be working on TIO. Is it written for some specific implementation?
eush77

@eush77 Looks like TIO expects a fixed 80 char width grid, causing the "#" to skip empty space instead of the next instruction. I usually test here, where the torus is adjusted to the size of the actual code.
karhell


2

Aceto, 20 bytes

 pL*
pd12<
p"M"
1+1/

Prints the sequence without any spaces. When run, you won't see anything for a little while, because of buffering, run with -F to immediately see everything.

  1. Pushes and prints a 1, then stores "+1/" in quick storage (the register).
  2. Pushes a 1.
  3. Multiplies by two, loads from the register, prints, duplicates, and prints.
  4. GOTO 3.

2

Go, 102 100 bytes

Go can be almost as bad as Java, apparently.

import(."fmt"
."math/big")
func main(){n:=NewInt(1);for{Print(n.String()+"+1/");n.Mul(n,NewInt(2))}}

Try it online! (Would be a good idea to avoid running any of these locally. :P)


No, not as bad as Java: Go is 5 bytes shorter :P
Olivier Grégoire

2

QBIC, 18 bytes

?1{q=q*2?@+1/`';`q

Prints each term on a new line.

Explanation:

?1       Prints 1
{        Infinite loop
q=q*2    Doubles q, starts at 1*2=2
?@+1/`  Prints the string +1/ 
  ';`      without tabs, newlines or other terminators (code literal, ; is a QBIC function)
q        Also prints q
         The infinite loop is auto-closed by QBIC at EOF.

We can save a byte with a more liberal output format:

{?q,A,┘q=q*2#+1/


2

C#, ̶6̶8̶ 154 bytes

void A(int b=1){System.Console.Write($"1{(b>1?"/"+b:"")}+");A(b*2);}

Here is a version not constrained by int

using System.Numerics;BigInteger b=new BigInteger(1);void A(){System.Console.Write($"1{(b>1?"/"+b:"")}+");b=BigInteger.Multiply(new BigInteger(2),b);A();}

Stops working very quickly once the denominator hits int.MaxValue
Rob

@Rob what should the behavior be?
LiefdeWen


Okay thanx, the new version should be sufficient.
LiefdeWen

As-is, nothing is actually printed because there's no call to A(); outside of the recursive call in the function. Also, BigIntegers have implicit conversions from primitive numeric types and built-in operators. So you can shave a lot (54 bytes?) off by changing the initial declaration to just BigInteger b=1; and shortening the multiplication to b*=2;
goric

2

JavaScript (ES6), 45 43 42 bytes

Saved 2 bytes, thanks @DanielM ! Saved 1 byte, thanks @eush77 for pointing it out.

=console.log;a=1;(1);for(;;)_(+1/${a*=2})

=console.log;(a=1);for(;;)_(+1/${a*=2})

_=console.log;for(_(a=1);;)_(`+1/${a*=2}`)

My first go at Codegolf, go easy!


3
I was going to edit a snippet in for you, but then I broke my browser and remembered this is an infinite loop question xD
Stephen

2
Yeah, had to restart my dev tools a couple times doing this!
Jake Taylor

The a=1 can go in the first part of the for, for(a=1;;) saving you a byte in extra semicolon.
DanielM

_(a=1), work's with DanielM's suggestion too
Felipe Nardi Batista

@eush77 That doesn't create the right output imo. It will always have a trailing +1/, not a fraction.
Jake Taylor


2

AWK, 3732 bytes

BEGIN{for(;;)printf 2^i++"+1/"}

Try it online!

Could remove the BEGIN and save 5 bytes if input were allowed. Using exponents definitely cheaper byte-wise than multiplication. :)

Hopefully 2^1023 is close enough to infinity (on my work computer). Unfortunately the TIO link truncates earlier than that (around 921). But 17726622920963562283492833353875882150307419319860869157979152909707315649514250439943889552308992750523075148942386782770807567185698815677056677116184170553481231217950104164393978236130449019315710017470734562946173533283208371259654747728689409291887821024109648618981425152 does seem pretty close to infinity. :)


2

Haskell - 66 62 60 51 49 chars

import Data.List
main=print$intercalate" + 1/"$map(show.(2^))[0..]

This prints the string constructed by printing the string representations of the powers of two starting from 1, separated by the string " + 1/".

The code itself is 49 bytes, the import and newline push it up to 66

Edit: (62)

Shaved 4 bytes by cutting out the import and defining intercalate with a much shorter name

f(x:xs)s=x++s++xs`f`s
main=print$map(show.(2^))[0..]`f`" + 1/"

Edit 2: (60)

Shaved 2 more characters by realizing I didn't need to use the (x:xs) list convention:

f(x:y)s=x++s++y`f`s
main=print$map(show.(2^))[0..]`f`" + 1/"

Edit 3: (51)

Reimplemented the definition of f and the map as the body of a fold to save 9 more characters

main=print$foldr((++).(++" + 1/").show.(2^))""[0..]

Edit 4: (49)

As was pointed out by Laokoni, I can remove the spaces to cut down 2 more bytes off the total:

main=print$foldr((++).(++"+1/").show.(2^))""[0..]

The challenge states that spaces in the output are optional, so you can save another two bytes.
Laikoni

Also noticed that the most recent version is the same number of bytes as the original would be if "intercalate" was in the Haskell base library.
archaephyrryx

1

Braingolf, 41 37 bytes

Saved 4 bytes because I realised I don't need the spaces, always read the spec thoroughly kids

1!_V"+/">!@R.[<!_>2*v<!@>R!_v!@R<1+>]

Try it online!

Can probably be golfed better, but it works.


1

Fourier, 20 bytes

1~io(43a1o47ai*2~io)

Try it online!

I think this may only work on Try it Online due to differences in how Python and Javascript handle large numbers.

Explanation Psuedocode:

i = 1
Print i
While i != 0
    Print "+1/"
    i = i * 2
    Print i
End While

Can you not move the Print i to the start of the While loop?
Neil

@Neil I could, but it wouldn't say any bytes
Beta Decay

Oh, I see now, you're not actually printing i.
Neil
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.