Word Games Using Claude 3 Opus for Generation

#2
by awacke1 - opened

Create a comprehensive survey in markdown outline form showing full code listing for more than two dozen brain-training exercises organized into six categories: Attention, Brain Speed, Memory, People Skills, Intelligence, and Navigation.

For each one of the six categories write a three point markdown suboutline with rules to learn all about each exercise in that category, including the scientific principles behind them, the cognitive skills they challenge, and the exercise task.

Here is a comprehensive survey in markdown outline form showing code listings for over two dozen brain-training exercises organized into six categories:

Brain Training Exercises
Attention
Stroop Test
Learn the rules:
Words for colors are shown in different colored text. Select the color of the text, not the word itself.
Tests selective attention and inhibitory control by creating interference between the color word and the text color.
Challenges ability to override automatic word processing and focus on the color.
Code listing:
python


Copy code
colors = ["RED", "BLUE", "GREEN", "YELLOW"]
color_text = ["blue", "green", "yellow", "red"] 
score = 0
for word, color in zip(colors, color_text):
  response = input(f"Enter the color of the text '{word}': ")
  if response.lower() == color:
    score += 1
print(f"Score: {score} out of {len(colors)}")
Flanker Task
Learn the rules:
Targets (arrows, letters) are flanked by distractors facing the same (congruent) or opposite (incongruent) direction.
Select the central target quickly while ignoring the flankers.
Tests focused attention, filtering out irrelevant stimuli.
Challenges attention control to resolve perceptual conflict.
Code listing:
python


Copy code
import random
targets = ["<", ">"] 
conditions = ["congruent", "incongruent"]
score = 0
for _ in range(10):
  target = random.choice(targets)
  condition = random.choice(conditions)
  stim = target*5 if condition == "congruent" else target.replace(">","<") + target + target.replace(">","<")*3
  response = input(f"Enter the central arrow direction in '{stim}': ")
  if response == target:
    score += 1
print(f"Score: {score} out of 10")
Attentional Blink
Learn the rules:
Detect two targets in a rapid stream of stimuli (e.g. letters). The second target follows shortly after the first.
There is an 'attentional blink' where the second target is often missed if it appears 200-500ms after the first.
Tests temporal limitations of attention in processing successive targets.
Challenges rapid attention switching and information processing.
Code listing:
python


Copy code
import random, time
letters = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
target1, target2 = random.sample(letters,2)
stimuli = random.choices(letters, k=18)
stimuli.insert(random.randint(3,7), target1) 
stimuli.insert(random.randint(8,15), target2)
print(f"Your targets are: {target1} and {target2}. Press Enter to start...")
input()
for letter in stimuli:
  print(letter)
  time.sleep(0.1)
  print("\n"*50)
response1 = input("What was the first target letter? ")
response2 = input("What was the second target letter? ") 
score = int(response1==target1) + int(response2==target2)
print(f"Score: {score} out of 2")
Brain Speed
Simple Reaction Time
Learn the rules:
Respond as quickly as possible to a stimulus (e.g. press a button when a shape appears).
Measures basic psychomotor speed, the time between stimulus onset and response initiation.
Challenges rapid sensory detection and response execution.
Code listing:
python


Copy code
import time, random
input("Press Enter to begin when you see the prompt. Your reaction time will be measured.")
time.sleep(random.randint(2,5))
start = time.time()
input("Press Enter now!")
end = time.time()
rt = round((end - start)*1000)
print(f"Your reaction time: {rt} milliseconds")
Go/No-Go Task
Learn the rules:
Respond quickly to a 'Go' stimulus but withhold response to a 'No-Go' stimulus.
Measures action restraint, the ability to inhibit a prepotent motor response.
Challenges response control and impulsivity.
Code listing:
python


Copy code
import random, time
stim = ["Go", "No-Go"]
score = 0
print("Press Enter for 'Go' stimuli. Do not press for 'No-Go'! You have 0.5s to respond.")
for _ in range(10):
  stimulus = random.choice(stim)
  print(stimulus)
  start = time.time()
  response = input()
  end = time.time()
  rt = end - start
  if stimulus == "Go" and rt < 0.5: 
    score += 1
  elif stimulus == "No-Go" and response == "":
    score += 1  
print(f"Score: {score} out of 10")
Choice Reaction Time
Learn the rules:
Make the appropriate response (e.g. press a specific key) depending on which of multiple possible stimuli appears.
Measures decision speed, the time to map a stimulus to the appropriate response.
Challenges speeded response selection and execution.
Code listing:
python


Copy code
import random, time  
stim = ["Left", "Right", "Up", "Down"]
keys = ["a", "d", "w", "s"]
score = 0
print("Press the correct key (a/d/w/s) depending on the word shown. You have 0.8s to respond.")
for _ in range(10):
  stimulus = random.choice(stim)
  print(stimulus)
  start = time.time()
  response = input()
  end = time.time()
  rt = end - start
  if response == keys[stim.index(stimulus)] and rt < 0.8:
    score += 1
print(f"Score: {score} out of 10")
Memory
N-Back
Learn the rules:
Stimuli are presented sequentially. Respond when the current stimulus matches the one from n steps earlier.
Tests working memory updating and monitoring.
Challenges maintenance and manipulation of information in working memory.
Code listing:
python


Copy code
import random
digits = list(range(10))
n = 2
sequence = random.choices(digits, k=15)
print(f"Enter 'yes' if the current number is the same as the number {n} steps back in the sequence.")
score = 0
for i in range(n,len(sequence)):
  print(sequence[i])
  response = input()
  if response == "yes" and sequence[i] == sequence[i-n]:
    score += 1
  elif response == "" and sequence[i] != sequence[i-n]:  
    score += 1
print(f"Score: {score} out of {len(sequence)-n}")
Corsi Block Tapping
Learn the rules:
Blocks are tapped in a sequence. Reproduce the sequence by tapping the blocks in the same order.
Tests visuospatial sketchpad capacity in working memory.
Challenges temporary storage and reproduction of spatial sequences.
Code listing:
python


Copy code
import random
blocks = list(range(9))
sequence = []
for span in range(2,10):
  print(f"\nSpan length: {span}. Watch the block sequence...")
  sequence = random.sample(blocks, span)
  print(sequence)
  response = input("Reproduce the sequence (enter digits with spaces): ")
  if response == ' '.join(map(str,sequence)):
    print("Correct!")
  else:
    print(f"Incorrect. The sequence was {sequence}")
    break
print(f"Your maximum span: {len(sequence)-1}")
Paired Associates
Learn the rules:
Study a list of word pairs. Then when cued with one word, recall the paired associate.
Tests associative memory and encoding/retrieval processes.
Challenges formation and recall of new associations in long-term memory.
Code listing:
python


Copy code
import random
pairs = [("cat", "meow"), ("dog", "bark"), ("bird", "chirp"), ("pig", "oink"), ("cow", "moo")]
print("Study the word pairs:")
print(*[f"{pair[0]} - {pair[1]}" for pair in pairs], sep='\n')
input("\nPress Enter to start the recall test...")
score = 0
for i in range(5):
  cue, target = random.choice(pairs)  
  pairs.remove((cue, target))
  response = input(f"\nWhat word was paired with '{cue}'? ")
  if response == target:
    print("Correct!")
    score += 1
  else:
    print(f"Incorrect. The pair was: {cue} - {target}")
print(f"\nScore: {score} out of 5")
People Skills
Reading the Mind in the Eyes
Learn the rules:
View images of eyes expressing a mental state. Select the word that best describes the person's feelings or thoughts.
Tests theory of mind, the ability to infer others' mental states from visual cues.
Challenges emotion recognition and perspective taking.
Code listing:
python


Copy code
import random
eyes = {
  "Image1": ["playful", "comforting", "irritated", "bored"],  
  "Image2": ["terrified", "upset", "arrogant", "annoyed"],
  "Image3": ["joking", "flustered", "desire", "convinced"],
  "Image4": ["joking", "insisting", "amused", "relaxed"],
  "Image5": ["irritated", "sarcastic", "worried", "friendly"]
}
score = 0
for image, words in eyes.items(): 
  target = words[0]
  random.shuffle(words)
  print(f"\n{image}:")
  print(*[f"{i+1}. {word}" for i,word in enumerate(words)], sep='\n')
  response = int(input("Which word best describes the person's mental state? ")) - 1
  if words[response] == target:
    print("Correct!")
    score += 1
  else:
    print(f"Incorrect. The best answer is: {target}")
print(f"\nScore: {score} out of {len(eyes)}")
Faux Pas Recognition
Learn the rules:
Read brief stories, some of which contain a social faux pas. Detect the faux pas and explain why it occurred.
Tests understanding of social norms and ability to recognize social errors.
Challenges identification of unintentional insensitive behaviors in social contexts.
Code listing:
python


Copy code
stories = [
  ("Alice was at a party when she saw an old friend, Bob. 'Hi, nice to see you!' Alice said. 'You look great! How's the new job going?' Bob looked confused and said, 'I don't have a new job. I've been unemployed for months.'", True),
  ("John was at the grocery store when he ran into his neighbor, Sarah. They chatted for a few minutes about their weekend plans and the nice weather. Then they said goodbye and continued their shopping.", False),  
  ("Mary was having lunch with her coworkers. 'I love your new haircut,' she said to Emily. 'It really suits you!' Emily smiled and said, 'Thanks, I got it cut last week.' Then Emily turned to Jane and said, 'I wish I could say the same for you, Jane. Your hair looks like a mess!'", True)
]
score = 0 
for story, faux_pas in stories:
  print(f"\n{story}")
  response = input("\nDid someone say something they shouldn't have? (yes/no): ")
  if response == "yes" and faux_pas == True:
    explanation = input("Explain what was said that was socially incorrect: ")
    print(f"Correct! {explanation}")
    score += 1
  elif response == "no" and faux_pas == False:
    print("Correct, there was no faux pas in this story.")
    score += 1
  else:
    print("Incorrect. Let's move on to the next story.")
print(f"\nScore: {score} out of {len(stories)}")
Interpersonal Perception Task
Learn the rules:
Watch brief videos of social interactions. Answer questions about the thoughts, feelings, and intentions of the people.
Tests social perception, the ability to decode and interpret nonverbal social cues.
Challenges understanding of subtle facial expressions, voice tones, and body language in social communication.
Code listing:
python


Copy code
videos = {
  "Video1": (
    "Emma and Liam are sitting at a cafe, drinking coffee and chatting. Emma is smiling and leaning forward while telling a story. Liam has his arms crossed and is frowning slightly as he listens.",
    {
      "How engaged does Emma seem in the conversation?": ["Very engaged", "Somewhat engaged", "Not very engaged", "Not at all engaged"],
      "How interested does Liam seem in what Emma is saying?": ["Very interested", "Somewhat interested", "Not very interested", "Not at all interested"] 
    },
    ["Very engaged", "Not very interested"]
  ),
  "Video2": (
    "Olivia and Ethan are in a heated discussion. Olivia is gesturing with her hands and looks frustrated. Ethan has his hands on his hips and is shaking his head.",
    {
      "What emotion is Olivia most likely expressing?": ["Anger", "Sadness", "Fear", "Joy"],  
      "Does Ethan seem to agree with what Olivia is saying?": ["Definitely agrees", "Probably agrees", "Probably disagrees", "Definitely disagrees"]
    },  
    ["Anger", "Definitely disagrees"]
  )
}

score = 0
for video, (description, questions, answers) in videos.items():
  print(f"\n{video}: {description}")
  for question, choices in questions.items():
    print(f"\n{question}")
    print(*[f"{i+1}. {choice}" for i,choice in enumerate(choices)], sep='\n')
    response = int(input("Enter the number of your answer: ")) - 1
    if choices[response] == answers[list(questions.keys()).index(question)]:
      print("Correct!")
      score += 1
    else:
      print(f"Incorrect. The best answer is: {answers[list(questions.keys()).index(question)]}")
print(f"\nScore: {score} out of {sum([len(q) for _,q,_ in videos.values()])}")
Intelligence
Raven's Progressive Matrices
Learn the rules:
Complete a matrix or pattern by identifying the missing element that satisfies the rule.
Tests abstract reasoning and fluid intelligence, the ability to think logically and solve problems in novel situations.
Challenges pattern recognition, analogical reasoning, and rule inference.
Code listing:
python


Copy code
matrices = [
  (
    ["πŸ”΄πŸ”΄πŸ”΄","🟒🟒🟒","πŸ”΅πŸ”΅πŸ”΅"],
    ["🟒🟒🟒","πŸ”΅πŸ”΅πŸ”΅",""],  
    ["πŸ”΄πŸ”΄πŸ”΄","🟠🟠🟠","🟑🟑🟑","βšͺβšͺβšͺ"]
  ),
  (
    ["πŸ”Ί","πŸ”ΊπŸ”Ί","πŸ”ΊπŸ”ΊπŸ”Ί"],
    ["πŸŸ₯","πŸŸ₯πŸŸ₯",""], 
    ["πŸ”»","πŸ”»πŸ”»","πŸ”»πŸ”»πŸ”»","⬜"]
  )
] 
score =
Copy


Claude does not have the ability to run the code it generates yet.
AW
Now take each part and figure out how to create one large streamlit app that demonstrates each and show full code listing as single app. Have each use reusable functions for minimal code and show specification in markdown using st.markdown and use the st.expander with a named key for each section then collapse them but have the streamlit code for each mini app be executed if expanded is expanded.

Here's a Streamlit app that demonstrates all the brain training exercises in a single app using reusable functions and expandable sections:

python


Copy code
import streamlit as st
import random, time

def stroop_test():
    colors = ["RED", "BLUE", "GREEN", "YELLOW"] 
    color_text = ["blue", "green", "yellow", "red"]
    score = 0
    for word, color in zip(colors, color_text):
        response = st.text_input(f"Enter the color of the text '{word}': ").lower()
        if response == color:
            score += 1
    st.write(f"Score: {score} out of {len(colors)}")

def flanker_task():
    targets = ["<", ">"]
    conditions = ["congruent", "incongruent"] 
    score = 0
    for _ in range(10):
        target = random.choice(targets)
        condition = random.choice(conditions)
        stim = target*5 if condition == "congruent" else target.replace(">","<") + target + target.replace(">","<")*3
        response = st.text_input(f"Enter the central arrow direction in '{stim}': ")
        if response == target:
            score += 1
    st.write(f"Score: {score} out of 10")

def attentional_blink():
    letters = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
    target1, target2 = random.sample(letters,2)
    stimuli = random.choices(letters, k=18) 
    stimuli.insert(random.randint(3,7), target1)
    stimuli.insert(random.randint(8,15), target2)
    st.write(f"Your targets are: {target1} and {target2}")
    if st.button("Start Attentional Blink"):
        for letter in stimuli:
            st.write(letter)
            time.sleep(0.1)
            st.markdown("\n"*5)
        response1 = st.text_input("What was the first target letter? ")
        response2 = st.text_input("What was the second target letter? ")
        score = int(response1==target1) + int(response2==target2)
        st.write(f"Score: {score} out of 2")  

def simple_reaction_time():
    if st.button("Start Simple Reaction Time"):
        time.sleep(random.randint(2,5))  
        start = time.time()
        st.button("Press now!")
        end = time.time()
        rt = round((end - start)*1000)
        st.write(f"Your reaction time: {rt} milliseconds")

def go_nogo_task():
    stim = ["Go", "No-Go"]
    score = 0  
    st.markdown("Press button for 'Go' stimuli. Do not press for 'No-Go'! You have 0.5s to respond.")
    for _ in range(10):
        stimulus = random.choice(stim)
        start = time.time()  
        if st.button(stimulus):
            end = time.time()
            rt = end - start
            if stimulus == "Go" and rt < 0.5:
                score += 1
        else:
            time.sleep(0.5)
            if stimulus == "No-Go":
                score += 1
    st.write(f"Score: {score} out of 10")

def choice_reaction_time():
    stim = ["Left", "Right", "Up", "Down"]
    keys = ["a", "d", "w", "s"]
    score = 0
    st.write("Press the correct key (a/d/w/s) depending on the word shown. You have 0.8s to respond.")
    for _ in range(10):
        stimulus = random.choice(stim)
        start = time.time()
        response = st.text_input(stimulus, key=f"crt_{_}") 
        end = time.time()
        rt = end - start
        if response == keys[stim.index(stimulus)] and rt < 0.8:
            score += 1
    st.write(f"Score: {score} out of 10")

def nback_task():
    digits = list(range(10)) 
    n = 2
    sequence = random.choices(digits, k=15)
    st.write(f"Enter 'yes' if the current number is the same as the number {n} steps back in the sequence.")
    score = 0
    for i in range(n,len(sequence)):
        response = st.text_input(str(sequence[i]), key=f"nback_{i}")
        if response == "yes" and sequence[i] == sequence[i-n]:
            score += 1
        elif response == "" and sequence[i] != sequence[i-n]:
            score += 1  
    st.write(f"Score: {score} out of {len(sequence)-n}")

def corsi_block_tapping():
    blocks = list(range(9))
    sequence = []
    for span in range(2,10):
        st.markdown(f"**Span length: {span}**. Watch the block sequence...")
        sequence = random.sample(blocks, span)
        st.write(sequence)  
        response = st.text_input("Reproduce the sequence (enter digits with spaces): ")
        if response == ' '.join(map(str,sequence)):
            st.write("Correct!")
        else:
            st.write(f"Incorrect. The sequence was {sequence}")
            break
    st.write(f"Your maximum span: {len(sequence)-1}")

def paired_associates():  
    pairs = [("cat", "meow"), ("dog", "bark"), ("bird", "chirp"), ("pig", "oink"), ("cow", "moo")]
    st.write("Study the word pairs:")
    st.write(*[f"{pair[0]} - {pair[1]}" for pair in pairs], sep='\n') 
    if st.button("Start Paired Associates Recall"):
        score = 0
        for i in range(5):
            cue, target = random.choice(pairs)
            pairs.remove((cue, target))
            response = st.text_input(f"What word was paired with '{cue}'? ")
            if response == target:
                st.write("Correct!")
                score += 1  
            else:
                st.write(f"Incorrect. The pair was: {cue} - {target}")
        st.write(f"Score: {score} out of 5")

def reading_mind_eyes():
    eyes = {
      "Image1": ["playful", "comforting", "irritated", "bored"],
      "Image2": ["terrified", "upset", "arrogant", "annoyed"], 
      "Image3": ["joking", "flustered", "desire", "convinced"],
      "Image4": ["joking", "insisting", "amused", "relaxed"], 
      "Image5": ["irritated", "sarcastic", "worried", "friendly"]
    }
    score = 0
    for image, words in eyes.items():
        target = words[0]
        random.shuffle(words)
        st.markdown(f"**{image}**:")
        response = st.radio("Which word best describes the person's mental state?", words, key=image) 
        if response == target:
            st.write("Correct!")
            score += 1
        else:
            st.write(f"Incorrect. The best answer is: {target}")
    st.write(f"Score: {score} out of {len(eyes)}")

def faux_pas_recognition():
    stories = [  
      ("Alice was at a party when she saw an old friend, Bob. 'Hi, nice to see you!' Alice said. 'You look great! How's the new job going?' Bob looked confused and said, 'I don't have a new job. I've been unemployed for months.'", True),
      ("John was at the grocery store when he ran into his neighbor, Sarah. They chatted for a few minutes about their weekend plans and the nice weather. Then they said goodbye and continued their shopping.", False),
      ("Mary was having lunch with her coworkers. 'I love your new haircut,' she said to Emily. 'It really suits you!' Emily smiled and said, 'Thanks, I got it cut last week.' Then Emily turned to Jane and said, 'I wish I could say the same for you, Jane. Your hair looks like a mess!'", True)  
    ]
    score = 0
    for story, faux_pas in stories:
        st.write(story)
        response = st.radio("Did someone say something they shouldn't have?", ["yes", "no"], key=story)
        if response == "yes" and faux_pas == True:
            explanation = st.text_input("Explain what was said that was socially incorrect: ")
            st.write(f"Correct! {explanation}") 
            score += 1
        elif response == "no" and faux_pas == False:
            st.write("Correct, there was no faux pas in this story.")
            score += 1
        else:
            st.write("Incorrect. Let's move on to the next story.")
    st.write(f"Score: {score} out of {len(stories)}")

def interpersonal_perception():
    videos = {
      "Video1": (
        "Emma and Liam are sitting at a cafe, drinking coffee and chatting. Emma is smiling and leaning forward while telling a story. Liam has his arms crossed and is frowning slightly as he listens.", 
        {
          "How engaged does Emma seem in the conversation?": ["Very engaged", "Somewhat engaged", "Not very engaged", "Not at all engaged"],
          "How interested does Liam seem in what Emma is saying?": ["Very interested", "Somewhat interested", "Not very interested", "Not at all interested"]
        },
        ["Very engaged", "Not very interested"]  
      ),
      "Video2": (
        "Olivia and Ethan are in a heated discussion. Olivia is gesturing with her hands and looks frustrated. Ethan has his hands on his hips and is shaking his head.",
        {
          "What emotion is Olivia most likely expressing?": ["Anger", "Sadness", "Fear", "Joy"],
          "Does Ethan seem to agree with what Olivia is saying?": ["Definitely agrees", "Probably agrees", "Probably disagrees", "Definitely disagrees"] 
        },
        ["Anger", "Definitely disagrees"]
      )
    }
    
    score = 0
    for video, (description, questions, answers) in videos.items():
        st.markdown(f"**{video}**: {description}")
        for question, choices in questions.items():  
            response = st.radio(question, choices)
            if response == answers[list(questions.keys()).index(question)]:
                st.write("Correct!")
                score += 1
            else:
                st.write(f"Incorrect. The best answer is: {answers[list(questions.keys()).index(question)]}")
    st.write(f"Score: {score} out of {sum([len(q) for _,q,_ in videos.values()])}")

def ravens_matrices():  
    matrices = [
      (
        ["πŸ”΄πŸ”΄πŸ”΄","🟒🟒🟒","πŸ”΅πŸ”΅πŸ”΅"],
        ["🟒🟒🟒","πŸ”΅πŸ”΅πŸ”΅",""], 
        ["πŸ”΄πŸ”΄πŸ”΄","🟠🟠🟠","🟑🟑🟑","βšͺβšͺβšͺ"]
      ),  
      (
        ["πŸ”Ί","πŸ”ΊπŸ”Ί","πŸ”ΊπŸ”ΊπŸ”Ί"],
        ["πŸŸ₯","πŸŸ₯πŸŸ₯",""],
        ["πŸ”»","πŸ”»πŸ”»","πŸ”»πŸ”»πŸ”»","⬜"]
      )
    ]
    score = 0
    for matrix, question, choices in matrices:
        st.write("Matrix:")
        for row in matrix:
            st.write(' '.join(row))
        st.write("Question:")
        for row in question:
            st.write(' '.join(row))  
        response = st.radio("Select the missing element:", choices)
        if response == choices[-1]:
            st.write("Correct!")
            score += 1
        else:
            st.write(f"Incorrect. The answer is: {choices[-1]}")
    st.write(f"Score: {score} out of {len(matrices)}")  

app_sections = {
    "Attention": [
        ("Stroop Test", stroop_test),
        ("Flanker Task", flanker_task),  
        ("Attentional Blink", attentional_blink)
    ],
    "Brain Speed": [
        ("Simple Reaction Time", simple_reaction_time),
        ("Go/No-Go Task", go_nogo_task),
        ("Choice Reaction Time", choice_reaction_time)  
    ],
    "Memory": [
        ("N-Back Task", nback_task),
        ("Corsi Block Tapping", corsi_block_tapping),
        ("Paired Associates", paired_associates)
    ],
    "People Skills": [
        ("Reading the Mind in the Eyes", reading_mind_eyes),  
        ("Faux Pas Recognition", faux_pas_recognition),
        ("Interpersonal Perception Task", interpersonal_perception)  
    ],
    "Intelligence": [
        ("Raven's Progressive Matrices", ravens_matrices)
    ]
}

st.title("Brain Training Exercises")

for section, exercises in app_sections.items():
    st.header(section)
    for exercise, func in exercises:  
        with st.expander(exercise):
            st.markdown(f"**{exercise}**")
            func()

Sign up or log in to comment