7 kyu

Count the Digit

1,213 of 50,091g964

Description:

Take an integer n (n >= 0) and a digit d (0 <= d <= 9) as an integer.

Square all numbers k (0 <= k <= n) between 0 and n.

Count the numbers of digits d used in the writing of all the k**2.

Implement the function taking n and d as parameters and returning this count.

Examples:

n = 10, d = 1 
the k*k are 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
We are using the digit 1 in: 1, 16, 81, 100. The total count is then 4.

The function, when given n = 25 and d = 1 as argument, should return 11 since
the k*k that contain the digit 1 are:
1, 16, 81, 100, 121, 144, 169, 196, 361, 441.
So there are 11 digits 1 for the squares of numbers between 0 and 25.

Note that 121 has twice the digit 1.

Fundamentals

More By Author:

Check out these other kata created by g964

Stats:

CreatedDec 15, 2015
PublishedDec 15, 2015
Warriors Trained116850
Total Skips24957
Total Code Submissions150585
Total Times Completed50091
Ruby Completions1213
Python Completions12908
JavaScript Completions16489
CoffeeScript Completions35
Haskell Completions512
Java Completions4466
C# Completions2108
Clojure Completions262
Elixir Completions346
C++ Completions2663
PHP Completions1458
Crystal Completions41
F# Completions134
TypeScript Completions964
C Completions1543
Shell Completions237
OCaml Completions67
Kotlin Completions1088
Fortran Completions29
Swift Completions1111
NASM Completions23
Julia Completions52
R Completions130
PowerShell Completions100
Go Completions1588
Nim Completions25
Rust Completions833
Reason Completions7
Racket Completions31
Scala Completions269
Groovy Completions52
Haxe Completions10
Pascal Completions42
Dart Completions589
Perl Completions64
Prolog Completions15
Lua Completions135
Elm Completions16
COBOL Completions16
D Completions15
Erlang Completions15
Total Stars948
% of votes with a positive feedback rating88% of 4731
Total "Very Satisfied" Votes3734
Total "Somewhat Satisfied" Votes839
Total "Not Satisfied" Votes158
Ad
Contributors
  • g964 Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • B1ts Avatar
  • Voile Avatar
  • Madjosz Avatar
  • monadius Avatar
  • hobovsky Avatar
  • uniapi Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • Rocketboomer Avatar
  • Just4FunCoder Avatar
  • yLaWy Avatar
  • KayleighWasTaken Avatar
Ad