Skip to content

Instantly share code, notes, and snippets.

@Alekseyyy
Last active February 17, 2022 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alekseyyy/c013a7786655de51ffa28c6187888e67 to your computer and use it in GitHub Desktop.
Save Alekseyyy/c013a7786655de51ffa28c6187888e67 to your computer and use it in GitHub Desktop.
# Aleksey's solution to the Collatz problem
count = 0
x = 33
while x > 1:
print("Iteration:", count, "\tx =", x)
if x % 2 == 0:
x = x / 2
else:
x = (3 * x) + 1
count += 1
print("Total number of iterations to x = 1:", count)
# A brute force solution to the 25 Nov., 2020 @GWOMaths #dailymaths challenge
# ... and it's brute force cos I'm lazy like Homer Simpson :P
# By Aleksey (@EpsilonCalculus)
# Link to their problem:
# https://twitter.com/GWOMaths/status/133149281757551682
die_1 = [x for x in range(1, 7)]
die_2 = [x for x in range(1, 7)]
target = 0
combinations = [x + y for y in die_2 for x in die_1]
for w in combinations:
if (w == 5 or w == 6) and not (w == 5 and w == 6):
target += 1
print("Solution:", (target / len(combinations)) * 100, "per cent")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment