Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @NicknamedTwice,validated by @LeMasSon,@DrBrask and @David_Augusto_Villa.

If you have any issues, feel free to ping them.

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @NicknamedTwice,validated by @LeMasSon,@DrBrask and @David_Augusto_Villa.

If you have any issues, feel free to ping them.

Python:

Tried iterating through strings, concatenating into one long string, tried some divmodding to separate the tens thousands etc into integers then comparing, still the final validation was too memory intensive or took way too long. Whichever way I tried to cut it I couldnâ€™t seem to get away from iterating for loops millions of times. Any ideas? My best solutions work but take too long to complete.

Try to see whatâ€™s happening when you print each result from 1 to 1020, for example.

For a continuous sequence of numbers, there is a fixed pattern for digits to appear.

e.g. 0000â€¦4218

print out the numbers line-by-line to study the digits. Use space or zero to force them to align to the right.

The last digit changes from 0 to 9 and then repeats.

If the target is to find a 4 in this digit, it means

for every 10 numbers there is one wanted digit to appear.

=> there are about 421.8 chance to meet a 4 in this digit.

For the tenth-place digit, there is a sequence of 0 and then a sequence of 1,â€¦ finally to see a sequence of 9. And then repeats. For every 100 numbers there are 10 occurrence of the wanted digit.

=> there are about 42.18 x 10 chance to meet a 4 in this digit.

The above is a guesstimation shedding light on a possible approach.

You can refine the algorithm (how to handle cut-offs from some blocks of wanted digits at the end) to make it an accurate calculation.

Thanks, I am not certain that I have found the correct solution but, Iâ€™m certain the validations are wrong - it is for sure double counting:

Example for n = 219, for digit 5. expected answer is 42, but the actual answer is 40

This was one of my slower solutions, it validated all but the final large number, but it is incorrect

[Mod edit: Please avoid posting codes on the forum.]

Console:

```
3
5
15
25
35
45
50
51
52
53
54
55
55
56
57
58
59
65
75
85
95
105
115
125
135
145
150
151
152
153
154
155
155
156
157
158
159
165
175
185
195
205
215
42
```

[Mod edit: Please avoid posting codes on the forum.]

returns 40 as the answer

which would be correct as in the first example: 55 and 155 is counted twice

5, 15, 25, 35, 45, 65, 75, 85, 95 (9 5â€™s)

50 to 59 (11 5â€™s)

105, 115, 125, 135, 145, 165, 175, 185, 195 (9 5â€™s)

150 to 159 (11 5â€™s)

205, 215 (2 5â€™s)

Total number of 5â€™s = 9 + 11 + 9 + 11 + 2 = 42

Ah, I see- it would be correct to count 55 as 2 as it is double digits

1 Like

I pass everything for submission then it says the last two validators fail. Not sure why.

In those cases, the given number n contains the given digit k (not in the initial position nor the final position). You may first check whether your code handles such a scenario correctly.

I now have a solution that works for all test cases, every case Iâ€™ve thrown at it works, but the first validator isnâ€™t passing when I submit, I guess because Iâ€™ve hardcoded something in? All the other validators pass. Hard to tell where Iâ€™ve gone wrong without knowing n and k Iâ€™ve gone wrong with.

Thanks for the support, my criticism of this puzzle is that it seems more about a problem to find a series formula from a mathematics perspective than an actual coding challenge.

â€śactual coding challengesâ€ť are straight forward coding exercises or tests - for testing how much one knows about a language. I do not feel they are true puzzles.

True puzzles challenge problem solving skills, not coding knowlege.