Skip to content

Instantly share code, notes, and snippets.

@caub
Last active September 19, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caub/d7f326aeea492189aa0b14ba36478e8e to your computer and use it in GitHub Desktop.
Save caub/d7f326aeea492189aa0b14ba36478e8e to your computer and use it in GitHub Desktop.
// 2 globals defined at boot of nodejs engine
rl = cb => require('readline').createInterface({input:process.stdin}).on('line',cb);
print = console.log;
/*
Let's call an integer "repetitive" if it contains two of the same digit in a row. For example, 12232 is repetitive but 1232 is not.
Given a positive integer n < 10^15, return the number of nonrepetitive integers in [1..n].
*/
// prog
rl(s=>{r=0;d=s.length-1;for(i=0;i<=d;i++){r+=(i>0&&s[i-1]<s[i]?s[i]-1:s[i])*9**(d-i);if(s[i-1]==s[i]){r--;break}}for(i=0;i<d;i++)r+=9**i;print(r)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment