+ 13

CODING CHALLENGE (...or maybe not!)

In the language of your choice, try making a function which: - takes a string of code (called sCode) as a parameter, - returns 0 if sCode is fine, - returns 1 if sCode would ever encounter any infinite loop such as a while(true). Or else, if you think it is, try prooving why a such function is impossible in the comments below. Good luck!

1st Oct 2017, 4:02 PM
Dapper Mink
Dapper Mink - avatar
5 Respuestas
+ 3
My try to explain: If such function f/1 exists then you could build a function g/1 around it like g(code){ while(f(code)==0); } now you give the code g to itself. What happens ? option 1) if g halts, f(code) is 0 but then g does not halt --> contradiction option 2) if g does not halt f(code) is 1 but then g halts --> contradiction --> no such function exists hope this is ok =P , i really enjoied this challenge!
1st Oct 2017, 8:43 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
Chrizzhigh, you are completely right!! Good job solving it :D Thanks! :')
1st Oct 2017, 8:59 PM
Dapper Mink
Dapper Mink - avatar
+ 1
Isn't this a different form of the basic "Halting problem" ? ^^
1st Oct 2017, 6:56 PM
Chrizzhigh
Chrizzhigh - avatar
+ 1
Yes it is! So go ahead!!
1st Oct 2017, 8:02 PM
Dapper Mink
Dapper Mink - avatar