Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use Math::BigInt;
- #As Mr.dloser pointed out, I can only learn from harsh comments. So I will post it for you guys to take a look at it. I will comment it so you get an idea of what Im doing...hopefully I get an idea of what Im doing as well ;)
- #The Keypad which is implemented in a hash; I think its the most practical way of asscociating the numbers with the letters.
- my%keypad=(2=>"abc",3=>"def",4=>"ghi",5=>"jkl",6=>"mno",7=>"pqrs",8=>"tuv",9=>"wxyz");
- my(@wordSums,@fib); #Arrays for the number of strokes for a word and the fibonacci sequence.
- @fib=fib(10);
- open(DATEI,"<words.txt");
- foreach(<DATEI>){
- my($word,$wordCounter,@splitted);
- chomp($_);
- $word=$_;
- @splitted=split("",$word); #split the actual word into letters
- foreach(@splitted){
- my($char,$strokeCounter,$charIndex);
- $char=$_;
- for(my$i=2;$i<=9;$i++){ #determine in which "number" the actual character is in.
- #while($keypad{$i}=~m/$char/g){ #Here it wont work anymore I think. For some reason I cant seem to find a way to search for the character in $keypad{$i}.
- #$charIndex=$i;
- #while($keypad{$i}=~m/(.)/gs){ #Just an alternative Version which wont work as well
- # print $1." ";
- #}
- #print "\n";
- }
- #while($keypad{$charIndex}=~m/(.)/gs){ #was supposed to "push" the determined key and leave when it is found.
- # $strokeCounter++;
- # if($1 eq $char){
- # #print "$keypad{$charIndex}:$charIndex:$char:$strokeCounter\n";
- # last;
- # }
- #}
- #$wordCounter+=$strokeCounter;
- }
- #push(@wordSums,$wordCounter);
- }
- close(DATEI);
- sub fib{
- my($a,$b,$n,$sum,$primeSum,@primes);
- $n=$_[0];
- $a=Math::BigInt->new(0);
- $b=Math::BigInt->new(1);
- $primeSum=Math::BigInt->new(2);
- for (my$i=1;$i<=$n;$i++){
- push(@primes,$b);
- $sum=Math::BigInt->new(Math::BigInt->new($a)->badd($b));
- $a=Math::BigInt->new($b);
- $b=Math::BigInt->new($sum);
- }
- return @primes;
- }
Add Comment
Please, Sign In to add comment