···1616 src = pins.nixpkgs;
1717 };
1818 };
1919- shells.default = {
1919+ shells.default = config.shells.python;
2020+ shells.python = {
2021 # Declare what systems the shell can be used on.
2122 systems = [ "x86_64-linux" ];
2223···3031 mkShell {
3132 packages = [
3233 pkgs.python314
3434+ pkgs.black
3335 ];
3436 };
3537 };
+1
python/assignments/sep30/level1/numberOfBricks.py
···223344def numberOfBricks(steps: int) -> int:
55+ """Calculate the number of bricks in some steps using arithmetic series: S(n) = n(n+1)/2."""
56 return ceil((steps * (steps + 1)) / 2)
6778
+2
python/assignments/sep30/level1/pizzas.py
···11def howManyPizzas(students: int, slicesPerStudent: int) -> int:
22+ """Check how many pizzas are needed given that each pizza has 8 slices."""
23 neededSlices = students * slicesPerStudent
34 return (neededSlices + 7) // 8
455667def leftoverPizzaSlices(students: int, slicesPerStudent: int) -> int:
88+ """Check how many slices of pizza will be leftover given that each pizza has 8 slices."""
79 neededSlices = students * slicesPerStudent
810 totalSlices = howManyPizzas(students, slicesPerStudent) * 8
911 return totalSlices - neededSlices
···11def isPythagoreanTriple(a: float, b: float, c: float) -> bool:
22+ """
33+ Return true if all the following are True:
44+ - check that numbers are ascending
55+ - check that a^2 + b^2 = c^2
66+ - check that a, b, and c are positive
77+ """
28 return (
39 (a < b and b < c) and ((a**2 + b**2) == c**2) and not (a < 0 or b < 0 or c < 0)
410 )
+1
python/assignments/sep30/level1/triangleArea.py
···667788def triangleArea(a: float, b: float, c: float) -> float:
99+ """Use herons formula: `sqrt(sp(sp-a)(sp-b)(sp-c))` to calculate the area of a triangle using it's side lengths."""
910 semiperimeter = 0.5 * (a + b + c)
1011 return sqrt(
1112 semiperimeter * (semiperimeter - a) * (semiperimeter - b) * (semiperimeter - c)
+2
python/assignments/sep30/level2/dotsOverlap.py
···223344def distance(a: tuple[float, float], b: tuple[float, float]) -> float:
55+ """Calculate the distance between two points using the Euclidean distance formula."""
56 return sqrt((b[0] - a[0]) ** 2 + (b[1] - a[1]) ** 2)
677889def dotsOverlap(
910 x1: float, y1: float, r1: float, x2: float, y2: float, r2: float
1011) -> bool:
1212+ """Check if two circles overlap."""
1113 d = distance((x1, y1), (x2, y2))
1214 return d <= (r1 + r2)
1315
+2
python/assignments/sep30/level2/getGreen.py
···11def fullRGB(rgb: int) -> str:
22+ """Left pad 0's to make the string of length 9."""
23 return str(rgb).zfill(9)
344556def getGreen(rgb: int) -> int:
77+ """Return the green portion of an RGB value."""
68 return int(fullRGB(rgb)[3:6])
79810
+2
python/assignments/sep30/level2/isGray.py
···11def fullRGB(rgb: int) -> str:
22+ """Left pad 0's to make the string of length 9."""
23 return str(rgb).zfill(9)
344556def isGray(rgb: int) -> bool:
77+ """Return True if the RGB value passed is considered 'gray'."""
68 rgbStr = fullRGB(rgb)
79 return (rgbStr[0:3] == rgbStr[3:6]) and (rgbStr[3:6] == rgbStr[6:9])
810
···223344def numberOfSteps(bricks: int) -> int:
55+ """
66+ Given a number of bricks return how many steps would be required to use them all given that:
77+ S(0) = 0
88+ S(n) = S(n-1) + n
99+ Formula: `n=(-1+sqrt(1+8*bricks))/2`
1010+ """
511 return ceil((-1 + sqrt(1 + 8 * bricks)) / 2)
612713