110 likes | 196 Views
Very Hard Problems. I am so not kidding about this. Please grab a handout. Theory. What do you think?. There are some well-formed mathematical problems that computers can’t solve, no matter how fast computers get. True False. Java Programs That Take Files as Inputs. For example:
E N D
Very Hard Problems I am so not kidding about this. Please grab a handout.
What do you think? There are some well-formed mathematical problems that computers can’t solve, no matter how fast computers get. • True • False
Java Programs That Take Files as Inputs For example: CountOfWordsInFile.java …we run it like this “CountWordsInFile file.txt” And it prints the number of words in that file.txt. What if we ran it like this: “CountWordsInFile CountWordsInFile.java” What would it print? • That doesn’t make sense • It would run forever • The number of words in the CountWordsInFile.java file (say 100)
Ok, another program • RunForever.java • It’s a program with an infinite loop • …we run it like this “RunForever file.txt” • But no matter what file we put in, it runs forever • So what would happen if we run it like this: “RunForever RunForever.java” • That doesn’t make sense • It would run forever • It would print something
Still Another Program • RunWithItself.java • Just runs the java program passed in, with itself as input. So “RunWithItselfJavaProg.java” is the same thing as “JavaProg JavaProg.java” • So say we ran “RunWithItself CountWordsInFile.java” • That doesn’t make sense • It would run forever • It would print out a number
Penultimate Program WillRunForever.java • Really handy program that determines if a program will run forever *if passed itself as an input* (it acts a lot like RunWithItself.java) • Prints either “SAFE” or “DANGER” • This program never runs forever • What is the output of:
Last Program • StrangeProgram.java • Runs WillRunForever.java on it’s input. If WillRunForever.java prints “SAFE”, StrangeProgram runs forever. If WillRunForever.java prints “DANGER” StrangeProgram prints “STRANGE” and exits.
Final Question • What is the output of: StrangeProgram StrangeProgram.java • Hint: It helps if you figure out the output of WillItRunForever StrangeProgram.java first
You can see my PNP “slides” here: • http://prezi.com/k8e5v1wgicit/copy-of-copy-of-ghp-pnp/