Theonlyfunctions you may use are:print, str, int, float, bool, len, list, range, abs, round,andpow. Note that you may not use slicing(AKA colons in your indicies) and sorting functions are prohibited....

1 answer below »

Theonlyfunctions you may use are:print, str, int, float, bool, len, list, range, abs, round,andpow.Note that you may not use slicing(AKA colons in your indicies) and sorting functions are prohibited. The random library is imported in the template for you for Problem 2, but do not import any other libraries.

Design and code python solutions for the puzzle problems. You must come up with your own algorithm and the honor code applies (no references). Your solutions will not be graded for efficiency or for hardcoding.



Problem 1 (50pts)



The Bridge Puzzle


Four people wish to cross a bridge. It is dark, and it is necessary to use a torch when crossing the bridge, but they have only one torch between them. The bridge is narrow, and only two people can be on it at any one time. The four people take different amounts of time to cross the bridge; when two cross together they proceed at the speed of the slowest. The torch must be ferried back and forth across the bridge, so that it is always carried when the bridge is crossed.


Come up with a solution and write a python functionacross_bridge(people)that expects an array [A,B,C,D] of times as positive integers(in minutes) for persons A,B,Cand D and returns the minimum time it takes for all the people to get across bridge as an integer. (Note: Do not assume the input is sorted)



Problem 2 (50pts)


The Kangaroo Cross Puzzle


In the second problem for this homework, there is code that has been adapted into Python 3 in your template file based on the code foundhere(Links to an external site.). By default, the code successfully implements Warnsdorff’s algorithm to solve the Knight's Tour Problem. The goal is to adapt this code to work with the irregular board shape that was given to you below:


(will attach picture in the following file)


There are three comments labeled “#### CHANGE HERE ####” that give hints about where in the code a change should be made. Understanding the original code that works for the 8 by 8 board is key to making the proper changes and making the program work for our irregular board shape. The input for your program will take the initial x and initial y coordinate for the closed tour. The output is a successful closed tour that gets printed at the end.


Recommended Approach:





    1. Run the program as it is originally on the 8 by 8 board to inspect firsthand its input and output.

    2. Then, try to have your board start at different locations by giving it a different input. (In the comments at the top of Problem 2 the coordinates for a board configuration for a 4 by 4 are listed. This could be expanded to represent the board configuration for the 8 by 8 as you are testing different inputs for the starting square).

    3. After you are comfortable successfully running the program with different inputs, then start to analyze Problem 2 function by function.

    4. There is not a solution for all square board configurations, but there is for a 6x6, so you can experiment with that configuration too(Note there is no solution for an NxN board when N is 2,4 or odd).

    5. There are three major changes that need to be made to get the problem to work for our irregular board shape. The “#### CHANGE HERE ####” comments are a guide to where those changes should be made.

    6. When you run the program, you should eventually see your closed tour printed as output. Thus, there is no reason to use a WebCAT submission if you are not able to see the output of a successful closed tour.



Answered 1 days AfterOct 05, 2021

Answer To: Theonlyfunctions you may use are:print, str, int, float, bool, len, list, range, abs, round,andpow....

Sathishkumar answered on Oct 07 2021
136 Votes
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 6 23:19:00 2021
@author: Sathish
"""
'''
HW 7 Template
@author:
@pid:
@CRN:
@date:
@Honor Code Pledge:
'''
import ra
ndom;
#Problem 1
def across_bridge(people: list) -> int:
"""Finds the minimum time for 4 people to cross a bridge.
It is dark, and it is necessary to use a torch when crossing the bridge,
but they have only one torch between them. The bridge is narrow, and only two
people can be on it at any one time. The four people take the given amounts of
time to cross the bridge; when two cross together they proceed at the speed
of the slowest. The torch must be ferried back and forth across the bridge,
so that it is always carried when the bridge is crossed.
@param a list of 4 positive integers representing the times of the 4 people
@return the minimum amount of time possible for the 4 people to get across the bridge
"""
###################################################################################
#Problem 2
'''
The Knight's tour problem solved via Warnsdorff's algorithm.
Warnsdorff's algorithm: https://www.geeksforgeeks.org/warnsdorffs-algorithm-knights-tour-problem/
More info: https://en.wikipedia.org/wiki/Knight%27s_tour
King's Cross Board Configuration:
*(0,0) (0,1) (0,2) *(0,3)
(1,0) (1,1) (1,2) (1,3)
(2,0) (2,1) (2,2) (2,3)
*(3,0) (3,1) (3,2) *(3,3)
* - the value in these corner squares will remain -1 because they are
not a part of the King's Cross Board
'''
class Cell:
def __init__(self, x, y):
self.x = x;
self.y = y;
class GFG:
#### CHANGE HERE ####
# Dimensions of a square chessboard
N = 12

possible_knight_movements = 8
#...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here