P-Adic numbers, basic: Difference between revisions
→{{header|Raku}}: fix copypasto and test again data set from peer entries, WIP
(→{{header|Raku}}: add a gist method and output changes) |
(→{{header|Raku}}: fix copypasto and test again data set from peer entries, WIP) |
||
Line 1,601:
=={{header|Raku}}==
<lang perl6># 20210225 Raku programming solution
class Padic { has ($.p is default(2), @.v is default([])) is rw ;
Line 1,611 ⟶ 1,609:
my %d = ^p Z=> (( $x «-« ^p ) »/» p )».&{ .denominator % p }; # .kv
for %d.keys { self.v.unshift: $_ and last if %d{$_} != 0 }
$x = ($x - self.v.first) / p ;
}
self
Line 1,625 ⟶ 1,623:
method gist { # en.wikipedia.org/wiki/P-adic_number#Notation
my %H = (0..9) Z=> ('
'
}
}
my @T;
my \DATA = < 5/8 353/30809 47 11 > ;▼
for my \D = (
#`[[[[[ these are not working
< -7/5 99/70 7 4> ,
< 26/25 -109/125 5 5 >,
< 49/2 -4851/2 7 6 >,
< -9/5 27/7 3 8>,
< 5/19 -101/384 2 12>,
< 6/7 -5/7 10 7 >,
< 2/7 -3/7 10 7 >,
< 2/7 -1/7 10 7 >,
<34/21 -39034/791 10 9 >,
< 11/4 679001/207 2 43>,
< 11/4 679001/207 3 27 >,
< -22/7 46071/379 2 37 >,
< -22/7 46071/379 3 23 >,
< -22/7 46071/379 7 13 >,
< -101/109 583376/6649 2 40>,
< -101/109 583376/6649 61 7>,
< -101/109 583376/6649 32749 3>,
< -25/26 5571/137 7 13>,
< 122/407 -517/1477 7 11>,
# ]]]]]
#`[[[[[ working cases
< 2/1 1/1 2 4>,
< 4/1 3/1 2 4>,
< 4/1 3/1 2 5>,
< 4/9 8/9 5 4>,
< 11/4 679001/207 11 13 >,
< 1/4 9263/2837 7 11 >,
# ]]]]]
given my $a = Padic.new { say .r2pa: DATA[0], DATA[2], DATA[3] }▼
) -> \D {
given @T[1] = Padic.new { say D[1]~' = ', .r2pa: D[1],D[2],D[3] }
say "Addition result = ", $_.gist, ( $_.gist eqv @T[2].gist ) ?? ''
▲given my $c = Padic.new { say .r2pa: DATA[0]+DATA[1] , DATA[2], DATA[3] }
!! ' but ' ~ (D[0]+D[1]).nude.join('/') ~ ' = ' ~ @T[2].gist
}
}
</lang>
{{out}}
<pre>
</pre>
=={{header|Wren}}==
|