Quizzical?

W

Wyatt Greene

Can you guess what this program will do when run?

a = ?????:????????:??:?????:??
puts a


Feel free to post answers and spoilers to this below. If you don't
want to see the answer, stop reading! :)
 
P

Phrogz

Can you guess what this program will do when run?

a = ?????:????????:??:?????:??
puts a

Feel free to post answers and spoilers to this below.  If you don't
want to see the answer, stop reading!  :)

It's either going to be 58 or 63, is my guess before IRB. :)
 
V

vsv

Can you guess what this program will do when run?

a = ?????:????????:??:?????:??
puts a

Feel free to post answers and spoilers to this below. If you don't
want to see the answer, stop reading! :)

I guess same as a = ?? ? ?? : _any_
 
S

Sebastian Hungerecker

Wyatt said:
Can you guess what this program will do when run?

a = ?????:????????:??:?????:??

a = ?? ? ?? : ?? ? ?? ? ?? : ?? : ?? ? ?? : ??
It's pretty clear to see that this will return ??(63) without looking further
into the structure of the code, but let's take a closer look at the order in
which the ternaries are executed anyway:
a = ?? ? (??) : (?? ? (?? ? ?? : ??) : (?? ? ?? : ??))
So we have:
if 63
63
else
if 63
if 63
63
else
63
end
else
if 63
63
else
63
end
end
end
Result: 63
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,282
Messages
2,571,404
Members
48,095
Latest member
WalkerBore

Latest Threads

Top