Skip to content

Commit ed9570f

Browse files
committed
[euler] further whitespace, formatting cleanups
1 parent 34504cc commit ed9570f

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

categories/euler/prob065-andreoss.pl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env perl6
21
use v6;
32

43
=begin pod
@@ -9,8 +8,6 @@
98
109
L<https://projecteuler.net/problem=65>
1110
12-
13-
1411
The square root of 2 can be written as an infinite continued fraction.
1512
1613
√2 = 1 + 1
@@ -23,24 +20,25 @@
2320
______
2421
2 + ...
2522
26-
The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates that
27-
2 repeats ad infinitum. In a similar way, √23 = [4;(1,3,1,8)].
23+
The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates
24+
that 2 repeats ad infinitum. In a similar way, √23 = [4;(1,3,1,8)].
25+
26+
It turns out that the sequence of partial values of continued fractions for
27+
square roots provide the best rational approximations. Let us consider the
28+
convergents for √2.
2829
29-
It turns out that the sequence of partial values of continued fractions for square
30-
roots provide the best rational approximations. Let us consider the convergents for √2.
31-
3230
1 + 1
3331
___ = 3/2
34-
2
32+
2
3533
3634
1 + 1
3735
_________ = 7/5
3836
2 + 1 / 2
39-
37+
4038
....
4139
42-
Hence the sequence of the first ten convergents for √2 are:
43-
1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378, ...
40+
Hence the sequence of the first ten convergents for √2 are: 1, 3/2, 7/5,
41+
17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378, ...
4442
4543
What is most surprising is that the important mathematical constant,
4644
e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].
@@ -50,12 +48,12 @@
5048
5149
The sum of digits in the numerator of the 10th convergent is 1+4+5+7=17.
5250
53-
Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.
54-
51+
Find the sum of digits in the numerator of the 100th convergent of the
52+
continued fraction for e.
5553
5654
Expected result: 272
5755
58-
=end pod
56+
=end pod
5957

6058
sub continued-fraction(@sequence, :$depth) {
6159
my $x = @sequence.shift;
@@ -67,3 +65,5 @@
6765
my @e := gather { take 2; take (1; $_; 1) for 2,4 ... * };
6866

6967
say [+] continued-fraction(@e, depth => 100).numerator.comb;
68+
69+
# vim: expandtab shiftwidth=4 ft=perl6

categories/euler/prob066-andreoss.pl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/perl6
21
use v6;
32

43
=begin pod
@@ -7,28 +6,31 @@
76
87
=AUTHOR Andrei Osipov
98
10-
L<https://projecteuler.net/problem=66>
9+
L<https://projecteuler.net/problem=66>
1110
1211
Consider quadratic Diophantine equations of the form:
1312
1413
x² – D×y² = 1
1514
1615
For example, when D=13, the minimal solution in x is 649² – 13×180² = 1.
1716
18-
It can be assumed that there are no solutions in positive integers when D is square.
17+
It can be assumed that there are no solutions in positive integers when D is
18+
square.
1919
20-
By finding minimal solutions in x for D = {2, 3, 5, 6, 7}, we obtain the following:
20+
By finding minimal solutions in x for D = {2, 3, 5, 6, 7}, we obtain the
21+
following:
2122
2223
3²– 2×2²= 1
2324
2²– 3×1²= 1
2425
9²– 5×4²= 1
2526
5²– 6×2²= 1
2627
8²– 7×3²= 1
2728
28-
Hence, by considering minimal solutions in x for D ≤ 7, the largest x is obtained when D=5.
29-
30-
Find the value of D ≤ 1000 in minimal solutions of x for which the largest value of x is obtained.
29+
Hence, by considering minimal solutions in x for D ≤ 7, the largest x is
30+
obtained when D=5.
3131
32+
Find the value of D ≤ 1000 in minimal solutions of x for which the largest
33+
value of x is obtained.
3234
3335
Expected result: 661
3436
@@ -37,7 +39,7 @@
3739
3840
=end pod
3941

40-
subset NonSquarable where *.sqrt !%% 1;
42+
subset NonSquarable where *.sqrt !%% 1;
4143

4244
sub next-triplet([\a,\b,\k], \N) {
4345

@@ -59,18 +61,18 @@
5961
my $a = N.sqrt.floor;
6062
my $b = 1;
6163
my $k = $a ** 2 - N;
62-
64+
6365
$a, $b, $k;
6466
}
6567

6668
sub chakravala(NonSquarable \N) {
67-
# Start with a solution for a² - N b² = k
69+
# Start with a solution for a² - N b² = k
6870

6971
my ($a, $b, $k) = simple-solution N;
70-
72+
7173
($a,$b,$k) = next-triplet [$a,$b,$k], N
7274
while $k != 1;
73-
75+
7476
$a, $b, $k;
7577
}
7678

@@ -81,3 +83,5 @@ (NonSquarable \N)
8183
==> sort *[2] ==> my @x;
8284

8385
say @x.pop[0];
86+
87+
# vim: expandtab shiftwidth=4 ft=perl6

categories/euler/prob080-andreoss.pl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,23 @@
66
77
=AUTHOR Andrei Osipov
88
9-
L<https://projecteuler.net/problem=80>
9+
L<https://projecteuler.net/problem=80>
1010
11-
It is well known that if the square root of a natural number is not an integer, then it is irrational.
12-
The decimal expansion of such square roots is infinite without any repeating pattern at all.
13-
The square root of two is 1.41421356237309504880..., and the digital sum of the first one
14-
hundred decimal digits is 475.
11+
It is well known that if the square root of a natural number is not an
12+
integer, then it is irrational. The decimal expansion of such square roots
13+
is infinite without any repeating pattern at all. The square root of two is
14+
1.41421356237309504880..., and the digital sum of the first one hundred
15+
decimal digits is 475.
1516
16-
For the first one hundred natural numbers, find the total of the digital sums of the first
17-
one hundred decimal digits for all the irrational square roots.
17+
For the first one hundred natural numbers, find the total of the digital
18+
sums of the first one hundred decimal digits for all the irrational square
19+
roots.
1820
1921
The following algoritm was used for the solution:
2022
L<http://www.afjarvis.staff.shef.ac.uk/maths/jarvisspec02.pdf>
2123
2224
Expected result: 40886
23-
25+
2426
=end pod
2527

2628
use v6;
@@ -39,7 +41,7 @@
3941
}
4042
when Less {
4143
# add two zeros to a
42-
$a *= 100;
44+
$a *= 100;
4345
# add a zero to b just before the final digit (which will always be ‘5’).
4446
$b = ($b - (my $x = $b % 10)) * 10 + $x;
4547
}
@@ -50,13 +52,12 @@
5052

5153
sub MAIN(Bool :$verbose = False) {
5254
say [+] do for 1 ... 100 -> $n {
53-
next if $n.sqrt.floor ** 2 == $n;
55+
next if $n.sqrt.floor ** 2 == $n;
5456
my $x = [+] $n.&sqrt-subtraction.comb[^$limit];
5557
say "$n $x" if $verbose;
5658
$x;
5759
}
5860
say "Done in {now - INIT now}" if $verbose;
5961
}
6062

61-
62-
63+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)