From 4d0254bd743bd9f34fe951259d1939d555d0209a Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Sat, 21 Jan 2023 13:16:28 +0000 Subject: [PATCH] FP: Solution for ex9 from AP2 added --- 1ano/fp/avaliacao/ap2/ex9.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 1ano/fp/avaliacao/ap2/ex9.py diff --git a/1ano/fp/avaliacao/ap2/ex9.py b/1ano/fp/avaliacao/ap2/ex9.py new file mode 100644 index 0000000..0a70e33 --- /dev/null +++ b/1ano/fp/avaliacao/ap2/ex9.py @@ -0,0 +1,19 @@ +def score(guess, secret): + assert len(guess) == len(secret) + + bulls_index: list[int] = [] + + for i in range(len(guess)): + if guess[i] == secret[i]: + bulls_index.append(i) + + new_g: list[str] = [guess[i] for i in range(len(guess)) if i not in bulls_index] + new_s: list[str] = [secret[i] for i in range(len(secret)) if i not in bulls_index] + + cows_index: list[int] = [] + for i in range(len(new_g)): + for j in range(len(new_s)): + if new_g[i] == new_s[j] and i not in cows_index: + cows_index.append(i) + + return len(bulls_index), len(cows_index)