aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-03-18 21:35:18 +0000
committerGitHub <noreply@github.com>2023-03-18 21:35:18 +0000
commit8b3cc26686bb78b8ca425a9d7036eef152e849a9 (patch)
tree77eca801ce399a0a18611f2487d7d2ac899ce17d
parentb3c3ecb1de5ee2622b63b089aba08f9457f3e818 (diff)
parentdabf4465ced41400d83e484b11d338ec02654c42 (diff)
downloadperlweeklychallenge-club-8b3cc26686bb78b8ca425a9d7036eef152e849a9.tar.gz
perlweeklychallenge-club-8b3cc26686bb78b8ca425a9d7036eef152e849a9.tar.bz2
perlweeklychallenge-club-8b3cc26686bb78b8ca425a9d7036eef152e849a9.zip
Merge pull request #7736 from codereport/master
Python & BQN to 208 P2
-rw-r--r--challenge-208/conor-hoekstra/ch-02.bqn4
-rw-r--r--challenge-208/conor-hoekstra/ch-02.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/challenge-208/conor-hoekstra/ch-02.bqn b/challenge-208/conor-hoekstra/ch-02.bqn
new file mode 100644
index 0000000000..4913670e2e
--- /dev/null
+++ b/challenge-208/conor-hoekstra/ch-02.bqn
@@ -0,0 +1,4 @@
+FindDuplicate ← {¯1⌈´1+/2=+˝𝕩=⌜1+↕≠𝕩}
+
+# Tests
+FindDuplicate ¨ ⟨1,2,2,4⟩‿⟨1,2,3,4⟩‿⟨1,2,3,3⟩ # ⟨ 1 ¯1 2 ⟩
diff --git a/challenge-208/conor-hoekstra/ch-02.py b/challenge-208/conor-hoekstra/ch-02.py
new file mode 100644
index 0000000000..fdc6510062
--- /dev/null
+++ b/challenge-208/conor-hoekstra/ch-02.py
@@ -0,0 +1,9 @@
+
+from collections import Counter, defaultdict
+
+def find_duplicate(nums):
+ return defaultdict(lambda:-1, map(reversed, Counter(nums).items()))[2]
+
+print(find_duplicate([1,2,2,4])) # 2
+print(find_duplicate([1,2,3,4])) # -1
+print(find_duplicate([1,2,3,3])) # 3