From bd2d7b8f0b545578d2f6a0865316b0cfa0bde4a7 Mon Sep 17 00:00:00 2001 From: Chris Proctor Date: Fri, 1 Mar 2024 18:10:43 -0500 Subject: [PATCH] Adding assessment --- assessment.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 assessment.md diff --git a/assessment.md b/assessment.md new file mode 100644 index 0000000..390c401 --- /dev/null +++ b/assessment.md @@ -0,0 +1,57 @@ +# Dice Lab Assessment + +Everything works as expected. Nice work! + +## Comments + +I thought your observation that "This method of problem solving is more +organized than how I would have written a Yahtzee program using +my past experience" was interesting. I agree, though it's certainly possible to write +OOP badly, and thereby increase the complexity of a problem :) +I find that I increasingly think deeply about whether to use an OO approach +or a functional approach--basically, whether to focus on nouns or verbs. + +Your decision to count 3- and 4-of-a-kind with a zero-initialized +dict works well: + +``` +of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0} +``` + +Two alternatives from the standard library are worth keeping in mind for +the future. A Counter just takes a list and counts instances of each value. + +``` +>>> from collections import Counter +>>> counter = Counter([1, 3, 3, 5, 3]) +>>> print(counter) +Counter({3: 3, 1: 1, 5: 1}) +``` + +A defaultdict is like a normal dict, but when you first access a key, its value is +initialized for you if it's not already present. + +``` +>>> from collections import defaultdict +>>> counts = defaultdict(int) +>>> for face in die_faces: +... counts[face] += 1 +``` + +Another "pythonic" trick would be available for GoalYahtzee, where you check whether +all the dice faces are the same: + +``` +for die in dice: + if die!=dice[0].face: + flag=False +``` + +In this case, I'll often convert the list into a set, which enforces member uniqueness. + +``` +unique_faces = set(dice) +if len(unique_faces) == 1: + print("Yahtzee!") +``` +