Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Polynomial JAPH

by tweetiepooh (Friar)
on Oct 11, 2006 at 13:21 UTC ( #577605=obfuscated: print w/ replies, xml ) Need Help??

Not sure if this belongs here but I can't hide the code and give credit to the original source.

When I worked for a company writing education software many moons ago on the BBC micro we had a product that would work out the polynonial function for a sequence of number. We actually used this in some crude protection schemes.

Excel offers a smaller version of this in trending so I thought I could use the principle to generate a JAPH. Limitations in Excel mean accuracy is limited to 6 characters at a time.

I dare say those with a more maths bent can get this even better.

#!/usr/local/bin/perl -w use strict; map{ eval} ('map{printf "%c" ,3.55*$_**5-57.583*$_**4+347.75*$_**3-972.92*$_**2+1 +249.2*$_-463.5}(1..6)', 'map{printf "%c", -0.55*$_**5+10.208*$_**4-69.833*$_**3+215.29*$_**2-2 +92.12*$_+247.5}(1..6)', 'map{printf "%c", 1.25*$_**5-25.333*$_**4+191.25*$_**3-672.17*$_**2+10 +99*$_-561.5}(1..6)', 'map{printf "%c", 0.5833*$_**5-9.4583*$_**4+56.167*$_**3-148.54*$_**2+ +169.25*$_+36.5}(1..6)'); print "\n"
Note I'm not a mathematician so if this is named wrongly and someone else already has this then I appologise.

Update

With some playing I have this down to

for('3.55*$i**5-57.583*$i**4+347.75*$i**3-972.92*$i**2+1249.2*$i-463.5 +','-0.55*$i**5+10.208*$i**4-69.833*$i**3+215.29*$i**2-292.12*$i+247.5 +','1.25*$i**5-25.333*$i**4+191.25*$i**3-672.17*$i**2+1099*$i-561.5',' +0.5833*$i**5-9.4583*$i**4+56.167*$i**3-148.54*$i**2+169.25*$i+36.5'){ +{for$i(1..6){printf"%c",eval$_}}};
Update 2 This is now at 306 chars.
map{$i=$_%6+1;print chr${[3.55*$i**5-57.583*$i**4+347.75*$i**3-972.92* +$i**2+1249.2*$i-463.5,-0.55*$i**5+10.208*$i**4-69.833*$i**3+215.29*$i +**2-292.12*$i+247.5,1.25*$i**5-25.333*$i**4+191.25*$i**3-672.17*$i**2 ++1099*$i-561.5,0.5833*$i**5-9.4583*$i**4+56.167*$i**3-148.54*$i**2+16 +9.25*$i+36.5]}[$_/6]}(0..23)
Update 3 Shaved another char off (305)
map{print chr${[3.55*++($i=$_%6)**5-57.583*$i**4+347.75*$i**3-972.92*$ +i**2+1249.2*$i-463.5,-0.55*$i**5+10.208*$i**4-69.833*$i**3+215.29*$i* +*2-292.12*$i+247.5,1.25*$i**5-25.333*$i**4+191.25*$i**3-672.17*$i**2+ +1099*$i-561.5,0.5833*$i**5-9.4583*$i**4+56.167*$i**3-148.54*$i**2+169 +.25*$i+36.5]}[$_/6]}(0..23)

Comment on Polynomial JAPH
Select or Download Code
Re: Polynomial JAPH (golf?)
by dewey (Pilgrim) on Oct 12, 2006 at 06:05 UTC
    This is really neat, I haven't seen this approach to a japh before. A nice demonstration of a novel way to encode the text.
    If you are golfing, here's a (very) slight reduction:
    for('3.55*$i**5-57.583*$i**4+347.75*$i**3-972.92*$i**2+1249.2*$i-463.5 +','-0.55*$i**5+10.208*$i**4-69.833*$i**3+215.29*$i**2-292.12*$i+247.5 +','1.25*$i**5-25.333*$i**4+191.25*$i**3-672.17*$i**2+1099*$i-561.5',' +0.5833*$i**5-9.4583*$i**4+56.167*$i**3-148.54*$i**2+169.25*$i+36.5'){ +for$i(1..6){print chr eval}};
    Makes me wonder about other mathematical ways of encoding the text, maybe as solutions to other kinds of equations or as fixed points of some system...
    ~dewey
      Thankyou.

      Excel seems limited to 6 orders of polynomial (or whatever) and the coding seems to break down if the text is longer than that. Maybe those who are in the know could get an equation that would work on longer strings, all 24 chars in JAPH, then you may have one equation called 24 times.

      while(++$1<25){print chr "<equation>"}
      A weakness may be in how computer handles numbers with rounding etc.

      As for other mathematical ways, you can use some variants of the Fourier transformation. My Fast Japh does that, for example. It's called "fast" because for long strings it would be much faster to do than the simple polynomial thing.

      Now, as is, that japh encodes and decodes the string again so it's not much useful, but I've converted it to a japh that does the decoding only:

      use warnings; use strict; @,="-34-7-76+39-90+35-38-253-8+111-6+113-90-97-134+263+-4-49+38-75-6 -69-10+263+90+49+88+67-26-133-38+1271"=~/.\d+/g;for$,(0..4){2**$,&$_ or$,[uc]+=$,[2**$,+$_]-=($,[lc]*=2)/2for 0..31}print chr($_/16)for@, +

      Update: fixed code, which accidentally had its output appended to it.

Re: Polynomial JAPH
by ambrus (Abbot) on Oct 12, 2006 at 10:19 UTC
      Thanks for the link, I'll have to go figure yours out in more detail. Cool JAPHs, people!
      ~dewey
Re: Polynomial JAPH
by jdporter (Canon) on Apr 18, 2008 at 13:22 UTC
    Another follow-on: fft japh. Does the same kind of thing, but doesn't have the limitation. The function generation routine is written in C.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://577605]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-08-02 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (55 votes), past polls