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.