> Very hard programming problem..?

Very hard programming problem..?

Posted at: 2014-12-18 
I wrote a (partial) solution in Python2 for you.

This will fail on extremely small and extremely large inputs, as well as those like this

3.1415900000... 00000124123

This is basically due to me having to fight with the multiple-precision library. I am not an experienced user and while I'm sure there's a better way, I chose not to hack around with it.

Irrationals work fine, i.e.,

$ python ./evilno.py "4*atan(1)"

Says that's evil (that's pi), and

$ python ./evilno.py "(sqrt(5) + 1)/2

Says that's evil too (that's phi)

See:

http://pastebin.com/UqkQH7DA

Or below, if the link becomes broken.

#!/bin/python

from sympy import sympify

import sys

ExpressionString = ""

if len (sys.argv) != 2:

? ? ExpressionString = raw_input ('Enter the expression: ')

else:

? ? ExpressionString = sys.argv [1]

Expression = sympify (ExpressionString, rational=True)

Sum = 0

Precision = 1000

while Sum <= 666:

? ? Digits = map (int, str (Expression.evalf (Precision)).split ('.') [1])

? ? for Num in Digits:

? ? ? ? Sum += Num

? ? ? ? if Sum == 666:

? ? ? ? ? ? print "Call the priests! This hellish thing!"

? ? ? ? ? ? sys.exit ()

? ? if Sum > 666 or Expression - Expression.evalf (Precision + 100) == 0:

? ? ? ? print "We're safe, it's harmless...."

? ? ? ? sys.exit ()



? ? Precision += 100

you need to specify the language..are you using C or C++, OR JAVA

Write a program which indicates whether a number is evil or not.

An evil number is a number which has the sum of its first n-digits, for some positive integer n, equal to 666.

Example: pi and phi are evil (the sum of their first 100 something digits is 666).

I don't even know if its possible to create such a program. Thank you in advance.