s

Code Golf: Saving Time

Aug 28, 2008

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