implemented getRung
This commit is contained in:
@@ -24,7 +24,15 @@ License along with this program. If not, see
|
||||
|
||||
-}
|
||||
|
||||
module Abacus (Abacus, newAbacus, getNumBeads, getNumRungs) where
|
||||
module Abacus (
|
||||
Abacus,
|
||||
newAbacus,
|
||||
getNumBeads,
|
||||
getNumRungs,
|
||||
getRung,
|
||||
) where
|
||||
|
||||
import Data.List (find)
|
||||
|
||||
import Abacus.Internal
|
||||
|
||||
@@ -48,4 +56,16 @@ getNumBeads = abacusNumBeads
|
||||
getNumRungs :: Abacus -> Int
|
||||
getNumRungs = length . abacusRungs
|
||||
|
||||
-- | Returns the number of beads slid across a given rung
|
||||
getRung
|
||||
:: Int
|
||||
-- ^ The rung number
|
||||
-> Abacus
|
||||
-- ^ Abacus being checked
|
||||
-> Maybe Int
|
||||
-- ^ The number of beads slid across (if the rung exists)
|
||||
getRung r a = snd <$> find
|
||||
(\(n, _) -> n == r)
|
||||
(zip [0..] $ abacusRungs a)
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user