30 Days of Code — Day 3
As a forcing function to get myself into the habit of writing these articles — I have decided to write an article for each day of the 30 Days of Code challenge from Hacker Rank.
The Task
Given an integer, n
, perform the following conditional actions:
- If
n
is odd, printWeird
. - If
n
is even and in the inclusive range of 2 to 5 , printNot Weird
. - If
n
is even and in the inclusive range of 6 to 20 , printWeird
. - If
n
is even and greater than 20, printNot Weird
.
Complete the stub code provided in your editor to print whether or not n
is weird.
The Code
The Result
>? 3
… Weird
>? 24
… Not Weird
>? 18
… Weird
Conclusion
I actually overcomplicated this one. I was going to create a function to define what constituted ‘weird’ versus ‘not weird’. But I decided to keep it simple. While not the most elegant solution it was within the defined task and solved the problem.
Here is a link to the day_2 answer/challenge I wrote about previously: 30 Days of Code — Day 2