diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-17 00:11:10 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-01-17 00:11:10 +0000 |
| commit | 8e6c9cdc060aa5442ef97a656714d25ed6533298 (patch) | |
| tree | 9f1e0b51b58168996b6a3bd21e6ccf838383ba7e | |
| parent | 5da29e1d9fa562a75644ff3f26d4667eafacff1c (diff) | |
| download | perlweeklychallenge-club-8e6c9cdc060aa5442ef97a656714d25ed6533298.tar.gz perlweeklychallenge-club-8e6c9cdc060aa5442ef97a656714d25ed6533298.tar.bz2 perlweeklychallenge-club-8e6c9cdc060aa5442ef97a656714d25ed6533298.zip | |
- Added guest contributions by Laurent Rosenfeld.
| -rw-r--r-- | challenge-147/laurent-rosenfeld/ring/ch-1.ring | 43 | ||||
| -rw-r--r-- | challenge-147/laurent-rosenfeld/ring/ch-2.ring | 21 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-147/laurent-rosenfeld/ring/ch-1.ring b/challenge-147/laurent-rosenfeld/ring/ch-1.ring new file mode 100644 index 0000000000..578e9db72c --- /dev/null +++ b/challenge-147/laurent-rosenfeld/ring/ch-1.ring @@ -0,0 +1,43 @@ +max = 20 +primes = [2, 3, 5] +primes_h = [] +count = len(primes) +for i = 1 to count + primes_h[string(primes[i])] = i +next +truncatables = primes +candidate = primes[count] +while count < max + candidate += 2 + not_prime = false + pos = substr(string(candidate), "0") + if pos > 0 loop ok + sq_cand = floor(sqrt(candidate)) + for i in primes + if candidate % i = 0 + not_prime = true + exit + ok + if i > sq_cand exit ok + next + if not_prime loop ok + add (primes, candidate) + primes_h[string(candidate)] = 1 + // We've found a prime, now check if truncatable prime + length = len(string(candidate)) + is_truncatable = true + for i = 1 to length + truncated = right(string(candidate), i) + if isnull(primes_h[truncated]) + is_truncatable = false + exit + ok + next + if is_truncatable + add(truncatables, candidate); + count += 1 + ok + +end +for val in truncatables see "" + val + " " next +see " " + nl diff --git a/challenge-147/laurent-rosenfeld/ring/ch-2.ring b/challenge-147/laurent-rosenfeld/ring/ch-2.ring new file mode 100644 index 0000000000..b5bd69f2a6 --- /dev/null +++ b/challenge-147/laurent-rosenfeld/ring/ch-2.ring @@ -0,0 +1,21 @@ +max = 3000 +pentanums = [] +for i = 1 to max + add (pentanums, i * (3 * i - 1) / 2) +next +// see pentanums + nl +penta_h = [] +for i = 1 to max + penta_h[ string(pentanums[i])] = i +next +for i = 1 to max + for j = i+1 to max + diff = pentanums[j] - pentanums[i] + diff_s = string(diff) + if isnull(penta_h[diff_s]) loop ok + sum = pentanums[i] + pentanums[j] + sum_s = string(sum) + if isnull(penta_h[sum_s]) loop ok + see "" + diff + " " + sum + " " + pentanums[i] + " " + pentanums[j] + nl + next +next |
