Last active
August 29, 2015 14:03
-
-
Save sushain97/a2d6683e1dfee360415f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, itertools | |
from fractions import Fraction | |
#Squares | |
a = range(1, 26) + range(20, 26) | |
random.shuffle(a) | |
print('\n'.join(map(lambda x: str(x).rjust(2) + '² = ' + '_' * 15, a))) | |
#Cubes | |
a = range(1, 13) + range(10, 13) | |
random.shuffle(a) | |
print('\n'.join(map(lambda x: str(x).rjust(2) + '³ = ' + '_' * 15, a))) | |
#Figurate Numbers | |
numtypes = 'triangular square cube pentagonal octagonal hexagonal heptagonal'.split() | |
a = list(itertools.chain(*[['%s %s number = ________________' % (ordinal(random.choice(range(1, 10))), numtype) for i in range(1, 5)] for numtype in numtypes])) | |
random.shuffle(a) | |
print('\n'.join(map(lambda x: x.rjust(max(map(len, a))), a))) | |
def ordinal(value): | |
if value % 100//10 != 1: | |
if value % 10 == 1: | |
ordval = u"%d%s" % (value, "st") | |
elif value % 10 == 2: | |
ordval = u"%d%s" % (value, "nd") | |
elif value % 10 == 3: | |
ordval = u"%d%s" % (value, "rd") | |
else: | |
ordval = u"%d%s" % (value, "th") | |
else: | |
ordval = u"%d%s" % (value, "th") | |
return ordval | |
# Common Decimals/Fractions/Percentages | |
nums = map(Fraction, '1/2 1/3 2/3 1/5 2/5 3/5 4/5 1/6 2/6 3/6 4/6 5/6 1/8 3/8 5/8 7/8 1/9 2/9 4/9 5/9 7/9 8/9 1/10 1/12 1/16 1/32'.split()) | |
random.shuffle(nums) | |
print('\n'.join([(('%s as a' % num) + (' decimal ' if float(num) * 1000000 % 1 == 0 else ' percent ')).rjust(18) + '_' * 15 for num in nums])) | |
# Roman Numerals <-> Arabic Numerals | |
print('\n'.join([str(int_to_roman(random.choice(range(1000, 3000)))).rjust(13) + ' = ' + '_' * 15 for i in range(1, 25)])) | |
print('\n'.join([str(random.choice(range(1, 3000))).rjust(4) + ' = ' + '_' * 15 for i in range(1, 30)])) | |
numeral_map = tuple(zip( | |
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1), | |
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I') | |
)) | |
def int_to_roman(i): | |
result = [] | |
for integer, numeral in numeral_map: | |
count = i // integer | |
result.append(numeral * count) | |
i -= integer * count | |
return ''.join(result) | |
def roman_to_int(n): | |
i = result = 0 | |
for integer, numeral in numeral_map: | |
while n[i:i + len(numeral)] == numeral: | |
result += integer | |
i += len(numeral) | |
return result | |
# Consecutive Integer Sums | |
evens = map(lambda x: (('2 + 4 + 6 + ... + %s = ' % x) + '_' * 15).rjust(44), [random.choice(range(10, 30, 2)) for i in range(0, 7)]) | |
odds = map(lambda x: (('1 + 3 + 5 + ... + %s = ' % x) + '_' * 15).rjust(44), [random.choice(range(9, 30, 2)) for i in range(0, 7)]) | |
consecs = map(lambda x: (('1 + 2 + 3 + ... + %s = ' % x) + '_' * 15).rjust(44), [random.choice(range(5, 30, 2)) for i in range(0, 7)]) | |
squares = map(lambda x: (('1² + 2² + 3² + ... + %s² = ' % x) + '_' * 15).rjust(44), [random.choice(range(5, 15, 2)) for i in range(0, 4)]) | |
cubes = map(lambda x: (('1³ + 2³ + 3³ + ... + %s³ = ' % x) + '_' * 15).rjust(44), [random.choice(range(5, 10, 2)) for i in range(0, 4)]) | |
sums = evens + odds + consecs + squares + cubes | |
random.shuffle(sums) | |
print('\n'.join(sums)) | |
# Ending in 5 Multiplication | |
print('\n'.join(map(lambda x: ('%s5 × %s5 = ' % x) + '_' * 15, [(random.choice(range(2, 10)), random.choice(range(2, 10))) for i in range(0, 30)]))) | |
# Multiplying Numbers in the 90s/990s | |
n90s = map(lambda x: (' 9%s × 9%s = ' % x) + '_' * 15, [(random.choice(range(1, 10)), random.choice(range(1, 10))) for i in range(0, 15)]) | |
n990s = map(lambda x: ('99%s × 99%s = ' % x) + '_' * 15, [(random.choice(range(1, 10)), random.choice(range(1, 10))) for i in range(0, 15)]) | |
q = n90s + n990s | |
random.shuffle(q) | |
print('\n'.join(q)) | |
# Reciprocal Work | |
plus = map(lambda x: ('1/%s + 1/%s = 1/X ' % x) + '_' * 15, [(random.choice(range(2, 10)), random.choice(range(2, 10))) for i in range(0, 15)]) | |
minus = map(lambda x: ('1/%s - 1/%s = 1/X ' % (x, random.choice(range(x, 10)))) + '_' * 15, [random.choice(range(2, 10)) for i in range(0, 15)]) | |
q = plus + minus | |
random.shuffle(q) | |
print('\n'.join(q)) | |
# Subsets/Proper Subsets/Improper Subsets | |
words = [set('a'), set('an'), set('cat'), set('duck'), set('cobra'), set('badger'), set('dolphin')] | |
types = 'subsets_improper subsets_proper subsets'.split('_') | |
q = list(itertools.chain(*list(map(lambda x: map(lambda y: ('%s %s = ' % (y, x)).rjust(55) + '_' * 15, types), words)))) | |
random.shuffle(q) | |
print('\n'.join(q)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment