From de3a7abafe86d772614d6245214f3d0b709e7901 Mon Sep 17 00:00:00 2001 From: wi11-holdsworth <83637728+wi11-holdsworth@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:32:39 +1000 Subject: [PATCH] refactor: inline functions in feedback for clarity --- Proj2.hs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Proj2.hs b/Proj2.hs index 489760e..9c67d4a 100644 --- a/Proj2.hs +++ b/Proj2.hs @@ -130,26 +130,23 @@ toPitch _ = Nothing -- performer to decide on the best guess to make each turn -- feedback :: [Pitch] -> [Pitch] -> (Int, Int, Int) -feedback target guess = (length correctPitches, correctNotes, correctOctaves) +feedback target guess = (pitches, notes, octaves) where -- since pitches are unique in a guess, -- we can use set math to count how many are correct targetSet = S.fromList target guessSet = S.fromList guess - correctPitches = S.intersection targetSet guessSet - - newTarget = S.toList $ S.difference targetSet correctPitches - newGuess = S.toList $ S.difference guessSet correctPitches - - (targetNotes, guessNotes) = (map note newTarget, map note newGuess) - (targetOctaves, guessOctaves) = (map octave newTarget, map octave newGuess) + pitchSet = S.intersection targetSet guessSet + pitches = length pitchSet -- since notes and octaves are not unique in a guess, -- we can compare the guess to all possible permutations of the target -- and count the pairwise note/octave matches - correctNotes = matches targetNotes guessNotes - correctOctaves = matches targetOctaves guessOctaves + targetNoPitches = S.toList $ S.difference targetSet pitchSet + guessNoPitches = S.toList $ S.difference guessSet pitchSet + notes = matches (map note targetNoPitches) (map note guessNoPitches) + octaves = matches (map octave targetNoPitches) (map octave guessNoPitches) -- TODO: comment me --