Last active
August 29, 2015 14:01
-
-
Save tos-kamiya/b57eec2f93adc34c7b6a to your computer and use it in GitHub Desktop.
brute force solution for a math question
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
#coding: utf-8 | |
import sys | |
import itertools | |
write = sys.stdout.write | |
nums = [i for i in range(1, 9+1)] | |
for hidden in itertools.combinations(nums, 2): | |
shown = list(sorted(set(nums) - set(hidden))) | |
assert len(shown) == 7 | |
for num_on_blackboard in range(10, 99+1): | |
mod_0_stus = 0 | |
for stu in shown: | |
possible_nums = [stu] + list(hidden) | |
if all(num_on_blackboard % pn == 0 for pn in possible_nums): | |
mod_0_stus += 1 | |
if mod_0_stus == 5: | |
write("hidden = %s\n" % list(hidden)) | |
write("num on blackboard = %d\n" % num_on_blackboard) | |
write("\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment