diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-07-31 23:36:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-31 23:36:16 +0100 |
| commit | 059d8def9e7d907983456027e4cf9eec146c23d4 (patch) | |
| tree | 8c8475990445bf49a7504172060f68080747df01 | |
| parent | a398fdd66391b0a33676eb54a9c4097547a40974 (diff) | |
| parent | f55055faeb76ab3ed8c29167e03e7f0ed29e1ce6 (diff) | |
| download | perlweeklychallenge-club-059d8def9e7d907983456027e4cf9eec146c23d4.tar.gz perlweeklychallenge-club-059d8def9e7d907983456027e4cf9eec146c23d4.tar.bz2 perlweeklychallenge-club-059d8def9e7d907983456027e4cf9eec146c23d4.zip | |
Merge pull request #8479 from codereport/master
Week 228P1 in Python, Rust, BQN & APL
| -rw-r--r-- | challenge-228/conor-hoekstra/ch-01.apl | 6 | ||||
| -rw-r--r-- | challenge-228/conor-hoekstra/ch-01.bqn | 6 | ||||
| -rw-r--r-- | challenge-228/conor-hoekstra/ch-01.py | 7 | ||||
| -rw-r--r-- | challenge-228/conor-hoekstra/ch-01.rs | 14 |
4 files changed, 33 insertions, 0 deletions
diff --git a/challenge-228/conor-hoekstra/ch-01.apl b/challenge-228/conor-hoekstra/ch-01.apl new file mode 100644 index 0000000000..ad2c531256 --- /dev/null +++ b/challenge-228/conor-hoekstra/ch-01.apl @@ -0,0 +1,6 @@ +UniqueSum ← +/(∪×1=(+⌿⊢∘.=∪)) + +⍝ Tests +UniqueSum 2 1 3 2 ⍝ 4 +UniqueSum 1 1 1 1 ⍝ 0 +UniqueSum 1 2 3 4 ⍝ 10 diff --git a/challenge-228/conor-hoekstra/ch-01.bqn b/challenge-228/conor-hoekstra/ch-01.bqn new file mode 100644 index 0000000000..060ee089ec --- /dev/null +++ b/challenge-228/conor-hoekstra/ch-01.bqn @@ -0,0 +1,6 @@ +UniqueSum ← +´⍷×1=·+˝=⌜⟜⍷ + +# Tests +UniqueSum 2‿1‿3‿2 # 4 +UniqueSum 1‿1‿1‿1 # 0 +UniqueSum 1‿2‿3‿4 # 10 diff --git a/challenge-228/conor-hoekstra/ch-01.py b/challenge-228/conor-hoekstra/ch-01.py new file mode 100644 index 0000000000..28b58a09e6 --- /dev/null +++ b/challenge-228/conor-hoekstra/ch-01.py @@ -0,0 +1,7 @@ +def unique_sum(nums): + return sum(k for k,v in Counter(nums).items() if v == 1) + +# Tests +unique_sum([2,1,3,2]) # 4 +unique_sum([1,1,1,1]) # 0 +unique_sum([2,1,3,4]) # 10 diff --git a/challenge-228/conor-hoekstra/ch-01.rs b/challenge-228/conor-hoekstra/ch-01.rs new file mode 100644 index 0000000000..be2eb5b2c2 --- /dev/null +++ b/challenge-228/conor-hoekstra/ch-01.rs @@ -0,0 +1,14 @@ +fn unique_sum(nums: Vec<i32>) -> i32 { + nums.iter() + .counts() + .iter() + .map(|(k, v)| if v == &1 { k } else { &0 }) + .sum() +} + +// Tests +fn main() { + println!("{}", unique_sum(vec![2, 1, 3, 2])); // 4 + println!("{}", unique_sum(vec![1, 1, 1, 1])); // 0 + println!("{}", unique_sum(vec![2, 1, 3, 4])); // 10 +} |
