aboutsummaryrefslogtreecommitdiff
path: root/challenge-030
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2019-10-19 22:18:48 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2019-10-19 22:18:48 +0100
commit189a23b1fdc5cf531c5a18fbb96fd97fab0b09e1 (patch)
tree5942778156273bbf673dac8e7f854f0cf0feaa5b /challenge-030
parent006e4d3a07838f66081dd057f6131fab6329632a (diff)
downloadperlweeklychallenge-club-189a23b1fdc5cf531c5a18fbb96fd97fab0b09e1.tar.gz
perlweeklychallenge-club-189a23b1fdc5cf531c5a18fbb96fd97fab0b09e1.tar.bz2
perlweeklychallenge-club-189a23b1fdc5cf531c5a18fbb96fd97fab0b09e1.zip
- Added solution by Ulrich Rieke.
Diffstat (limited to 'challenge-030')
-rw-r--r--challenge-030/ulrich-rieke/haskell/ch-1.hs21
-rw-r--r--challenge-030/ulrich-rieke/haskell/ch-2.hs4
-rw-r--r--challenge-030/ulrich-rieke/perl5/ch-1.pl14
3 files changed, 39 insertions, 0 deletions
diff --git a/challenge-030/ulrich-rieke/haskell/ch-1.hs b/challenge-030/ulrich-rieke/haskell/ch-1.hs
new file mode 100644
index 0000000000..1dd73a5458
--- /dev/null
+++ b/challenge-030/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,21 @@
+module Christmas
+ where
+import Data.Time.Calendar( fromGregorian )
+import Data.Time.Calendar.WeekDate( toWeekDate , showWeekDate )
+import qualified Data.Set as S
+import Data.List ( sort )
+
+sundayChristmas :: [ String ]
+sundayChristmas =
+ let christmasses = map (\i -> fromGregorian i 12 25 ) [2019..2100]
+ sundays = filter (\d -> ( findThirdElement $ toWeekDate d ) == 7 ) christmasses
+ in map printDate $ map (\d -> findFirstElement $ toWeekDate d ) sundays
+
+findThirdElement :: ( Integer , Int , Int ) -> Int
+findThirdElement (year, month, day) = day
+
+findFirstElement :: ( Integer , Int , Int ) -> Integer
+findFirstElement ( year , month, day ) = year
+
+printDate :: Integer -> String
+printDate year = show year ++ " Dec." ++ " 25" ;
diff --git a/challenge-030/ulrich-rieke/haskell/ch-2.hs b/challenge-030/ulrich-rieke/haskell/ch-2.hs
new file mode 100644
index 0000000000..2be3683777
--- /dev/null
+++ b/challenge-030/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,4 @@
+solution :: [[Int]]
+solution = S.toList $ S.fromList $ map sort $ [[a , b , c] | a <-[1..10] ,
+ b <- [1..10] , c <- [1..10] , a + b + c == 12 ,
+ any (\i -> even i) [a , b , c]]
diff --git a/challenge-030/ulrich-rieke/perl5/ch-1.pl b/challenge-030/ulrich-rieke/perl5/ch-1.pl
new file mode 100644
index 0000000000..1c4237d75d
--- /dev/null
+++ b/challenge-030/ulrich-rieke/perl5/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use DateTime ;
+
+my @dates ;
+for my $year (2019..2100) {
+ my $date = DateTime->new( year => $year , month => 12 , day => 25 ) ;
+ if ( $date->day_of_week == 7 ) {
+ push( @dates , $date ) ;
+ }
+}
+print "These are the Christmas days on a Sunday:\n" ;
+map {print $_->ymd . "\n"} @dates ;