Skip to content

Instantly share code, notes, and snippets.

@marklin-latte
Last active May 27, 2020 03:08
Show Gist options
  • Save marklin-latte/371ea3109a1d835488578635a3c4c0ef to your computer and use it in GitHub Desktop.
Save marklin-latte/371ea3109a1d835488578635a3c4c0ef to your computer and use it in GitHub Desktop.
function g(n){
let res = 0;
for (let i=1; i <= n; i++){
let temp = i;
while(temp != 0){
let digit = temp % 10;
if(digit == 7){
res++;
break;
}
temp = Math.floor(temp / 10);
}
}
return res;
}
g(70); // 8
g(100); // 19 (1*9 + 10) = 19
g(1000); // 271 (19*9 + 100) = 271
g(10000); // 3439 (271*9 + 1000) = 3439
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment