Powers in range
Let's say you have an inclusive range of integers [a, b]
. You also have an exponent n
. What numbers k^n
(integer k
raised to the n
th power) occur in that range? Write a function that takes a
, b
, and n
and returns the numbers k^n
.
Examples
;; n = 2, [a, b] = [49, 65]
(powers-in-range 2 49 65) ;=> [49 64] ;; that is, 7^2 and 8^2
;; n = 3, [a, b] = [1, 27]
(powers-in-range 3 1 27) ;=> [1 8 27] ;; 1^3, 2^3, and 3^3
;; n = 10, [a, b] = [1, 5]
(powers-in-range 10 1 5) ;=> [1] ;; 1^10
Thanks to this site for the challenge idea where it is considered Hard level in Python.
Email submissions to eric@purelyfunctional.tv before August 15, 2020. You can discuss the submissions in the comments below.
it is not so complicated if we can assume that the variables a, b, and n take only positive integers.