Posts Tagged with "code golf"

Code Golf: Seven-Segment Displays

SEP

08

2008

0 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: ruby, code golf

Code Golf: Bob Ross' The Joy of ASCII Art

SEP

01

2008

0 comments

Here is my submission for the Bob Ross' The Joy of ASCII Art challenge. Code size: 116 bytes.

            a=(['']*39).map{[' ']*79}
            while gets
            x=split
            a[x[1].to_i][x[0].to_i]=x[2].to_i.chr
            end
            a.each{|x|puts x.join.rstrip}
            

Tagged: code golf, ruby

Code Golf: Grid Computing

AUG

31

2008

0 comments

Here is my submission for the Grid Computing challenge. Code size: 135 bytes.

            a=[]
            10.times{|x|a<<gets.split}
            y=[0]*20
            10.times{|i|a.each{|x|y[i]+=x[i].to_i}}
            a.each{|x|x.each{|i|y[a.index(x)+10]+=i.to_i}}
            p y.max
            

Tagged: code golf, ruby

Code Golf: Saving Time

AUG

28

2008

1 comment

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: code golf, ruby

Code Golf: Choose

JAN

16

2008

0 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: code golf, ruby


© 2008 Travis Roberts. All rights reserved.