You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.1 KiB

7 years ago
  1. from funcs import *
  2. from termcolor import colored
  3. ops = (
  4. '+',
  5. '-',
  6. '*',
  7. '/',
  8. )
  9. par = (
  10. '{n[0]}{o[0]}{n[1]}{o[1]}{n[2]}{o[2]}{n[3]}',
  11. '({n[0]}{o[0]}{n[1]}){o[1]}({n[2]}{o[2]}{n[3]})',
  12. '({n[0]}{o[0]}{n[1]}{o[1]}{n[2]}){o[2]}{n[3]}',
  13. '({n[0]}{o[0]}{n[1]}){o[1]}{n[2]}{o[2]}{n[3]}',
  14. )
  15. colors = [
  16. 'red',
  17. 'green',
  18. 'yellow',
  19. 'blue',
  20. 'magenta',
  21. 'cyan'
  22. ]
  23. var = ('a','b','c','d')
  24. ps = perms(4)
  25. def find(numbs,fast = False):
  26. answers = [[],[]]
  27. t = True
  28. for perm in ps:
  29. perm = list(
  30. map(
  31. lambda x:x-1,perm
  32. )
  33. )
  34. org = perm
  35. perm = choose(numbs,perm)
  36. for o in range(4**3):
  37. o = zp(con_base(o,4),3)
  38. o = choose(ops,o)
  39. for p in par:
  40. g = p.format(**{'n':perm,'o':o})
  41. try:
  42. if round(eval(g),2) == 10:
  43. if fast:
  44. return [g]
  45. else:
  46. var_subbed = choose(var,org)
  47. org = p.format(**{
  48. 'n':var_subbed,
  49. 'o':o
  50. })
  51. d = simplify(org)
  52. if not (d in answers[0]):
  53. answers[0].append(d)
  54. answers[1].append(g)
  55. except:
  56. pass
  57. return tuple(set(answers[1]))
  58. Strng0 = 'Fancy colors? (y or n):'
  59. Strng1 = 'One or all solutions (one or all):'
  60. fancy_colors = input(Strng0) == 'y'
  61. fast = input(Strng1) == 'all'
  62. print(
  63. find(
  64. list(range(1,5)),False
  65. )
  66. )
  67. while True:
  68. if fancy_colors:
  69. random.shuffle(colors)
  70. for col in colors:
  71. for ans in find(getInput(input('Numbers:')),fast):
  72. print(colored(ans,col))
  73. else:
  74. for ans in find(getInput(input('Numbers:')),fast):
  75. print(ans)