During the talk, I will show a number of short Perl 6 fragments (mostly one-liners), that can express complex problems in a very concise way.
We will also solve a few problems from Project Euler, where Perl 6 can demonstrate its extreme beauty.
71. 1. Print the sum of all multiples
of 3 and 5 below 1000
say sum((1..999).grep: * %% (3 | 5))
72. 1. Print the sum of all multiples
of 3 and 5 below 1000
sub f($n) {
($n <<*>> (1...1000 / $n)).grep: * < 1000
}
say (f(3) ∪ f(5)).keys.sum;
My initial solution :-)
73. 2. Print the sum of all even
Fibonacci numbers
below 4,000,000
(1, 1, * + * ...^ * >
4_000_000).grep(* %% 2).sum.say
74. 3. Find the largest palindromic
number, which is a product
of two three-digit numbers.
(((999...100) X* (999...100)).grep:
{$^a eq $^a.flip}).max.say
75. 3. Find the largest palindromic
number, which is a product
of two three-digit numbers.
(((999...100) X* (999...100)).grep:
{$^a eq $^a.flip}).head(10).max.say
77. 4. Print the sum
of big numbers
<
371072874339021027987979982208375902465101357402
# Other 98 numbers here
535035345264725242508740540755917897812643303316
>.sum.substr(0, 10).say
78. 19. Count Sundays between
the two dates
say (
Date.new(year => 1901) ..^ Date.new(year => 2001)
).grep({.day == 1 && .day-of-week == 7}).elems
79. 19. Count Sundays between
the two dates
say (
Date.new(year => 1901, month => 1, day => 1) ..
Date.new(year => 2000, month => 12, day => 31)
).grep(*.day == 1).grep(*.day-of-week == 7).elems
80. 19. Count Sundays between
the two dates
say +(1901..2000 X 1..12).map(
{Date.new(|@_, 1)}
).grep(*.day-of-week == 7);
81. 34. Print the sum of all numbers,
which are equal to the sum
of factorials of their digits
say [+] (3..50_000).grep(
{$_ == [+] .comb.map({[*] 2..$_})})