Skip to content

Conversation

@HassanOHOsman
Copy link

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

This PR implements methods to allocate one laptop per person while minimising overall sadness. Each person is assigned one of their preferred operating systems whenever possible; otherwise, their sadness defaults to the maximum value of 100

@HassanOHOsman HassanOHOsman added 📅 Sprint 5 Assigned during Week 5 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Dec 8, 2025
@OracPrime OracPrime added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Jan 6, 2026
Copy link

@OracPrime OracPrime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the readability of the code, but there are two aspects from an efficiency perspective that need addressing: the exception is a "it would be better if" so could be left alone, but the algorithm you have chosen has a problem with scalability.

@@ -0,0 +1,42 @@
In the prep, there was an exercise around finding possible laptops for a group of people.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including the problem statement as a readme really helps me as a reviewer, so I don't have to go and find it. Thanks!

name: str
age: int
# Sorted in order of preference, most preferred is first.
preferred_operating_system: List[OperatingSystem]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general naming tip, if you have something which is a list or an array, give it a plural name. So preferred_operating_systems in this case. Helps the reader understand the use of the code

try:
return person.preferred_operating_system.index(laptop.operating_system)
except ValueError:
return 100

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the way you have separated this into a separate function, that's good. However it's bad practice to use exceptions in "normal" code execution, as they are very expensive in terms of processing time. They're great for error handling and have particular strengths there. On the next Saturday session, whether it's me or someone else, ask whoever's running it to talk about when using exceptions is a good or a bad idea, it would be a good discussion for the wider group to take part in.

How would you implement this function without try/except?

best_scenario_assignment = None
best_total_sadness = float("inf")

for scenario in permutations(laptops):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! OK, if you've got 5 laptops you're looking at 120 possibilities here, that's manageable.
If you've got 10, you're looking at nearly 4 million possibilities. Hey, it's a computer, it will cope.
How many possibilities are you enumerating if you've got 20 laptops?

How else could you do this?

@OracPrime OracPrime added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 5 Assigned during Week 5 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants