Tag Archives: Python

Legible Word Scrambling

I was recently reading the Lucky Basartd page on the Stone Brewery website and I remembered an (unverified) study claiming “scrambled words are legible as long as first and last letters are in place.” For grins, I whipped up a Python script to scramble a word/sentence.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Syntax highlighting comes to Posterous

Here is some Python code!

# sample Python code snippet
# bonus points if you know what this is
from __future__ import generators

def firstn(g, n):
    for i in range(n):
        yield g.next()

def intsfrom(i):
    while 1:
        yield i
        i = i + 1

def exclude_multiples(n, ints):
    for i in ints:
        if (i % n): yield i

def sieve(ints):
    while 1:
        prime = ints.next()
        yield prime
        ints = exclude_multiples(prime, ints)

if __name__ == '__main__':
    for i in firstn(sieve(intsfrom(2)), 400):
    print i