Skip to content

London | 25-SDC-Nov | Emiliano Uruena | Sprint 5 | Laptops Allocation#307

Open
Emilianouz wants to merge 3 commits intoCodeYourFuture:mainfrom
Emilianouz:Sprint5-Laptop
Open

London | 25-SDC-Nov | Emiliano Uruena | Sprint 5 | Laptops Allocation#307
Emilianouz wants to merge 3 commits intoCodeYourFuture:mainfrom
Emilianouz:Sprint5-Laptop

Conversation

@Emilianouz
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

Changelist

Implementing Laptop allocation exercise.

@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@Emilianouz Emilianouz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 5 Assigned during Week 5 of this module labels Dec 18, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@github-actions github-actions bot removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 18, 2025
@github-actions
Copy link

Your PR's title isn't in the expected format.

Please check the expected title format, and update yours to match.

Reason: Wrong number of parts separated by |s

If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed).

If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above.

@Emilianouz Emilianouz changed the title London | 25-SDC-Nov | Emiliano Uruena | Module tools | Sprint 5 | Laptops-allocation London | 25-SDC-Nov | Emiliano Uruena | Sprint 5 | Module tools Laptops-allocation Dec 18, 2025
@Emilianouz Emilianouz added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 18, 2025
@OracPrime OracPrime added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. 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 11, 2026
@Emilianouz
Copy link
Author

README file no necessary. It was removed.

@Emilianouz Emilianouz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 16, 2026
@Emilianouz Emilianouz changed the title London | 25-SDC-Nov | Emiliano Uruena | Sprint 5 | Module tools Laptops-allocation London | 25-SDC-Nov | Emiliano Uruena | Sprint 5 | Laptops Allocation Feb 16, 2026
@SlideGauge SlideGauge added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. 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 Feb 22, 2026
@SlideGauge
Copy link

Made review, interesting approach but there are some errors in the implementation itself worthy fixing + the algorithm won't find the most minimal possible configuration

Implement calcutate_sandess and backtracking for laptop allocation based on user preferences and minimize sadness.
@Emilianouz Emilianouz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Feb 25, 2026
@OracPrime
Copy link

I'll leave @SlideGauge to carry on with this since he's most recent reviewer

@OracPrime OracPrime requested a review from SlideGauge February 28, 2026 18:01
@SlideGauge SlideGauge added the Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. label Mar 1, 2026
Copy link

@SlideGauge SlideGauge left a comment

Choose a reason for hiding this comment

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

Overall really good solution, please change the returning type of the function and I will mark the review as complete.

for laptop in laptops:
if (laptop.operating_system == os and not laptop.assigned):
allocation[person.name] = laptop.id
assigned = True

Choose a reason for hiding this comment

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

Does this assigned variable prevent us from selecting the same laptop several times?

allocation[person.name] = laptop.id
assigned = True
break
if assigned:

Choose a reason for hiding this comment

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

what happens if we did not found the laptop after the first loop
for laptop in laptops?

allocation[person.name] = laptop.id
assigned = True
break
if assigned:

Choose a reason for hiding this comment

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

if assigned was set to True, what happens after iterating the first os?

operating_system: OperatingSystem
assigned: bool = False

def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[str, int]:

Choose a reason for hiding this comment

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

The algorithm belongs to the type of algorithms called "Greedy", i.e. on each step the algorithm takes the most suitable choice seen at this moment, not globally.
Consider:
Imran wants UBUNTU, ARCH
Eliza wants UBUNTU

The algorithm will give UBUNTU to Imran and nothing to Eliza, leading to sadness 100.

But we can invent different algorithm: if we distribute UBUNTU to Eliza and ARCH to Imran, we will have sadness 1. This algorithm will be slower, but our task is not to create the quickest algorithm, but minimizing the sadness.

Hint: this task requires analyzing of all possible permutations of laptops distribution.

name: str
age: int
preferred_operating_system: List[OperatingSystem]
assigned_laptop: Optional[int] = None

Choose a reason for hiding this comment

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

Since the dataclass is frozen, we won't be able to change the value of this variable

return person.preferred_operating_system.index(laptop.operating_system)
return 100

def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[str, int]:

Choose a reason for hiding this comment

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

Really nice, yes, backtrack will solve the task.

return person.preferred_operating_system.index(laptop.operating_system)
return 100

def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[str, int]:

Choose a reason for hiding this comment

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

One thing to take into account:
the task demands us for the function to have this signature:
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]:
Note, we return Dict of Person->Laptop, not str->int. It is valuable to take into account, as if we just return str->int, we won't be able to distinguish to people with the same name.

Copy link
Author

Choose a reason for hiding this comment

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

Right. We should return Dict[Person, Laptop] so people with the same name are handled correctly.

@SlideGauge SlideGauge 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 Mar 1, 2026
…on: Person and Laptop objects

Change allocation function to change the returning type of the function: Person and Laptop objects
@Emilianouz
Copy link
Author

Emilianouz commented Mar 1, 2026

@SlideGauge , I changed it to return type of the function: Person and Laptop objects. Thank you

@Emilianouz Emilianouz added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Mar 1, 2026
@SlideGauge
Copy link

Very nice, thank you, accepted

@SlideGauge SlideGauge added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 5 Assigned during Week 5 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants