The Holy Numbers
Ruby, 109 105 95 82 bytes
->n,h{(?0..?9*99).select{|x|x.count('469')+2*x.count('80')>=h&&/[12357]/!~x}[n-1]}
This is the terrible "calculate from 0 to 99999999999..." approach that happens to be 13 bytes shorter than its lazy counterpart. However, this version is unlikely to finish before the heat death of the universe. Worth 13 bytes, anyway ¯\_(ツ)_/¯
You can test it for smaller values by changing ?9*99
to, say, '99999'
.
Here's the old version (95 bytes, with lazy evaluation, which runs near-instantly rather than near-never):
->n,h{(?0..?9*99).lazy.select{|x|x.count('469')+2*x.count('80')>=h&&/[12357]/!~x}.first(n)[-1]}
->n,h{
(?0..?9*99) # range '0' (string) to '9' repeated 99 times, way more than 2**64
.lazy # make the range lazy, so we can call `select' on it
.select{|x| # choose only elements such that...
x.count('469')+2*x.count('80') # naive holiness calculation
>=h # is at least h
&&/[12357]/!~x # naive "is holy" calculation
}
.first(n) # take the first n elements that satisfy the condition
[-1] # choose the last one from this array
}
Pyth, 32 bytes
e.fg*g.{`46890J`Z++lJ/J`8/J`0QE0
Explanation
- autoassign Q = eval(input())
.f E0 - first eval(input()) terms of func V starting Z=0
g.{`46890J`Z - Are all the digits in Z in "46890"?
`Z - str(Z)
J - autoassign J = ^
g - is_subset(V,^)
.{`46890 - set("46890")
* - ^*V (Only return non-zero if only contains holy numbers)
++lJ/J`8/J`0 - Get the holiness of the number
lJ - len(J)
+ - ^+V
/J`8 - J.count("8")
+ - ^+V
/J`0 - J.count("0")
g Q - ^>=Q (Is the holiness great enough)
e - ^[-1]
Try it here
Takes input in the form h \n n
Python 3, 103
lambda n,h,l='4698080':[y for y in range(2**64-1)if(sum(l.count(x)-(x not in l)for x in str(y))>=h)][n]
Here's a solution that uses a more memory efficient approach, but otherwise uses the same algorithm if you want to test it.
l='4689080'
def f(n,h):
c=i=0
while i<n:
if sum(l.count(x)-(x not in l)for x in str(c))>=h:u=c;i+=1
c+=1
return u
Test cases:
assert f(3, 1) == 6
assert f(4, 2) == 44