Skip to content

Solutions to #1 and #2. #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 5 additions & 32 deletions challenge-014/jaime/README
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,14 @@ Solution by Jaime Corchado, (@tortsnare)[https://twitter.com/tortsnare].

# Challenge #1

The numbers formed by adding one to the products of the smallest
primes are called the Euclid Numbers (see wiki). Write a script that
finds the smallest Euclid Number that is not prime.

## Solution

Calculate the product of prime numbers and check if each successor is a prime.
Write a script to generate Van Eck’s sequence.

# Challenge #2

Write a script that finds the common directory path, given a
collection of paths and directory separator. For example, if the
following paths are supplied.

```
/a/b/c/d
/a/b/cd
/a/b/cc
/a/b/c/d/e
```

and the path separator is `/`. Your script should return `/a/b` as common
directory path.

## Solution

```
perl -- ch-2.pl <*delimiter*> <*list of strings*>
```

The path *delimiter* is a string like `/`.
The *list of strings* is a string like `/usr/bin:/usr/sbin`.

The solution is to find the consecutive intersection of all paths.
Using only the official postal (2-letter) abbreviations for the 50 U.S. states,
write a script to find the longest English word you can spell.

# Challenge #3

Find out the synonyms of a given word using the Synonyms API.
Find the given city current time using the Geo DB Cities API.

26 changes: 26 additions & 0 deletions challenge-014/jaime/perl5/ch-1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Solution by Jaime Corchado, (@tortsnare)[https://twitter.com/tortsnare].
#
# Challenge #1
#
# Write a script to generate Van Eck’s sequence.

my @ecks = (0);
print "0\n"; # start the sequence.

for (my $n = 0; ; $n++) {
$a1 = 0;
$an = shift @ecks;

my $m = 1; # the distance between matching entries.
for my $am (@ecks) {
if ($an == $am) {
$a1 = $m;
last; # only update with most recent entry.
}
} continue { $m++; }

unshift @ecks, $an;
unshift @ecks, $a1; # series is stored in reverse.

print "@ecks[0]\n"; # filter series with `perl ch-1.pl | head -n $LENGTH`
}
20 changes: 20 additions & 0 deletions challenge-014/jaime/perl5/ch-2.pl

Large diffs are not rendered by default.