I've managed to get the code to check whether or not it's a concatenation of 1, 14, or 144 but the main problem here is that when I print numbers like 144441 it returns "YES" when it should give a "NO."
This problem occurs as long as there are at least 3 fours sandwiched between 2 ones (i.e. 14441, 14444444444441, 1444441)
def magic_num(N):
magic = N
while magic in range(1,1000000001):
if (magic % 1000 == 144):
magic /= 1000
elif (magic % 100 == 14):
magic /= 100
elif (magic % 10 == 1):
magic /= 10
else:
return"NO"
return "YES"
N = int(input("Enter an integer between 1 and 10^9: "))
print(magic_num(N));