#include <iostream>
using namespace std;

    // valid transition from x to n[x-'1'][0 or 1]

    int n[9][2] =
    {
        {'6','8'},{'7','9'},{'4','8'},
        {'3','9'},{ 0 , 0 },{'1','7'},
        {'2','6'},{'1','3'},{'2','4'}
    };

    // i is a pointer to where to start on a string

    bool L(char * i)
    {
        char c = 0;
        
        // move if not \0 and (not-first-char or is a valid move)

        while(*i && (!c || *i==n[c-'1'][0] || *i==n[c-'1'][1]))
        {
            c=*i++;
        }
        
        return !*i; // success if it's \0
    }

int main()
{
	char *falsy = "183492760";
	printf("%s ~ %s \n", falsy, L(falsy)?"true":"false");
	
	char *truthy = "618349276";
	printf("%s ~ %s \n", truthy, L(truthy)?"true":"false");
	
	return 0;
}

