We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

1

Pyth, 12 bytes qhQeo+*6hNeN Try it online! Pretty simple but Im happy with it. Takes (g1,b1),(g2,b2), returns True or False How it works qhQeo+*6hNeN qhQ - The first input is equal to.. eo - The last input of a sorted list (implicitly the input) +*6hNeN - With the key 6 * first (hN) + last (eN)


1

R, 28 bytes function(a,b,c,d)a*6+b>c*6+d Try it online!


2

Poetic, 751 bytes the game:a game o soccer for a moment of my fun,i kicked my leg o,i hurt a player o.m.gee,o no suddenly i then apologized a little o.m.gee,o no but really,i loved a good soccer battle a game i am doing,i love it there is a game,a twenty-to-one unwinnable match(as we called it,i mean)a match we won a wonder of an event i saw i played,i go ...


1

JavaScript, 40 bytes s=>['Spock','Lizard','Rock'][s.length%4] Try it online!


1

R, 52 bytes function(x)c("Spock","Lizard","Rock")[nchar(x)%%4+1]


1

Excel, 49 bytes Mod4 approach: =CHOOSE(MOD(LEN(A1),4)+1,"Spock","Lizard","Rock") Switching on last character: 57 bytes =CHOOSE(MOD(CODE(RIGHT(A1)),3)+1,"Lizard","Rock","Paper")


1

Pyth, 24 bytes @c."Lzž›^ºéëEL”‡"\`lz Try it online! Port of Jo King's mod-4 answer. Without the compressed string, it's 2 bytes longer: @c"Spock`Lizard`Rock`"\`lz


1

Python 3, 69 64 61 57 bytes lambda s:[["Scissors","Paper"]['k'in s],"Rock"]['i'in s] Not as short as the mod 4 solution, but not a bad alternative. Try it online!


3

Haskell, 43 bytes (k!!).length k="Spock":"Lizard":"Rock":"":k Try it online! The mod-4 approach. Longer approaches: f t|t<"Q"="Scissors"|t<"Sd"="Spock"|1<2="Paper" (47) f.last;f 'k'="Paper";f 'r'="Lizard";f _="Rock" (46) (["Spock","Lizard","Rock"]!!).(`mod`4).length (45) (words"Spock Lizard Rock"!!).(`mod`4).length (44) (cycle["...


1

Japt, 24 bytes `Spock Lizd Rock`¸gUÊu4 Try it "Spock Lizard Rock" //=>compressed .q(S) // split on " " .g(U.l().u(4)) // return element at index ( length of input % 4 ) Thanks to @Shaggy for the help


0

Batch, 87 bytes @set/ps= @for %%a in (Rock.d Rock.s Paper.k Lizard.r)do @if %%~xa==.%s:~-1% echo %%~na Takes input on STDIN. Works by switching on the last character of the input, which saves a case.


1

V (vim), 28 bytes 2ORock Lizard SpockLÝkYHVGp Try it online! Hexdump: 00000000: 324f 526f 636b 0d4c 697a 6172 640d 5370 2ORock.Lizard.Sp 00000010: 6f63 6b1b 4cdd 6b59 4856 4770 ock.L.kYHVGp


18

Perl 5 -p, 28 bytes $_=/k/?Paper:/i/?Rock:Lizard Try it online! Tried @JoKing's length mod 4 method, but this turned out to be even shorter.


2

Ruby, 42 36 bytes ->c{%w(Spock Lizard Rock)[c.size%4]} Try it online! Ruby, 43 39 bytes ->c{%w(Lizard Rock Paper)[c[-1].ord%3]} Try it online! The second one is an alternative I found to Jo's method, using the ASCII value of the last character, but alas is 3 bytes longer in Ruby. It is conceivable that my method is better in some language where ...


2

Retina, 30 27 bytes 'R(`R Sp 'i(K`Rock K`Lizard Try it online! Link includes all possible test cases. @BusinessCat's answer works perfectly well in Retina 0.8.2 but for Retina 1 we can do a little better by using a conditional stage. Explanation: 'R(` If the input contains R... R Sp ... then replace the R with Sp, thus turning Rock into Spock... 'i( ....


0

Retina 0.8.2, 36 33 31 bytes -3 thanks to Neil R s .{6,} Rock .{5} Lizard s Sp Try it online!


2

Python 2, 73 69 bytes lambda i:l[l.index(i)-1] l="Rock Lizard Spock Scissors Paper".split() Try it online! Since there are already plenty of ports of @JoKing's excellent answer, here is a different way of doing it.


1

F# (.NET Core), 53 49 46 bytes ["Spock";"Lizard";"Rock"].[String.length n%4] Try it online! I am using the input-length-modulo-4 strategy from Jo King's answer, so please check his answer. And I know it's not in competition but I wanted to try something new…


0

05AB1E, 16 bytes ”‰«†ÕâŸard”#I3öè Try it online!


0

Wren, 47 bytes Fn.new{|s|["Spock","Lizard","Rock"][s.count%4]} Try it online! Uses the input-length-modulo-4 strategy in Jo King's answer.


3

C (gcc), 51 49 bytes Thanks to Unrelated String for the suggestion. The second byte of the string has sufficient uniqueness that I can take its two least-significant bits and use them to then index into a string (with the longest-length result at the end if I rotate the result, fortunately!) The separator between the strings should be a literal NUL ...


13

PHP, 39 bytes Shorter md5 variants by Christoph and Benoit Esnard. <?=[Lizard,Spock,Rock][md5(y.$argn)%3]; Try it online! <?=[Spock,Rock,Lizard][md5($argn.m)%7]; Try it online! PHP, 40 bytes <?=[Rock,Spock,Lizard][md5($argn)[5]%3]; Try it online! Takes sixth character of md5 of input, which gives unique number of 1 for "Rock" and "Scissors",...


2

Python 3, 44 bytes lambda s:["Spock","Lizard","Rock"][len(s)%4] Try it online! Uses the input-length-modulo-4 strategy in Jo King's answer.


5

Jelly, 16 14 bytes Lị“ŀ¡ḋ¤:1KỌ»Ḳ¤ Try it online! -2 bytes thanks to Jonathan Allan and Nick Kennedy both independently coming up with splitting on spaces instead of using a list literal. A translation of Jo King's Perl 6 solution, using Jelly's compressed strings and modular indexing. ị The element of “ŀ¡ḋ¤:1KỌ» "Lizard Rock ...


3

Runic Enchantments, 42 bytes il͍4%:0)9*?~"Spock"@1)9*?"Lizard"@"Rock"@ Try it online! Footer runs all five input possibilities (the y sequences make them print in the correct order, no I'm not sure why the last one needed so many) and presets the stack with an input value (the input command then reads no input) and a newline. Remove the footer to use ...


7

APL (Dyalog Unicode), 28 bytes 'Spock' 'Lizard' 'Rock'⊃⍨4|≢ Try it online! Uses the simple strategy based on input length modulo 4 (idea from Jo King's answer). ⎕IO←0. APL (Dyalog Unicode), 34 bytes 'Lizard' 'Rock' 'Paper'⊃⍨'Xbj'⍸2∘⊃ Try it online! Uses the shortest choice for all cases. ⎕IO←1. How it works 'Lizard' 'Rock' 'Paper'⊃⍨'Xbj'⍸2∘⊃ 2∘⊃ ...


59

Perl 6, 36 30 bytes {<Spock Lizard Rock>[.comb%4]} Try it online! Gets each output based on the length of the input modulo 4. I think this is probably the optimal strategy.


1

Charcoal, 133 bytes NθNηUOθη.WS«JNNι»≔⟦⟧ζFθ⊞ζ⟦²ι±¹⟧Fη⊞ζ⟦⁰θι⟧Fθ⊞ζ⟦⁶⁻θ⊕ιη⟧Fη⊞ζ⟦⁴±¹⁻η⊕ι⟧Fζ«J§ι¹§ι²≔﹪⁺⁴§ι⁰¦⁸δM✳δW¬№ζ⟦δⅈⅉ⟧«≡KK/≦⁻⁶δ\≔﹪⁻χδ⁸δPωM✳δ»⊞υ⌕ζ⟦δⅈⅉ⟧»⎚Iυ Try it online! Link is to verbose version of code. Takes input on separate lines with a blank trailing line but for convenience the test case uses spaces instead of newlines. Explanation: NθNηUOθη. ...


Top 50 recent answers are included