Ram Rachum | 17 Dec 2011 13:14
Gravatar

Silly Python riddle

Here's a silly Python riddle for you.

Today I opened up a Python 2.7 shell, and ran two commands in it.

>>> f = lambda: g(???)
>>> f() 

(Note that these are the only commands that I ran. You're not allowed to run any other commands before them.)

The riddle: What's the shortest thing you can put instead of ??? so my second command would not raise an exception?


Ram.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
asaf greenberg | 17 Dec 2011 13:55
Picon

Re: Silly Python riddle

On 17/12/2011 14:14, Ram Rachum wrote:
f = lambda: g(???)

i didn't know lambdas can be used with a function call. 

actaully - i can't even use lambda: f() at all, even without your restrictions.

unless there's a jit compiler easter egg built in, like lambda g('if this string then return a 3d-maze with pictures of the developers')...

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Ram Rachum | 17 Dec 2011 13:56
Gravatar

Re: Silly Python riddle

Of course you can put a function call inside a lambda:

>>> f = lambda: sum((1, 2, 3))
>>> f()
6

No easter eggs or JIT magic are involved in this riddle.

On Sat, Dec 17, 2011 at 2:55 PM, asaf greenberg <asafgreenberg <at> gmail.com> wrote:
On 17/12/2011 14:14, Ram Rachum wrote:
f = lambda: g(???)

i didn't know lambdas can be used with a function call. 

actaully - i can't even use lambda: f() at all, even without your restrictions.

unless there's a jit compiler easter egg built in, like lambda g('if this string then return a 3d-maze with pictures of the developers')...


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
ofri raviv | 17 Dec 2011 14:04
Picon
Gravatar

Re: Silly Python riddle

my trivial 13 char solution is
);g=lambda:(0
which gives 
f = lambda: g();g=lambda:(0)
but i'm sure this can be done with less...

On Sat, Dec 17, 2011 at 2:56 PM, Ram Rachum <ram <at> rachum.com> wrote:
Of course you can put a function call inside a lambda:

>>> f = lambda: sum((1, 2, 3))
>>> f()
6

No easter eggs or JIT magic are involved in this riddle.

On Sat, Dec 17, 2011 at 2:55 PM, asaf greenberg <asafgreenberg <at> gmail.com> wrote:
On 17/12/2011 14:14, Ram Rachum wrote:
f = lambda: g(???)

i didn't know lambdas can be used with a function call. 

actaully - i can't even use lambda: f() at all, even without your restrictions.

unless there's a jit compiler easter egg built in, like lambda g('if this string then return a 3d-maze with pictures of the developers')...


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Ram Rachum | 17 Dec 2011 14:13
Gravatar

Re: Silly Python riddle

Haha, I didn't consider that solution. And yes, it can be done with less characters than 13.

On Sat, Dec 17, 2011 at 3:04 PM, ofri raviv <ofri.raviv <at> gmail.com> wrote:
my trivial 13 char solution is
);g=lambda:(0
which gives 
f = lambda: g();g=lambda:(0)
but i'm sure this can be done with less...


On Sat, Dec 17, 2011 at 2:56 PM, Ram Rachum <ram <at> rachum.com> wrote:
Of course you can put a function call inside a lambda:

>>> f = lambda: sum((1, 2, 3))
>>> f()
6

No easter eggs or JIT magic are involved in this riddle.

On Sat, Dec 17, 2011 at 2:55 PM, asaf greenberg <asafgreenberg <at> gmail.com> wrote:
On 17/12/2011 14:14, Ram Rachum wrote:
f = lambda: g(???)

i didn't know lambdas can be used with a function call. 

actaully - i can't even use lambda: f() at all, even without your restrictions.

unless there's a jit compiler easter egg built in, like lambda g('if this string then return a 3d-maze with pictures of the developers')...


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
shaharr | 17 Dec 2011 14:11

Re: Silly Python riddle

oops, i dislectically thought the g() is before the colon!
(still, i can't figure it out.)

On 17/12/2011 14:56, Ram Rachum wrote:
Of course you can put a function call inside a lambda:

>>> f = lambda: sum((1, 2, 3))
>>> f()
6

No easter eggs or JIT magic are involved in this riddle.

On Sat, Dec 17, 2011 at 2:55 PM, asaf greenberg <asafgreenberg <at> gmail.com> wrote:
On 17/12/2011 14:14, Ram Rachum wrote:
f = lambda: g(???)

i didn't know lambdas can be used with a function call. 

actaully - i can't even use lambda: f() at all, even without your restrictions.

unless there's a jit compiler easter egg built in, like lambda g('if this string then return a 3d-maze with pictures of the developers')...


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il




_______________________________________________ Python-il mailing list Python-il <at> hamakor.org.il http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Omer Zak | 17 Dec 2011 13:55
Picon
Favicon
Gravatar

Re: Silly Python riddle

I do not have Python 2.7, so I did the following on Python 2.6.6.
>>> f = lambda: g(); g = lambda:()
>>> f()
()
>>> 

In other words, '???' is replaced by '); g = lambda:('

--- Omer

On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
> Here's a silly Python riddle for you.
> 
> 
> Today I opened up a Python 2.7 shell, and ran two commands in it.
> 
> 
>         >>> f = lambda: g(???)
>         >>> f() 
> 
> (Note that these are the only commands that I ran. You're not allowed
> to run any other commands before them.)
> 
> 
> The riddle: What's the shortest thing you can put instead of ??? so my
> second command would not raise an exception?

--

-- 
"Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
are menace to the deaf.  They must be outlawed!
(See also:
http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/
and http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

cool-RR | 17 Dec 2011 15:10
Gravatar

Re: Silly Python riddle

So you got it down to 12 characters, nice. But it can be made much shorter.

On Sat, Dec 17, 2011 at 2:55 PM, Omer Zak <w1 <at> zak.co.il> wrote:
I do not have Python 2.7, so I did the following on Python 2.6.6.
>>> f = lambda: g(); g = lambda:()
>>> f()
()
>>>

In other words, '???' is replaced by '); g = lambda:('

--- Omer


On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
> Here's a silly Python riddle for you.
>
>
> Today I opened up a Python 2.7 shell, and ran two commands in it.
>
>
>         >>> f = lambda: g(???)
>         >>> f()
>
> (Note that these are the only commands that I ran. You're not allowed
> to run any other commands before them.)
>
>
> The riddle: What's the shortest thing you can put instead of ??? so my
> second command would not raise an exception?


--
"Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
are menace to the deaf.  They must be outlawed!
(See also: http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/ and http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



--
Sincerely,
Ram Rachum
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Alon Levy | 17 Dec 2011 15:12
Picon
Gravatar

Re: Silly Python riddle

);g=f;(

7

but don't run it :)

On Sat, Dec 17, 2011 at 4:10 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
> So you got it down to 12 characters, nice. But it can be made much shorter.
>
>
> On Sat, Dec 17, 2011 at 2:55 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>>
>> I do not have Python 2.7, so I did the following on Python 2.6.6.
>> >>> f = lambda: g(); g = lambda:()
>> >>> f()
>> ()
>> >>>
>>
>> In other words, '???' is replaced by '); g = lambda:('
>>
>> --- Omer
>>
>>
>> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
>> > Here's a silly Python riddle for you.
>> >
>> >
>> > Today I opened up a Python 2.7 shell, and ran two commands in it.
>> >
>> >
>> >         >>> f = lambda: g(???)
>> >         >>> f()
>> >
>> > (Note that these are the only commands that I ran. You're not allowed
>> > to run any other commands before them.)
>> >
>> >
>> > The riddle: What's the shortest thing you can put instead of ??? so my
>> > second command would not raise an exception?
>>
>>
>> --
>> "Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
>> are menace to the deaf.  They must be outlawed!
>> (See also:
>> http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/
>> and
>> http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
>> My own blog is at http://www.zak.co.il/tddpirate/
>>
>> My opinions, as expressed in this E-mail message, are mine alone.
>> They do not represent the official policy of any organization with which
>> I may be affiliated in any way.
>> WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
>>
>> _______________________________________________
>> Python-il mailing list
>> Python-il <at> hamakor.org.il
>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>
>
>
>
> --
> Sincerely,
> Ram Rachum
>
> _______________________________________________
> Python-il mailing list
> Python-il <at> hamakor.org.il
> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>

--

-- 
Alon Levy
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Alon Levy | 17 Dec 2011 15:13
Picon
Gravatar

Re: Silly Python riddle

ok, it raises RuntimeException so it doesn't count.

On Sat, Dec 17, 2011 at 4:12 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
> );g=f;(
>
> 7
>
> but don't run it :)
>
> On Sat, Dec 17, 2011 at 4:10 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
>> So you got it down to 12 characters, nice. But it can be made much shorter.
>>
>>
>> On Sat, Dec 17, 2011 at 2:55 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>>>
>>> I do not have Python 2.7, so I did the following on Python 2.6.6.
>>> >>> f = lambda: g(); g = lambda:()
>>> >>> f()
>>> ()
>>> >>>
>>>
>>> In other words, '???' is replaced by '); g = lambda:('
>>>
>>> --- Omer
>>>
>>>
>>> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
>>> > Here's a silly Python riddle for you.
>>> >
>>> >
>>> > Today I opened up a Python 2.7 shell, and ran two commands in it.
>>> >
>>> >
>>> >         >>> f = lambda: g(???)
>>> >         >>> f()
>>> >
>>> > (Note that these are the only commands that I ran. You're not allowed
>>> > to run any other commands before them.)
>>> >
>>> >
>>> > The riddle: What's the shortest thing you can put instead of ??? so my
>>> > second command would not raise an exception?
>>>
>>>
>>> --
>>> "Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
>>> are menace to the deaf.  They must be outlawed!
>>> (See also:
>>> http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/
>>> and
>>> http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
>>> My own blog is at http://www.zak.co.il/tddpirate/
>>>
>>> My opinions, as expressed in this E-mail message, are mine alone.
>>> They do not represent the official policy of any organization with which
>>> I may be affiliated in any way.
>>> WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
>>>
>>> _______________________________________________
>>> Python-il mailing list
>>> Python-il <at> hamakor.org.il
>>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>
>>
>>
>>
>> --
>> Sincerely,
>> Ram Rachum
>>
>> _______________________________________________
>> Python-il mailing list
>> Python-il <at> hamakor.org.il
>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>
>
>
>
> --
> Alon Levy

--

-- 
Alon Levy
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Alon Levy | 17 Dec 2011 15:19
Picon
Gravatar

Re: Silly Python riddle

10

);f=help;(

On Sat, Dec 17, 2011 at 4:13 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
> ok, it raises RuntimeException so it doesn't count.
>
> On Sat, Dec 17, 2011 at 4:12 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
>> );g=f;(
>>
>> 7
>>
>> but don't run it :)
>>
>> On Sat, Dec 17, 2011 at 4:10 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
>>> So you got it down to 12 characters, nice. But it can be made much shorter.
>>>
>>>
>>> On Sat, Dec 17, 2011 at 2:55 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>>>>
>>>> I do not have Python 2.7, so I did the following on Python 2.6.6.
>>>> >>> f = lambda: g(); g = lambda:()
>>>> >>> f()
>>>> ()
>>>> >>>
>>>>
>>>> In other words, '???' is replaced by '); g = lambda:('
>>>>
>>>> --- Omer
>>>>
>>>>
>>>> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
>>>> > Here's a silly Python riddle for you.
>>>> >
>>>> >
>>>> > Today I opened up a Python 2.7 shell, and ran two commands in it.
>>>> >
>>>> >
>>>> >         >>> f = lambda: g(???)
>>>> >         >>> f()
>>>> >
>>>> > (Note that these are the only commands that I ran. You're not allowed
>>>> > to run any other commands before them.)
>>>> >
>>>> >
>>>> > The riddle: What's the shortest thing you can put instead of ??? so my
>>>> > second command would not raise an exception?
>>>>
>>>>
>>>> --
>>>> "Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
>>>> are menace to the deaf.  They must be outlawed!
>>>> (See also:
>>>> http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/
>>>> and
>>>> http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
>>>> My own blog is at http://www.zak.co.il/tddpirate/
>>>>
>>>> My opinions, as expressed in this E-mail message, are mine alone.
>>>> They do not represent the official policy of any organization with which
>>>> I may be affiliated in any way.
>>>> WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
>>>>
>>>> _______________________________________________
>>>> Python-il mailing list
>>>> Python-il <at> hamakor.org.il
>>>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>>
>>>
>>>
>>>
>>> --
>>> Sincerely,
>>> Ram Rachum
>>>
>>> _______________________________________________
>>> Python-il mailing list
>>> Python-il <at> hamakor.org.il
>>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>>
>>
>>
>>
>> --
>> Alon Levy
>
>
>
> --
> Alon Levy

--

-- 
Alon Levy
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
cool-RR | 17 Dec 2011 15:22
Gravatar

Re: Silly Python riddle

Very creative man! I definitely didn't think of that.

Still, the best solution I got runs at 7 characters.


On Sat, Dec 17, 2011 at 4:19 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
10

);f=help;(

On Sat, Dec 17, 2011 at 4:13 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
> ok, it raises RuntimeException so it doesn't count.
>
> On Sat, Dec 17, 2011 at 4:12 PM, Alon Levy <alonlevy1 <at> gmail.com> wrote:
>> );g=f;(
>>
>> 7
>>
>> but don't run it :)
>>
>> On Sat, Dec 17, 2011 at 4:10 PM, cool-RR <cool-rr <at> cool-rr.com> wrote:
>>> So you got it down to 12 characters, nice. But it can be made much shorter.
>>>
>>>
>>> On Sat, Dec 17, 2011 at 2:55 PM, Omer Zak <w1 <at> zak.co.il> wrote:
>>>>
>>>> I do not have Python 2.7, so I did the following on Python 2.6.6.
>>>> >>> f = lambda: g(); g = lambda:()
>>>> >>> f()
>>>> ()
>>>> >>>
>>>>
>>>> In other words, '???' is replaced by '); g = lambda:('
>>>>
>>>> --- Omer
>>>>
>>>>
>>>> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
>>>> > Here's a silly Python riddle for you.
>>>> >
>>>> >
>>>> > Today I opened up a Python 2.7 shell, and ran two commands in it.
>>>> >
>>>> >
>>>> >         >>> f = lambda: g(???)
>>>> >         >>> f()
>>>> >
>>>> > (Note that these are the only commands that I ran. You're not allowed
>>>> > to run any other commands before them.)
>>>> >
>>>> >
>>>> > The riddle: What's the shortest thing you can put instead of ??? so my
>>>> > second command would not raise an exception?
>>>>
>>>>
>>>> --
>>>> "Kosher" Cellphones (cellphones with blocked SMS, video and Internet)
>>>> are menace to the deaf.  They must be outlawed!
>>>> (See also:
>>>> http://www.zak.co.il/tddpirate/2006/04/21/the-grave-danger-to-the-deaf-from-kosher-cellphones/
>>>> and
>>>> http://www.zak.co.il/tddpirate/2007/02/04/rabbi-eliashiv-declared-war-on-the-deaf/)
>>>> My own blog is at http://www.zak.co.il/tddpirate/
>>>>
>>>> My opinions, as expressed in this E-mail message, are mine alone.
>>>> They do not represent the official policy of any organization with which
>>>> I may be affiliated in any way.
>>>> WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
>>>>
>>>> _______________________________________________
>>>> Python-il mailing list
>>>> Python-il <at> hamakor.org.il
>>>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>>
>>>
>>>
>>>
>>> --
>>> Sincerely,
>>> Ram Rachum
>>>
>>> _______________________________________________
>>> Python-il mailing list
>>> Python-il <at> hamakor.org.il
>>> http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
>>>
>>
>>
>>
>> --
>> Alon Levy
>
>
>
> --
> Alon Levy



--
Alon Levy
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il



--
Sincerely,
Ram Rachum
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Omer Zak | 17 Dec 2011 15:38
Picon
Favicon
Gravatar

Re: Silly Python riddle

Another attempt at golfing down the solution:
>>> f=lambda:g(0);g=(id)
>>> f()
10482512

The solution is '0);g=(id', 8 characters long.
If there is a built-in function whose name is 1-character long, then the
solution can be made to be 7 characters long.

On Sat, 2011-12-17 at 14:55 +0200, Omer Zak wrote:
> I do not have Python 2.7, so I did the following on Python 2.6.6.
> >>> f = lambda: g(); g = lambda:()
> >>> f()
> ()
> >>> 
> 
> In other words, '???' is replaced by '); g = lambda:('
> 
> --- Omer
> 
> 
> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
> > Here's a silly Python riddle for you.
> > 
> > 
> > Today I opened up a Python 2.7 shell, and ran two commands in it.
> > 
> > 
> >         >>> f = lambda: g(???)
> >         >>> f() 
> > 
> > (Note that these are the only commands that I ran. You're not allowed
> > to run any other commands before them.)
> > 
> > 
> > The riddle: What's the shortest thing you can put instead of ??? so my
> > second command would not raise an exception?
> 
> 

--

-- 
$ python
>>> type(type(type))
<type 'type'>          My own blog is at http://www.zak.co.il/tddpirate/
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Ram Rachum | 17 Dec 2011 15:41
Gravatar

Re: Silly Python riddle

Haha, I didn't think of all those creative answers when I asked this riddle! I'm sure happy that none of them (so far!) have reached 7 characters, which is the length of my solution.

On Sat, Dec 17, 2011 at 4:38 PM, Omer Zak <w1 <at> zak.co.il> wrote:
Another attempt at golfing down the solution:
>>> f=lambda:g(0);g=(id)
>>> f()
10482512

The solution is '0);g=(id', 8 characters long.
If there is a built-in function whose name is 1-character long, then the
solution can be made to be 7 characters long.


On Sat, 2011-12-17 at 14:55 +0200, Omer Zak wrote:
> I do not have Python 2.7, so I did the following on Python 2.6.6.
> >>> f = lambda: g(); g = lambda:()
> >>> f()
> ()
> >>>
>
> In other words, '???' is replaced by '); g = lambda:('
>
> --- Omer
>
>
> On Sat, 2011-12-17 at 14:14 +0200, Ram Rachum wrote:
> > Here's a silly Python riddle for you.
> >
> >
> > Today I opened up a Python 2.7 shell, and ran two commands in it.
> >
> >
> >         >>> f = lambda: g(???)
> >         >>> f()
> >
> > (Note that these are the only commands that I ran. You're not allowed
> > to run any other commands before them.)
> >
> >
> > The riddle: What's the shortest thing you can put instead of ??? so my
> > second command would not raise an exception?
>
>

--
$ python
>>> type(type(type))
<type 'type'>          My own blog is at http://www.zak.co.il/tddpirate/
My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
asaf greenberg | 17 Dec 2011 15:27
Picon

Re: Silly Python riddle

f=lambda: g();g=set#)

(yuck. why am i participating in this riddle anyway..)


if i there's a class whose constructor returns a callable, it can be shorter.


On 17/12/2011 14:14, Ram Rachum wrote:
Here's a silly Python riddle for you.

Today I opened up a Python 2.7 shell, and ran two commands in it.

>>> f = lambda: g(???)
>>> f() 

(Note that these are the only commands that I ran. You're not allowed to run any other commands before them.)

The riddle: What's the shortest thing you can put instead of ??? so my second command would not raise an exception?


Ram.


_______________________________________________ Python-il mailing list Python-il <at> hamakor.org.il http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il


_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il
Shai Berger | 17 Dec 2011 16:01
Gravatar

Re: Silly Python riddle

On Saturday 17 December 2011, Ram Rachum wrote:
> Here's a silly Python riddle for you.
> 
> Today I opened up a Python 2.7 shell, and ran two commands in it.
> 
> >>> f = lambda: g(???)
> >>> f()
> 
> (Note that these are the only commands that I ran. You're not allowed to
> run any other commands before them.)
> 
> The riddle: What's the shortest thing you can put instead of *???* so my
> second command would not raise an exception?
> 
I have a cheating solution that goes down to 3: """

It's cheating because your second line is not a command (and in fact, it makes 
the whole thing not yet a commnd):

>>> f = lambda: g(""")
... f()
... 

But still, at this point, no exception has been raised.
_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Ram Rachum | 17 Dec 2011 16:03
Gravatar

Re: Silly Python riddle

On Sat, Dec 17, 2011 at 5:01 PM, Shai Berger <shai <at> platonix.com> wrote:
On Saturday 17 December 2011, Ram Rachum wrote:
> Here's a silly Python riddle for you.
>
> Today I opened up a Python 2.7 shell, and ran two commands in it.
>
> >>> f = lambda: g(???)
> >>> f()
>
> (Note that these are the only commands that I ran. You're not allowed to
> run any other commands before them.)
>
> The riddle: What's the shortest thing you can put instead of *???* so my
> second command would not raise an exception?
>
I have a cheating solution that goes down to 3: """

It's cheating because your second line is not a command (and in fact, it makes
the whole thing not yet a commnd):

>>> f = lambda: g(""")
... f()
...

But still, at this point, no exception has been raised.


Yeah, that's a good cheat :)

_______________________________________________
Python-il mailing list
Python-il <at> hamakor.org.il
http://hamakor.org.il/cgi-bin/mailman/listinfo/python-il

Gmane