Posts by snail_
Ahead, 3 bytes SW@ S Slurp entire input to stack W Write entire stack @ End Try it online!
Two words are anagrams of each other if the letters of one can be reordered to spell the other; e.g. ADOBE and ABODE are anagrams. An alternate way of describing it is that both words contain the s...
Ruby, 38 bytes Simple map and sum over the coefficients. No TIO link, this uses numbered lambda parameters which require Ruby 2.7. ->l,x{l.each_with_index.sum{_1*x**_2}}
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, 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!
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....
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, 34 29 bytes ->s,n{s.chars.map{_1*n}*""} Try it online!
If you have any tips for golfing in Ruby, share them as answers to this post.
Ruby, 7 solutions 256 4**4 -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-...
Ruby, 27 bytes ->n{x=[];n.times{x<<x*1};x} ->n{ } # lambda taking n x=[]; # set x to empty array n.times{ }; # repeat...
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 ...
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!
jq, 32 27 bytes -5 bytes (thank you Razetime) .n as$n|.s/""|map(.*$n)|add Try it online!
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, 43 bytes ->n{(1..n).map{|i|" "*(n-i)+?/*i+?\\*i}*$/} ->n{ } # lambda (1..n).map{|i| } # map over 1 to n ...
Ruby, 58 bytes Simple eval solution. Using ** for exponentiation. ->a,b,c{%w[+ - * / % **].select{eval("#{a}#{_1}#{b}")==c}} Attempt This Online!
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...
Ahead, 10 bytes IO"@O+I"W@ This prints N1I+0@. Try it online!
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...
Ruby, 28 bytes puts"puts #{gets}+gets.to_i" puts"puts # print P2, which prints #{gets} # P1's input value, interpolated +gets.to_i" ...
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!