3
\$\begingroup\$

First post here! I recently participated in a small friendly competition and this was one of the questions:


A positive integer whose only prime factors are 2, 3, 5 or 7 is called a humble number.

The first 20 humble numbers are:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27

Write a program of function that when given a positive integer N, prints or returns the Nth humble number.

Examples

1 -> 1
11 -> 12
22 -> 30

This is so the shortest answer in bytes wins. I'm interested in seeing solutions that run in O(N) but this is not a requirement.

\$\endgroup\$
4
  • \$\begingroup\$ @Calvin'sHobbies: I thought that too, but the very last line was what made me wonder if this post was misplaced. \$\endgroup\$ Nov 13 '15 at 8:49
  • \$\begingroup\$ 1 doesn't contain either one of the factors 2,3,5,7. \$\endgroup\$
    – mroman
    Nov 13 '15 at 11:30
  • 1
    \$\begingroup\$ @mroman the linked OEIS page describes them less ambiguously as "Numbers whose prime divisors are all <= 7". \$\endgroup\$
    – trichoplax
    Nov 13 '15 at 12:44
  • \$\begingroup\$ @mroman - 1 doesn't contain any prime factors that aren't 2, 3, 5, or 7. That it doesn't contain those four either isn't relevant. \$\endgroup\$
    – Glen O
    Nov 13 '15 at 16:29

Browse other questions tagged or ask your own question.