Skip to content

Commit 2e3be0b

Browse files
committed
prep fin
1 parent 22dccbc commit 2e3be0b

File tree

5 files changed

+149
-11
lines changed

5 files changed

+149
-11
lines changed

implement-shell-tools/cat/notes.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import process from "node:process";
2+
import { promises as fs } from "node:fs";
3+
// const fs = promises
4+
5+
// * `cat sample-files/1.txt`
6+
// * `cat -n sample-files/1.txt`
7+
// * `cat sample-files/*.txt`
8+
// * `cat -n sample-files/*.txt`
9+
// * `cat -b sample-files/3.txt`
10+
11+
//from coursework
12+
// const content = await fs.readFile(path, "utf-8");
13+
// const countOfWordsContainingEs = content
14+
// .split(" ")
15+
// .filter((word) => word.includes("e"))
16+
// .length;
17+
// console.log(countOfWordsContainingEs);
18+
19+
// process.argv documentation that process.argv[0] will be the path to node
20+
// process.argv[1] will be the path to this file
21+
// the arguments start at index 2
22+
23+
24+
25+
// 1 `cat sample-files/1.txt`
26+
// async function caseOne(oneFile) {
27+
// const content = await fs.readFile(file, "utf-8");
28+
// console.log(content);
29+
// }
30+
// 3 `cat sample-files/*.txt`
31+
// async function caseThree(listOfFiles) {
32+
// for (const file of listOfFiles) {
33+
// const content = await fs.readFile(file, "utf-8");
34+
35+
// console.log(content);
36+
// }
37+
// }
38+

implement-shell-tools/ls/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// fs.readdir
2+
import process from "node:process";
3+
import { promises as fs } from "node:fs";
4+
5+
6+
// `ls -1`
7+
async function showAllFilesInDir(directory) {
8+
const listOfFiles = await fs.readdir(directory);
9+
10+
for (const eachFile of listOfFiles) {
11+
console.log(eachFile);
12+
}
13+
}
14+
15+
// `ls -1 sample-files`
16+
async function showVisibleInSampleFiles() {
17+
const listOfFiles = await fs.readdir('sample-files');
18+
19+
for (const eachFile of listOfFiles) {
20+
if (eachFile[0] !== '.') {
21+
console.log(eachFile);
22+
}
23+
24+
}
25+
}
26+
27+
28+
// `ls -1 -a sample-files`
29+
async function showAllInSampleFiles() {
30+
const listOfFiles = await fs.readdir('sample-files');
31+
32+
for (const eachFile of listOfFiles) {
33+
34+
console.log(eachFile);
35+
36+
}
37+
}
38+
39+
40+
41+
const argv = process.argv.slice(2);
42+
43+
if (argv.includes('-a')) {
44+
await showAllInSampleFiles();
45+
} else if (argv.includes('sample-files')) {
46+
await showVisibleInSampleFiles();
47+
} else {
48+
await showCurrentDir();
49+
}
50+

individual-shell-tools/ls/script-02.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ set -euo pipefail
44

55
# TODO: Write a command which lists all of the files in the directory named child-directory.
66
# The output should be a list of names: helper-1.txt, helper-2.txt, helper-3.txt.
7+
ls child-directory

prep/12.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ def __init__(self, first_name: str, last_name: str):
1010
def get_name(self) -> str:
1111
return f"{self.first_name} {self.last_name}"
1212

13-
1413
class Child(Parent):
1514
def __init__(self, first_name: str, last_name: str):
1615
super().__init__(first_name, last_name)
@@ -27,15 +26,15 @@ def get_full_name(self) -> str:
2726
return f"{self.first_name} {self.last_name}{suffix}"
2827

2928
person1 = Child("Elizaveta", "Alekseeva")
30-
print(person1.get_name())
31-
print(person1.get_full_name())
32-
person1.change_last_name("Tyurina")
33-
print(person1.get_name())
34-
print(person1.get_full_name())
29+
print(person1.get_name()) # prints Elizaveta Alekseeva
30+
print(person1.get_full_name()) # prints Elizaveta Alekseeva
31+
person1.change_last_name("Tyurina") # no print
32+
print(person1.get_name()) # prints Elizaveta Tyurina
33+
print(person1.get_full_name()) # prints Elizaveta Tyurina (née Alekseeva)
3534

3635
person2 = Parent("Elizaveta", "Alekseeva")
37-
print(person2.get_name())
38-
print(person2.get_full_name())
39-
person2.change_last_name("Tyurina")
40-
print(person2.get_name())
41-
print(person2.get_full_name())
36+
print(person2.get_name()) #print Elizaveta Alekseeva
37+
print(person2.get_full_name()) #no full name method
38+
person2.change_last_name("Tyurina") #no change last name method
39+
print(person2.get_name()) # print Elizaveta Alekseeva
40+
print(person2.get_full_name()) #no full name method so err

sprint 5/laptop.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
In the prep, there was an exercise around finding possible laptops for a group of people.
2+
3+
Your exercise is to extend this to actually allocate laptops to the people.
4+
5+
Given these class definitions:
6+
7+
from dataclasses import dataclass
8+
from enum import Enum
9+
from typing import List
10+
11+
class OperatingSystem(Enum):
12+
MACOS = "macOS"
13+
ARCH = "Arch Linux"
14+
UBUNTU = "Ubuntu"
15+
16+
@dataclass(frozen=True)
17+
class Person:
18+
name: str
19+
age: int
20+
# Sorted in order of preference, most preferred is first.
21+
preferred_operating_system: List[OperatingSystem]
22+
23+
24+
@dataclass(frozen=True)
25+
class Laptop:
26+
id: int
27+
manufacturer: str
28+
model: str
29+
screen_size_in_inches: float
30+
operating_system: OperatingSystem
31+
Write a function with this signature:
32+
33+
def allocate_laptops(people: List[Person], laptops: List[Laptop]) -> Dict[Person, Laptop]:
34+
Every person should be allocated exactly one laptop.
35+
36+
If we define "sadness" as the number of places down in someone's ranking the
37+
operating system the ended up with (i.e. if your preferences were [UBUNTU, ARCH, MACOS]
38+
39+
and you were allocated a MACOS machine your sadness would be 2), we want to minimise the total sadness of
40+
all people. If we allocate someone a laptop with an operating system not in their preferred list, treat
41+
them as having a sadness of 100.
42+
43+
def ranking():
44+
45+
46+
def minimize_sandess():
47+
48+
49+
def allocate_laptops():
50+

0 commit comments

Comments
 (0)