# exam1 - M ath 470/501 Spring 2011 Exam 1 M aple allowed...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: M ath 470/501 Spring 2011 Exam 1 M aple allowed Name: U IN: #1. The title of this 1966 musical has been encrypted by a shift cipher: For \$200, Watson, what is its name? > restart: with(LinearAlgebra): with(numtheory): with(plots): numb:=table([""=0,"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]): alph:=table([0="",1="a",2="b",3="c",4="d",5="e",6="f",7="g",8= "h",9="i",10="j",11="k",12="l",13="m",14="n",15="o",16="p",17= "q",18="r",19="s",20="t",21="u",22="v",23="w",24="x",25="y",26= "z"]): shift:=proc(txt,n) local i,z; # remove the # on only the following line to trace the internal outputs # option trace; # Create a NULL string on which to add letters. z:=NULL; # While i is less than or equal to the number of letters in the string, do for i from 1 while i<=length(txt) do # Grab the substring (letter) in the i-th place of txt. substring(txt,i); # Use the numb table to convert the letter to a n umber between 1 and 26. numb[%]; # Arithmetic mod 26 uses numbers between 0 and 25, not 1 and 26 %-1; # Now cyclically shift the letter mod 26. %+n mod 26; # Take the numbers between 0 and 25 and again make them between 1 and 26, as people count letters. %+1; # Use the alph table to convert the shifted number back to a letter. alph[%]; # Add the new letter on the right side of the shifted string. z:=cat(z,%); end do; return(z); # To check that syntax is correct, change end: to end; Blue output means "syntax is OK." end: allshifts:= proc(txt) local i; for i from 0 while i<26 do shift(txt,26+i); print(%); end do; end: mu s i c a l:=" te d lmtc o te d lawlypt eddf apcxly"; allshifts(musical); "tedlmtcotedlawlypteddfapcxly" "ufemnudpufembxmzqufeegbqdymz" "vgfnoveqvgfncynarvgffhcrezna" "whgopwfrwhgodzobswhggidsfaob" "xihpqxgsxihpeapctxihhjetgbpc" "yjiqryhtyjiqfbqduyjiikfuhcqd" "zkjrsziuzkjrgcrevzkjjlgvidre" "alkstajvalkshdsfwalkkmhwjesf" "bmltubkwbmltietgxbmllnixkftg" "cnmuvclxcnmujfuhycnmmojylguh" "donvwdmydonvkgvizdonnpkzmhvi" "epowxenzepowlhwjaepooqlaniwj" "fqpxyfoafqpxmixkbfqpprmbojxk" "grqyzgpbgrqynjylcgrqqsncpkyl" "hsrzahqchsrzokzmdhsrrtodqlzm" "itsabirditsaplaneitssuperman" "jutbcjsejutbqmbofjuttvqfsnbo" "kvucdktfkvucrncpgkvuuwrgtocp" "lwvdeluglwvdsodqhlwvvxshupdq" "mxwefmvhmxwetperimxwwytivqer" "nyxfgnwinyxfuqfsjnyxxzujwrfs" " ozyghoxjozygvrgtkozyyavkxsgt" "pazhipykpazhwshulpazzbwlythu" "qbaijqzlqbaixtivmqbaacxmzuiv" "rcbjkramrcbjyujwnrcbbdynavjw" "sdcklsbnsdckzvkxosdccezobwkx" (1.1) (1.1) #2. After the pair 2, 3, which are separated by 1, all further primes must be s eparated by at least two. 3 and 1223 are primes. What fraction of the primes p b etween 3 and 1223 are twin primes, meaning that p is prime and p+2 is also p rime? Write a short loop in Maple to determine the answer. Execute your loop. P rint your output. > p:=0: t:=0: for i from 3 to 1223 do if isprime(i) then p:=p+1; if isprime(i+2) then t:=t+1; #print(i,i+2); fi; fi; od; t/p; evalf(%); 41 199 0.2060301508 (2.1) ...
View Full Document

## This note was uploaded on 02/14/2012 for the course MATH 470 taught by Professor Staff during the Spring '08 term at Texas A&M.

Ask a homework question - tutors are online