New answers tagged

0

naz, 64 bytes 9a5m2x1v3a2x2v1x1f1o0m1a1o0x1x2f1o0x1x3f1r3x1v1e3x2v2e0m1a1o0x3f Explanation (with 0x commands removed) 9a5m2x1v # Set variable 1 equal to 45 ("-") 3a2x2v # Set variable 2 equal to 48 ("0") 1x1f1o0m1a1o # Function 1 # Output once, set the register equal to 1, and output ...


0

Rogex, 27 bytes 90B300d00901e00100701a20f00 Try it online! Explained 90B 300 d00 # Set the loop value to 11 901 # Set the buffer to 1 e00 # While the buffer isn't equal to 11 100 701 # Print the buffer then increment it a20 # Print a space f00 # End loop Rogex answer number 2! Also, my 101st answer! (´• ヮ •`)


0

Rogex, 15 bytes 701300001600200 Try it online! The actual language isn't on TIO yet, so a python 3.8 interpreter with the program in the code section and the python interpreter split in the header and footer is provided Rogex is a newly developed language that I've recently discovered, so I though I'd give it a crack and write an answer. Explained ...


0

W, 3 bytes You know, we can't beat the built-ins. 1S/ Explanation a1S % Stack : 1 a / % Divide.(1/a) % Output.


2

naz, 50 bytes 1x1f1a1o2x1v0m9a1a1o1v0x1f1f1f1f1f1f1f1f1f8s1o1s1o Explanation (with 0x commands removed) 1x1f # Function 1 1a1o # Add 1 to the register and output 2x1v # Store the new value in variable 1 0m9a1a1o # Output a newline 1v # Read variable 1 into the register ...


0

TI-BASIC, 13 bytes sum(Ans=seq(X!,X,1,69 Input is an integer in Ans. Output is 1 if the input is a factorial, 0 if not. Due to precision in = checks being limited to 10 decimal places, this program will produce erroneous answers for numbers whose length is \$>10\$ digits. Explanation: seq(X!,X,1,69 ;generate a list of all factorial numbers ...


0

Fortran (GFortran), 57 bytes read*,i k=1 do j=1,i k=k*j if(i==k)l=1 enddo print*,l end Try it online! On some compilers may result in gibberish on false-y due to uninitialised l. Can be solved with 3 bytes (l=0) or compiler flags (e.g. -finit-integer=0). Strictly 1 is not a truthy in Fortran, but spec specified 1/0 for true/false.


0

Burlesque, 13 bytes riJro?!jFi0>= Try it online! If you accept -1 as falsey (technically isn't in burlesque) and >0 as truthy can save 3 bytes. riJ # Read as int and duplicate on stack ro # Range from [1,N] ?! # Factorial each jFi # Find the index of the element == N 0>= # Found index


0

GolfScript, 17 bytes ~.),{,1\{)*}/}%?) Try it online! Explanation ~ # Evaluate the input . # Duplicate the value ) # Increment the value , # Generate range from 1 to input { }% # Map every item , # Generate a to-0 range 1\ # Make the initial ...


1

Burlesque, 1000 or 1111111 1e3 1cy7.+ Try it online! First the boring method just printing 1000, or making an infinite number of 1s and clipping it to the length of the code+1.


0

Fortran (GFortran), 24 ones print*,("1",i=1,23) end Try it online! Better Fortran score by avoiding formats entirely.


1

naz, 100,000,000 11,111 1a5o Explanation 1a5o # Output "1" five times I slightly misunderstood the question at first — here's my original 8-byte solution: 1a1o1s8o


1

TI-BASIC, 3 bytes Ans-0 Very simple and works the same way as the top J answer. Input is an integer in Ans. Examples: 4:Ans-0 4 4:0-Ans -4


1

x86-16, IBM PC DOS, 47 bytes Binary: 00000000: 33c9 bd0a 0050 0bc0 7d09 50b8 2d0e cd10 3....P..}.P.-... 00000010: 58f7 d833 d2f7 f552 410b c075 f658 b40e X..3...RA..u.X.. 00000020: 0c30 cd10 e2f7 b020 cd10 5840 75d7 c3 .0..... ..X@u.. Build and test using xxd -r Unassembled listing: 33 C9 XOR CX, CX ; clear counter B3 0A MOV ...


3

APL (Dyalog Extended), 16 bytesSBCS ⎕0+⌈3÷⍨1 2×⌊⎕×√3 Try it online! A full program that takes y then x from standard input and prints a 2-element vector of integers. How it works: the math First of all, note that any Gaussian integer will be placed on the vertical diagonal of a diamond, with the point \$Z\$ placed at \$(x,\sqrt3y)\$ for some integer \$x,...


0

Burlesque, 24 bytes pe@3r@2././J2./x/.+CL)R_ Try it online! Pretty sure this can be shorter. Input read as a b pe # Parse input to two ints @3r@2./ # sqrt(3)/2 ./ # Divide b by sqrt(3)/2 J2./ # Duplicate and divide by 2 x/.+ # swap stack around and add to a CL # Collect the stack to a list )R_ # Round to ints


0

Burlesque, 122 bytes pe'1'9r@3co{".-"".*""./"}z[)FL{'0'0'.".+"}+]j{{}{tp}{)<-<-}{tp)<-}}j!!e!<-Ppra{pPj<-d!}msJ'=_+j{><}gB3co{rtp^}mwpe?+'.;;++ Try it online! Takes args as: "[[1,2],[2,3],[0,3],[1,0],[1,1]]" 3 pe # Push args to stack '1'9r@ # Range of characters [1,9] 3co # Split into ...


0

05AB1E, 57 54 bytes εžm3ôí…/*-ø"00.+"ª€SIFøí}yθèyнè}JD'=s.γžh'.«så}R2ôR».VJ Uses 0-based coordinates similar as the challenge description, and [0,1,2,3] for [0,90,180,270] respectively as inputs. Try it online or verify all test cases. Explanation: ε # Map over each of the (implicit) input-coordinates: žm # Push ...


1

PHP, 267 235 229 225 221 213 bytes <?php $t=[1,12,15,4,1];$j=$t[$k=$argv[1]];($o=$i=$t[$k+1])<5&&$o--;foreach(json_decode($argv[2])as$c){echo$s='/*-+963.85207410'[($c[0]*$i+$c[1]*$j+$o)%16];strpos(' /*-+',$s)&&$e="($e)";$e.=$s;}eval("echo'=',$e;"); Try it online! 6 bytes thanks to @Kevin Cruijssen. Input directions are: 0 is 0, 1 is ...


1

Burlesque, 39 bytes riXX:nz{J2dv{{9r@}{ro}}che!<-}m[tp)im++ Try it online! ri #Read as int XX #Return list of digits :nz #Filter for non-zero { J2dv #Divisible by 2? { {9r@} #Range a, 9 {ro} #Range 1, a }che! #Run based on if divisible <- #Reverse the range }m[ #Apply to each digit tp #Transpose digits )im #...


1

05AB1E, 16 bytes 0KεDÈi9ŸëL]íõζJO Try it online or verify all test cases. Or alternatively: 0KεDÈ8*>Ÿ{R}õζJO 0Kε9Ÿ¬L‚yèR}õζJO Explanation: 0K # Remove all 0s from the (implicit) input-integer ε # Map each digit to: D # Duplicate the digit Èi # If it's even: 9Ÿ # Pop and push a list in the range [digit, 9] ...


0

JVM Byte Code, 79 bytes The byte count given is for a complete class file that defines a class Code containing single static method Code which implement Fibonacci. A hex dump of the file is given below. 0000000: cafe babe 0003 002d 0004 0100 0428 4929 .......-.....(I) 0000010: 4901 0004 436f 6465 0700 0200 2000 0300 I...Code.... ... 0000020: 0000 0000 ...


3

Microsoft PowerPoint (33 Slides, 512 shapes to meet minimum requirements) Storage representation is in hexadecimal. Directions Click the blue square to advance the counter (or propagate the carry), or make an AutoHotKey Script to click it for you. You can view the number's digits at any time using the green buttons. (It causes unintended behavior if you ...


0

Ruby, D^6(9) (553 bytes) _='F=$a=0TEK#y-~yUx.Z@#F=x%2G1?0R1+Z(x/2).L@#x/2>>Z@.8t)VHt);x=F#fG2?A(8L@C8Z@IRf>2?fGv ?yRt-(f>v ?1R0)*cREf,E8L@CS(v+2,t6yCc,Z@I).A(K#Hy)G1?Mx,4,Z(FIR5UEK.D@;$>UxVd=c=0;t=7;u=14;while[xNOx-1CB>0][1];d=HHD@IVW;x=W;cGF&&[Hu)G0&&WGf&&![u=Md,4,FCt=A(t,d)],fJd,cCt6tCu6u)]];cNB&&[t=E~u&...


0

Ruby, 52 bytes ->x,y{a=x.size;a/=g=a.gcd b=y.size;(x*b/=g).zip y*a} Try it online!


2

C (clang), 70 68 bytes i;f(*a,*b,x,y){for(i=0;printf("(%d,%d)",a[i%x],b[i%y]),++i%x+i%y;);} Try it online! Takes input as pointer to a and b and the lengths, prints q to std out. We use the modulo of an iterator by the data lengths e.g. i % x and i % y to access data, when both modules are equal to 0 , i is LCM and the function terminates.


1

05AB1E, 7 bytes €g.¿δ∍ø Takes the input as a pair of lists of integers. Try it online or verify all test cases. Explanation: €g # Get the length of each inner list in the (implicit) input-pair of lists .¿ # Take the Least Common Multiple for the two values in this pair of lengths δ∍ # Extend both inner list in the (implicit) input-pair ...


1

APL (Dyalog Extended), 9 bytes ,¨/∧⍥≢⍴¨⍮ Try it online! Takes two input strings as left and right arguments respectively. Being able to take lengths as separate arguments doesn't really help. How it works ,¨/∧⍥≢⍴¨⍮ ⍝ left: string a, right: string b ⍮ ⍝ 2-item nested array of [a, b] ⍴¨ ⍝ Reshape (by cycling elements) each of [a, b] to ...


2

Perl 6, 35 bytes {$^a <<,<<flat $^b xx($a lcm$b)/$b} Try it online!


0

Ruby, 108 bytes ->a{b=[0];m=a.min (1..1.0/0).map{|n|c=p a.map{|x|c|=(b!=b-[n-x])} c&& b<<=n return n-m if b[-m]&&b[-m]>n-m}} Try it online! Explanation ->a{ input list b=[0]; list of representable integers m=a.min ...


1

Perl 6, 39 36 25 bytes -3 bytes thanks to Jo King {zip $_>>[^[lcm]($_)X%*]} Try it online! Explanation { } # Anonymous block $_>>[ ] # Index into both input arrays ^[lcm]($_) # Range [0,lcm) X%* # modulo array size zip # Zip


0

Z80Golf, 11 bytes 00000000: cd03 8047 af80 0520 fcff 76 ...G... ..v Try it online! I/O as byte values, takes a byte, outputs a byte. Assembly: call $8003 ld b, a xor a loop: add a, b dec b jr nz, loop rst $38 halt Z80Golf, 13 bytes 00000000: cd03 805f 193d 20fb 7dff 7cff 76 ..._.= .}.|.v Try it ...


1

JavaScript (ES6),  77 68 64  58 bytes Saved 6 bytes thanks to @AZTECCO Takes input as (a, b, a_length, b_length). (a,b,n,N)=>(g=i=>[[a[i%n],b[i%N]],...++i%n+i%N?g(i):[]])`` Try it online!


1

C (gcc), 85 76 bytes n;z(a,i,j)int*a;{for(n=0;a[n*2+i+j]=a[n%i],a[n+++n+i+j]=a[n%j+i],n%i+n%j;);} Try it online! Thanks to ceilingcat for reduction 85->76 bytes. The code above is golfed so that all the information is stored in a single integer array, which saves 2 bytes; the logic though is the same as previously with three arrays. Try code with three ...


3

J, 14 13 bytes ,./@($&>~*./) Try it online! -1 byte thanks to Bubbler This answer takes the two lists as its left arg, and the two list lengths as its right arg. ($&>~*./) is a dyadic hook which applies gcd between the two right arg lengths *./ and the reshapes the two left arg lists $ to that length after opening them &>. At this ...


1

Python 3.8 (pre-release), 78 76 bytes -2 bytes thanks to Noodle9 lambda a,b:zip((x:=len(b))//(g:=math.gcd(y:=len(a),x))*a,y//g*b) import math Try it online!


1

Wolfram Language (Mathematica), 42 bytes Thread@PadRight[#,{2,LCM@@(Length/@#)},#]& Try it online!


0

Rust, 12 bytes |n|n*(n+1)/2 Try it online! Anonymous function.


1

Charcoal, 21 bytes ≔¹ηW⊙θ﹪ηLκ≦⊕ηIEηEθ§λκ Try it online! Link is to verbose version of code. Takes input as an array of arrays and outputs as a double-spaced list of pairs. Explanation: ≔¹ηW⊙θ﹪ηLκ≦⊕η Count up from 1 until the LCM of the lengths of the arrays has been reached. (This O(n²) but even O(n) would cost 3 bytes.) IEηEθ§λκ Map over the implicit ...


0

Perl 5, 104 bytes sub f{($A,$B,%s)=@_;map[$$A[$$_[0]],$$B[$$_[1]]],grep!$s{$$_[0],$$_[1]}++,map[$_%@$A,$_%@$B],0..@$A*@$B} Try it online! Slightly ungolfed: sub f { ($A,$B,%s) = @_; #input A and B, %s is the "seen" dictionary map [$$A[$$_[0]], $$B[$$_[1]]], #convert indexes to values from input A and B, return that. grep !$s{$$_[0],$$...


3

R, 69 60 54 51 bytes function(a,b,x,y)cbind(rep(a,y/sum(!(1:x*y)%%x)),b) Try it online! Loosely based on my answer to this question. Takes a,b, and the lengths as x and y, respectively. Returns a two-column matrix. Thanks to Robin Ryder for saving 4 bytes, and then another 3. Relies on the identity \$xy=GCD(x,y)\cdot LCM(x,y)\$; repeats a by \$y/GCD(x,...


3

Jelly, 7 bytes ṁ€æl/}Z A dyadic Link accepting a list of the two lists on the left and a list of their respective lengths on the right which yields a lists of lists. (A monadic Link accepting only the left argument costs 8 bytes, ṁ€Ẉæl/$Z) Try it online! Or see the test-suite. How? ṁ€æl/}Z - Link: list of lists [a, b], list [length(a), length(b)] } ...


0

PHP, 380 338 287 279 bytes <?php $s=array_fill(0,$n=strlen($u=$argv[1]),0);$m=[];g:if(array_sum($s)==$n){$b=[];$p=0;$k=1;foreach($s as$c){$c&&($b[]=substr($u,$p,$c))[0]==0&&$c>1&&$k=0;$p+=$c;}if($k&&array_unique($b)==$b&&$b>$m)$m=$b;}for($i=0;;){if(++$s[$i]<=$n)goto g;$s[$i++]=0;$i==$n&&die(print_r(...


1

Burlesque, 24 bytes PppPsu5cb{++pP==}f[:U_[~ Try it online! Not necessarily the best method, think I could probably save on some loading. Pp #Save number (as str) for later use pP #Load number su #Find all substrings of number 5cb #Find all combinations of substrings of length 5 (as list of list of str) { ++ #Concatenate all strings pP #...


2

APL, 9 chars/bytes 2≡≢∪∨∘⍳⍨⎕ get the input ⎕ compute least common divisor between n and all integers from 1 to n ∨∘⍳⍨ count of unique values ≢∪ if it's exactly 2, then it's prime 2≡


1

C (gcc), 19 bytes #define f(n)n*-~n/2 Try it online! C (gcc), 15 bytes f(n){n*=-~n/2;} -5 bytes thanks to ceilingcat! Try it online!


0

Perl 5, 119 bytes sub f{($s=$_=shift)=~/\b(\d+)\b.*\b\1\b/?push@_,grep!/\b0\d/,map$s=~s/^((.*?,){$_}.*?),/$1/r,0..y/,//:return$s while@_} Try it online! sub f { ($s=$_=shift) #get next trial =~ /\b(\d+)\b.*\b\1\b/ #duplicate exist in trial? ? push @_, #if so, add ...


2

BrainFuck, 41 Bytes -[----->+>+<<]>---<++++[->+.+.<]>+.>--.-. Output 12345678910 Try it online


1

GolfScript, 6 bytes It hasn't been done? Then great. Generates 0 to 10 and removes 0, then it evaluates. 11,1>` Try it online!


0

GolfScript, 10 bytes Empty list is false, a list with something is true. (Seems like cheating. But it isn't.) ~32base 4& Try it online! Explanation ~ # Evaluate the input 32base # Convert to base-32 # Copy 4& # Setwise and: does this list have 4?


Top 50 recent answers are included