In my earlier submission I showed a means of JAPHing using a polynomial generated by Excel. Here now is some code to calculate the equation from a string all in Perl.

It works fine with the JAPH string upto 19 characters above which I think the limitations on internal maths stuff breaks. It's not obfusctation at this point and suggestions to get it work with the full 25 characters in JAPH (include line feed) would be fun. Note the code has been cobbled together on a Friday afternoon and I've made no attempt to make it elegant

#!/usr/local/bin/perl -w use strict; use Math::Polynomial; my %h = (); my $s = "Just another Perl h"; # put string into a hash {0=>J, 1=>u ...) map { $h{$_}=ord(substr($s,$_,1))}(0..length($s)-1); # use the library to get the polynomial factors my @p = split / /, Math::Polynomial::interpolate(%h); # generate the calculation string from factors my $p; my $i = length($s)-1; map{ $p .= "+$_*\$i**$i";$i-- } @p; # tidy the string, remove $i**0 (=1) # add .5 to total for rounding purposes $p =~ s/\+\-/\-/g; $p =~ s/.*\(//; $p =~ s/\).*/.5/; print "$p\n"; # test the equation for $i (0..length($s)-1) { print chr eval $p; }
Update

Links and spelling corrected as per chatterbox


In reply to Polynomial JAPH revisited by tweetiepooh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.