Skip to content

Instantly share code, notes, and snippets.

@kaapstorm
Last active April 17, 2024 21:44
Show Gist options
  • Save kaapstorm/7abab0bd1cbdccec9846f62046e0f174 to your computer and use it in GitHub Desktop.
Save kaapstorm/7abab0bd1cbdccec9846f62046e0f174 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from collections import Counter
num_to_word = {
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
}
def get_arrow(ee_int, nn_int, rr_int):
ee = num_to_word[ee_int]
nn = num_to_word[nn_int]
rr = num_to_word[rr_int]
return f"in this arrow there are {ee} e's, {nn} n's, and {rr} r's"
def solve():
for ee in range(4, 8):
for nn in range(3, 8):
for rr in range(5, 8):
arrow = get_arrow(ee, nn, rr)
c = Counter(arrow)
if (c['e'], c['n'], c['r']) == (ee, nn, rr):
return arrow
if __name__ == '__main__':
print(solve())
@millerdev
Copy link

Recursive solution with even fewer iterations. Requires a trick to prevent infinite recursion/no solution.

#!/usr/bin/env python3
# Did I take the arrow analogy too far? Is that a sin?
from collections import Counter

feathers = {
    3: 'three',
    4: 'four',
    5: 'five',
    6: 'six',
    7: 'seven',
    8: 'eight',
    10: 'ten',
}


def fletch(ee, nn, rr):
    es = feathers[ee]
    ns = feathers[nn]
    rs = feathers[rr]
    return f"in this arrow there are {es} e's, {ns} n's, and {rs} r's"


def shoot(*shaft, quiver):
    while (arrow := fletch(*shaft)) in quiver:
        # Without this trick we have infinite recursion/no solution.
        shaft = (shaft[0] + 1,) + shaft[1:]
    cc = Counter(arrow)
    straight = cc['e'], cc['n'], cc['r']
    if shaft == straight:
        return arrow
    quiver.append(arrow)
    return shoot(*straight, quiver=quiver)


if __name__ == '__main__':
    quiver = []
    print(shoot(4, 3, 5, quiver=quiver))
    print("\nbroken arrows:", len(quiver))
    print("\n".join(quiver))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment