diff options
| -rw-r--r-- | challenge-004/yet-ebreo/README | 1 | ||||
| -rw-r--r-- | challenge-004/yet-ebreo/perl5/ch-1.pl | 21 | ||||
| -rw-r--r-- | challenge-004/yet-ebreo/perl5/ch-2.pl | 23 | ||||
| -rw-r--r-- | challenge-004/yet-ebreo/perl5/words.txt | 26 | ||||
| -rw-r--r-- | challenge-023/yet-ebreo/perl5/ch-2.pl | 1 | ||||
| -rw-r--r-- | challenge-023/yet-ebreo/perl5/ch-3.pl | 3 | ||||
| -rw-r--r-- | challenge-023/yet-ebreo/perl6/ch-3.p6 | 22 |
7 files changed, 95 insertions, 2 deletions
diff --git a/challenge-004/yet-ebreo/README b/challenge-004/yet-ebreo/README new file mode 100644 index 0000000000..08724e9a99 --- /dev/null +++ b/challenge-004/yet-ebreo/README @@ -0,0 +1 @@ +Solution by Yet Ebreo
\ No newline at end of file diff --git a/challenge-004/yet-ebreo/perl5/ch-1.pl b/challenge-004/yet-ebreo/perl5/ch-1.pl new file mode 100644 index 0000000000..91f1675d7a --- /dev/null +++ b/challenge-004/yet-ebreo/perl5/ch-1.pl @@ -0,0 +1,21 @@ +# Write a script to output the same number of PI digits as the size of your script. +# Say, if your script size is 10, it should print 3.141592653. + +use strict; +use warnings; +use 5.010; + +my $size = -s $0; +use bigint; +my $n = 10 ** ($size+5) * 2; +my $p = 4 * $n; +my $i = 0; +while ($n) { + $p += $n; + $i += 1; + $n *= $i; + $n = $n /(2 * $i + 1); +} + +say "File Size: $size Bytes"; +say "PI ($size-digits): 3.".substr $p,2,$size-1;
\ No newline at end of file diff --git a/challenge-004/yet-ebreo/perl5/ch-2.pl b/challenge-004/yet-ebreo/perl5/ch-2.pl new file mode 100644 index 0000000000..9bfb7976d5 --- /dev/null +++ b/challenge-004/yet-ebreo/perl5/ch-2.pl @@ -0,0 +1,23 @@ +# You are given a file containing a list of words (case insensitive 1 word per line) +# and a list of letters. Print each word from the file that can be made using only +# letters from the list. You can use each letter only once (though there can be duplicates and you can use each of them once), +# you don’t have to use all the letters. (Disclaimer: The challenge was proposed by Scimon Proctor) + +use strict; +use warnings; +use 5.010; + +die "Usage:\n\tch-2.pl <file> <letters>\n\n\t<file>\t\t- file containing 1 word perline\n\t<letters>\t- letters to search (no space)\n" if @ARGV<2; + +my $filename = shift @ARGV; +my @letters = shift =~/./g; + +open(my $fh, '<', $filename) + or die "Could not open file '$filename' $!"; + +while (my $row = <$fh>) { + chomp $row; + my $hold = $row; + $row=~s/$_// for @letters; + say $hold if !$row +}
\ No newline at end of file diff --git a/challenge-004/yet-ebreo/perl5/words.txt b/challenge-004/yet-ebreo/perl5/words.txt new file mode 100644 index 0000000000..a6de6a1457 --- /dev/null +++ b/challenge-004/yet-ebreo/perl5/words.txt @@ -0,0 +1,26 @@ +a +quick +brown +fox +jumps +over +lazy +dog +peter +piper +picked +a +pan +of +pickled +pepper +banana +pine +trees +shark +whale +zebra +monkey +alpha +bravo +charlie
\ No newline at end of file diff --git a/challenge-023/yet-ebreo/perl5/ch-2.pl b/challenge-023/yet-ebreo/perl5/ch-2.pl index 8af3986a73..e817d6995f 100644 --- a/challenge-023/yet-ebreo/perl5/ch-2.pl +++ b/challenge-023/yet-ebreo/perl5/ch-2.pl @@ -25,6 +25,7 @@ say "@r\n"; #But I feel like I should do a non-backtick/module solution so here we go: #It's slow(and inaccurate) on very large numbers say "Using non-backticks solution (trial division/modulo):"; +use bigint; @r = (); while ($n % 2<1) { push @r, 2; diff --git a/challenge-023/yet-ebreo/perl5/ch-3.pl b/challenge-023/yet-ebreo/perl5/ch-3.pl index 7d4bd97110..cfc3f47b72 100644 --- a/challenge-023/yet-ebreo/perl5/ch-3.pl +++ b/challenge-023/yet-ebreo/perl5/ch-3.pl @@ -12,8 +12,7 @@ use JSON; binmode STDOUT, ":encoding(UTF-8)"; my $api_content = get "https://www.poemist.com/api/v1/randompoems"; -my @data; -push @data, @{$_} for JSON->new->utf8->decode($api_content); +my @data = @{ JSON->new->utf8->decode($api_content) }; #Printing the info of the first poem say "$data[0]{title} - $data[0]{poet}{name} - $data[0]{url}\n"; diff --git a/challenge-023/yet-ebreo/perl6/ch-3.p6 b/challenge-023/yet-ebreo/perl6/ch-3.p6 new file mode 100644 index 0000000000..c3f8ddabe1 --- /dev/null +++ b/challenge-023/yet-ebreo/perl6/ch-3.p6 @@ -0,0 +1,22 @@ +# Write a script to use Random Poems API. This is the easiset API, +# I have come across so far. You don’t need API key for this. +# They have only route to work with (GET). +# The API task is optional but we would love to see your solution. + + +use LWP::Simple; +use JSON::Tiny; +my $api_content = LWP::Simple.get('https://www.poemist.com/api/v1/randompoems'); + +my @data = @(from-json($api_content)); + +#Printing the info of the first poem +say "@data[0].{'title'} - @data[0].{'poet'}{'name'} - @data[0].{'url'}"; + +#Accessing all(5) poems +# for (@data) { +# say "$_.{'title'} - $_.{'poet'}{'name'} - $_.{'url'}"; +# } + +#Printing the content of the first poem +say "@data[0].{'content'}"; |
