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}
Leave a comment:
Popular Posts
Search
Tags
actionmailer activerecord ajax apache apple barcamp caching capistrano centos code golf css db delete eager loading ebay email attachment erb flash ftp fun generators get haml helpers ie sucks javascript jquery lightbox lost merb net ftp paperclip passenger php plexus post presentation rails rails machine railsconf redesign rest rjs routes rss ruby ruby on rails safari script sinatra symfony text replacement tips tutorial twitter xhtml
Projects
© 2010 Travis Roberts. All rights reserved.
hint said on October 20, 2008:
% will help you a little