Presentation is loading. Please wait.

Presentation is loading. Please wait.

Very Hard Problems I am so not kidding about this. Please grab a handout.

Similar presentations


Presentation on theme: "Very Hard Problems I am so not kidding about this. Please grab a handout."— Presentation transcript:

1 Very Hard Problems I am so not kidding about this. Please grab a handout.

2 Theory

3 What do you think? There are some well-formed mathematical problems that computers can’t solve, no matter how fast computers get. 1.True 2.False

4 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? 1.That doesn’t make sense 2.It would run forever 3.The number of words in the CountWordsInFile.java file (say 100) Java Programs That Take Files as Inputs

5 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” 1.That doesn’t make sense 2.It would run forever 3.It would print something

6 Still Another Program RunWithItself.java Just runs the java program passed in, with itself as input. So “RunWithItself JavaProg.java” is the same thing as “JavaProg JavaProg.java” So say we ran “RunWithItself CountWordsInFile.java” 1.That doesn’t make sense 2.It would run forever 3.It would print out a number

7 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: Thing To RunAnd it outputs WillRunForever CountWordsInFile.java WillRunForever RunForever.java WillRunForever WillRunForever.java

8 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. Thing To RunAnd it outputs StrangeProgram CountWordsInFile.java StrangeProgram RunForever.java StrangeProgram WillRunForever.java

9 Final Question What is the output of: StrangeProgram StrangeProgram.java Hint: It helps if you figure out the output of WillItRunForever StrangeProgram.java first

10 The halting problem is not computable. There are others.

11 You can see my PNP “slides” here: http://prezi.com/k8e5v1wgicit/copy-of-copy- of-ghp-pnp/


Download ppt "Very Hard Problems I am so not kidding about this. Please grab a handout."

Similar presentations


Ads by Google