diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-03-20 19:19:43 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-20 19:19:43 +0000 |
| commit | 41ee39b0db49a63a84935bfdf77bbe7b8acde3f0 (patch) | |
| tree | 968e33602c0b0a9dd0e8f5c713819fa691c6c129 | |
| parent | 18824bd635a6e006123c1b8ba3b2ed1eaaf6fc96 (diff) | |
| parent | d921cf0a61d06448eea780928454dd22ae7b38e0 (diff) | |
| download | perlweeklychallenge-club-41ee39b0db49a63a84935bfdf77bbe7b8acde3f0.tar.gz perlweeklychallenge-club-41ee39b0db49a63a84935bfdf77bbe7b8acde3f0.tar.bz2 perlweeklychallenge-club-41ee39b0db49a63a84935bfdf77bbe7b8acde3f0.zip | |
Merge pull request #9780 from asherbhs/challenge-261
Challenge 261
| -rw-r--r-- | challenge-261/asherbhs/ch-1.apl | 5 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-1.bqn | 5 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-1.ijs | 5 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-1.raku | 8 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-2.apl | 4 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-2.bqn | 4 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-2.ijs | 4 | ||||
| -rw-r--r-- | challenge-261/asherbhs/ch-2.raku | 9 |
8 files changed, 44 insertions, 0 deletions
diff --git a/challenge-261/asherbhs/ch-1.apl b/challenge-261/asherbhs/ch-1.apl new file mode 100644 index 0000000000..30cb3c0d31 --- /dev/null +++ b/challenge-261/asherbhs/ch-1.apl @@ -0,0 +1,5 @@ +ElementDigitSum←|⊢-⍥(+/)10(+/⊢⊤⍨(⌊1+⍟)⍴⊣)¨⊢ +⎕←ElementDigitSum 1 2 3 45 +⎕←ElementDigitSum 1 12 3 +⎕←ElementDigitSum 1 2 3 4 +⎕←ElementDigitSum 236 416 336 350 diff --git a/challenge-261/asherbhs/ch-1.bqn b/challenge-261/asherbhs/ch-1.bqn new file mode 100644 index 0000000000..ee314180ae --- /dev/null +++ b/challenge-261/asherbhs/ch-1.bqn @@ -0,0 +1,5 @@ +ElementDigitSum←|⊢-○(+´)(+´'0'-˜•Repr)¨ +•Show ElementDigitSum 1‿2‿3‿45 +•Show ElementDigitSum 1‿12‿3 +•Show ElementDigitSum 1‿2‿3‿4 +•Show ElementDigitSum 236‿416‿336‿350 diff --git a/challenge-261/asherbhs/ch-1.ijs b/challenge-261/asherbhs/ch-1.ijs new file mode 100644 index 0000000000..cd882f85c9 --- /dev/null +++ b/challenge-261/asherbhs/ch-1.ijs @@ -0,0 +1,5 @@ +ElementDigitSum=:[:|]-&(+/)10([:+/]#:~[$~[:<.1+^.)"0] +echo ElementDigitSum 1 2 3 45 +echo ElementDigitSum 1 12 3 +echo ElementDigitSum 1 2 3 4 +echo ElementDigitSum 236 416 336 350 diff --git a/challenge-261/asherbhs/ch-1.raku b/challenge-261/asherbhs/ch-1.raku new file mode 100644 index 0000000000..ef62ff6e85 --- /dev/null +++ b/challenge-261/asherbhs/ch-1.raku @@ -0,0 +1,8 @@ +sub element-digit-sum(Int @ints --> Int) { + return abs @ints.sum - @ints».polymod(10 xx ∞)».sum.sum +} + +say element-digit-sum Array[Int].new(1, 2, 3, 45); +say element-digit-sum Array[Int].new(1, 12, 3); +say element-digit-sum Array[Int].new(1, 2, 3, 4); +say element-digit-sum Array[Int].new(236, 416, 336, 350); diff --git a/challenge-261/asherbhs/ch-2.apl b/challenge-261/asherbhs/ch-2.apl new file mode 100644 index 0000000000..e9c1c6d686 --- /dev/null +++ b/challenge-261/asherbhs/ch-2.apl @@ -0,0 +1,4 @@ +MultiplyByTwo←{⍵∊⍺: ⍺∇2×⍵ ⋄ ⍵} +⎕←5 3 6 1 12 MultiplyByTwo 3 +⎕←1 2 4 3 MultiplyByTwo 1 +⎕←5 6 7 MultiplyByTwo 2 diff --git a/challenge-261/asherbhs/ch-2.bqn b/challenge-261/asherbhs/ch-2.bqn new file mode 100644 index 0000000000..39f08f4d79 --- /dev/null +++ b/challenge-261/asherbhs/ch-2.bqn @@ -0,0 +1,4 @@ +MultiplyByTwo←{⊑𝕩∊𝕨 ? 𝕨𝕊2×𝕩 ; 𝕩} +•Show 5‿3‿6‿1‿12 MultiplyByTwo 3 +•Show 1‿2‿4‿3 MultiplyByTwo 1 +•Show 5‿6‿7 MultiplyByTwo 2 diff --git a/challenge-261/asherbhs/ch-2.ijs b/challenge-261/asherbhs/ch-2.ijs new file mode 100644 index 0000000000..df677aed4c --- /dev/null +++ b/challenge-261/asherbhs/ch-2.ijs @@ -0,0 +1,4 @@ +MultiplyByTwo=:{{ if. y e. x do. x MultiplyByTwo 2*y else. y end. }} +echo 5 3 6 1 12 MultiplyByTwo 3 +echo 1 2 4 3 MultiplyByTwo 1 +echo 5 6 7 MultiplyByTwo 2 diff --git a/challenge-261/asherbhs/ch-2.raku b/challenge-261/asherbhs/ch-2.raku new file mode 100644 index 0000000000..34d46b3688 --- /dev/null +++ b/challenge-261/asherbhs/ch-2.raku @@ -0,0 +1,9 @@ +sub multiply-by-two(Int @ints, Int $start --> Int) { + return $start ∈ @ints + ?? multiply-by-two(@ints, 2 * $start) + !! $start +} + +say multiply-by-two Array[Int].new(5, 3, 6, 1, 12), 3; +say multiply-by-two Array[Int].new(1, 2, 4, 3), 1; +say multiply-by-two Array[Int].new(5, 6, 7), 2; |
