DEV Community staff staff

Posted on

Daily Challenge #75 - Set Alarm

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.


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 with your suggestions!

Discussion (21)

willsmart profile image

How about prolog?
A file with one fact should do it...


To run..

> gprolog --consult-file
GNU Prolog 1.4.5 (64 bits)
Compiled Aug 20 2018, 15:27:00 with clang
By Daniel Diaz
Copyright (C) 1999-2018 Daniel Diaz
compiling /Users/Will/ for byte code...
/Users/Will/ compiled, 1 lines read - 257 bytes written, 4 ms
| ?- setAlarm(false,false).

| ?- setAlarm(false,true).

| ?- setAlarm(true,false).

| ?- setAlarm(true,true).

not_jffrydsr profile image

Prolog still scares me . . . not its syntax, but seemingly untapped potential.

peledzohar profile image
Zohar Peled • Edited on

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:

object challenge {
   def setAlarm( employed:Boolean, vacation:Boolean ) : Boolean = {
      return employed && !vacation

Nope, sorry, still too easy.

thejessleigh profile image
jess unrein


public class Employment
  private static boolean setAlarm(boolean employed, boolean vacation) {
    return employed && !vacation;

  public static void main(String[] args)
    System.out.println(setAlarm(false, false));
    System.out.println(setAlarm(false, true));
    System.out.println(setAlarm(true, true));
    System.out.println(setAlarm(true, false));
thejessleigh profile image
jess unrein • Edited on

Python with optional typing indicators and tests

def set_alarm(employed: bool, vacation: bool) -> bool:
  return employed and not vacation

assert not set_alarm(True, True)
assert not set_alarm(False, True)
assert not set_alarm(False, False)
assert set_alarm(True, False)

brightone profile image
Oleksii Filonenko • Edited on

x86-64 assembly (NASM syntax):

section .text
global set_alarm
    mov rax, rsi
    not rax
    and rax, rdi
aminnairi profile image


setAlarm : Bool -> Bool -> Bool
setAlarm employed onVacation =
    case (employed, onVacation) of
        (True, False) ->

        _ ->


module SetAlarm exposing (setAlarm)

This will expose our only function setAlarm to the outside world (used in our tests, see below).

setAlarm : Bool -> Bool -> Bool
setAlarm employed onVacation =

This will define a function named setAlarm. It takes three parameters. Which are all three booleans.

    case (employed, onVacation) of

We wrap our two parameters into a tuple. That way we can easily work with pattern matching.


module SetAlarmTest exposing (suite)

import Expect exposing (equal)
import SetAlarm exposing (setAlarm)
import Test exposing (Test, describe, test)

suite : Test
suite =
    describe "Set alarm"
        [ test "It should return true when employed and not on vacation" <| \_ -> equal True <| setAlarm True False
        , test "It should return true when unemployed and not on vacation" <| \_ -> equal False <| setAlarm False False
        , test "It should return true when employed and on vacation" <| \_ -> equal False <| setAlarm True True
        , test "It should return true when unemployed and on vacation" <| \_ -> equal False <| setAlarm False True
not_jffrydsr profile image

crackin' out the ol' Clojure 🤔

(ns dailyChallenge.seventyFive)

(defn- setAlarm [& {:keys [employed? vacation?]}]
  "A vacation is what you take when you can no longer take what you've
   been taking - Wise Man #42"
    (and employed? vacation?) false
    (and employed? (not vacation?)) true))

don't test me 😗

(deftest sunrise_mutha_fcka
 (is (= true (setAlarm :employed? true :vacation? false))
 (is (= false (and
                (setAlarm :employed? false :vacation? false)
                (setAlarm :employed? true :vacation? true) 
                (setAlarm :employed? false :vacation? true)))))
                  ;;i don't know if you can be unemployed and temporarily away 
                  ;;from work | in fact, you can't. 🤔🤔🤔

(run-tests 'dailyChallenge.seventyFive)

at least with named non-positional parameters . . .

. . . there's less confusion about how silly this is 😂

kvharish profile image
K.V.Harish • Edited on

My solution in js

const setAlarm = (employed = true, vacation = true) => employed && !vacation;

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

def setAlarm(employed = True, onVacation = True):
  return employed and not onVacation
fennecdjay profile image
Jérémie Astor • Edited on

in Gwion.
Using the newly implemented pattern matching ability.

fun int setalarm(const bool employed, const bool vacation) {
  match employed {
    case true: return !vacation;
    case _: return false;

<<< setalarm(true, true) >>>;
<<< setalarm(false, true) >>>;
<<< setalarm(false, true) >>>;
<<< setalarm(true, false) >>>;

I should implement implicit casting from bool to int and vice-versa.

EDIT: done and working.


  • set ! operator as boolean, which hopefully makes more sense
  • demonstrate (very) bad git usage 😕
karthicktamil17 profile image
karthick rajan • Edited on

Solved On Purescript

setAlarm :: Boolean -> Boolean -> Boolean
setAlarm employed vacation =
   case (Tuple employed vacation) of
     (Tuple true false) ->

     (Tuple _ _) ->
terabytetiger profile image
Tyler V. (he/him) • Edited on


setAlarm(employed, onVacation) => employed && !onVacation
brightone profile image
Oleksii Filonenko


def set_alarm(true, false), do: true
def set_alarm(_, _), do: false
vinniew1rus profile image
Vinnie • Edited on


const setalarm = (e,v) => e && !v;
avalander profile image
Avalander • Edited on


set_alarm :: Bool -> Bool -> Bool
set_alarm True False = True
set_alarm a b        = False
pmkroeker profile image

In go:

func setAlarm(e, v bool) bool {
    return e && !v

Go Playground example

lordapple profile image
LordApple • Edited on


const auto setAlarm = [](const bool& employed, const bool& vacation){
    return employed && !vacation;
manjunath12github profile image
Manjunath Hegde

In C#

Public bool setalarm(bool employed = false, bool vacation = false){
return !vacation && employed;

fennecdjay profile image
Jérémie Astor

nicer with some formatting:

Public bool setalarm(bool employed = false, bool vacation = false){
  return !vacation && employed;

Interresting of you use vacation first and your use of default values 😄

earlware profile image

Swift version:

import Foundation

 SetAlarm challenge function

 @param currentlyEmployed: Bool indicating if we are currently employed.
 @param onVacation: Bool indicating if we are currently on vacation.

 @return Bool indicating if we need to set our alarm.  Only true if both employed and not on vacation.
func setAlarm(currentlyEmployed:Bool, onVacation:Bool) -> Bool{
    return (currentlyEmployed && !onVacation)

//  run with all examples
print("Ex1 setAlarm(true,true)   -> false:     ", setAlarm(currentlyEmployed: true, onVacation: true))
print("Ex2 setAlarm(false,true)  -> false:     ", setAlarm(currentlyEmployed: false, onVacation: true))
print("Ex3 setAlarm(false,false) -> false:     ", setAlarm(currentlyEmployed: false, onVacation: false))
print("Ex4 setAlarm(true,false)  -> true:      ", setAlarm(currentlyEmployed: true, onVacation: false))

//  not exactly proper test suite, but you get the idea.
print("Passed all tests:    ", (!setAlarm(currentlyEmployed: true, onVacation: true) &&
                                !setAlarm(currentlyEmployed: false, onVacation: true) &&
                                !setAlarm(currentlyEmployed: false, onVacation: false) &&
                                setAlarm(currentlyEmployed: true, onVacation: false)))

Outputs the following:

Ex1 setAlarm(true,true)   -> false:      false
Ex2 setAlarm(false,true)  -> false:      false
Ex3 setAlarm(false,false) -> false:      false
Ex4 setAlarm(true,false)  -> true:       true
Passed all tests:     true
Program ended with exit code: 0

Overkill with all the printouts, but hey, why not?