aboutsummaryrefslogtreecommitdiff
path: root/challenge-095
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-01-12 11:58:16 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-01-12 11:58:16 +0000
commit69261ac16ceb1e44ea94be1f8918688b2b5cda7a (patch)
treeaf7244bd55fd413ed27961a8f5bb3c779d4699fe /challenge-095
parentc817a5d0faab93ce96ad6f142dcd2bc715763e99 (diff)
downloadperlweeklychallenge-club-69261ac16ceb1e44ea94be1f8918688b2b5cda7a.tar.gz
perlweeklychallenge-club-69261ac16ceb1e44ea94be1f8918688b2b5cda7a.tar.bz2
perlweeklychallenge-club-69261ac16ceb1e44ea94be1f8918688b2b5cda7a.zip
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-095')
-rw-r--r--challenge-095/ulrich-rieke/cpp/ch-1.cpp20
-rw-r--r--challenge-095/ulrich-rieke/haskell/ch-1.hs13
-rw-r--r--challenge-095/ulrich-rieke/perl/ch-1.pl12
-rw-r--r--challenge-095/ulrich-rieke/raku/ch-1.raku10
-rw-r--r--challenge-095/ulrich-rieke/raku/ch-2.raku35
5 files changed, 90 insertions, 0 deletions
diff --git a/challenge-095/ulrich-rieke/cpp/ch-1.cpp b/challenge-095/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..2e6417d643
--- /dev/null
+++ b/challenge-095/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,20 @@
+#include <algorithm>
+#include <string>
+#include <iostream>
+#include <cstdlib>
+
+bool isPalindrome( int n ) {
+ std::string numstring { std::to_string( n ) } ;
+ std::string original( numstring ) ;
+ std::reverse( numstring.begin( ) , numstring.end( ) ) ;
+ return original == numstring ;
+}
+
+int main( int argc , char * argv[ ] ) {
+ if ( isPalindrome( std::atoi( argv[1] ) ))
+ std::cout << 1 ;
+ else
+ std::cout << 0 ;
+ std::cout << std::endl ;
+ return 0 ;
+}
diff --git a/challenge-095/ulrich-rieke/haskell/ch-1.hs b/challenge-095/ulrich-rieke/haskell/ch-1.hs
new file mode 100644
index 0000000000..ef30717e98
--- /dev/null
+++ b/challenge-095/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,13 @@
+module Challenge095
+ where
+
+isPalindrome :: Int -> Bool
+isPalindrome n = numstr == reverse numstr
+ where
+ numstr :: String
+ numstr = show n
+
+solution :: Int -> Int
+solution n
+ |isPalindrome n = 1
+ |otherwise = 0
diff --git a/challenge-095/ulrich-rieke/perl/ch-1.pl b/challenge-095/ulrich-rieke/perl/ch-1.pl
new file mode 100644
index 0000000000..f8314ccc97
--- /dev/null
+++ b/challenge-095/ulrich-rieke/perl/ch-1.pl
@@ -0,0 +1,12 @@
+#!/usr/bin/perl ;
+use strict ;
+use warnings ;
+use feature 'say' ;
+
+sub isPalindrome {
+ my $N = shift ;
+ return $N eq join( '' , reverse split( // , $N ) ) ;
+}
+
+my $N = $ARGV[0] ;
+say isPalindrome( $N ) ? 1 : 0 ;
diff --git a/challenge-095/ulrich-rieke/raku/ch-1.raku b/challenge-095/ulrich-rieke/raku/ch-1.raku
new file mode 100644
index 0000000000..9b9d19b1ae
--- /dev/null
+++ b/challenge-095/ulrich-rieke/raku/ch-1.raku
@@ -0,0 +1,10 @@
+use v6 ;
+
+sub isPalindrome( Int $n --> Bool ) {
+ my $numstring = $n.Str ;
+ return $numstring eq $numstring.flip ;
+}
+
+sub MAIN( Int $N ) {
+ say isPalindrome( $N ) ?? 1 !! 0 ;
+}
diff --git a/challenge-095/ulrich-rieke/raku/ch-2.raku b/challenge-095/ulrich-rieke/raku/ch-2.raku
new file mode 100644
index 0000000000..8da65699a5
--- /dev/null
+++ b/challenge-095/ulrich-rieke/raku/ch-2.raku
@@ -0,0 +1,35 @@
+use v6 ;
+
+class Stack {
+ has Mu @!elements ;
+
+ method top(--> Mu ) {
+ return @!elements[0] ;
+ }
+
+ method pop(--> Mu ) {
+ return @!elements.shift ;
+ }
+
+ method push( Mu $data ) {
+ @!elements.unshift( $data ) ;
+ }
+
+ method min(--> Mu ) {
+ return @!elements.min ;
+ }
+
+ method isEmpty(--> Bool ) {
+ return @!elements.elems == 0 ;
+ }
+}
+
+my Stack $sta = Stack.new( elements => ( ) ) ;
+$sta.push( 1 ) ;
+$sta.push( 19 ) ;
+$sta.push( 44 ) ;
+say $sta.top( ) ;
+say $sta.pop( ) ;
+$sta.push( -33 ) ;
+say "The top element is { $sta.top( ) }!" ;
+say "The minimum element is { $sta.min( ) } !" ;