Haskell program simple game

basti12354

I am very new in haskell-programming. I try to program a simple dice-game, but I don't know to do it in haskell.

 suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool

 suc  (a₁,a₂,a₃) c (d₁,d₂,d₃)

I want to consider each difference dᵢ - aᵢ (but not if aᵢ > dᵢ) and return False if (d1-a1)+(d2-a2)+(d3-a3) are larger than c. (if aᵢ > dᵢ then I sum up 0 instead the difference)

I try something like this:

suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) = ?????
    where diff1 = if (d1 > a1) then d1-a1       
          diff2 = if (d2 > a2) then d2-a2
          diff3 = if (d3 > a3) then d3-a3
Tomas Pastircak

How about this?

suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) = 
    ((if a1> d1 then 0 else d1-a1) + (if a2> d2 then 0 else d2-a2) + (if a3>d3 then 0 else d3-a3) > c )

Or alternatively

suc :: (Int,Int,Int) -> Int -> (Int,Int,Int) -> Bool
suc (a1, a2, a3) c (d1, d2, d3) = 
    max 0 (d1-a1) + max 0 (d2-a2) + max 0 (d3-a3) > c 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related