Wow ... Jannis Harder's solution is really short ....
This is base on Jannis Harder's solution (398 bytes) ...
We could make Jannis Harder's solution even shorter, for example:
(1) y.map!{|v|v<<32} could rewrite to y.map!{|v|v<<f} ==> save 1 byte
(2) many ?: code like ?x: y could rewrite to ?x:y ( no need space
before y) ==> save n bytes
(3) and ... (see my code about my idea to make it even shorter )
Here is my even shorter solution ( base on Jannis Harder's solution )
it is 349 bytes ( 49 bytes shorter than Jannis Harder's solution )
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
i=$*.join.split("").map{|x|x.to_i}
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*")
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=([0]*5).map{""}
i.each{|z|u=d[z*7,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f}
[1,3].each{|x|y[x]<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<0 ?f:c)<<f}}
y[1,1]*=s
y[2+s,1]*=s
puts y
The digits 2 5 and 6 doesn't work
Input: 0123456789
Output:
~ -- -- -- -- -- -- -- --
> > > > > > > > > > > > > > >
~ -- -- -- -- -- -- --
> > > > > > > > > > > > >
~ -- -- -- -- -- -- --
Thanks Jannis Harder found the bug.
It is still 349 bytes program:
( the bug is on "u[x==1?2:5]<0", it should be "u[x==1?2:5]<o", typo
error "o" instead of "0")
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
i=$*.join.split("").map{|x|x.to_i}
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*")
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=([0]*5).map{""}
i.each{|z|u=d[z*7,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f}
[1,3].each{|x|y<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<o ?f:c)<<f}}
y[1,1]*=s
y[2+s,1]*=s
puts y
···
On Sun, 9 Jan 2005 15:13:25 -0500, email55555 email55555 <email55555@gmail.com> wrote:
Wow ... Jannis Harder's solution is really short ....
This is base on Jannis Harder's solution (398 bytes) ...
We could make Jannis Harder's solution even shorter, for example:
(1) y.map!{|v|v<<32} could rewrite to y.map!{|v|v<<f} ==> save 1 byte
(2) many ?: code like ?x: y could rewrite to ?x:y ( no need space
before y) ==> save n bytes
(3) and ... (see my code about my idea to make it even shorter )
Here is my even shorter solution ( base on Jannis Harder's solution )
it is 349 bytes ( 49 bytes shorter than Jannis Harder's solution )
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
i=$*.join.split("").map{|x|x.to_i}
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*")
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=([0]*5).map{""}
i.each{|z|u=d[z*7,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f}
[1,3].each{|x|y<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<0 ?f:c)<<f}}
y[1,1]*=s
y[2+s,1]*=s
puts y
Wow ... Jannis Harder's program is down to 295 bytes ...
Mmm... Let me try to squeeze a little bit more.
First, according to the Quiz, we do not need to take care of multi-mumbers,
so, I change $*.join to $*[0] ==> just take the first number ==> save
me 2 bytes.
Second, I got new idea again ( always base on Jannis Harder's lastest code ),
this time it is down to 264 bytes
( note: run this program without any parameter will fail after replace
$*.join by $*[0],
if this is not acceptable, replace back, so my program will become 266 bytes.
After all, this program likes Jannis Harder's origin, do not do many
error checking;
for example: if input is "lcd.rb -s abc xxx" ==> size invalid will
become size zero,
and any no digit character will become zero digit)
s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2
d,="\21\265\22H\245\10-\0\23".unpack"B*"
f=" "
o=48
y=(0..4).map{|x|$*[0].split('').map{|z|u=d[7*z.to_i,7]
x%2==0 ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}
y[3,1]*=s
y[1,1]*=s
puts y
256 bytes.
Shrik again from 264 bytes. New idea again.
I agree, at this point, this program is not readable at all.
If you like a readable version,
please check my solution #1
( maybe it is not readable either
)
What I did is I try to make a as small as possible program for the solution.
I have fun for this solution is about its size,
not the readable / maintenace / performance ... etc.
There are many ways to play, I just try to take other way and have fun.
(Of couse, if this is my job, I would not solve as it right now
)
OK, anyway, like it or not; here is the 256 bytes program.
( Not the gmail wrap line, it is this mailing list wrap my code.
So this time, I list the line number as [n],
if the program wrapped, join the line together yourself,
sometime the line is wrap when a blank character to separate "word",
so when join line, you may need add a blank character)
[1] s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2
[2] d,="\21\265\22H\245\10-\0\23".unpack"B*"
[3] f=" "
[4] o=48
[5] 5.times{|x|((t=x%2==0)?1:s).times{puts
$*[0].split('').map{|z|u=d[7*z.to_i,7]
[6] t ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}}
···
--
David Tran
http://www.doublegifts.com
email55555 email55555 wrote:
Thanks Jannis Harder found the bug.
It is still 349 bytes program:
( the bug is on "u[x==1?2:5]<0", it should be "u[x==1?2:5]<o", typo
error "o" instead of "0")
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
Why the spaces? Why the parentheses?
s=$*.index "-s";s=s?$*.slice!(s,2)[1].to_i:2
i=$*.join.split("").map{|x|x.to_i}
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*")
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=([0]*5).map{""}
y=(1..5).map{""}
i.each{|z|u=d[z*7,7]
i.map
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f}
space after o
[1,3].each{|x|y<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<o ?f:c)<<f}}
[1,3].map, space after o
And shorter and shorter and:
Based on my solution and the ideas from email55555
1. Removed split("").map..... I'm using each_byte now ( z*7 to z*7-336)
2. replaced x==1?1:4 with h=x*4/3
2. replaced x==1?2:5 with h+1 
3. replaced <<f with +f
4. repalced
~ y[1,1]*=s
~ y[2+s,1]*=s
with
~ y[3,1]*=s
~ y[1,1]*=s
323 byte:
### (this is 100bytes shorter than my first solution)
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
i=$*.join
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*")
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=([0]*5).map{""}
i.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)+f}
[1,3].each{|x|y[x]<<(u[h=x*4/3]<o ?f:c)+a+(u[h+1]<o ?f:c)+f}}
y[3,1]*=s
y[1,1]*=s
puts y
···
###
303 bytes. 
s=$*.index"-s";s=s ?$*.slice!(s,2)[1].to_i: 2
d,="7krtt1r30v/s".unpack("m")[0].unpack"B*"
f=" "
a,c,o=f*s,"|",49
y=(0..4).map{""}
$*.join.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?a+f+f:f+"-"*s+f)+f}
[1,3].map{|x|y[x]<<(u[h=x*4/3]<o ?f:c)+a+(u[h+1]<o ?f:c)+f}}
y[3,1]*=s
y[1,1]*=s
puts y
264 bytes.
gmail wrap again my program.
the 2 lines
x%2==0 ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}
should be one line instead of two ( it should join together like)
... :(u[h=x*4/3]>o ?f:"|")+ ...
···
On Mon, 10 Jan 2005 00:03:53 -0500, email55555 email55555 <email55555@gmail.com> wrote:
Wow ... Jannis Harder's program is down to 295 bytes ...
Mmm... Let me try to squeeze a little bit more.
First, according to the Quiz, we do not need to take care of multi-mumbers,
so, I change $*.join to $*[0] ==> just take the first number ==> save
me 2 bytes.
Second, I got new idea again ( always base on Jannis Harder's lastest code ),
this time it is down to 264 bytes
( note: run this program without any parameter will fail after replace
$*.join by $*[0],
if this is not acceptable, replace back, so my program will become 266 bytes.
After all, this program likes Jannis Harder's origin, do not do many
error checking;
for example: if input is "lcd.rb -s abc xxx" ==> size invalid will
become size zero,
and any no digit character will become zero digit)
s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2
d,="\21\265\22H\245\10-\0\23".unpack"B*"
f=" "
o=48
y=(0..4).map{|x|$*[0].split('').map{|z|u=d[7*z.to_i,7]
x%2==0 ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}
y[3,1]*=s
y[1,1]*=s
puts y
--
http://www.doublegifts.com
Florian Gross schrieb:
email55555 email55555 wrote:
Thanks Jannis Harder found the bug. It is still 349 bytes
program: ( the bug is on "u[x==1?2:5]<0", it should be
"u[x==1?2:5]<o", typo error "o" instead of "0")
s=$*.index("-s");s=(s ?$*.slice!(s,2)[1].to_i: 2)
Why the spaces? Why the parentheses? s=$*.index
"-s";s=s?$*.slice!(s,2)[1].to_i:2
spaces:
~ syntax error without " "
paranthese:
~ no reasen 
i=$*.join.split("").map{|x|x.to_i}
d,="7krtt1r30v/s".unpack("m")[0].unpack("B*") f=" "
a,b=f*s,f+"-"*s+f c,e,o="|",a+f+f,49 y=([0]*5).map{""}
y=(1..5).map{""}
i.each{|z|u=d[z*7,7]
i.map
.each_byte is shorter
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)<<f}
space after o
again, syntax error without " "
[1,3].each{|x|y<<(u[x==1?1:4]<o ?f:c)+a+(u[x==1?2:5]<o
?f:c)<<f}}
[1,3].map, space after o
good idea, syntax error without
315 bytes:
···
###
s=$*.index"-s";s=s ?$*.slice!(s,2)[1].to_i: 2
i=$*.join
d,="7krtt1r30v/s".unpack("m")[0].unpack"B*"
f=" "
a,b=f*s,f+"-"*s+f
c,e,o="|",a+f+f,49
y=(0..4).map{""}
i.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]<o ?e:b)+f}
[1,3].map{|x|y<<(u[h=x*4/3]<o ?f:c)+a+(u[h+1]<o ?f:c)+f}}
y[3,1]*=s
y[1,1]*=s
puts y
###
### 300 byte 
s=$*.index"-s";s=s ?$*.slice!(s,2)[1].to_i: 2
d,="\21\265\22H\245\10-\0\23".unpack"B*"
f=" "
a,c,o=f*s,"|",48
y=(0..4).map{""}
$*.join.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]>o ?a+f+f:f+"-"*s+f)+f}
[1,3].map{|x|y[x]<<(u[h=x*4/3]>o ?f:c)+a+(u[h+1]>o ?f:c)+f}}
y[3,1]*=s
y[1,1]*=s
puts y
···
###
That's what I love about ruby - the readability of its code 
* email55555 email55555 <email55555@gmail.com> [0109 05:09]:
···
264 bytes.
gmail wrap again my program.
the 2 lines
> x%2==0 ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
> ?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}
should be one line instead of two ( it should join together like)
... :(u[h=x*4/3]>o ?f:"|")+ ...
On Mon, 10 Jan 2005 00:03:53 -0500, email55555 email55555
> s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2
> d,="\21\265\22H\245\10-\0\23".unpack"B*"
> f=" "
> o=48
> y=(0..4).map{|x|$*[0].split('').map{|z|u=d[7*z.to_i,7]
> x%2==0 ?u[x/2*3]>o ?f*s+f+f:f+"-"*s+f:(u[h=x*4/3]>o
> ?f:"|")+f*s+(u[h+1]>o ?f:"|")}*f}
> y[3,1]*=s
> y[1,1]*=s
> puts y
>
--
'You may need to metaphorically make a deal with the devil.
By 'devil' I mean robot devil and by 'metaphorically' I mean get your coat.'
-- Bender
Rasputin :: Jack of All Trades - Master of Nuns
### 296 byte
s=$*.index"-s";s=s ?$*.slice!(s,2)[1].to_i: 2
d,="\21\265\22H\245\10-\0\23".unpack"B*"
f=" "
o=48
y=(0..4).map{""}
$*.join.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]>o ?f*s+f+f:f+"-"*s+f)+f}
[1,3].map{|x|y[x]<<(u[h=x*4/3]>o ?f:"|")+f*s+(u[h+1]>o ?f:"|")+f}}
y[3,1]*=s
y[1,1]*=s
puts y
···
###
* On Jan 10 21:02, Dick Davies (ruby-talk@ruby-lang.org) thusly jotted:
That's what I love about ruby - the readability of its code 
I know that's what I love about it - that both are equally possible and
come naturally to different people. We have both the Jannis Harders and
the David Heinemeier Hanssons. 
I tend to switch between the two extremes based on the task at hand.
Concise code is to be valued for certain things, elegant code for others,
and if you can get both - well, then you're golden. Not many languages
other than Ruby can accomplish that 
Tom
### 295 bytes
s=(s=$*.index"-s")?$*.slice!(s,2)[1].to_i: 2
d,="\21\265\22H\245\10-\0\23".unpack"B*"
f=" "
o=48
y=(0..4).map{""}
$*.join.each_byte{|z|u=d[z*7-336,7]
3.times{|x|y[x*2]<<(u[x*3]>o ?f*s+f+f:f+"-"*s+f)+f}
[1,3].map{|x|y[x]<<(u[h=x*4/3]>o ?f:"|")+f*s+(u[h+1]>o ?f:"|")+f}}
y[3,1]*=s
y[1,1]*=s
puts y
···
###
Just to be clear, I'm more in line with David's approach and so is Ruby Quiz, by extension.
I'm not trying to stop or degrade the the golf game going on here. I have enjoyed looking over the ever shrinking offerings and I've listed every one of them on the quiz page.
However, that's probably all the attention they'll get from me. I wouldn't break them down in my summary, for example. It's nothing personal. My interests are just different.
Don't let that stop you though. Golf away, as long as your enjoying yourself!
(This has been in the Ruby Quiz FAQ since day one, but I wanted to make my position clear since this is the first time it has come up.)
James Edward Gray II
···
On Jan 10, 2005, at 7:04 AM, Thomas Kirchner wrote:
* On Jan 10 21:02, Dick Davies (ruby-talk@ruby-lang.org) thusly jotted:
That's what I love about ruby - the readability of its code 
I know that's what I love about it - that both are equally possible and
come naturally to different people. We have both the Jannis Harders and
the David Heinemeier Hanssons. 
* On Jan 11 0:02, James Edward Gray II (ruby-talk@ruby-lang.org) thusly jotted:
Just to be clear, I'm more in line with David's approach and so is Ruby
Quiz, by extension.
[...]
Don't let that stop you though. Golf away, as long as your enjoying
yourself!
That was my idea - Ruby allows everyone to express themselves and have fun
programming. I wasn't (necessarily) encouraging byte-size code for the
Quiz, nor overly wordy code for other things. I haven't yet found another
language that allows the user to decide their own style as well as Ruby.
This ties in to the thread about braces - I personally prefer {} to do/end,
where possible. Just another nicety. (Thanks Matz!)
Tom