I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:
if a==0
1
else
2
end
Thanks for the help!
I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:
if a==0
1
else
2
end
Thanks for the help!
On Thu, 12 Oct 2006, Drew O. wrote:
I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:if a==0
1
else
2
end
a==0?1:2
Kirk H.
On Oct 11, 2006, at 10:54 AM, Drew O. wrote:
I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:if a==0
1
else
2
end
a==0?1:2
James Edward G. II
Hi –
On Thu, 12 Oct 2006, Drew O. wrote:
I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:if a==0
1
else
2
end
The smallest I can think of is:
a==0?1:2
David
unknown wrote:
On Thu, 12 Oct 2006, Drew O. wrote:
I’m working on my codegolfing skills and was wondering, what is the
shortest possible way to write the following in ruby:if a==0
1
else
2
enda==0?1:2
Kirk H.
Exactly what I was looking for! Thanks!
On Thu, 12 Oct 2006 [email protected] wrote:
2
endThe smallest I can think of is:
a==0?1:2
if a will only have values 0 or 1 you could use
2**a
if a is always positive you could use
a>0?2:1
cheers.
-a
Hi –
On Thu, 12 Oct 2006, [email protected] wrote:
1
2**a
if a is always positive you could use
a>0?2:1
And if a is always 0 you could use:
1
Sorry, couldn’t resist
David
On Thu, 12 Oct 2006, Joel VanderWerf wrote:
if a==0
if a will only have values 0 or 1 you could use2**a
In that case:
a+1
touche techer, touche.
-a
Relm wrote:
On Thu, 12 Oct 2006 [email protected] wrote:
1
a>0?2:1
or for positive integers
2-0**a
Very useful
~r
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs