mirror of
https://bitbucket.org/Mattrixwv/projecteulerpython.git
synced 2025-12-06 17:43:58 -05:00
Updated to use new library layout
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#ProjectEuler/Python/Problem26.py
|
||||
#Matthew Ellison
|
||||
# Created: 07-29-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
|
||||
#Unless otherwise listed, all of my non-standard imports can be gotten from my pyClasses repository at https://bitbucket.org/Mattrixwv/pyClasses
|
||||
"""
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
class Problem26(Problem):
|
||||
@@ -32,14 +31,14 @@ class Problem26(Problem):
|
||||
|
||||
#Function
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.")
|
||||
self.longestCycle = 0
|
||||
self.longestNumber = 0
|
||||
|
||||
#Operational function
|
||||
#Solve the problem
|
||||
def solve(self):
|
||||
def solve(self) -> None:
|
||||
#If the problem has already been solved do nothing and end the function
|
||||
if(self.solved):
|
||||
return
|
||||
@@ -47,6 +46,7 @@ class Problem26(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Start with 1/2 and find out how long the longest cycle is by checking the remainders
|
||||
#Loop through every number from 2-999 and use it for the denominator
|
||||
for denominator in range(2, self.__topNumber):
|
||||
@@ -79,6 +79,7 @@ class Problem26(Problem):
|
||||
self.longestCycle = len(remainderList)
|
||||
self.longestNumber = denominator
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -86,30 +87,24 @@ class Problem26(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.longestCycle = 0
|
||||
self.longestNumber = 0
|
||||
|
||||
#Gets
|
||||
#Returns the result of solving the problem
|
||||
def getResult(self):
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before you can see the result")
|
||||
def getResult(self) -> str:
|
||||
self.solvedCheck("result")
|
||||
return f"The longest cycle is {self.longestCycle} digits long\n" \
|
||||
f"It is started with the number {self.longestNumber}"
|
||||
#Returns the length of the longest cycle
|
||||
def getLongestCycle(self) -> int:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before can you see the length of the longest cycle")
|
||||
self.solvedCheck("length of the longest cycle")
|
||||
return self.longestCycle
|
||||
#Returns the denominator that starts the longest cycle
|
||||
def getLongestNumber(self) -> int:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before can you see the denominaotr that started the cycle")
|
||||
self.solvedCheck("denominator that starts the longest cycle")
|
||||
return self.longestNumber
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user