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
Sheet1Maze Solver - RubricStudent Name:For each evaluation criteria, fill out the deserved number of marks (out of the total shown) :DescriptionSelf assessmentmarks out ofTeacher evaluationload_maze functionthe function returns two-dimentional list1the returned list is exact representation of the input file - each character is an element 1the 'new line' characters are not included in the returned list1the function does not alter the input file1pick_random_location functionthe function returns a tuple of two integer numbers - column and row1the chosen location falls inside the maze1the chosen location is an empty alley spot1print_maze functionthe function prints arbitrary 2D array of single characters1the elements from each nested list are agregated into a string1strings are printed on separate lines, one after another, no spacing between them1find_path RECURSIVE functionthe base cases are propely defined3the function returns result when a base cases is encountered2the function marks current location with a '+' sign, as part of the path 1the function calls itself recursively for all surrounding cells4the function unmarks current location as part of the path if there is no path via any of the surrounding cells1Application of conceptsthe program visualizes the process of solving the maze by drawing it at each step3the program uses properly two-dimensional list2the program converts efficiently string to list and vice versa2Overallfunctionality4program appearance (header/comments/docstrings/names/spacing)4TOTAL0360Comments:
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 ...
1. 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]
2. 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)
3. print ''
print 'End Result: ',one,two,three
print "It took", int((2**insert_numbers)-1), "steps."
python_assignment/Maze Solver - Rubric.xlsx
Sheet1Maze Solver - RubricStudent Name:For each evaluation
criteria, fill out the deserved number of marks (out of the total
shown) :DescriptionSelf assessmentmarks out ofTeacher
evaluationload_maze functionthe function returns two-
dimentional list1the returned list is exact representation of the
input file - each character is an element 1the 'new line'
characters are not included in the returned list1the function does
not alter the input file1pick_random_location functionthe
function returns a tuple of two integer numbers - column and
row1the chosen location falls inside the maze1the chosen
location is an empty alley spot1print_maze functionthe function
prints arbitrary 2D array of single characters1the elements from
each nested list are agregated into a string1strings are printed
on separate lines, one after another, no spacing between
them1find_path RECURSIVE functionthe base cases are propely
defined3the function returns result when a base cases is
encountered2the function marks current location with a '+' sign,
as part of the path 1the function calls itself recursively for all
surrounding cells4the function unmarks current location as part
of the path if there is no path via any of the surrounding
cells1Application of conceptsthe program visualizes the process
of solving the maze by drawing it at each step3the program uses
4. properly two-dimensional list2the program converts efficiently
string to list and vice versa2Overallfunctionality4program
appearance
(header/comments/docstrings/names/spacing)4TOTAL0360Com
ments:
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:
5. # - 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
###############################
# # # # #
8. #####################
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
9. # - 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
###############################
# # # # #
# # # # ##### # ##### # ### ###
# # # # # # # # #
# # ### ######### # # ####### #