Recursive Python Program

From GM-RKB
Jump to navigation Jump to search

A Recursive Python Program is a recursive program that is a Python program.



References

2016

#################################################
# the integer that we want to start dish identifiers with (likely the human standard of 1).
index_start=1
#################################################
# Read the life into an array
infile = open('menu_gen_input.csv')
menu_options = [line.rstrip().split(',') for line in infile.readlines()]
#menu_options = [['B', '4'], ['E', '5'], ['C', '3']] # to debug
#print menu_gen_dict # to debug
#################################################
# Recursively traverse the menu space
menus=[]
#################################################
def menu_combinations(menu_options, menus, menu=""):
   this_cuisine      = menu_options[0]
   cuisine_name      = this_cuisine[0]
   dishes_in_cuisine = this_cuisine[1]
   #
   for dish in range(0, int(dishes_in_cuisine)):
       next_dish = cuisine_name + str(dish + index_start)
       this_menu = menu + next_dish
       #
       if len(menu_options) == 1: # last cuisine
           menus.append(this_menu)
       else:
           sub_menu_options = menu_options[1:]
           menu_combinations(sub_menu_options, menus, menu+next_dish)
#################################################
menu_combinations(menu_options, menus)
for menu in menus: print "menu:", menu
menu: B1E1C1
menu: B1E1C2
menu: B1E1C3
...
menu: B4E5C1
menu: B4E5C2
menu: B4E5C3