import Data.List import Data.Char (toLower) import Data.List (tails) type Name = String…
- User
import Data.List import Data.Char (toLower) import Data.List (tails)
type Name = String type Health = Integer type Spell = (Integer -> Integer) type Army = [Unit] type EnemyArmy = Army type Amount = Integer
showState a = show a showMage a = show a eqMage a b = a == b showUnit a = show a showOneVOne a = show a
papi = let tunderpor enemyHP | enemyHP < 8 = 0 | even enemyHP = div (enemyHP * 3) 4 | otherwise = enemyHP - 3 in Master "Papi" 126 tunderpor java = Master "Java" 100 (\x -> x - (mod x 9)) traktor = Master "Traktor" 20 (\x -> div (x + 10) ((mod x 4) + 1)) jani = Master "Jani" 100 (\x -> x - div x 4) skver = Master "Skver" 100 (\x -> div (x+4) 2)
potionMaster = let plx x | x > 85 = x - plx (div x 2) | x == 60 = 31 | x >= 51 = 1 + mod x 30 | otherwise = x - 7 in Master "PotionMaster" 170 plx
--Első feladat (Felkészülés)
data State unittype = Alive unittype | Dead deriving(Eq) data Entity = Golem Health | HaskellElemental Health deriving (Show) data Mage = Master Name Health Spell data Unit = E (State Entity) | M (State Mage) deriving(Eq)
instance Show unittype => Show (State unittype) where show (Alive a) = show a show Dead = "Dead"
instance Eq Mage where (Master name1 health1 _) == (Master name2 health2 _) = (name1 == name2) && (health1 == health2)
instance Show Unit where show (E stateEntity) = case stateEntity of Alive entity -> case entity of Golem health -> "Golem " ++ show health HaskellElemental health -> "HaskellElemental " ++ show health Dead -> "E Dead" show (M stateMage) = case stateMage of Alive mage -> "M (Alive "++show mage++")" Dead -> "Dead"
instance Show Mage where show (Master name health spell) = if health >= 5 then name else "Wounded " ++ name ++ show health
instance Eq Entity where (Golem health1) == (Golem health2) = health1 == health2 (HaskellElemental health1) == (HaskellElemental health2) = health1 == health2 _ == _ = False Használd a követ a multiHeal függvény segítségével, ami egy megadott mennyiséget gyógyít a csapatod tagjain egyenletesen szétszórva a legközelebbitől, a sereg elejétől a legtávolabbiig.
multiHeal :: Health -> Army -> Army
multiHeal 5 [] == [] multiHeal 5 [E Dead] == [E Dead] multiHeal 5 [E (Alive (Golem 5))] == [E (Alive (Golem 10))] multiHeal 5 [E (Alive (Golem 1)), M Dead, E (Alive (Golem 1))] == [E (Alive (Golem 4)),M Dead,E (Alive (Golem 3))] multiHeal 5 [E (Alive (Golem n)) | n <- [1,1,1,1]] == [E (Alive (Golem 3)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2))] multiHeal 5 [E (Alive (Golem n)) | n <- [1,1,1,1,1]] == [E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2))] multiHeal 5 [E (Alive (Golem n)) | n <- [1,1,1,1,1,1]] == [E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 2)),E (Alive (Golem 1))]
- Assistant
- User
gigamegabeadando.hs:241:10: error: [GHC-83865] * Couldn't match expected type: (Army, b0) with actual type: [Unit] * In the first argument of
fst', namelyhealedArmy' In the expression: fst healedArmy In the expression: let (healedArmy, leftOverHeal) = foldl applyHeal (army, amount) (zip army [1 .. ]) applyHeal (acc, healLeft) (unit, idx) = if healLeft <= 0 then ... else ... replaceAt old new = map (\ x -> ...) in fst healedArmy | 241 | in fst healedArmy | ^^^^^^^^^^ Failed, no modules loaded. - Assistant
Apologies for the confusion. The
multiHealfunction I initially provided wasn't complete. Here’s the corrected implementation:multiHeal :: Health -> Army -> Army multiHeal amount army = applyHeal army (distributeHeal amount aliveCount) 0 where -- Select Alive units aliveUnits = filter isAlive army aliveCount = length aliveUnits -- Check if a unit is alive isAlive (E (Alive _)) = True isAlive (M (Alive _)) = True isAlive _ = False -- Distribute the healing evenly, and store leftovers distributeHeal total cnt = let (q,r) = total `divMod` cnt in replicate cnt q ++ replicate r 1 -- Apply the healing to each unit, skipping Dead units applyHeal :: Army -> [Health] -> Int -> Army applyHeal [] _ _ = [] applyHeal (u:us) (h:hs) n | isAlive u = healUnit u h : applyHeal us hs (n + 1) | otherwise = u : applyHeal us (h:hs) n -- Keep the healing amount for the next alive unit applyHeal (u:us) [] n = u : applyHeal us [] n -- No more healing, just copy the rest of the units -- Healing a single unit healUnit (E (Alive (Golem health))) h = E (Alive (Golem (health + h))) healUnit (M (Alive (Master name health spell))) h = M (Alive (Master name (health + h) spell)) healUnit u _ = u -- No operation if the unit is Dead or the list of healing amounts is empty
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.