Posts by snail_β
BQN (CBQN), 10 bytes Anonymous function that takes m on the left and n on the right. {π¨βΏπ©β₯βπ¨Γπ©} βπ¨Γπ© # list of range [0,m*n) π¨βΏπ©β₯ # reshape list to m*n Try it here!
BQN, 13 bytes {+Β΄(π¨βββ π©)Γπ©} { } # fn +Β΄ # sum reduce (π¨βββ π©) # x^i for each term Γπ© # times each coefficient Try it
Ruby, 28 bytes puts"puts #{gets}+gets.to_i" puts"puts # print P2, which prints #{gets} # P1's input value, interpolated +gets.to_i" ...
Ruby, 58 bytes Simple eval solution. Using ** for exponentiation. ->a,b,c{%w[+ - * / % **].select{eval("#{a}#{_1}#{b}")==c}} Attempt This Online!
Ruby, 110 106 bytes Fixed capitalization and refactored for -4. ->p,s{d=s-p s<2&&"Hole in one"||%w[Albatross Eagle Birdie Par Bogey Double Triple][d+3]+(d>1?" bogey":"")} Att...
Ruby, 51 bytes ->a{(0..a.map(&:size).max).map{|n|a.map{_1[n]}}*""} ->a{ } # lambda taking array `a` (0..a.map(&:size).max) ...
Ruby, 33 bytes Recursive lambda solution. c=->n{n<2?0:1+c[n%2<1?n/2:n*3+1]} c=->n{ } # c = lambda taking `n` n<2? : # if n...
jq, 32 27 bytes -5 bytes (thank you Razetime) .n as$n|.s/""|map(.*$n)|add Try it online!
Ruby, 34 29 bytes ->s,n{s.chars.map{_1*n}*""} Try it online!
Ruby, 15 bytes ->a{a.all?a[0]} ->a{ } # lambda taking array `a` a.all? # do all items in the array match... a[0] # ...the first? Try it online!
Ahead, 10 bytes IO"@O+I"W@ This prints N1I+0@. Try it online!
jq --raw-output, 32 bytes jq is the language of the month, apparently. Here it is! Not sure if the --raw-output flag really matters, someone let me know. "#"*.+(" #"+" "*(.-2)+"#")*(.-1) Try ...
Omitting parens on function calls You can omit parentheses on function calls in many cases. foo(bar,baz) foo bar,baz This is even true if a function call doesn't have any parameters. (This is...
Ruby, 51 50 bytes -1 from Razetime ->p,n{while i=p.find{(_1*n).to_f%1==0} n*=i end n} Try it online!
Ahead, 20 bytes I>:2%r vn:/2\< >}KO@ Control flow goes like this: # orange path: init I # read number # green path: main loop > # go east (start of loop) : # dup inpu...
Ruby, 11 bytes ->n{"%b"%n} Simple string formatting. Try it online!
Ruby, 7 solutions 256 4**4 -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-...
If you have any tips for golfing in Ruby, share them as answers to this post.
Ruby, 53 bytes ->n{n-=3;[?β+?β¦*n+?β,*[?β +?β¬*n+?β£]*(n+1),?β+?β©*n+?β]} Try it online!
Somewhere Else, there was a long-standing rule that to answer a challenge, you couldn't use languages, language versions, or features that were created or introduced after the challenge was posted....
Ruby, 67 65 bytes -2 from Razetime ->s,a{[s.center(l=a.map(&:size).max),*a,"BOTTOM TEXT".center(l)]} Takes the art and outputs as a list of lines. Try it online!
Ruby, 36 bytes ->a{i=-1;a.map{a[0..i+=1].count _1}} Try it online! The code in the TIO link is 2 bytes longer because _n block parameter names are not supported on TIO's Ruby instance yet. ...