Permalink
Browse files

i am dumb

  • Loading branch information...
1 parent a099344 commit 1e9d384f7fbab5fdf243316ab54e7f138dc565f8 @leto leto committed Jul 24, 2009
Showing with 100 additions and 0 deletions.
  1. +2 −0 perl6/001/01.pl
  2. +6 −0 perl6/001/02.pl
  3. +6 −0 perl6/001/03.pl
  4. +5 −0 perl6/001/04.pl
  5. +6 −0 perl6/001/05.pl
  6. +17 −0 perl6/002/01.pl
  7. +22 −0 perl6/004/01.pl
  8. +36 −0 perl6/008/01.pl
View
@@ -0,0 +1,2 @@
+say [+] grep { $_ % 3 == 0 or $_ % 5 == 0}, (1..1000);
+
View
@@ -0,0 +1,6 @@
+my $s = 0;
+for (1..1000) {
+ $s += $_ if $_ % 3 == 0 or $_ % 5 == 0
+}
+say $s;
+
View
@@ -0,0 +1,6 @@
+my $s = 0;
+for (1..1000) {
+ $s += $_ if $_ % 3 == 0 || $_ % 5 == 0;
+}
+say $s;
+
View
@@ -0,0 +1,5 @@
+my $s = 0;
+for (1..1000) {
+ $s += $_ if $_ % 3 == 0 or $_ % 5 == 0
+}
+say $s;
View
@@ -0,0 +1,6 @@
+my $s = 0;
+$s += $_ for grep { $_ % 3 == 0 or $_ % 5 == 0}, (1..1000);
+say $s;
+
+
+
View
@@ -0,0 +1,17 @@
+#!/usr/bin/perl6
+=begin
+Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
+
+1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
+
+Find the sum of all the even-valued terms in the sequence which do not exceed four million.
+=end
+
+my @fib = (1,2); #start the list as stated in the problem
+my $stop = 4000000; #where to stop
+while 1 { # stop case is in the loop
+ my $next = @fib[@fib.end-1] + @fib[@fib.end];
+ last if $next > $stop;
+ @fib.push( $next );
+}
+say [+] grep { $_ % 2 == 0 }, @fib;
View
@@ -0,0 +1,22 @@
+#!/Users/jeff/Code/rakudo/perl6
+
+
+# Problem 4
+# 16 November 2001
+#
+# A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
+#
+# Find the largest palindrome made from the product of two 3-digit numbers.
+
+
+my $max = 0;
+for (100..999) -> $x {
+ for ($x..999) -> $y {
+ my $product = $x * $y;
+
+ $max = $product if $product > $max
+ and $product eq $product.flip;
+ }
+}
+
+say "$max";
View
@@ -0,0 +1,36 @@
+#!/Users/jeff/Code/rakudo/perl6
+
+#Problem 8
+#
+#Find the greatest product of five consecutive digits in the 1000-digit number.
+
+my $number_string = join '',qw/
+73167176531330624919225119674426574742355349194934
+96983520312774506326239578318016984801869478851843
+85861560789112949495459501737958331952853208805511
+12540698747158523863050715693290963295227443043557
+66896648950445244523161731856403098711121722383113
+62229893423380308135336276614282806444486645238749
+30358907296290491560440772390713810515859307960866
+70172427121883998797908792274921901699720888093776
+65727333001053367881220235421809751254540594752243
+52584907711670556013604839586446706324415722155397
+53697817977846174064955149290862569321978468622482
+83972241375657056057490261407972968652414535100474
+82166370484403199890008895243450658541227588666881
+16427171479924442928230863465674813919123162824586
+17866458359124566529476545682848912883142607690042
+24219022671055626321111109370544217506941658960408
+07198403850962455444362981230987879927244284909188
+84580156166097919133875499200524063689912560717606
+05886116467109405077541002256983155200055935729725
+71636269561882670428252483600823257530420752963450
+/;
+
+my $max = 0;
+for 0..995 -> $x {
+ my $product = [*] $number_string.substr($x, 5).comb;
+ $max = $product if $product > $max;
+}
+
+say "final: $max";

0 comments on commit 1e9d384

Please sign in to comment.