0

Bee numbers are numbers that can be expressed in the form (3^a)*(5^b)*(7^c). where a, b and c are positive integers.

Task:

Write a function that takes in a positive integer n and returns the nth smallest Bee number

Example:

bNumber(1)===1//(3^0)*(5^0)*(7^0)

bNumber(2)===3//(3^1)*(5^0)*(7^0)

bNumber(3)===5//(3^0)*(5^1)*(7^0)

bNumber(4)===7//(3^0)*(5^0)*(7^1)

bNumber(100)===33075//(3^3)*(5^2)*(7^2)

My attempt:

let bNumber = (n) => {
    var beenumbers = []
    var a = 0
    var b = 0
    var c = 0
    while (beenumbers.length <= n) {
        var beeSchema = Math.pow(3,a)*Math.pow(5,b)*Math.pow(7,c);
        var beeArray = [] 
        var bee = Math.min((Math.pow(3, a + 1) * Math.pow(5, b) * Math.pow(7, c)),
            (Math.pow(3, a) * Math.pow(5, b + 1) * Math.pow(7, c)), (Math.pow(3, a) * Math.pow(5, b) * Math.pow(7, c + 1)))
        beenumbers.push(bee);
    }
    return beenumbers;

}

The problem for me has to perfect the system that would successfully validate what increment of 1 in a, b or c would give the next bee number. I used Math.min to get the smallest result in an increment of a, b or c but it still doesn't work.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
  • 2
    constraints on N? – Primusa May 27 '20 at 04:48
  • Welcome to SO! I'm not really clear on what a bee number is. What is bee number 5? It could go one of a few ways based on 1-4, and bee number 100 is sort of too far out to make it obvious. – ggorlen May 27 '20 at 05:04
  • 2
    Your example is very confusing, it doesn't make sense: bNumber(1)===1//(3^0)*(5^0)*(7^0) – Aks Jacoves May 27 '20 at 05:04
  • How do you define the umpteenth number of bees with the expression depending on a, b and c? For example, what would be the first and second bee numbers? – Aks Jacoves May 27 '20 at 05:07
  • 1
    @AksJacoves for example the 3rd bnumber is 5 ie bnumber(3) == 5 and 5 can be represented in the form (3^a)*(5^b)*(7^c) by (3^0)*(5^1)*(7^0). – Preshy Jones May 27 '20 at 05:09
  • Ok, understand. – Aks Jacoves May 27 '20 at 05:10
  • 4
    Look at k-smooth numbers. https://stackoverflow.com/questions/25344313/generating-ascending-sequence-2p3q – MBo May 27 '20 at 05:11
  • Could it be that you forgot considering that any number ```x^0 = 1``` for ```x >= 0``` ? This means that your examples are wrong. – mozart_kv467 May 31 '20 at 16:32
  • Should "where a, b and c are positive integers" actually say "where a, b and c are non-negative integers?" 0 is not a positive integer, so your examples don't match your definition. – Nick Russo Jun 02 '20 at 16:44

0 Answers0