Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps

by Calaban (Beadle)
on Jan 10, 2002 at 04:46 UTC ( [id://137638]=obfuscated: print w/replies, xml ) Need Help??

#!c:\perl\perl.exe -w use strict; my $A="a";for(0..285074){$A++;}print"$A";
  • Comment on First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
  • Download Code

Replies are listed 'Best First'.
Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by Veachian64 (Scribe) on Jan 10, 2002 at 07:34 UTC
    Corollary 1: $A="a";for(0..176858){$A++;}print"$A";
      Combining those I can convert 'japh' into 'perl' in a mere 108216 steps.....
      % perl -e '$\="japh";$\++for 0..108215;print' perl

      -Blake

Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by VSarkiss (Monsignor) on Jan 10, 2002 at 05:36 UTC

    You have a picket-fence problem: it's actually 285,075 iterations. ;-)

Re: First JAPH - Spell perl in 285074 easy steps
by jmcnamara (Monsignor) on Jan 10, 2002 at 18:47 UTC

    Clever idea. :-)

    In reply to juerd's golf (28 chars):     perl -e '$\=a;$\++for-74..285e3;print'

    --
    John.

Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by Juerd (Abbot) on Jan 10, 2002 at 16:57 UTC
    Haha! ++! Great one!

    Nice piece of code for a game of golf too...
    # First attempt # 1 2 3 #23456789012345678901234567890 $a=a;$a++for 0..285074;print$a # Second attempt (cheating :P) print'perl'

    2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$

      # 1 2 #234567890123456789012345678 $\=z;$\++for 0..285049;print
      Faster, too ;-)

      update
      Cheating: \:->>
      # 1 2 #2345678901234567890123456 $\=z;$\++for z..perk;print
       _  _ _  _  
      (_|| | |(_|><
       _|   
      
        So then, if we really want to cheat:
        # 1 #234567890123456 print++($_=perk)
Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by Starky (Chaplain) on Jan 10, 2002 at 06:09 UTC
    So simple it's brilliant! I laughed myself silly.
Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by pokemonk (Scribe) on Jan 12, 2002 at 07:11 UTC
    I find this really amazing, but i can't figure out why it happens. can someone please explain?

    pokmon
      From perlop:

        The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern /^[a-zA-Z]*[0-9]*$/, the increment is done as a string, preserving each character within its range, with carry:

          print ++($foo = '99'); # prints '100'
          print ++($foo = 'a0'); # prints 'a1'
          print ++($foo = 'Az'); # prints 'Ba'
          print ++($foo = 'zz'); # prints 'aaa'

        The auto-decrement operator is not magical.

      -Blake

      #!/usr/bin/perl use strict; my $theword = @ARGV[0]; my $A='a'; FINDIT: for (0..99999999){ $A++; if ($A eq "$theword") {print "$_\n"; last FINDIT; } }
        Wow. That can take a really long time to count. This little bit o' code is much faster.
        #!/usr/bin/perl -w # Convert pseudo-base26 number (digits: a-z) to decimal # really intended to find the ending number needed in # the for loop for any given string to be used my $num = 0; my $char = "a"; my $answer = 0; until ($char eq "aa") { $equiv{$char}=$num; $num++; $char++; } print "Enter your lowercase string: "; chomp($string = <STDIN>); @strArray=reverse(split(//,$string)); for ($i = 0; $i < @strArray; $i++) { $answer += ($equiv{$strArray[($i)]} * (25 ** $i)); } print --$answer;
      hi pokemonk;

      In order to get an idea of how the word 'perl' gets printed, you may want to modify the code as follows:

      #!c:\perl\perl.exe -w use strict; my $A="a";for(0..285074){$A++; print"$A";}
      That is, you place the 'print "$A"' statement inside the loop. To see what what happens when, say, 1000 characters are printed, you stop the loop by pressing Ctr 'C' (if you're using Windows).

      kiat
Re: First JAPH - Spell perl in two hundred and eighty five thousand and seventy four easy steps
by /dev/null (Chaplain) on Sep 11, 2002 at 18:07 UTC
    Great script!! It gave me plenty of pseudo-base 26 fun. The number is incremented exponentially as the number of characters increases. i.e. devnull in base 26 is:
     ((4*26**6) + (5*26**5) + (22*26**4) + (14*26**3) + (21*26**2) + (12*26**1) + (12*26**0))

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2025-04-17 17:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.