This is our first ever guest challenge, written by the amazing @star3lord with no help from myself or Dan. If you would like to have your own challenge published, please pm me. Enjoy!
Code Challenge #24: October 11, 2017
Basic Difficulty
Write a function,
semiPrimeDetector
, that tests if a number,n
is a semi-prime number.
- Function Name:
semiPrimeDetector
- Input:
integer n
- Output:
boolean
:true
ifn
is a semi-prime number elsefalse
. - Example:
semiPrimeDetector(194) => True
Find out more about basic challenges.
Intermediate difficulty
Write a function,
semiPrimeCount
, that will print total number of semi-prime numbers below a number,n
.
- Function Name:
semiPrimeCount
- Input:
integer n
- Output: An
integer c
, count of all the semi-prime numbers belown
. - Example:
semiPrimeCount(30)
will output 10, which includes semi-prime numbers -[4, 6, 9, 10, 14, 15, 21, 22, 25, 26]
.
Find out more about intermediate challenges.
Hard Difficulty
Write
semiPrimeDetector
andsemiPrimeCount
as efficiently as possible.
Find out more about hard challenges and Big O
EXTRA
Write a function to check if the output of
semiPrimeCount
is odd or even.
-
Output: 0 if semiPrimeCount output an even number, 1 if the output is odd
-
Example:
semiPrimeCount(30)
will output10
, so this function should output0
-
Try to solve this without using
semiPrimeCount
.
Reply
to this thread with a link to your code on repl.it to participate! Don’t just submit your code, remember to explain
your solution, too! If you want to be considered as the winner, your function must
have the correct name
and provide output in the format specified
above, you also need to abide by our other simple rules.
The fine print:
Click the links to find out more about:
- the rules & how to participate in challenges
- how challenges are used as job interview questions
- why Codecademy runs challenges (and why they are formatted this way)
- more details about the challenges and why we think they are useful.
- find previous challenges (and see the past winners) in our Challenge Index