aboutsummaryrefslogtreecommitdiff
path: root/challenge-062
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-31 13:04:43 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-31 13:04:43 +0100
commit4322b2ed7c473df1e89df1a5f6893a1719436301 (patch)
tree0285f3688cd0c4efff3dd0263b81235b3380b011 /challenge-062
parent718ccc1b5387a1139f1671bf2f5f4d32044d5205 (diff)
downloadperlweeklychallenge-club-4322b2ed7c473df1e89df1a5f6893a1719436301.tar.gz
perlweeklychallenge-club-4322b2ed7c473df1e89df1a5f6893a1719436301.tar.bz2
perlweeklychallenge-club-4322b2ed7c473df1e89df1a5f6893a1719436301.zip
- Added solutions by Shahed Nooshmand.
Diffstat (limited to 'challenge-062')
-rw-r--r--challenge-062/shahed-nooshmand/blog.txt1
-rw-r--r--challenge-062/shahed-nooshmand/raku/ch-1.sh1
-rw-r--r--challenge-062/shahed-nooshmand/raku/ch-2.raku29
3 files changed, 31 insertions, 0 deletions
diff --git a/challenge-062/shahed-nooshmand/blog.txt b/challenge-062/shahed-nooshmand/blog.txt
new file mode 100644
index 0000000000..304969afaa
--- /dev/null
+++ b/challenge-062/shahed-nooshmand/blog.txt
@@ -0,0 +1 @@
+https://rafraichisso.ir/2020/05/31/pwc-62
diff --git a/challenge-062/shahed-nooshmand/raku/ch-1.sh b/challenge-062/shahed-nooshmand/raku/ch-1.sh
new file mode 100644
index 0000000000..b7c130b8f6
--- /dev/null
+++ b/challenge-062/shahed-nooshmand/raku/ch-1.sh
@@ -0,0 +1 @@
+raku -e '.key.put for <name@example.org rjt@cpan.org Name@example.org rjt@CPAN.org user@alpha.example.org>.map({/(.+) "@" (.+)/; $_ => [$1.fc, ~$0]}).sort(*.value)'
diff --git a/challenge-062/shahed-nooshmand/raku/ch-2.raku b/challenge-062/shahed-nooshmand/raku/ch-2.raku
new file mode 100644
index 0000000000..811dd75d4a
--- /dev/null
+++ b/challenge-062/shahed-nooshmand/raku/ch-2.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+
+display-cube(2, n-queens 2);
+
+
+sub display-cube(\n, @queens) {
+ my @cube = [[0 xx n] xx n] xx n;
+ for @queens -> (\x, \y, \z) {
+ @cube[x][y][z] = 1;
+ }
+ .say for @cube
+}
+
+sub n-queens(\n) {
+ my @solutions;
+ my @available = ^n X ^n X ^n;
+ next-queen( @available, [], @solutions );
+ max @solutions
+}
+
+sub next-queen( @available, @post, @pre ) {
+ @pre.push([@post]) unless @available;
+ next-queen @available.grep({.&isn't-attacked: by => $^q}), [|@post, $_], @pre for @available
+}
+
+sub isn't-attacked($pos, :by($queen)) {
+ my $diff = (@$pos Z- @$queen).unique(as => &abs);
+ $diff == 3 or ($diff == 2 and 0 ∉ $diff)
+}