Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,65 @@
|
|||
Class Rational {
|
||||
\\ this is a compact version for this task
|
||||
numerator as decimal, denominator as decimal
|
||||
gcd=lambda->0
|
||||
lcm=lambda->0
|
||||
operator "+" {
|
||||
Read l
|
||||
denom=.lcm(l.denominator, .denominator)
|
||||
.numerator<=denom/l.denominator*l.numerator+denom/.denominator*.numerator
|
||||
if .numerator==0 then denom=1
|
||||
.denominator<=denom
|
||||
}
|
||||
Group Real {
|
||||
value {
|
||||
link parent numerator, denominator to n, d
|
||||
=n/d
|
||||
}
|
||||
}
|
||||
Group ToString$ {
|
||||
value {
|
||||
link parent numerator, denominator to n, d
|
||||
=Str$(n)+"/"+Str$(d,"")
|
||||
}
|
||||
}
|
||||
class:
|
||||
Module Rational (.numerator, .denominator) {
|
||||
if .denominator=0 then Error "Zero denominator"
|
||||
sgn=Sgn(.numerator)*Sgn(.denominator)
|
||||
.denominator<=abs(.denominator)
|
||||
.numerator<=abs(.numerator)*sgn
|
||||
gcd1=lambda (a as decimal, b as decimal) -> {
|
||||
if a<b then swap a,b
|
||||
g=a mod b
|
||||
while g {
|
||||
a=b:b=g: g=a mod b
|
||||
}
|
||||
=abs(b)
|
||||
}
|
||||
gdcval=gcd1(abs(.numerator), .denominator)
|
||||
if gdcval<.denominator and gdcval<>0 then
|
||||
.denominator/=gdcval
|
||||
.numerator/=gdcval
|
||||
end if
|
||||
.gcd<=gcd1
|
||||
.lcm<=lambda gcd=gcd1 (a as decimal, b as decimal) -> {
|
||||
=a/gcd(a,b)*b
|
||||
}
|
||||
}
|
||||
}
|
||||
sum=rational(1, 1)
|
||||
onediv=rational(1,1)
|
||||
divcand=rational(1,1)
|
||||
Profiler
|
||||
For sum.denominator= 2 to 2**15 {
|
||||
divcand.denominator=sum.denominator
|
||||
For onediv.denominator=2 to sqrt(sum.denominator) {
|
||||
if sum.denominator mod onediv.denominator = 0 then {
|
||||
divcand.numerator=onediv.denominator
|
||||
sum=sum+onediv+divcand
|
||||
}
|
||||
}
|
||||
if sum.real=1 then Print sum.denominator;" is perfect"
|
||||
sum.numerator=1
|
||||
}
|
||||
Print timecount
|
||||
Loading…
Add table
Add a link
Reference in a new issue