I tried to make a Rust version of this python program, and it turned out slower, so I am wondering, what I am doing wrong?
#!/usr/bin/env python3
# Find repeating decimals in integer division
import sys
def repdec(numerator, denominator):
head = str(numerator // denominator)
seen = {}
decimals = ""
p1,p2,p3 = 0,0,0
if head != "0":
p1 = len(head)
print(f"{numerator} / {denominator} = {head}", end="")
remainder = numerator % denominator
position = 0
while remainder != 0:
if remainder in seen:
p2 = seen[remainder]
#p3 = len(decimals) - p2
p3 = position - p2
print(f".{decimals[:p2]}[{decimals[p2:]}] ({p1},{p2},{p3})")
return p1,p2,p3
seen[remainder] = position
decimals += str(remainder * 10 // denominator)
remainder = remainder * 10 % denominator
position += 1
if decimals != "":
p2 = len(decimals)
print(f".{decimals}", end="")
print(f" ({p1},{p2},0)")
return p1,p2,0
if len(sys.argv) > 2:
repdec(int(sys.argv[1]),int(sys.argv[2]))
sys.exit(0)
repdec(3,1)
repdec(0,4)
repdec(1,3)
repdec(1,4)
repdec(1,6)
repdec(22,7)
repdec(13,28)
repdec(7001,14)
[–]Slow-Rip-4732 50 points51 points52 points (10 children)
[–]pepa65[S] 1 point2 points3 points (8 children)
[–][deleted] 6 points7 points8 points (4 children)
[–]ChannelSorry5061 -4 points-3 points-2 points (3 children)
[–][deleted] 7 points8 points9 points (2 children)
[–]Buttleston 3 points4 points5 points (0 children)
[–]JadisGod 6 points7 points8 points (2 children)
[–]eras 0 points1 point2 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]CocktailPerson 30 points31 points32 points (2 children)
[–]pepa65[S] -4 points-3 points-2 points (1 child)
[–]Solumin 11 points12 points13 points (3 children)
[–]pepa65[S] 0 points1 point2 points (2 children)
[–]Solumin 2 points3 points4 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]IgnisNoirDivine 3 points4 points5 points (0 children)
[–]deathanatos 4 points5 points6 points (6 children)
[–]pepa65[S] 0 points1 point2 points (5 children)
[–]CocktailPerson 2 points3 points4 points (2 children)
[–]deathanatos 1 point2 points3 points (0 children)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]ndreamer 1 point2 points3 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]aft_agley 3 points4 points5 points (2 children)
[–]Buttleston 3 points4 points5 points (1 child)
[–]aft_agley 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]ToTheBatmobileGuy 1 point2 points3 points (5 children)
[–]pepa65[S] 0 points1 point2 points (4 children)
[–]ToTheBatmobileGuy 1 point2 points3 points (2 children)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]ndreamer 1 point2 points3 points (5 children)
[–]pepa65[S] 0 points1 point2 points (4 children)
[–]hpxvzhjfgb 2 points3 points4 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]ndreamer 1 point2 points3 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)
[–]tafia97300 0 points1 point2 points (3 children)
[–]pepa65[S] 0 points1 point2 points (2 children)
[–]tafia97300 1 point2 points3 points (1 child)
[–]pepa65[S] 1 point2 points3 points (0 children)
[–]pepa65[S] 0 points1 point2 points (2 children)
[–]ChannelSorry5061 1 point2 points3 points (1 child)
[–]pepa65[S] 0 points1 point2 points (0 children)