Mathematics and False Number Essay

Submitted By shannonbodily
Words: 1116
Pages: 5

IP[y]: Notebook
Homework1 Last Checkpoint: Jan 19 07:57 (autosaved)
File
Edit
View
Insert
Cell
Kernel
Help
Cell Toolbar:
Finance 4480
Homework 1
Due January 23, 2015
This homework is all about putting to use your knowledge of Python from the different building blocks that you have seen so far.
We will be talking about these problems and I will give lots of hints in class!
1.1.1 Problem 1
This problem is known as the chicken nuggets problem. It goes like this: you walk into Chick Fil-A with an unlimited amount of money (and appetite!). You can purchase nuggets in containers of 6, 9, and 20.
Write a program to tell you the highest number of nuggets that you cannot purchase! Re-read that just in case it went past you the first time! The highest number that you cannot get. For example, you can get 15 nuggets by purchasing and box of 6 and a box of 9 nuggets. You can get 18 by purchasing 2 boxes of 9 nuggets. But with no combination of 6, 9, and 20 can you purchase 17 nuggets. What is the highest number that you cannot get?!
This simple game will give you experience assembling different bits of Python programming to find the solution. It will also employ a very simple numerical method called brute force search.
Please write your solution in the code cell below:
In [5]:

import numpy as np def main(): # your code goes here! print("Nuggets Problem") # remove this line of code for your final solution! number_array = np.array([ False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False]) print ("Initializing Array") number = 1 while number < 100: number_array[number] = False number = number + 1 print ("Adding 6's") n6 = 1 number = n6 * 6 while number < 100: number_array[number] = 1 n6 = n6 + 1 number = n6 * 6 print ("Adding 9's") n9 = 1 number = n9 * 9 while number < 100: number_array[number] = 1 n9 = n9 + 1 number = n9 * 9 print ("Adding 20's") n20 = 1 number = n20 * 20 while number < 100: number_array[number] = 1 n20 = n20 + 1 number = n20 * 20 print ("Adding 6, 9, and 20") number = 1 while number < 100: if number_array[number] == 1: number_array[number + 6] = 1 number_array[number + 9] = 1 number_array[number + 20] = 1 number = number + 1 print ("Looking for highest") highest = 0 number = 1 while number < 100: if number_array[number] == 0: highest = number number = number + 1 print "Highest=" print highest if __name__ == "__main__": main()
Initializing Array
Adding 6's
Adding 9's
Adding 20's
Adding 6, 9, and 20
Looking for highest
Highest=
43
Nuggets Problem
Problem 2
In the book Python Programming for the Absolute Beginner, 3rd Edition the author teaches Python through some simple game programming. One of the first games that he shows how to write is the so-called Guess My Number game, which is the children's game of guessing some one's secret number (a number between 1 and 100).
An implementation of the game in Python might look something like this:
In [ ]:

import random def print_header(): print("\tWelcome to 'Guess My Number'!") print("\tI'm thinking of a number between 1 and 100.") print("\tTry to guess it in as few…