diff options
author | Adolfo Rios <adolforinu@gmail.com> | 2010-05-21 13:14:03 (GMT) |
---|---|---|
committer | Adolfo Rios <adolforinu@gmail.com> | 2010-05-21 13:14:03 (GMT) |
commit | 3a24a5c2588fe2cc3f7701b4e7e13125bfae6882 (patch) | |
tree | 34a90608f073fc4b91b63100dc15aabd4c991403 | |
parent | 321b9403e5690af32a3d5717cca9fff51b1523fd (diff) | |
parent | e3300563245acf23fd894c5ecad43ef1c21b17b6 (diff) |
Merge branch 'master' of git.sugarlabs.org:pintando-fracciones/mainline
-rw-r--r-- | ChallengeGenerator.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/ChallengeGenerator.py b/ChallengeGenerator.py new file mode 100644 index 0000000..191adfd --- /dev/null +++ b/ChallengeGenerator.py @@ -0,0 +1,75 @@ +import random + +WHITE = 0 +RED = 1 +GREEN = 2 +BLUE = 3 +BROWN = 4 +PURPLE = 5 +YELLOW = 6 +PINK = 7 +ORANGE = 8 +GRAY = 9 + +COLORS = [WHITE, RED, GREEN, BLUE, BROWN, PURPLE, YELLOW, PINK, ORANGE, GRAY] + +class ColoredFraction(): + def __init__(self, numerator, denominator, color): + self._numerator = numerator + self._denominator = denominator + self._color = color + + def get_numerator(self): + return self._numerator + + def get_denominator(self): + return self._denominator + + def get_color(self): + return self._color + + def __str__(self): + return str(self._numerator) + "/" + str(self._denominator) + " : " + str(self._color) + +def general(amount_of_fractions, denominator): + numerators_list = range(1, denominator) + fractions = [] + numerators = [] + + while (sum(numerators) != denominator): + numerators = [] + for i in range(amount_of_fractions): + numerators.append(random.choice(numerators_list)) + + colors = [c for c in COLORS] + + for numerator in numerators: + color = random.choice(colors) + colors.remove(color) + fraction = ColoredFraction(numerator, denominator, color) + fractions.append(fraction) + + return fractions + +def easy(amount_of_fractions): + fractions = [] + + colors = [c for c in COLORS] + + for i in range(amount_of_fractions): + color = random.choice(colors) + colors.remove(color) + fraction = ColoredFraction(1,amount_of_fractions, color) + fractions.append(fraction) + + return fractions + +print "General" +fracciones = general(9,10) +for f in fracciones: + print f + +print "Facil" +fracciones = easy(5) +for f in fracciones: + print f |