Engel expansion: Difference between revisions

m
→‎{{header|Raku}}: remove some intermediate variables, slightly more compact
m (→‎{{header|Raku}}: remove some intermediate variables, slightly more compact)
Line 95:
 
=={{header|Raku}}==
<lang perl6>sub to-engel ( $rat is copy) { do while $rat { my $a = ceiling 1 / $rat; $rat = $rat × $a - 1; $a } }
my $u = $rat;
do while $u { my $a = ceiling 1 / $u; $u = $u × $a - 1; $a }
}
 
sub from-engel (@expanded) { sum [\×] @expanded.map: { FatRat.new: 1, $_ } }
 
for # low precision 𝜋, 𝑒, √2 and 1.5 to a power
for flat
# low precision 𝜋, 𝑒, √2 and 1.5 to a power
3.14159265358979, 2.71828182845904, 1.414213562373095, 1.5 ** 5,
 
10,333

edits