-
Notifications
You must be signed in to change notification settings - Fork 0
/
p.sf
83 lines (50 loc) · 1.21 KB
/
p.sf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/ruby
#~ a(n) = my(d=divisors(4*n)); vecmin(select(v -> floor(v) == v, vector(#d, k, (d[k]^2 + (4*n/d[k])^2)/4)))
# a(n) = my(d=divisors(n)); vecmin(vector(#d, k, 4*((d[k]/2)^2 + (n/d[k]/2)^2)))
#~ __END__
#x*y = (x - y)/2,
func foo(n) {
var D = divisors(n)
var arr = []
for d in (D) {
var x = d/2
var y = (n / d)/2
var t = [x,y, 4*(x**2 + y**2)]
# say t
arr << t
}
arr.map{_[2]}
#arr.min_by {|a| a[2] }[2]
}
#say 50.of{foo(_+1)}
#say foo(10*10)
for n in (1..30) {
var t = foo(n).min
print (t - 2*n -> sqrt, ", ")
#var t = foo(n)
#print("{", [t-2*n, t+2*n].join(", "), "}, ")
}
__END__
d.combinations(2, {|a,b|
if ((n-b) * (n-a) == n) {
say [a,b]
}
})
for d in D {
var p = d
var r = (4*n / d)
}
#~ sub difference_of_two_squares_solutions {
#~ my ($n) = @_;
#~ my @solutions;
#~ foreach my $divisor (divisors($n)) {
#~ last if $divisor > sqrt($n);
#~ my $p = $divisor;
#~ my $q = $n / $divisor;
#~ ($p + $q) % 2 == 0 or next;
#~ my $x = ($q + $p) >> 1;
#~ my $y = ($q - $p) >> 1;
#~ unshift @solutions, [$x, $y];
#~ }
#~ return @solutions;
#~ }