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"; | [reply] [Watch: Dir/Any] [d/l] |
|
Combining those I can convert 'japh' into 'perl' in a mere 108216 steps.....
% perl -e '$\="japh";$\++for 0..108215;print'
perl
-Blake
| [reply] [Watch: Dir/Any] [d/l] |
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. ;-)
| [reply] [Watch: Dir/Any] |
Re: First JAPH - Spell perl in 285074 easy steps
by jmcnamara (Monsignor) on Jan 10, 2002 at 18:47 UTC
|
| [reply] [Watch: Dir/Any] [d/l] |
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:~$
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
# 1 2
#234567890123456789012345678
$\=z;$\++for 0..285049;print
Faster, too ;-)
update
Cheating: \:->>
# 1 2
#2345678901234567890123456
$\=z;$\++for z..perk;print
_ _ _ _
(_|| | |(_|><
_|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
So then, if we really want to cheat:
# 1
#234567890123456
print++($_=perk)
| [reply] [Watch: Dir/Any] [d/l] |
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.
| [reply] [Watch: Dir/Any] |
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 | [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
#!/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;
}
}
| [reply] [Watch: Dir/Any] [d/l] |
|
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;
| [reply] [Watch: Dir/Any] [d/l] |
|
|
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 | [reply] [Watch: Dir/Any] [d/l] |
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))
| [reply] [Watch: Dir/Any] [d/l] [select] |