Solutions to Advent of Code 2017 https://adventofcode.com/2017/
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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. def part_one():
  2. # Part one: manually translated to Python
  3. mul, a, b, c, d, e, f, g, h = 0, 0, 84, 84, 0, 0, 0, 0 , 0 # set b 84
  4. # set c b
  5. if a != 0: # jnz a 2
  6. # jnz 1 5
  7. b *= 100
  8. mul += 1 # mul b 100
  9. b += 100000 # sub b -100000
  10. c = b # set c b
  11. c += 17000 # sub c -17000
  12. while True:
  13. f = 1 # set f 1
  14. d = 2 # set d 2
  15. while True:
  16. e = 2 # set e 2
  17. while True:
  18. g = d # set g d
  19. g *= e
  20. mul += 1 # mul g e
  21. g -= b # sub g b
  22. if g == 0: # jnz g 2
  23. f = 0 # set f 0
  24. e += 1 # sub e -1
  25. g = e # set g e
  26. g -= b # sub g b
  27. if g == 0: break # jnz g -8
  28. d += 1 # sub d -1
  29. g = d # set g d
  30. g -= b # sub g b
  31. if g == 0: break # jnz g -13
  32. if f == 0: # jnz f 2
  33. h += 1 # sub h -1
  34. g = b # set g b
  35. g -= c # sub g c
  36. if g == 0: break # jnz g 2
  37. # jnz 1 3
  38. b += 17 # sub b -17
  39. # jnz 1 -23
  40. return mul
  41. def part_two():
  42. # Part two: manually optimised and a little golfed... Turns out it's counting non-primes in a certain range.
  43. return sum(1 for b in range(108400, 125401, 17) if any(b % d == 0 for d in range(2, int(b**0.5)+1)))
  44. print(f'Part one: {part_one()}')
  45. print(f'Part two: {part_two()}')