From 806f70bfc10388c0b03aa8698600e75e24b59e22 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Sun, 22 Mar 2020 21:32:24 +0000 Subject: - Added APL solutions by Richard Park. --- challenge-052/richard-park/README | 1 + challenge-052/richard-park/apl/LuckyWinner.aplf | 956 ++++++++++++++++++++++++ challenge-052/richard-park/apl/SteppingNo.aplf | 945 +++++++++++++++++++++++ challenge-052/richard-park/apl/TieTest.aplf | 936 +++++++++++++++++++++++ challenge-052/richard-park/apl/ch-1.aplf | 945 +++++++++++++++++++++++ challenge-052/richard-park/apl/ch-2.aplf | 956 ++++++++++++++++++++++++ guests.json | 3 +- 7 files changed, 4741 insertions(+), 1 deletion(-) create mode 100644 challenge-052/richard-park/README create mode 100644 challenge-052/richard-park/apl/LuckyWinner.aplf create mode 100644 challenge-052/richard-park/apl/SteppingNo.aplf create mode 100644 challenge-052/richard-park/apl/TieTest.aplf create mode 100644 challenge-052/richard-park/apl/ch-1.aplf create mode 100644 challenge-052/richard-park/apl/ch-2.aplf diff --git a/challenge-052/richard-park/README b/challenge-052/richard-park/README new file mode 100644 index 0000000000..f9814e8239 --- /dev/null +++ b/challenge-052/richard-park/README @@ -0,0 +1 @@ +Solutions by Richard Park. diff --git a/challenge-052/richard-park/apl/LuckyWinner.aplf b/challenge-052/richard-park/apl/LuckyWinner.aplf new file mode 100644 index 0000000000..56fdec0ad5 --- /dev/null +++ b/challenge-052/richard-park/apl/LuckyWinner.aplf @@ -0,0 +1,956 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + PerlWeekly/LuckyWinner.aplf at master · rikedyp/PerlWeekly · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Skip to content + + + + + + + + + + + +
+ +
+ + +
+ +
+ + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + Permalink + + + + + +
+ + +
+ + Branch: + master + + + + +
+ + + +
+
+
+ +
+ + Find file + + + Copy path + +
+
+ + +
+ + Find file + + + Copy path + +
+
+ + + + +
+ Fetching contributors… +
+ +
+ + Cannot retrieve contributors at this time +
+
+ + + + + +
+ +
+
+ + 15 lines (15 sloc) + + 1.1 KB +
+ +
+ +
+ Raw + Blame + History +
+ + +
+ + + + + + +
+
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
LuckyWinner←{
⍝ The elements of ⍵ (coins) are arranged in a line (vector/list) in a random order
⍝ The player and computer take turns choosing from either the right- or left-most coins without replacement
⍝ Who has the highest total value of coins after they have all been chosen?
⎕IO←0 ⍝ ⎕IO delenda est
⎕←'A tie is ','possible',⍨'im' ''⊃⍨∨/=/+/TieTest ⍵
⍺←1 ⍝ Computer goes first by default (⍺←0 for player first)
n←≢⍵ ⍝ Number of coins
end←?2⍴⍨n ⍝ Random end choices (0 left, 1 right)
choose←{⌽@(0=⊢)⍋⍋⍵⍳⍵}end ⍝ Coin index choice sequence
turns←n⍴(~,⊢)⍺ ⍝ Turn sequence (0 player, 1 computer)
⎕←coins←↑⍵∘{⍵⌷⍤0 1⊢⍺}¨(turns(⊂⊢)⌸choose) ⍝ Coins chosen (1st row player, 2nd row computer)
=/+/coins:'It''s a tie!'
' wins!',⍨(>⌿+/coins)⊃'Player' 'Computer' ⍝ Return winner in text message
}
+ + + +
+ +
+ + + +
+ + +
+ + +
+
+ + + +
+
+ +
+
+ + +
+ + +