Guest User

Untitled

a guest
Jun 21st, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Math::BigInt;
  4.  
  5. #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 ;)
  6. #The Keypad which is implemented in a hash; I think its the most practical way of asscociating the numbers with the letters.
  7. my%keypad=(2=>"abc",3=>"def",4=>"ghi",5=>"jkl",6=>"mno",7=>"pqrs",8=>"tuv",9=>"wxyz");
  8. my(@wordSums,@fib); #Arrays for the number of strokes for a word and the fibonacci sequence.
  9.  
  10. @fib=fib(10);
  11.  
  12. open(DATEI,"<words.txt");
  13. foreach(<DATEI>){
  14. my($word,$wordCounter,@splitted);
  15. chomp($_);
  16. $word=$_;
  17. @splitted=split("",$word); #split the actual word into letters
  18. foreach(@splitted){
  19. my($char,$strokeCounter,$charIndex);
  20. $char=$_;
  21. for(my$i=2;$i<=9;$i++){ #determine in which "number" the actual character is in.
  22. #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}.
  23. #$charIndex=$i;
  24.  
  25. #while($keypad{$i}=~m/(.)/gs){ #Just an alternative Version which wont work as well
  26. # print $1." ";
  27. #}
  28. #print "\n";
  29. }
  30. #while($keypad{$charIndex}=~m/(.)/gs){ #was supposed to "push" the determined key and leave when it is found.
  31. # $strokeCounter++;
  32. # if($1 eq $char){
  33. # #print "$keypad{$charIndex}:$charIndex:$char:$strokeCounter\n";
  34. # last;
  35. # }
  36. #}
  37. #$wordCounter+=$strokeCounter;
  38. }
  39. #push(@wordSums,$wordCounter);
  40. }
  41. close(DATEI);
  42.  
  43.  
  44. sub fib{
  45. my($a,$b,$n,$sum,$primeSum,@primes);
  46. $n=$_[0];
  47. $a=Math::BigInt->new(0);
  48. $b=Math::BigInt->new(1);
  49. $primeSum=Math::BigInt->new(2);
  50.  
  51. for (my$i=1;$i<=$n;$i++){
  52. push(@primes,$b);
  53. $sum=Math::BigInt->new(Math::BigInt->new($a)->badd($b));
  54. $a=Math::BigInt->new($b);
  55. $b=Math::BigInt->new($sum);
  56. }
  57. return @primes;
  58. }
Add Comment
Please, Sign In to add comment