implemented setRung
This commit is contained in:
@@ -30,6 +30,7 @@ module Abacus (
|
||||
getNumBeads,
|
||||
getNumRungs,
|
||||
getRung,
|
||||
setRung,
|
||||
) where
|
||||
|
||||
import Data.List (find)
|
||||
@@ -68,4 +69,26 @@ getRung r a = snd <$> find
|
||||
(\(n, _) -> n == r)
|
||||
(zip [0..] $ abacusRungs a)
|
||||
|
||||
-- | Sets the number of beads slid across a given rung
|
||||
setRung
|
||||
:: Int
|
||||
-- ^ The rung number
|
||||
-> Int
|
||||
-- ^ The value being set
|
||||
-> Abacus
|
||||
-- ^ The original state
|
||||
-> Abacus
|
||||
-- ^ The new state
|
||||
setRung r v a = a
|
||||
{ abacusRungs = zipWith
|
||||
(\n x -> if n == r then v' else x)
|
||||
[0..]
|
||||
(abacusRungs a)
|
||||
}
|
||||
where
|
||||
v'
|
||||
| v < 0 = 0
|
||||
| v > getNumBeads a = getNumBeads a
|
||||
| otherwise = v
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user