Skip to content

Instantly share code, notes, and snippets.

@mark-andrews
Created November 1, 2020 16:54
Show Gist options
  • Save mark-andrews/a37be6e65ae7e30634dc26b11f629340 to your computer and use it in GitHub Desktop.
Save mark-andrews/a37be6e65ae7e30634dc26b11f629340 to your computer and use it in GitHub Desktop.
Python code to make a n-back sequence of 9 letters of length 36
import string
from random import choice
letters = list(string.ascii_uppercase[:9])
n = 2
K = 36
stimuli = [None] * K
response = [None] * K
for i in range(K):
if i < n:
stimuli[i] = choice(letters)
else:
if choice([True, False]):
stimuli[i] = stimuli[i-2]
response[i] = 'same'
else:
while True:
stimuli[i] = choice(letters)
if stimuli[i] != stimuli[i-2]:
break
assert stimuli[i] != stimuli[i-2]
response[i] = 'different'
# look at the stimuli and the correct responses
list(zip(stimuli, response))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment