Code golf challenge: XKCD 936 passwords

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Oct 8 03:48:17 EDT 2013


On 08/10/2013 07:48, sprucebondera at gmail.com wrote:
> On Monday, October 7, 2013 8:45:39 PM UTC-10, spruce... at gmail.com wrote:
>> On Monday, October 7, 2013 8:17:21 PM UTC-10, Chris Angelico wrote:
>>
>>> Who's up for some fun? Implement an XKCD-936-compliant password
>>> generator in Python 3, in less code than this:
>>> print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n"),4))
>>
>>> Second challenge: Use it for generating all your passwords :)
>>
>>> [1] https://en.wikipedia.org/wiki/Code_golf
>>> [2] http://xkcd.com/936/
>>
>>> ChrisA
>>
>> Well, here's a start:
>>
>> import random as r
>> print(*r.sample(open("/usr/share/dict/words").readlines(),4))
>> Shaves off 6 characters.
>
> And if we were actually trying then that filename should just be "/w". Would get rid of another 19 chars.
>

Very impressive, you've saved a total of 25 characters on one line and 
added too many lines to count to your emails, which I've snipped. 
Please read and digest this 
https://wiki.python.org/moin/GoogleGroupsPython, thanks in anticipation.

-- 
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence




More information about the Python-list mailing list