Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Athanasius

by Athanasius (Archbishop)
on May 01, 2012 at 11:13 UTC ( [id://968231]=user: print w/replies, xml ) Need Help??

Errors, like straws, upon the surface flow;
He who would search for pearls, must dive below.

— John Dryden

On Athanasius

Etymology

  • Latin Athanasius < Greek Ἀθανάσιος < ἀ- not + θανάτος death
  • Hence means “immortal” — see John 3:16 and John 11:25-26a

The Christian does not think God will love us because we are good,
but that God will make us good because He loves us.

— C. S. Lewis

Athanasius I of Alexandria

  • Renowned Christian theologian, Church Father, and chief defender of Trinitarianism against Arianism
  • Born c. 296–298 AD, died 2 May, 373
  • Wrote Contra Gentes and De Incarnatione (“a masterpiece”) aged 20–22
  • Served as secretary to Patriarch Alexander of Alexandria at the First Council of Nicæa in 325
  • Patriarch and Archbishop of Alexandria (Roman Provincia Ægyptus) for 45 years (328–373)
  • Spent more than 17 years in five exiles ordered by four different Roman emperors
  • Known as “Father of the Canon” because he was the first to identify the 27 books of the New Testament in use today
  • Said at Nicæa: “Jesus that I know as my Redeemer cannot be less than God”
  His epitaph is Athanasius contra mundum, “Athanasius against the world.” We are proud that our own country has more than once stood against the world. Athanasius did the same. He stood for the Trinitarian doctrine, “whole and undefiled,” when it looked as if all the civilised world was slipping back from Christianity into the religion of Arius — into one of those “sensible” synthetic religions which are so strongly recommended today and which, then as now, included among their devotees many highly cultivated clergymen. It is his glory that he did not move with the times; it is his reward that he now remains when those times, as all times do, have moved away.
 — C. S. Lewis, Introduction to On The Incarnation by Athanasius
 

Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.

— Winston Churchill

Athanasius the PerlMonk

Evangelical Christian (Baptist)

Web Presence

PerlMonks Poetry

Meditations

JAPHs

     

PerlMonks Career

Level Title XP Date

1 Initiate 0  1 May 2012
2 Novice 20  5 May 2012
3 Acolyte 50  9 May 2012
4 Sexton 90 17 May 2012
5 Beadle 150  4 Jun 2012
6 Scribe 250 14 Jun 2012
7 Monk 400 30 Jun 2012
8 Pilgrim 600 18 Jul 2012
9 Friar 900  8 Aug 2012
10 Hermit 1,300 31 Aug 2012
11 Chaplain 1,800 28 Sep 2012
12 Deacon 2,400 30 Oct 2012
13 Curate 3,000  3 Dec 2012
14 Priest 4,000 25 Jan 2013
15 Vicar 5,400 20 Apr 2013
16 Parson 7,000 17 Aug 2013
17 Prior 9,000 19 Dec 2013
18 Monsignor 12,000 18 Jul 2014
19 Abbot 16,000 13 Jan 2015
20 Canon 22,000 20 Sep 2015
21 Chancellor 30,000 9 Oct 2016
22 Bishop 40,000 19 Sep 2018
23 Archbishop 50,000 20 Mar 2021
24 Cardinal 60,000
25 Sage 70,000
26 Saint 80,000
27 Apostle 90,000
28 Patriarch 100,000
29 His Eminence 1,000,000


You know the old saying:
any technology sufficiently advanced
is indistinguishable from a Perl s‎crip‎t.

Programming Perl (The Camel Book)


Posts by Athanasius
Pangram challenge: greed and Scrabble in Meditations
2 direct replies — Read more / Contribute
by Athanasius
on Apr 24, 2022 at 10:43

    Task 2 of the current Perl Weekly Challenge is to generate a pangram from the English dictionary provided. “A pangram or holoalphabetic sentence is a sentence using every letter of a given alphabet at least once.”1 However, for this challenge the requirement that the words form a sentence is removed: a list of unrelated words is all that is required.

    The bonus challenge is to “Constrain or optimize for something interesting,” and the first suggestion given is:

    Shortest possible pangram (difficult)

    Ok, so just how difficult would it be to perform an exhaustive search? I don’t know the answer, but since the search space increases exponentially as words are added to the dictionary, a search for sequences (of varying lengths) drawn from a pool of 23,610 words (see below) would appear highly impractical. I haven’t attempted it.

    Before we proceed, it should be noted that the dictionary can be significantly reduced in size before the search begins. Where groups of words share the same set of letters, only one word from the group (the shortest) need be kept. For example, “abdicate,” “diabetic,” and “abdicated” all have the letter set {a, b, c, d, e, i, t}, so “abdicate” is retained but “diabetic” and “abdicated” are filtered out. This reduces the dictionary size from 39,172 to 23,610 — a saving of 15,562 words!

    As noted above, 23,610 is still far too many words for an exhaustive search. So we’re looking for a way to get a close-to-optimum result in a reasonable time. And as we’ve just noted, each dictionary word can be considered as a set of its component letters. So the task is to find a minimum set cover, a well-studied problem in combinatorics and computer science.2 And there is an algorithm that is known to give good results in polynomial time: the greedy algorithm:

    at each stage, choose the set that contains the largest number of uncovered elements.

    My initial implementation of this algorithm produced the following pangram:

    oversimplification ladybug hawk jazz equinox (40 letters)

    I wasn’t satisfied with this, so began looking for ways to improve the search. It occurred to me that words with rare letters should be preferred over words with common letters. This immediately suggested the Scrabble3 points system:

    const my %ALPHABET => ( a => 1, b => 3, c => 3, d => 2, e => 1, f => 4, g => 2, h => 4, i => 1, j => 8, k => 5, l => 1, m => 3, n => 1, o => 1, p => 3, q => 10, r => 1, s => 1, t => 1, u => 1, v => 4, w => 4, x => 8, y => 4, z => 10 );

    With this I was able to give each word a weighting based on its component letters, and prefer words with higher weightings. This produced the following pangram:

    sympathized quarterbacking reflexive jawbone (41 letters)

    — no improvement at all! The problem appears to be that the selected words contain too much deadweight — too many redundant letters. So would it help to adjust the weighting for each word by deducting points for redundant letters? I experimented with different values of $DUP_WEIGHT, the amount to deduct for each redundant letter. Here are the results:

    $DUP_WEIGHT Pangram Letter Count
    1 sympathized quarterbacking jinx overflow 37
    2 sympathized quacking overflow jinx be 33
    3 sympathized quacking fox jaw verb all 32
    4 sympathized unblock xv jaw qt frog 29

    Eureka! At 29 letters, the last pangram is only 3 letters above the theoretical best-possible result of 26. (For values of $DUP_WEIGHT above 4, the result does not change.)

    It should be emphasized that my improved results are not an improvement on the greedy algorithm. That algorithm applies to sets, whereas my search for pangrams is a search over words, which are essentially bags because they contain multiple instances of the same letters.

    For the implementation, I found the Set::Tiny module very useful. I highly recommend it for working with sets of strings.

    Wikipedia1 gives the following as a short pangram:

    Waltz, bad nymph, for quick jigs vex. (28 letters)

    Since all these words occur in the given dictionary, it would be possible for a search to improve on my best solution by at least one letter. Challenge: can anyone implement a search which finds this pangram (or a shorter one) within a reasonable time?

    Full code listings for my solution (in Perl and Raku) will shortly be are available on the Weekly Challenge’s GitHub repository at https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-161/athanasius.

    Cheers,

    1“Pangram, ” Wikipedia, https://en.wikipedia.org/wiki/Pangram
    2“Set cover problem,” Wikipedia, https://en.wikipedia.org/wiki/Set_cover_problem
    3 “Scrabble letter distributions,” Wikipedia, https://en.wikipedia.org/wiki/Scrabble_letter_distributions#English

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Recamán's sequence and memory usage in Meditations
3 direct replies — Read more / Contribute
by Athanasius
on Jul 13, 2015 at 04:41

    Esteemed Monks,

    I was looking at The On-Line Encyclopedia of Integer Sequences (OEIS) (you know, as one does), and on the Welcome page I found a list of Some Famous Sequences, of which the first is Recamán’s sequence, defined as follows:

    R(0) = 0; for n > 0, R(n) = R(n-1) - n if positive and not already in the sequence, oth +erwise R(n) = R(n-1) + n.

    What makes this sequence interesting is N. J. A. Sloane’s conjecture that every number eventually appears.

    Coding the sequence is simplicity itself; the challenge is to test Sloane’s conjecture by keeping track of the numbers that have not yet appeared in the series. My initial, naïve approach was to use a sieve, à la Eratosthenes:

    But this turned out to be far too memory-hungry: for values of MAX of the order of twenty million, RAM usage on my 3GB system approaches 100%, thrashing sets in, and the script (along with the rest of Windows) grinds to a shuddering halt.

    Surely, I thought, there must be a memory-efficient way to represent a sieve? And of course there is, and of course it was already implemented on CPAN. A little searching led to the Set::IntSpan module which stores runs of consecutive integers as spans, allowing large (even infinite) collections of integers to be represented very economically.

    Calculation of successive terms in the Recamán sequence is noticeably slower using Set::IntSpan for lookup than it is using a hash. But, as the adage says, it’s better to be late than be dead on time. (This was the slogan of an Australian safe driving ad campaign some years ago.) For the record: I also looked at Set::IntSpan::Fast and Set::IntSpan::Fast::XS. The latter failed to install on my system, and the former actually ran slower than Set::IntSpan for this use-case.

    Turns out that Set::IntSpan not only solves the memory problem, it also makes it possible to dispense with an upper bound for the sieve. How, then, to display progressive results? Well, the OEIS has a couple of additional series related to Recamán’s:

    • A064228: values of R(n) that take a record number of steps to appear: 1, 2, 4, 19, ...
    • A064227: the values of n corresponding to the values in A064228: 1, 4, 131, 99734, ...

    So I recast the script to output successive values of these two series:

    14:20 >perl recaman.pl 1 <-- 1 2 <-- 4 4 <-- 131 19 <-- 99734 ...

    Here is the new script:

    use strict; use warnings; use sigtrap handler => \&int_handler, 'INT', handler => \&break_handler, 'BREAK'; use Set::IntSpan; use Time::HiRes qw(gettimeofday tv_interval); $| = 1; my $t0 = [gettimeofday]; my $min0 = 1; my $n = 0; my $r0 = 0; my $missing = Set::IntSpan->new( '1-)' ); print "$min0 <-- "; while (++$n) { my $r = $r0 - $n; $r = $r0 + $n if $r < 0 || !$missing->member($r); $missing->remove($r); if ((my $min1 = $missing->min) > $min0) { print "$n\n$min1 <-- "; $min0 = $min1; } $r0 = $r; } sub int_handler { printf "\nn = %d, elapsed time: %.1fs\n", $n, tv_interval($t0); } sub break_handler { int_handler(); exit 0; }

    This script was developed under Windows 8.1, 64-bit, using Strawberry Perl:

    14:20 >perl -v This is perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x +64-multi-thread

    The two signal handlers allow the script to be interrupted as follows:

    • Control-C causes the script to display the current value of $n and the total running time of the script so far.
    • Control-Break causes the script to display the same information and then exit.

    My takeaways from this meditation?

    First, we all know that micro-optimisation is pointless until you have first selected the best algorithm(s). But optimising an algorithm may actually consist in optimising its underlying data structures. Obvious? Yes, but still worth a reminder now and then.

    Second, CPAN is awesome! But you knew that already. :-)

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Noël, Noël in Perl Poetry
2 direct replies — Read more / Contribute
by Athanasius
on Dec 25, 2014 at 01:03

    It’s Christmas! Ring the Monastery bell,
    As we with joy recall that first Noël
    When shepherds, watching through the lonely night,
    Were over-awed by heaven’s glorious light.

    With cheer, we’ll greet our brother monks, and sisters,
    And amnesty extend to Pythonistas,
    And other erring souls; foreach, today,
    We wish bright blessings in a long @array.

    And tho’ at times, alas!, we make a %hash
    Of our Monastic Rule, with insults rash
    And words unkind: today we start anew
    And map our way with kinder goals in view.

    A maid needs help with syntax? We’ll not fail ’er.
    A hill of bugs is in our way? We’ll $scalar.
    Tho’ all the year in Perl we script — and well, —
    Today it’s “Per”, in honour of Noël.

    © 2014

    Merry Christmas!

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

The PerlMonk's Progress in Perl Poetry
No replies — Read more | Post response
by Athanasius
on May 01, 2013 at 09:59
    Happy Monkday!!
    You’ve been here 1 thrilling year.

    Is it really a whole year since I joined the Monastery? I’m so glad I did, and so very grateful to all the monks whose enthusiasm and dedication make PerlMonks the special place it is.

    So this seems like a good opportunity to post a rather long poem I wrote to meet the challenge of finding rhymes for all the monastic levels, from Initiate to Pope.

    Enjoy! :-)

    Cheers,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Reflections from the Hermitage in Perl Poetry
1 direct reply — Read more / Contribute
by Athanasius
on Sep 08, 2012 at 04:59

    5 Perlimericks

    A team of aspiring Perlistas
    Would type till their fingers got blisters.
         But without their espresso,
         The code was a mess, so
    They had to take turns as baristas.
    A Perl coder sheepdog named Shep,
    As a herder acquired a rep —
         An array he did keep
         Full of cows, goats, and sheep,
    Then he gathered the sheep using grep.
    Said the Scribe, as his postings increased,
    “An obsession? No, not in the least!
         With my time I’m restrictive.
         I know it’s addictive.”
    At the last report, he was a Priest...
    An old coder’s wit (not a flash of it!)
    Rejected my Perl (the whole stash of it).
         He’d been coding all day
         An associative array,
    So I said, “Well, you’ve sure made a hash of it!”
    Said the boss, “Java’s pure and sublime;
    To use anything else is a crime.”
         But a rebel named Earl
         Said “I much prefer Perl” —
    And his project was finished on time.

    © 2012

    Athanasius <°(((><contra mundum

Scenes from the Monastery in Perl Poetry
No replies — Read more | Post response
by Athanasius
on Aug 17, 2012 at 05:38
    5 Rhyming Haikus
    Newcomer puzzled
    By de-refs; but quickly copes
    With lexical scopes.
    Seeker of wisdom
    Finds that reputation lags
    For want of <code> tags.
    Fresh-minted Friar
    Learning Consideration
    In Moderation.
    Tricky answer found—
    Dancing and cries of “Whoopie!”
    As in rolls XP.
    Newbies, scholars, saints,
    Together in the cloisters
    Opening oysters.

    © 2012

    Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-12-14 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (72 votes). Check out past polls.