Code used

In[20]:

a = 1 b = 6 c = 3 d = 2 e = 4 f = 5 g = 6 h = 2 i = 5 j = 2 k = 1 l = 3 m = 4 n = 5 o = 3 p = 5 q = 1 r = 1 s = 3

In[12]:

TN = 10

tplist = [('a', 'b', 'c'), ('a', 'd', 'h'), ('a', 'e', 'j'), ('b', 'e', 'i'), ('b', 'f', 'k'), ('c', 'f', 'j'), ('d', 'i', 'n'), ('d', 'e', 'f'), ('e', 'i', 'm'), ('e', 'f', 'g'), ('e', 'j', 'o'), ('f', 'j', 'n'), ('f', 'k', 'p'), ('g', 'k', 'o'), ('h', 'i', 'j'), ('h', 'm', 'q'), ('i', 'n', 'r'), ('i', 'j', 'k'), ('j', 'k', 'l'), ('j', 'n', 'q'), ('j', 'o', 's'), ('k', 'o', 'r'), ('l', 'p', 's'), ('m', 'n', 'o'), ('n', 'o', 'p'), ('q', 'r', 's'), ('c', 'g', 'l')]

# STREAMLIT ROUGH

In[151]:

import streamlit as st import itertools import uuid

st.title("Memory Magic: Hexagon Time!")

st.write('You will have 1 minute to memorize the following hexagon. You will then be shown a corresponding hexagon with letters instead.') st.write('You will be given a 1 minute to generate all the combinations of 3 letters in a row that form the target number.') st.write('However, you must state the corresponding letters in the hexagon, not the numbers, that add up to the target number.') st.write('One point will be awarded for every correct answer. However, one point will be deducted for every wrong answer.') st.write('You win the game once you reach 2 points! You automatically lose if you reach negative points.')

count = 0 wintotal = 2 submitted_combo = set() tplist = [('a', 'b', 'c'), ('a', 'd', 'h'), ('a', 'e', 'j'), ('b', 'e', 'i'), ('b', 'f', 'k'), ('c', 'f', 'j'), ('d', 'i', 'n'), ('d', 'e', 'f'), ('e', 'i', 'm'), ('e', 'f', 'g'), ('e', 'j', 'o'), ('f', 'j', 'n'), ('f', 'k', 'p'), ('g', 'k', 'o'), ('h', 'i', 'j'), ('h', 'm', 'q'), ('i', 'n', 'r'), ('i', 'j', 'k'), ('j', 'k', 'l'), ('j', 'n', 'q'), ('j', 'o', 's'), ('k', 'o', 'r'), ('l', 'p', 's'), ('m', 'n', 'o'), ('n', 'o', 'p'), ('q', 'r', 's'), ('c', 'g', 'l')]

while count < wintotal and count >= 0: # Get the letters from the user letters = st.text_input("Enter a sequence of 3 letters (e.g., abc): ", key=uuid.uuid4()).lower()

if letters:
    if len(letters) == 3:
        # Generate and print all permutations of the entered 3 letters
        permutations = itertools.permutations(letters)
        # Initialize flag
        flag = False

        for combo in permutations:
            combo_tuple = tuple(combo)

            if combo_tuple not in submitted_combo:
                submitted_combo.add(combo_tuple)

                for i in range(len(tplist)):
                    if tplist[i] == combo:
                        flag = True
                        if eval(combo[0]) + eval(combo[1]) + eval(combo[2]) == 10:  # Assuming TN is 10
                            ANSWER = True
                        else:
                            ANSWER = False
                        if ANSWER:
                            count += 1
                            st.write(f'You are correct! Your score is now {count}')
                        else:
                            count -= 1
                            st.write(f'You are incorrect. Your score is now {count}')

                if flag == False:
                    st.write('Not a possible combo/ Duplicate entries not allowed.')
        else:
            st.write("Please enter exactly 3 letters.")
    else:
        st.write("Please enter exactly 3 letters.")

if count < 0:
    st.write("Automatic Loss!")
elif count == wintotal:
    st.write("You win! Your score is now", count)

Built With

Share this project:

Updates