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,7 +1,7 @@
|
||||
#ProjectEuler/Python/Problem13.py
|
||||
#Matthew Ellison
|
||||
# Created: 01-31-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#Work out the first ten digits of the sum of the following one-hundred 50-digit numbers
|
||||
"""
|
||||
37107287533902102798797998220837590246510135740250
|
||||
@@ -107,7 +107,7 @@
|
||||
"""
|
||||
#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
|
||||
@@ -125,7 +125,6 @@
|
||||
|
||||
|
||||
from Problems.Problem import Problem
|
||||
from Unsolved import Unsolved
|
||||
|
||||
|
||||
class Problem13(Problem):
|
||||
@@ -233,13 +232,13 @@ class Problem13(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("Work out the first ten digits of the sum of the one-hundred 50-digit numbers")
|
||||
self.sum = 0
|
||||
|
||||
#Operational functions
|
||||
#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
|
||||
@@ -247,9 +246,11 @@ class Problem13(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Get the sum of all of the numbers in the list
|
||||
self.sum = sum(self.__numbers)
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -257,29 +258,23 @@ class Problem13(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.sum = 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 sum of all {len(self.__numbers)} numbers is {self.sum}\n" \
|
||||
f"The first 10 digits are: {str(self.sum)[0:10]}"
|
||||
#Returns the list of 50-digit numbers
|
||||
def getNumbers(self) -> list:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before you can get the numbers")
|
||||
self.solvedCheck("numbers")
|
||||
return self.__numbers
|
||||
#Returns the sum of the 50-digit numbers
|
||||
def getSum(self) -> int:
|
||||
#If the problem hasn't been solved throw an exception
|
||||
if(not self.solved):
|
||||
raise Unsolved("You must solve the problem before you can get the sum of the numbers")
|
||||
self.solvedCheck("sum")
|
||||
return self.sum
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user