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/Problem22.py
|
||||
#Matthew Ellison
|
||||
# Created: 03-20-19
|
||||
#Modified: 10-30-20
|
||||
#Modified: 07-24-21
|
||||
#What is the total of all the name scores in the file?
|
||||
#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 Problem22(Problem):
|
||||
@@ -399,14 +398,14 @@ class Problem22(Problem):
|
||||
|
||||
#Functions
|
||||
#Constructor
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__("What is the total of all the name scores in this file?")
|
||||
self.sums = [] #Holds the score based on the sum of the characters in the name
|
||||
self.prod = [] #Holds the score based on the sum of the characters and the location in alphabetical order
|
||||
|
||||
#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
|
||||
@@ -414,6 +413,7 @@ class Problem22(Problem):
|
||||
#Start the timer
|
||||
self.timer.start()
|
||||
|
||||
|
||||
#Sort all the names
|
||||
self.__names.sort()
|
||||
#Step through every name adding up the values of the characters
|
||||
@@ -428,6 +428,7 @@ class Problem22(Problem):
|
||||
for cnt in range(0, len(self.sums)):
|
||||
self.prod.append(self.sums[cnt] * (cnt + 1))
|
||||
|
||||
|
||||
#Stop the timer
|
||||
self.timer.stop()
|
||||
|
||||
@@ -435,26 +436,22 @@ class Problem22(Problem):
|
||||
self.solved = True
|
||||
|
||||
#Reset the problem so it can be run again
|
||||
def reset(self):
|
||||
def reset(self) -> None:
|
||||
super().reset()
|
||||
self.sums.clear()
|
||||
self.prod.clear()
|
||||
|
||||
#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 answer to the question is {sum(self.prod)}"
|
||||
#Returns the vecot of the names being scored
|
||||
def getNames(self) -> list:
|
||||
return self.__names
|
||||
#Returns the sum of the names scores
|
||||
def getNameScoreSum(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 sum")
|
||||
self.solvedCheck("score of the names")
|
||||
return sum(self.prod)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user