Programming Expert

profileJim_Ak
python_assignment.zip

python_assignment/Hanoi (1).py

####################################### # # Name: # Date: # File Name: tower_hanoi.py # Purpose: To create a function which # makes a user input into a hanoi tower formula # ####################################### def hanoi(n, one, two, three): if n > 0: hanoi(n - 1, one, three, two) if one[0]: disk = one[0].pop() print "moving " + str(disk) + " from " + one[1] + " to " + three[1] three[0].append(disk) hanoi(n - 1, two, one, three) insert_numbers = int(input('Put a number: ')) insertNumList = [] for disk in reversed(range(1, insert_numbers+1)): insertNumList.append(disk) print '' one = (insertNumList,'on peg one') two = ([],'on peg two') three = ([],'on peg three') print 'Start: ',one,two,three print '' hanoi(len(one[0]),one,two,three) print '' print 'End Result: ',one,two,three print "It took", int((2**insert_numbers)-1), "steps."

python_assignment/Maze Solver - Rubric.xlsx

Sheet1

Maze Solver - Rubric
Student Name:
For each evaluation criteria, fill out the deserved number of marks (out of the total shown) :
Description Self assessment marks out of Teacher evaluation
load_maze function
the function returns two-dimentional list 1
the returned list is exact representation of the input file - each character is an element 1
the 'new line' characters are not included in the returned list 1
the function does not alter the input file 1
pick_random_location function
the function returns a tuple of two integer numbers - column and row 1
the chosen location falls inside the maze 1
the chosen location is an empty alley spot 1
print_maze function
the function prints arbitrary 2D array of single characters 1
the elements from each nested list are agregated into a string 1
strings are printed on separate lines, one after another, no spacing between them 1
find_path RECURSIVE function
the base cases are propely defined 3
the function returns result when a base cases is encountered 2
the function marks current location with a '+' sign, as part of the path 1
the function calls itself recursively for all surrounding cells 4
the function unmarks current location as part of the path if there is no path via any of the surrounding cells 1
Application of concepts
the program visualizes the process of solving the maze by drawing it at each step 3
the program uses properly two-dimensional list 2
the program converts efficiently string to list and vice versa 2
Overall
functionality 4
program appearance (header/comments/docstrings/names/spacing) 4
TOTAL 0 36 0
Comments:

Sheet2

Sheet3

python_assignment/solution and iterations.zip

solution and iterations/maze.pyc

solution and iterations/maze_solver_main.py

######################################### # Programmer: Mr. G # Date: 28.02.2013 # File Name: maze_solver-main.py # Description: This program solves a maze of arbitrary size. # The program follows the algorithm described on the following website: # http://www.cs.bu.edu/teaching/alg/maze/ # Input file must comply with the following guidelines: # - walls are one character thick and represented with "#" # - alleys are one character wide and represented with spaces # - each line, including the last, ends with 'new line' character # Module maze contains the following functions: # - load_maze(fname) # - pick_random_location(maze) # - print_maze(maze) # - find_path(maze, x, y) # After importing the module, use help(function name), to understand how they work. # These functions exercise the following: # - reading from a file: # - nested lists (2D lists) # - string.join method: # L = ['i', 't', 'e', 'r', 'a', 'b', 'l', 'e'] # print ''.join(L) # - list comprehension # - recursion ######################################### import random from maze import * #---------------------------------------# # main program # #---------------------------------------# fname = raw_input("Enter filename: ") maze = load_maze(fname) # generate random start and goal locations Sx,Sy = pick_random_location(maze) maze[Sy][Sx] = 'S' Gx,Gy = pick_random_location(maze) maze[Gy][Gx] = 'G' print '\nHere is the maze with start and goal locations:' print_maze(maze) # now, find the path from S to G find_path(maze, Sx, Sy) print '\nHere is the maze with the path from start to goal:' print_maze(maze)

solution and iterations/maze1.txt

############################### # # # # # # # # # ##### # ##### # ### ### # # # # # # # # # # # ### ######### # # ####### # # # # # # # # # # ### # # # ######### ### # ### # # # # # # # # # # # ### ### # # ### ### ##### # # # # # # # # # # # # # # ### # # # ### # ### ### # ### # # # # # # # # # # # # ### ### # ######### # # # ### # # # # # # # # # # # # ### ### # ### # # ### # # # # # # # # # # ###############################

solution and iterations/maze2.txt

##################### # # # # ### # ##### ### # # # # # # # # # # ##### ##### ##### # # # # # # # # # # # # # # ##### # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # # # ### ##### # ### # # # # # # # # # ### # ######### # # # # # # # # # # ##### # ####### # # # # # # # ### ##### # # # ### # # # # # # # # ##### ########### # # # #####################

solution only/maze.pyc

solution only/maze_solver_main.py

######################################### # Programmer: Mr. G # Date: 28.02.2013 # File Name: maze_solver-main.py # Description: This program solves a maze of arbitrary size. # The program follows the algorithm described on the following website: # http://www.cs.bu.edu/teaching/alg/maze/ # Input file must comply with the following guidelines: # - walls are one character thick and represented with "#" # - alleys are one character wide and represented with spaces # - each line, including the last, ends with 'new line' character # Module maze contains the following functions: # - load_maze(fname) # - pick_random_location(maze) # - print_maze(maze) # - find_path(maze, x, y) # After importing the module, use help(function name), to understand how they work. # These functions exercise the following: # - reading from a file: # - nested lists (2D lists) # - string.join method: # L = ['i', 't', 'e', 'r', 'a', 'b', 'l', 'e'] # print ''.join(L) # - list comprehension # - recursion ######################################### import random from maze import * #---------------------------------------# # main program # #---------------------------------------# fname = raw_input("Enter filename: ") maze = load_maze(fname) # generate random start and goal locations Sx,Sy = pick_random_location(maze) maze[Sy][Sx] = 'S' Gx,Gy = pick_random_location(maze) maze[Gy][Gx] = 'G' print '\nHere is the maze with start and goal locations:' print_maze(maze) # now, find the path from S to G find_path(maze, Sx, Sy) print '\nHere is the maze with the path from start to goal:' print_maze(maze)

solution only/maze1.txt

############################### # # # # # # # # # ##### # ##### # ### ### # # # # # # # # # # # ### ######### # # ####### # # # # # # # # # # ### # # # ######### ### # ### # # # # # # # # # # # ### ### # # ### ### ##### # # # # # # # # # # # # # # ### # # # ### # ### ### # ### # # # # # # # # # # # # ### ### # ######### # # # ### # # # # # # # # # # # # ### ### # ### # # ### # # # # # # # # # # ###############################

solution only/maze2.txt

##################### # # # # ### # ##### ### # # # # # # # # # # ##### ##### ##### # # # # # # # # # # # # # # ##### # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # # # ### ##### # ### # # # # # # # # # ### # ######### # # # # # # # # # # ##### # ####### # # # # # # # ### ##### # # # ### # # # # # # # # ##### ########### # # # #####################