Skip to content

Instantly share code, notes, and snippets.

@cockscomb
Created November 10, 2011 12:24
Show Gist options
  • Save cockscomb/1354744 to your computer and use it in GitHub Desktop.
Save cockscomb/1354744 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from itertools import permutations
inputs = [1, 3, 5, 7, 9]
numbers = [7 * n[0] + 3 * n[1] + n[2] for n in permutations(inputs, 3)]
adoptables = list(filter(lambda x: x % 3 == 0, numbers))
print(numbers)
print(adoptables)
probability = float(len(adoptables)) / float(len(numbers))
print("Probability: {0}".format(probability))
[21, 23, 25, 25, 29, 31, 31, 33, 37, 37, 39, 41, 29, 31, 33, 37, 43, 45, 43, 47, 51, 49, 53, 55, 41, 45, 47, 45, 51, 53, 57, 59, 65, 63, 65, 69, 55, 57, 61, 59, 63, 67, 65, 67, 73, 77, 79, 81, 69, 71, 73, 73, 77, 79, 79, 81, 85, 85, 87, 89]
[21, 33, 39, 33, 45, 51, 45, 45, 51, 57, 63, 69, 57, 63, 81, 69, 81, 87]
Probability: 0.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment