Function to obtain the mask for any integer
function getmask ( val ) { var mask = 0 ; if ( val == 0 ) return 1 ; while ( val ) { var d = val % 10 ; mask |= ( 1 << d ) ; val = parseInt ( val / 10 ) ; } return mask ; }