Write a function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation.
The function should return true if you are employed and not on vacation (because these are the circumstances under which you need to set an alarm). It should return false otherwise.
Example:
setalarm(true, true) -> false
setalarm(false, true) -> false
setalarm(false, false) -> false
setalarm(true, false) -> true
This challenge comes from Swolebrain at CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (20)
How about prolog?
A file with one fact should do it...
To run..
Prolog still scares me . . . not its syntax, but seemingly untapped potential.
I'm sorry, but it seems like you've lost the challenge somewhere.
At first I thought I've probably missed something, but then I saw the comments and realized it wasn't me, it was whoever came up with this challenge.
If I may offer a twist - Do it in a language you've never worked with before.
I'll take Scala for a ride on this one:
Nope, sorry, still too easy.
Java
Python with optional typing indicators and tests
x86-64 assembly (NASM syntax):
Elm
Explainations
This will expose our only function
setAlarm
to the outside world (used in our tests, see below).This will define a function named
setAlarm
. It takes three parameters. Which are all three booleans.We wrap our two parameters into a tuple. That way we can easily work with pattern matching.
Tests
crackin' out the ol' Clojure 🤔
don'ttest me 😗at least with named non-positional parameters . . .
. . . there's less confusion about how silly this is 😂
My solution in js
No prior experience in Python just wanted to give it a try. Like it :) Going to spend more time on the docs in the coming days.
My solution in Python
in Gwion.
Using the newly implemented pattern matching ability.
I should implement implicit casting from bool to int and vice-versa.
EDIT: done and working.
BONUS:
!
operator as boolean, which hopefully makes more senseSolved On Purescript
Some comments may only be visible to logged-in visitors. Sign in to view all comments.