Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab1: Exercise 8 #1

Open
BertLisser opened this issue Sep 14, 2017 · 0 comments
Open

Lab1: Exercise 8 #1

BertLisser opened this issue Sep 14, 2017 · 0 comments

Comments

@BertLisser
Copy link

-- Because there is only one possibility where 3 people are correct according to the 
-- teacher the boy with 3 accusers will be found guilty. So we check for each person how 
-- many accusers he has untill we find the one with 3 accusers.
checkGuilty :: Boy -> [Boy] -> [Boy]
checkGuilty x xs = if length (accusers x) == 3 then [x] 
                             else checkGuilty (head xs) (tail xs)

The remark if the puzzle is well-designed... is not an assumption. So checkGuilty must be changed in:

checkGuilty :: Boy -> [Boy] -> [Boy]
checkGuilty x [] = []
checkGuilty x xs = if length (accusers x) == 3 then [x]++checkGuilty (head xs) (tail xs)  
                             else checkGuilty (head xs) (tail xs)

Simpler interface will be:

checkGuilty ::[Boy] -> [Boy]
checkGuilty [] =  ...
checkGuilty (x:xs) =  ...

Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant