I would like to build something that allows me to obtain potions using two identical lists of ingredients.
ingredients = ["frog", "butterflies", "stones"]
ingredients_2 = ["frog", "butterflies", "stones"]
If I combine frog and stones, for example, I get frog marmelade. If I combine butterfly and butterfly I get super butterfly and so on...
But other than a terrifyingly long list of ifs, is there a better and more clever way to implement this?
I thought about a matrix:
row_num = 4
col_num = 4
grid = [[x for x in range(col_num)] for y in range(row_num)]
def print_grid():
for row in grid:
print(row)
def get_ingredient_1_index(ingredient_1):
index = 0
for item in grid[0]:
if item == ingredient_1:
return index
index += 1
return -1
def get_ingredient_2_index(ingredient_2):
index = 0
column_headers = [row[0] for row in grid]
for item in column_headers:
if item == ingredient_2:
return index
index += 1
return -1
def mix_ingredients(ingredient_1, ingredient_2):
coordinates_ingredient_1 = get_ingredient_1_index(ingredient_1)
coordinates_ingredient_2 = get_ingredient_2_index(ingredient_2)
return grid[coordinates_ingredient_2][coordinates_ingredient_1]
grid[0][1] = "frog"
grid[0][2] = "butterfly"
grid[0][3] = "stone"
grid[1][0] = "frog"
grid[2][0] = "butterfly"
grid[3][0] = "stone"
grid[1][1] = "superfrog"
grid[1][2] = "froggerfly"
grid[1][3] = "frog marmelade"
grid[1][1] = "superfrog"
grid[1][2] = "froggerfly"
grid[1][3] = "frog marmelade"
grid[2][1] = "froggerfly"
grid[2][2] = "super butterfly"
grid[2][3] = "butterfly jam"
grid[3][1] = "frog marmelade"
grid[3][2] = "butterfly jam"
grid[3][3] = "super stone"
print_grid()
Output
[' ', 'frog', 'butterfly', 'stone']
['frog', 'superfrog', 'froggerfly', 'frog marmelade']
['butterfly', 'froggerfly', 'super butterfly', 'butterfly jam']
['stone', 'frog marmelade', 'butterfly jam'print(mix_ingredients("frog", 'super stone']"butterfly"))
But then I cannot picture how to query it...
I think I'd need to be able to useit is a function similar to mix(ingredient1, ingredient2)
bit of clunky and get the proper mixpoor solution.
Can you help in pointing me into a better direction?