Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 5183

Code-golf is a competition to solve a particular problem in the fewest bytes of source code.

6 votes

Russian Roulette

Ruby, 24-28 p rand(6)<5?"I survived!":1/0 Approx each 6 time, there is a ZeroDivisionError There is even a shorter version with 24 characters (Thanks to ugoren and histocrat): 6/rand(6);p"I survived! …
knut's user avatar
  • 269
1 vote

print 1 to 100 without using recursion and conditions

Ruby (11) [non-competitive] p *(1..100) (Thanks to histocrat) Previous 14-character solution: p *1.upto(100) This is a non-competitive answer (not C/C++ as requested)
knut's user avatar
  • 269
1 vote

Find the first word starting with each letter

Ruby 76 Bytes s;f={};s.scan(/(([\w])[\w]*)/).map{|h,i|f[j=i.upcase]?nil:(f[j]=!p; h)}.compact.*' ' Or with method definition 88 bytes def m s;f={};(s.scan(/((\w)\w*)/).map{|h,i|f[j=i.upcase]?nil:( …
knut's user avatar
  • 269
1 vote

Working Week Completion

Ruby, 191 116,115 113 The logic is stolen from Fraxtils Python solution. t=Time.now d=t.wday m=[0,t.hour*2+t.min/3e1-18].max p d<1?100:20*[5,(d-1+[15,m-[8,[7,m].max].min+7].min/15)].min If you wan …
knut's user avatar
  • 269
6 votes

Tips for golfing in Ruby

Use || instead or and && instead and. Beside the one character from and you can save the spaces (and perhaps the bracket) around the operator. p true and false ? 'yes' :'no' #-> true (wrong resul …
knut's user avatar
  • 269