Skip to content

Instantly share code, notes, and snippets.

@vexorian
Created May 20, 2015 05:57
Show Gist options
  • Save vexorian/888bff5c2bfdcf4fb435 to your computer and use it in GitHub Desktop.
Save vexorian/888bff5c2bfdcf4fb435 to your computer and use it in GitHub Desktop.
problem 2
>>> import random
>>> def alternate(a,b):
... c = a + b
... d = []
... wanted = 'a'
... while len(c) > 0:
... i = random.randint(0, len(c) - 1)
... print 'Is ',c[i],' from a or b?'
... if raw_input() == wanted:
... d.append( c[i] )
... c = c[:i] + c[i+1:]
... wanted = 'b' if wanted == 'a' else 'a'
... return d
...
>>> alternate( [1,2,3], ['a','b','c'] )
Is c from a or b?
b
Is 1 from a or b?
a
Is a from a or b?
b
Is b from a or b?
b
Is b from a or b?
b
Is b from a or b?
b
Is 3 from a or b?
a
Is b from a or b?
b
Is c from a or b?
b
Is 2 from a or b?
a
Is c from a or b?
b
[1, 'a', 3, 'b', 2, 'c']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment