s

Posts Tagged with "code golf"

Code Golf: Seven-Segment Displays

Sep 08, 2008  -  Comments

Here is my submission for the Seven-Segment Displays challenge. Code size: 292 bytes.

x=gets.chop.split ''
a=' ### '
b='#    '
c='    #'
d='#   #'
e=' '*5
f='  '
g=[a]
h=[d]*3
i=[e]
j=[c]*3
k=[b]*3
l=g+h
m=g+j
n=m+g
y={0=>l+i+h+g,1=>i+j+i+j+i,2=>n+k+g,3=>m+n,4=>i+h+m+i,5=>g+k+n,6=>g+k+l+g,7=>m+i+j+i,8=>l+l+g,9=>l+n}
9.times{|i|puts x.collect{|n|y[n.to_i][i]+f}.join.chop.chop}

Tagged: rubycode golf

Code Golf: Saving Time

Aug 28, 2008  -  Comments

Here is my submission for the Saving Time challenge. Code size: 319 bytes (not the worst, but close).

h,m=gets.split(':').map{|i|i.to_i}
h>11?h-=12:''
m=(m-m%5)/5
a=[]
11.times{|x|a<<[' ']*17}
b={}
c=[[0,8],[1,12],[3,15],[5,16],[7,15],[9,12],[10,8],[9,4],[7,1],[5,0],[3,1],[1,4]]
0.upto(11){|x|b[x]=c[x]}
b.map{|x,n|a[n[0]][n[1]]='o'}
a[b[h][0]][b[h][1]]='h'
a[b[m][0]][b[m][1]]=h==m ?'x':'m'
a.map{|x|puts x.join.rstrip}

Tagged: rubycode golf

Code Golf: Choose

Jan 16, 2008  -  Comments

Here is my submission for the Choose challenge. Code size: 88 bytes.

def g(r)(1..r).inject(1){|m,n|m*n}end
x,y=gets.split.map{|n|n.to_i}
p g(x)/(g(y)*g(x-y))

Tagged: rubycode golf