implemented setRung

This commit is contained in:
2024-08-21 14:34:46 -04:00
parent 768497d399
commit e52bee47c3
2 changed files with 43 additions and 3 deletions

View File

@@ -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