DEV Community

loading...

Discussion on: Daily Challenge #302 - setAlarm

Collapse
mbaas2 profile image
Michael Baas

A solution in Dyalog APL:
APL does not have true/false as a dedicated "logical values", but uses 0 or 1 to indicate false/true. So this can be done with a simple calculation: employed multiplied by not(vacation):

{⍺×~⍵}
Enter fullscreen mode Exit fullscreen mode

Here's the table of all possible results:

      0 1∘.{⍺×~⍵}0 1
0 0
1 0

Enter fullscreen mode Exit fullscreen mode

OK, I cheated: my fn uses the "dyadic" syntax where you provide a left arg (employed) and a right argument (vacation). I've also written an "enhanced" version that can deal with both syntaxes:

      setAlarm←{⍺←⊃⍵ ⋄ ⍺×~⊃⌽⍵}
      setAlarm 1 1
0
      setAlarm 0 1
0 
      setAlarm 0 0
0 
      setAlarm 1 0
1
     1 setAlarm 0
1
Enter fullscreen mode Exit fullscreen mode


`

Try it online!