<jupyter_start><jupyter_text>The last ray of sunshine  You are one of the most renowned investigators in the world. An email arrives asking your help:   You book the first ticket to the North of Canada and drive to the far north. The place is desolate and icy. In front of you there is a weird looking cave. You get out of the car and approach the entrance of the cave. Before you know it there is noise behind you and evil Dr. Cane and helpers are charging toward you with their bear cavalry. You get arrested and thrown in a dungeon deep in the cave.   A screen lights up and a video starts playing. Dr. Cane appears on the screen laughing his evil laugh.<jupyter_code>your_name = input('Please give me your name: ')
print('\n Welcome '+ your_name + 
      """. You really think that you can save summers from me??? Dr. Cane? Dr. H<NAME>!? Muahahaha!""")
print("""Just to prove you wrong I left some hints for you around the room.
They could help you escape and find my weather machine. But you will never make it on time! Muahahaha!""")
print("""I will release the eternal storms on April 28 at 12pm. Hope you like swimming!""")<jupyter_output>Welcome . You really think that you can save summers from me??? Dr. Cane? Dr. HARRY Cane!? Muahahaha!
Just to prove you wrong I left some hints for you around the room.
They could help you escape and find my weather machine. But you will never make it on time! Muahahaha!
I will release the eternal storms on April 28 at 12pm. Hope you like swimming!<jupyter_text>Problem 1.  Looking for a way out ( **10 points** )<jupyter_code>print( your_name + """, let's save the summers together. To escape from this 
      room you will need to use the coding knowledge you got this semester.""")
print('\n')
print("""Don't forget that a good log is part of a successful mission! Start your log please! (3 points)""")
print('\n')
print("""You will need to import the necesary packages to do numerical problems and plot images. Start 
      by doing all your imports here. (5 points)""")
#import your modules here:

import numpy as np
import math
import scipy as sp
from scipy.stats import chisquare
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from mpl_toolkits.mplot3d import Axes3D
import os 
print("""You also need to create an empty list named *key_code* that you will slowly populate 
with the keys you get as you solve the puzzles (2 points)""")
key_code = []
print("""Let's find our way out of here! """)<jupyter_output>Let's find our way out of here!<jupyter_text>You take a look around the dungeon.  At the other side you see the door. Next to it there is something that looks like a key pad. The hints that evil Dr. Cane left all around the room are needed to get the code and escape out of this room...  Desks, books, paintings, chests, chairs are all over the place. This room is so full of possible hiding places. Where to start?   Problem 2.    The encrypted note ( **15 points** )   Walking across the dungeon you notice a weird looking painting. It smells of fresh paint. Dr. Cane must have just made this for some reason! You take a closer look. It depicts the dungeon you are in, but it looks slightly different. There is an open book on the floor. At first glance the book contains a weird collection of numbers. What could this mean? You suddenly realize it's a code. - Make a list *message* that contains all the numbers on the note (3 points). - Write a dictionary *letters_to_numbers* that has as keys letters of the alphabet and as values numbers 1 to 26 (5 points). - Make a code that loops over the numbers in the note and uses the dictionary to decode the message (5 points). Print the message out (2 points).<jupyter_code>print( 'This is what is written on the book:')
print(""" 20 9 3 11  20 15 3 11 20 9 3 11  20 15 3 11 20 9 13 5 9  19 18 21 14 14 9 14 9 7  15 21 20 """)
message = [20,9,3,11,20,15,3,11,20,9,3,11,20,15,3,11,20,9,13,5,9,19,18,21,14,14,9,14,9,7,15,21,20]
letters_to_numbers = {'A':1, 'B':2, 'C':3, 'D':4, 'E':5, 'F':6, 'G':7, 'H':8, 'I':9, 'J':10, 'K':11, 'L':12, 'M':13, 'N':14, 'O':15, 'P':16, 'Q':17, 'R':18, 'S':19, 'T':20, 'U':21, 'V':22, 'W':23, 'X':24, 'Y':25, 'Z':26}
for j in message:
    for i in letters_to_numbers:
        if j == letters_to_numbers[i]:
            print(i, end='')<jupyter_output>TICKTOCKTICKTOCKTIMEISRUNNINIGOUT<jupyter_text>Problem 3.  The clock on the wall ( 15 points)  Just as you decode the message a cuckoo clock goes off  somewhere in the room. The time is ticking indeed....You walk toward the clock. It looks old, and has a big mirror at the bottom part. The cuckoo wears glasses?!?! You look around and notice a pair of glasses on the floor that looks exactly like the one the cuckoo wears. Can it be part of the solution? You put the glasses on and look at the clock. There is a secret message painted on the mirror of the clock! - Use your favorite numpy routine to read in the data from 'the_clock_mirror.dat' (3 points) - Make a contour plot using contouring levels 0, 1, 2. (4 points) - Make the plot publication ready. (3 points)- Populate your *key_code* with the number you see on the mirror (2 points).  Print the *key_code* (1 points).<jupyter_code>clock_data = np.loadtxt('the_clock_mirror.dat')
plt.figure( figsize = (10,10))
plt.contourf(clock_data, cmap = 'Blues')
plt.yticks( np.arange( 0, 25, step = 10 ) ,fontsize=36 ) 
plt.xticks( np.arange( 0, 25, step = 10) ,fontsize=36 )
plt.xlabel( 'X', fontsize = 36 )
plt.ylabel( 'Y' , fontsize = 36, rotation=0 )
plt.title( 'The Evil Clock Mirror Clue' , fontsize = 36 )
key_code.append(3)
print(key_code)<jupyter_output>[3]<jupyter_text>Problem 4.  The wooden chest ( 20 points)  You feel excited! You got the first number. However, you have no idea where to look at next...did you miss something? You put on the glasses again and look around. On the opposite wall you see another hidden message written. - Read the data from 'the_secret_message.dat' (1 point) - Make a contour plot using contouring levels 0, 1, 2 and 3. (2 points) - The message is flipped. Use the appropriate plt command to flip the y-axis (2 points).<jupyter_code>secret_message = np.loadtxt('the_secret_message.dat')

secret_message = np.flip(secret_message,0)

plt.figure( figsize = (10,10))
plt.contourf(secret_message, cmap = 'Blues')
plt.yticks( np.arange( 0, 15, step = 2.5 ) ,fontsize=36) 
plt.xticks( np.arange( 0, 55, step = 10) ,fontsize=36)
plt.xlabel( 'X', fontsize = 36)
plt.ylabel( 'Y' , fontsize = 36, rotation = 0)
plt.title( 'The Evil Secret Message Clue' , fontsize = 36)<jupyter_output><empty_output><jupyter_text>You look up. There is a big wooden chest on an elevated floor. You go running to the ladder and climb it. You approach the chest and open it. It is full of torn pages from a book. You remove them from the box and see a picture of <NAME> laughing his evil laughter. Interestingly, the first page has a hand-written 'muahaha' at the top. Can this be the next clue? - Write a code that reads the the_torn_book.dat line by line (5 points), and counts how many many times the word 'muahaha' appears in it (5 points). - The code should then print an informative statement to let you know  how many evil laughters it found (2 points).  This is the next number you need for the key pad. - Populate your *key_code* (2 points) and print the current *key_code* out (1 point) ! Warning: DO NOT change the lower/upper case of the words in the book; you might get a wrong answer!<jupyter_code>f = open('the_torn_book.dat','r',encoding='utf-8') 
counter = 0
for line in f:
    word = line.split()
    if 'muahaha' in word:
        counter = counter + 1
    #print(line)
f.close()
print("My investigation uncovered", counter, "evil laughs!")
key_code.append(7)
print(key_code)<jupyter_output>[3, 7]<jupyter_text>Problem 5.  But wait, there is more. (15 points)  <NAME> left you a message on the last line of the book- Adapt your previous code to print it out (4 points).<jupyter_code>f = open('the_torn_book.dat','r',encoding='utf-8') 

for line in f:
    last_line = f.readlines()[-1]
    print(last_line)
f.close()<jupyter_output>I love me some math! what is the integer of: Sigma( n= 1 ) / Sigma (n=7 )+ Sigma (n=2) / Sigma(n = 3) ?<jupyter_text>What could this mean? You look at the book contents and suddenly it all makes sense! The text is full of numbers. You just need to add the counts of each number equal to one, two, three and seven, and then use the equation <NAME> gave you to calculate the next key.- Make a code that reads all the book (2 points) and counts how many 'one's, 'two's,'three's and 'seven's the book has (4 points). - Use these sums in the equation Dr. Cane gave you (2 point). - The integer part is the next number you need for the key pad (1 point).- Populate your *key_code* with this number (1 points).  - Print the *key_code* (1 points).<jupyter_code>f = open('the_torn_book.dat','r',encoding='utf-8') 
ones = 0
twos = 0
threes = 0
sevens = 0
for line in f:
    word = line.split()
    for i in word:
        if 'one' == i:
            ones = ones + 1
        elif 'two' == i:
            twos = twos + 1
        elif 'three' == i:
            threes = threes + 1
        elif 'seven' == i:
            sevens = sevens + 1 
f.close()
print(ones, twos, threes, sevens)
sum =(ones/sevens+twos/threes)
integer = int(sum)
print(integer)
key_code.append(integer)
print(key_code)<jupyter_output>[3, 7, 8]<jupyter_text>Problem 6  Around, around spins the world (10 points)   At the bottom of the chest there is a little holographic machine with a big red button. You feel the urge to press it. This ***must*** be the clue about where to look next.- Read data from file the_holograph.dat and assign the three columns to variables x1, y1, z1 (2 points). - Make a 3D scatter plot with your x1,y1,z1 data (5 points). - Save the 3D plot with an appropriate name (2 points).- What does it look like? Where is your next clue in the room? Print an informative statement with your answer. (1 point)<jupyter_code>holograph = np.loadtxt('the_holograph.dat')
x1 = holograph[:,0]
y1 = holograph[:,1]
z1 = holograph[:,2]
fig = plt.figure( figsize = ( 16, 16) )
ax = fig.add_subplot(111, projection='3d')

x1 = holograph[:,0]
y1 = holograph[:,1]
z1 = holograph[:,2]

ax.scatter(x1,y1,z1, c='blue', marker='d') 

plt.title( 'Evil Holograph Scatter Plot' , fontsize = 35 )

plt.savefig( 'Evil Holograph.png', format = 'png', dpi = 100, bbox_inches = 'tight', pad_inches = 0.3 )

ax.set_xlabel('X1', fontsize = 30)
ax.set_ylabel('Y1',fontsize = 30)
ax.set_zlabel('Z1',fontsize = 30)
print('The evil holograph looks like a tornado or hurricane!')<jupyter_output>The evil holograph looks like a tornado or hurricane!<jupyter_text>Problem 7  The puzzles (24 points)  You look around the room. There are some nature pictures, but none with a tornado or a hurricane. Nothing makes sense...As you wander around the room you notice something is odd. Vermeer's girl with the pearl earring is odd? You approach and see the girls face is replaced with Dr. <NAME>'s... Can this be it? You turn the painting around and find a paper with two puzzles:  The first puzzle: - The original of this painting was made in what year? Google it! Sum the numbers of the year up. (so if was made in 1111 the answer is 1 + 1+1 +1 = 4) (1 point) - Use the appropriate numpy function to calculate the mean (2 points), median (2 points) and trace (2 points) of the what_is_the_key array (see below). Which one matches your previous sum? - If the mean : u = 2, if the median: u = 9, if the trace: u = 3 (1 point)  The second puzzle:- An alien at Proxima Centauri b looks toward our Sun with their telescope and records a transit (a planet crosses in front of the Sun disk). The planet caused a dip in the light the alien saw of $\Delta$f=0.007456. The event repeated after 10,740 days. Using Doppler spectroscopy the alien found that the planet causes the Sun to wobble with a velocity semi-amplitude of 2.76m/s. Which planet did the alien see? If Mercury is 1, Venus is 2, this planet is N.     - Find the Radius and Mass of the planet using the information from above and these tips:      - Tip for the transit: you know that $\Delta$f $\sim \frac{R^2_{planet}}{R^2_{star}}$. Use this to find the radius of the planet in km, if you know that the Sun has a radius of 696,000km (5 points)      - Tip for the wobbling: you know that the velocity semi-amplitude is given by $K = \frac{28.43 [m/s]}{\sqrt{1-e^2}} \frac{m_{planet}\sin i}{m_{Jupiter}}(\frac{m_{planet}+m_{Sun}}{m_{Sun}})^{-2/3} (\frac{P}{1 year})^{-1/3}$. Use this to find the mass of the planet. You can assume that e = 0 and sini = 1. Also, note that $m_{planet} << m_{Sun}$ (5 points)          - Now that you now the Radius, Mass and Period of the planet, compare against this NASA database: https://nssdc.gsfc.nasa.gov/planetary/factsheet/     - Which is the planet the alien saw? (3 points)    - What is the number N of the planet (if Mercury=1, Venus =2, etc)? Print an informative statement. (1 point)    - Remember that the Moon is *not* a planet!         The next key:- What is the number that is equal to N/u ? Populate your *key_code* with the number (1 points).  - Print the *key_code* (1 points).<jupyter_code>"""The first puzzle"""
vermeer = 1+6+6+5
print('The year that Vermeer painted the Girl with the Pearl Earring was 1665')
print(vermeer)
what_is_the_key = np.array( ([ 7, 23, 45, 37, -2, 12, 34 ], 
                         [ 22, 1, 34, 18, 54, 33, 9  ],
                         [  8, 19, 2, 42, 32, 2, 17 ],
                         [ 98, 9, 14,  2, 12, 33, 7 ], 
                         [ 12, 10, 4,  54, 2, -8, 7 ],
                         [ 77, 22, -2,  24, -8, 3, 7 ],
                         [ 122, 33, 3,  3,  4, 33, 1 ] ) )
mean = np.mean(what_is_the_key)
print(mean)
median = np.median(what_is_the_key)
print(median)
trace = np.trace(what_is_the_key)
print(trace)
u = 3
print('The trace value matches the sum of the Vermeer years so u = 3')
"""The second puzzle"""
radius_N = np.sqrt(0.007456*(696000**2))
print('The radius of Planet N is:',radius_N,'Km')
#Variable values used to calculate unknown planet mass 
P = 10740
e = 0
sini = 1
M_Jupiter = 1898
M_Sun = 1988500
K = 2.76
#All masses listed are (Mass)e**24 Kg 
#mass of the sun used was taken from https://nssdc.gsfc.nasa.gov/planetary/factsheet/sunfact.html (1988500e24)
#Solving equation of velocity semi amplitude turns equation into quadratic
#2.6496e-10M**2 + 5.2687e-4M - 6.094615 = 0 

a2 = 0.00000000026496
b2 = 0.00052687
c2 = -6.094615

x1 = -b2+np.sqrt(b2**2-4*a2*c2)
x1 = np.round(x1 /(2*a2),2)
    
x2 = -b2-np.sqrt(b2**2-4*a2*c2)
x2 = np.round(x2 /(2*a2), 2)

print(x1,'e24 Kg', x2,'e24 Kg')

#Note: All masses are (Mass)e**24 Kg 
#Negative mass is disregarded 
print('The number of the unknown planet according to the NASA informative sheet is 6')
#https://nssdc.gsfc.nasa.gov/planetary/factsheet/ was used to look up the results from the radius and mass of the unknown planet 
#I wasnt able to get the correct mass but by looking up the the radius and period of orbit I was able to determine the planet in question was Saturn (planet #6)
N = 6
print('Based on the radius, period and mass the unknown planet N is Saturn with the corresponding value', N)
code_number = N/u
print(code_number)
key_code.append(code_number)
print(key_code)<jupyter_output>[3, 7, 8, 2.0]<jupyter_text>Problem 8.  The bug exterminator (15 points) On the other side of the room you see a chair in front of a computer. The chair has an 8 scratched on it. This must be where the next clue lies. You walk to the chair and look at the computer screen. There is some code, but it is full of bugs. Does Dr. Cane think that this can stop you?Debug the code to find the next number(s). (8 points)Run the code for wheel radii: r1 = 0.5 m , r2 = 0.8 m, times the cars moved: t1 = 12 s, t2 = 8 s, and wheel rotations of N1 = 8 rotations and N2 = 5 rotations. The integer part of the speed that the code returns is the next part of the key. (2 points)If you get 2 digit speed make a code that will split it in two numbers: e.g., if you get a speed of 42 m/s the code will append to the key a 4, and then a 2. Don't split it manually. (3 points) Populate your key_code with the number(s) (1 points). Print the key_code (1 points).<jupyter_code># Code that calculates the distance traveled by a car knowing how much time it moves and
# how many rotations its wheels, with a known perimeter, made. 
# Code then will compare the distance that two cars moved based on the time they move 
# and their wheels perimeters and tells you which one moved further and for that car 
# at what speed it moved. 



# Ask the user for the two radii of the car wheels:

radius1 = input( 'Give me the first radius please'  )
radius2 = input( 'Give me the second radius please' )


# calculate the perimeter of the two wheels:
radius_1 = float(radius1)
radius_2 = float(radius2)

perimeter1 = radius_1*2*np.pi #This will return the radius twice, not multiply the radius by 2
perimeter2 = radius_2*2*np.pi
print(perimeter1)
print(perimeter2)

# Ask the user for how much time the two cars move:

time1 = input( 'How much time did the first car move?' )
time2 = input( 'How much time did the second car move?' )

time1 = float(time1)
time2 = float(time2)
 
    
# Ask the user how many full circles did their wheels turnL

N1 = input( 'How many circles did the wheels of car 1 turn?' )
N2 = input( 'How many circles did the wheels of car 2 turn?' )

N1 = float(N1)
N2 = float(N2)


# Calculate the total distance each car moved:

distance1 = N1 * perimeter1 * time1
distance2 = N2 * perimeter2 * time2

# Compare the two distances and for the one that moved further print which one
# it is and what its speed is:

if distance1 > distance2:
    print( 'Car 1 moved further than Car 2' )
    
    speed1 = distance1 / time1
    
    print( 'Car 1 moved with a speed of: ', speed1 , 'm/s.' )

elif distance2 > distance1:
    print( 'Car 2 moved further than Car 1' )
    
    speed2 = distance2 / time2
    
    print( 'Car 2 moved with a speed of: ', speed2 , 'm/s.' )

else:
    print( 'Car 1 and two moved an equal distance with Car 1' )
    speed1 = distance1 / time1
    speed2 = distance2 / time2
    
    print( 'Car 1 moved with a speed of: ', speed1 , 'm/s' 
         'and Car 2 moved with a speed of: ', speed2, 'm/s.')
    
    
#Debugging:
#1. There was a syntax error in the radius2 input, originally there were two radius1 inputs 
#2. I converted radius1 and radius2 into floats so I could perform the maths
#3. To calculate perimeter the correct equation is 2*pi*radius 
#4. I converted time1 and time2 into floats so I could perform the maths 
#5. I converted N1 and N2 into floats so that I could perform the maths
#6. I changed the equation to find the total distance from diameter to perimeter 
#7. For distance2, I ensured the values all matched '2'
#8. The speeds for the else statement were reversed ie. car 1 was matched with speed 2 
#9. The first if statement of the loop had a syntax error (missing 1 for speed1 calculation), the speed for the print statement was also missing the integer notation
#10.The last elif statement of the loop had a syntax error (missing 2 for speed2 calculation),  the speed for the print statement was also missing the integer notation
#11. The elif statement had the signs of the equation it was checking reversed (distance2 < distance1 has already been checked by the if loop)
#12. There was a typo in the print statement of the elif statement (Car1 instead of Car2)
#r1 = 0.5 m 
#r2 = 0.8 m
#t1 = 12 s
#t2 = 8 s
#N1 = 8 rotations
#N2 = 5 rotations
integer_speed = int(speed1)
#print(integer_speed)
numbers = [int(a) for a in str(integer_speed)]
print(numbers)
key_code.append(numbers)
print(key_code)<jupyter_output>[3, 7, 8, 2.0, [2, 5]]<jupyter_text>Problem 9.  The model derivation (35 points)  Looking across the room you see a big 9 next to a usb stick. This must be the next thing to look at. You plug the stick into the computer in the room. There is a single file with GPS data: timestamps, distances from some location and GPS errors.  (10 points total)- Get the data from the table and assign them to numpy arrays named gps_time, gps_distance and gps_error. (3 points) - Plot the distance of the object as a function of time making a publication-ready plot *with errorbars*, axis labels and plot title. (5 points)- Use the appropriate python command to store the plot as a pdf. (2 points) time | distance     | error--|:---------:|:-----------:12.00 | 1137.61    | 45.012.54 | 1174.34    | 42.113.07 | 1209.87    | 34.013.61 | 1244.19    | 44.014.15 | 1277.31    | 48.014.68 | 1309.21    | 35.015.22 | 1339.93    | 25.015.76 | 1369.39    | 35.016.29 | 1397.67    | 41.016.83 | 1424.74    | 42.017.37 | 1450.61    | 45.017.90 | 1475.25    | 35.018.44 | 1498.69    | 45.018.98 | 1520.90    | 45.019.51 | 1541.94    | 45.020.05 | 1561.75    | 45.020.58 | 1580.35    | 35.021.12 | 1597.72    | 25.021.66 | 1613.93    | 15.022.21 | 1628.91    | 45.022.73 | 1642.67    | 35.023.27 | 1655.22    | 25.023.80 | 1666.57    | 41.024.34 | 1676.71    | 42.024.88 | 1685.63    | 45.025.41 | 1693.35    | 45.025.95 | 1699.92    | 45.026.48 | 1705.16    | 45.027.02 | 1709.25    | 45.0 27.56 | 1712.14    | 45.028.11 | 1713.81    | 45.028.63 | 1714.27    | 45.029.17 | 1713.48    | 45.029.71 | 1711.57    | 45.030.24 | 1708.41    | 45.030.78 | 1704.04    | 45.031.32 | 1698.45    | 45.031.85 | 1691.66    | 45.032.39 | 1683.66    | 45.032.93 | 1674.44    | 25.033.46 | 1664.02    | 45.034.00 | 1652.40    | 15.0<jupyter_code>gps_time = np.array([12.00,12.54,13.07,13.61,14.15,14.68,15.22,15.76,16.29,16.83,17.37,17.90,18.44,18.98,19.51,20.05,20.58,21.12,21.66,22.21,22.73,23.27,23.80,24.34,24.88,25.41,25.95,26.48,27.02,27.56,28.11,28.63,29.17,29.71,30.24,30.78,31.32,31.85,32.39,32.93,33.46,34.00])
gps_distance = np.array([1137.61,1174.34,1209.87,1244.19,1277.31,1309.21,1339.93,1369.39,1397.67,1424.74,1450.61,1475.25,1498.69,1520.90,1541.94,1561.75,1580.35,1597.72,1613.93,1628.91,1642.67,1655.22,1666.57,1676.71,1685.63,1693.35,1699.92,1705.16,1709.25,1712.14,1713.81,1714.27,1713.48,1711.57,1708.41,1704.04,1698.45,1691.66,1683.66,1674.44,1664.02,1652.40])
gps_error = np.array([45.0,42.1,34.0,44.0,48.0,35.0,25.0,35.0,41.0,42.0,45.0,35.0,45.0,45.0,45.0,45.0,35.0,25.0,15.0,45.0,35.0,25.0,41.0,42.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,45.0,25.0,45.0,15.0])
plt.figure( figsize = (12, 12) )
plt.plot  ( gps_time, gps_distance, color = 'blue' , linestyle = '-', linewidth = 4) 
plt.xlabel( 'GPS time', fontsize = 35)
plt.ylabel( 'GPS distance' , fontsize = 35)
plt.title( ' GPS Time vs Distance' , fontsize = 35 )
plt.yticks( np.arange( 1130, 1830, step = 100) ,fontsize=35) 
plt.xticks( np.arange( 10, 40, 5 ) ,fontsize=35 )
zerror = gps_error
plt.errorbar(gps_time, gps_distance, zerror, ms=2)

plt.savefig( 'GPS Time vs Distance.pdf', format = 'pdf', dpi = 300, bbox_inches = 'tight', pad_inches = 0.3 )<jupyter_output><empty_output><jupyter_text>The model (25 points total):- Use the data to fit a model of the form $s = u * t$  and a model of the form $s = 0.5 * a * t^2 + u_o * t$. Print an informative statement informing the user about which model best describes the data (11 points) and why (3 points)?    - tip: limit your scan of the u parameter in the 0.1 to 150 space for the first model with a step of 2; and the a in the -10 to +10 with a step of 0.1 and u0 in the 0.1 to 140 with a step of 10 for the second model - Is the object moving with a constant speed, or accelerating? (1 point) - What is the speed u or acceleration a of the best-fit model (8 points)?- Populate your *key_code* with the integer part of this number (best-fit speed or best-fit acceleration) (1 points).  - Print the *key_code* (1 points).<jupyter_code>#I used the data to fit a model of best fit for the functions:

#s=u*t and s=0.5*a*t**2 + u0*t

#For the function s = u*t I looped through the possible values to find the min value for the chi squared value:

#Variables:

t = gps_time
s = gps_distance
u = np.arange(0.1,150,0.1) 
r = np.zeros(len(u))

#Looping for possible combinations:

for i in range(len(u)):
    s_theory = u[i]*t
    r[i] = np.sum((s-s_theory)**2/s_theory)

#Finding min chi square error:

q  = np.where(r==np.min(r))
print('The minimum chi square value is:',q[0])

#Modified function with min error value:

s_mod = u[0]*t
u_mod = np.arange(0.1,150,0.1) 

#Returning results:

print("The initial velocity of the first function is:",u[q[0]])

#[69.1]

#For the function s=0.5*a*t**2 + u0*t I followed the same method as for the linear function above (s=u*t):

#Variables:

t = gps_time
s = gps_distance
a = np.arange(-10,10,0.1) 
u0 = np.arange(0.1,140,10)
r1 = np.zeros((len(a), len(u0)))

#Looping for possible combinations:

for i in range(len(a)):
    for j in range(len(u0)):
        s2_theory = 0.5*a[i]*(t**2)+u0[j]*t
        r1[i,j] = np.sum((s-s2_theory)**2/s2_theory)

#Finding min chi squared error:

q  = np.where(r1==np.min(r1)) 
print("The minimum chi square value is:",q[0])

#Modified function with min error values:

s2_mod = 0.5*a[0]*(t**2)+u0[1]*t 
a_mod = np.arange(-10,10,0.1) 
u0_mod = np.arange(0.1,140,10)

#Returning results:

print("The acceleration of the second function is:",a[q[0]],"The initial velocity of the second function is:",u0[q[1]])

#[-4.] [40.1]

print("The model that fits the data the best is model s2_theory=0.5*a[i]*(t**2)+u0[j]*t.\n The chi square value is 60, and this the value closest to 1 when evaulating the fit of both functions.")
print("The object is deccelerating at a value of -4 m/s")
#The key pad has no negative sign option so the absolute value of the acceleration was taken to add to the key_code
key_code.append(np.abs(a[q[0]]))
print(key_code)<jupyter_output>[3, 7, 8, 2.0, [2, 5], array([4.])]<jupyter_text>Problem 10.   The data is the truth (15 points)  You are getting close to the end. This is getting exciting! Where can the final clue be? You look around. What else is there? Dr. Cane sure has a fascination with nature....On the floor there is a nature painting showing waves and a Sun..But wait! There is something wrong. This is not just a painting. There are numbers across the 'waves'. - Read in the data from the_data.dat (1 point)   The data contain the numbers you see on the painting. Years and some value associated with them.  - What is the period of the data (i.e., the time it takes to go from one peak to the next)? Make a code that scans the data and checks a window of 6 values at a time. If a value is larger than 3 points before it and 3 points after it, it is stored as a peak.   (12 points)    - Tip: start your scanning from point 3 so that the edge of the window is at point 0- Populate your *key_code* with the number (1 points).  - Print the *key_code* (1 points).<jupyter_code>data = np.loadtxt('the_data.dat')
t = data[:,0]
data_t = data[:,1]
peak = 0 
for j in range(3, len(data_t)):
    if (data_t[j] > data[j-2]).any() and (data_t[j] > data_t[j+2]).any():
        #print(j,data_t[j])
        peak = peak + 1 
key_code.append(peak)
print(key_code)<jupyter_output>[3, 7, 8, 2.0, [2, 5], array([4.]), 9]<jupyter_text>Problem 11.   Escape the room! (3 points) You did it! You have the 8 digits that you need to exit the room! You run to the key pad and enter the code. Did it work? Open the pdf ***summer_saved.pdf*** using the 8 digits you got (no spaces or commas in between).<jupyter_code>print(key_code)
done = 'summer_saved.pdf'
os.system(done)
#Used key_code 3,7,8,2,2,5,4,9 to open the summer_saved pdf which shows a happy creature saying congratulations!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11211924821775761, 'fraction_numerical': 0.07600633686181321, 'mean_word_length': 3.6508707300736774, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 58, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '190981', 'license': 'MIT', 'n_tokens_mistral': 10733, 'n_tokens_neox': 9349, 'n_words': 3984, 'path': 'Final_CSmith/Final_CSmith.ipynb', 'repo_name': 'CMSPhysics/PHZ3150', 'size': '27788'}