aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbagheera-sands <git@sandsscouts.org.uk>2019-10-14 13:01:08 +0100
committerbagheera-sands <git@sandsscouts.org.uk>2019-10-14 13:01:08 +0100
commitd44df656214d13eb7f7c4142548c8fd9c2e50764 (patch)
tree91ae7fd36ca0c54b360bec15b415c277022c9c79
parent0c023b7bed400bef13a672e507af7c60ccbda830 (diff)
downloadperlweeklychallenge-club-d44df656214d13eb7f7c4142548c8fd9c2e50764.tar.gz
perlweeklychallenge-club-d44df656214d13eb7f7c4142548c8fd9c2e50764.tar.bz2
perlweeklychallenge-club-d44df656214d13eb7f7c4142548c8fd9c2e50764.zip
foo - got the challenges the wrong way round!
-rw-r--r--challenge-030/james-smith/README.md38
-rwxr-xr-xchallenge-030/james-smith/perl5/ch1-better.sh (renamed from challenge-030/james-smith/perl5/ch2-better.sh)0
-rwxr-xr-xchallenge-030/james-smith/perl5/ch1.sh2
-rwxr-xr-xchallenge-030/james-smith/perl5/ch2-duplicates.sh (renamed from challenge-030/james-smith/perl5/ch1-duplicates.sh)0
-rwxr-xr-xchallenge-030/james-smith/perl5/ch2.sh2
5 files changed, 21 insertions, 21 deletions
diff --git a/challenge-030/james-smith/README.md b/challenge-030/james-smith/README.md
index 7ab802bd6c..35798e2bc6 100644
--- a/challenge-030/james-smith/README.md
+++ b/challenge-030/james-smith/README.md
@@ -2,44 +2,44 @@ Solutions by James Smith.
Sorry these are such nice golf questions they had to be golfed..
-# Challenge 1 - sum to 12
+# Challenge 1 - Christmas on a Sunday?
-I've included two solutions to this as the question was slighlty ambiguous
+Solving the actual problem - we need to work out which days have 5*year/4 mod 7 to be zero, so just use a simple grep, to keep the code sort we use "@{[ ]}" which at 7 bytes is one byte shorter than join" ",
-The first solution is for a strictly increasing sequence of numbers {no dupes}
```
-perl -E 'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a+1..5.5-$a/2}1..3'
+perl -E 'say"@{[grep{!(int(5*$_/4)%7)}2019..2099]}"'
```
-The second is for a series of sequences which can allow duplicates
+We can extend this to every year (since the Gregorian calendar was introduced) by subtracting
+int year/100 & adding int year/400...
+
```
-perl -E 'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a..6-$a/2}1..4'
+perl -E 'say"@{[grep{6==(int(5*$_/4)-int($_/100)+int$_/400)%7}2019..3e3]}"'
```
-In both cases we have used shortest loops - possible...
-
-# Challenge 2 - Christmas on a Sunday?
+# Challenge 2 - sum to 12
-Solving the actual problem - we need to work out which days have 5*year/4 mod 7 to be zero, so just use a simple grep, to keep the code sort we use "@{[ ]}" which at 7 bytes is one byte shorter than join" ",
+I've included two solutions to this as the question was slighlty ambiguous, as not sure if duplicates are allowed. Note the second requirement of one of the numbers being even is irrelevant as for three numbers to add to 12 then at least 1 must me even - 3 odds would add to an odd number...
+The first solution is for a strictly increasing sequence of numbers {no dupes}
```
-perl -E 'say"@{[grep{!(int(5*$_/4)%7)}2019..2099]}"'
+perl -E 'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a+1..5.5-$a/2}1..3'
```
-We can extend this to every year (since the Gregorian calendar was introduced) by subtracting
-int year/100 & adding int year/400...
-
+The second is for a series of sequences which can allow duplicates
```
-perl -E 'say"@{[grep{6==(int(5*$_/4)-int($_/100)+int$_/400)%7}2019..3e3]}"'
+perl -E 'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a..6-$a/2}1..4'
```
+In both cases we have used shortest loops - possible...
+
## Lengths of scripts:
All four scripts come in at: 259 bytes - the shortest two solutions come in at 116 bytes (pushing into a single script is just 107 bytes);
| Script | Bytes | Notes |
| :---: | ---: | :--- |
-| ch1.sh | 68 | Initial version of script with strictly increasing numbers |
-| ch1-duplicates.sh | 64 | Version of script which allows duplicates |
-| ch2.sh | 52 | Solve the actual problem of 2019-2099 - doesn't have issues with centuries |
-| ch2-better.sh | 75 | Include the century rules |
+| ch1.sh | 52 | Solve the actual problem of 2019-2099 - doesn't have issues with centuries |
+| ch1-better.sh | 75 | Include the century rules |
+| ch2.sh | 68 | Initial version of script with strictly increasing numbers |
+| ch2-duplicates.sh | 64 | Version of script which allows duplicates |
diff --git a/challenge-030/james-smith/perl5/ch2-better.sh b/challenge-030/james-smith/perl5/ch1-better.sh
index aef3dac8d2..aef3dac8d2 100755
--- a/challenge-030/james-smith/perl5/ch2-better.sh
+++ b/challenge-030/james-smith/perl5/ch1-better.sh
diff --git a/challenge-030/james-smith/perl5/ch1.sh b/challenge-030/james-smith/perl5/ch1.sh
index 587845fc98..334483a152 100755
--- a/challenge-030/james-smith/perl5/ch1.sh
+++ b/challenge-030/james-smith/perl5/ch1.sh
@@ -1 +1 @@
-perl -E'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a+1..5.5-$a/2}1..3'
+perl -E'say"@{[grep{!(int(5*$_/4)%7)}2019..2099]}"'
diff --git a/challenge-030/james-smith/perl5/ch1-duplicates.sh b/challenge-030/james-smith/perl5/ch2-duplicates.sh
index 69b9c25f92..69b9c25f92 100755
--- a/challenge-030/james-smith/perl5/ch1-duplicates.sh
+++ b/challenge-030/james-smith/perl5/ch2-duplicates.sh
diff --git a/challenge-030/james-smith/perl5/ch2.sh b/challenge-030/james-smith/perl5/ch2.sh
index 334483a152..587845fc98 100755
--- a/challenge-030/james-smith/perl5/ch2.sh
+++ b/challenge-030/james-smith/perl5/ch2.sh
@@ -1 +1 @@
-perl -E'say"@{[grep{!(int(5*$_/4)%7)}2019..2099]}"'
+perl -E'say map{$a=$_;map{" $a,$_,".(12-$a-$_)}$a+1..5.5-$a/2}1..3'