DEV Community 👩‍💻👨‍💻

Discussion on: Daily Challenge #275 - Casino Chips

Collapse
bubbler4 profile image
Bubbler

APL (using Dyalog APL):

      Solve←(⌊2÷⍨+/)⌊(+/-⌈/)
      Solve 1 1 1
1
      Solve 1 2 1
2
      Solve 4 1 1
2
      Solve 12 12 12
18
      Solve 7 4 10
10

(Use the bookmarklet on this post to see the code with APL font and syntax highlighting.)

Explanation: Two possible answers are the sum of two lower values, and half of the entire sum (floored). We need to take the lower of the two.

(⌊2÷⍨+/)⌊(+/-⌈/)  ⍝ Input: an array of 3 numbers
        ⌊         ⍝ Take minimum of two sides...
                  ⍝  Choice 1:
          +/      ⍝   Sum (reduction / by addition +)
            -     ⍝   Minus
             ⌈/   ⍝   Max (reduction / by max-of-two ⌈)
                  ⍝  Choice 2:
     +/           ⍝   Sum
  2÷⍨             ⍝   Divided by 2
 ⌊                ⍝   Floor of the above
Collapse
nocnica profile image
Nočnica Fee

Nice explanation!