How many cardboard digits do I need?
Jelly, 9 bytes
‘ḶDœ|/ḟ9L
Try it online!
How it works
‘ḶDœ|/ḟ9L
‘Ḷ [0,1,...,n]
D convert each to list of its digits
œ|/ fold by multiset union
ḟ9 remove 9
L length
Python 2, 49 bytes
lambda n:9*len(`n`)-9+(n*9+8)/10**len(`n`)+(n<10)
Try it online!
A clumsy arithmetical formula. Assume that n
fits within an int
so that an L
isn't appended.
Thanks to Neil for saving 5 bytes by pointing out that 9's being unused could be handled by doing n*9+8
instead of n*9+9
, so that, say, 999*9+8=8999
doesn't roll over to 9000.
Haskell, 117 114 108 95 89 88 87 84 82 63 bytes
6 bytes saved thanks to Laikoni
1 4 6 bytes saved thanks to nimi
g x=sum[maximum[sum[1|u<-show y,d==u]|y<-[0..x]]|d<-['0'..'8']]
Try it online!