Added practical swift

This commit is contained in:
Boyan 2025-02-03 20:44:36 +01:00
parent 5fd02a3287
commit cfd0587495
6 changed files with 11574 additions and 0 deletions

View File

@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

View File

@ -0,0 +1,14 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "swift",
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "swift"),
]
)

View File

@ -0,0 +1,8 @@
## Most likely teammates for Software engineering
In other words, parsing a CSV file and finding the most likely teammates for each person in the file.
> [!WARNING]
> Turns out, this is a pretty hard problem. I will have to think about it a bit more.

View File

@ -0,0 +1,86 @@
// https://developer.apple.com/documentation/foundation
import Foundation
// Foundation is a framework that provides a base layer of functionality
// Literally everything in Swift is built on top of Foundation
// Read the file
/**
- Parameters:
- file: The file to be read
- Returns: The contents of the file as a string
*/
func openFile(_ file: String) -> String {
var text = ""
do {
text = try String(contentsOfFile: file, encoding: .utf8)
} catch {
print("Error reading file")
}
return text
}
/**
- Parameters:
- text: The text to be parsed
- Returns: An array of dictoinaries representing the data
*/
func parseCSV(_ text: String) -> [[String: String]] {
var data = [[String: String]]()
let rows = text.components(separatedBy: "\n")
let headers = rows[0].components(separatedBy: ",")
for row in rows[1...] {
let values = row.components(separatedBy: ",")
if values.count == headers.count {
var dict = [String: String]()
for (index, header) in headers.enumerated() {
dict[header] = values[index]
}
data.append(dict)
}
}
return data
}
// The idea is to pair up the people who have the most in common
// We have people's preferences (P1-P5, all optional), and we want to find the most likely teammates
func mostLikelyTeammates(_ people:[[String: String]], _ groupSize: Int) -> [String: Int] {
var teammates = [String: Int]()
for (index, person) in people.enumerated() {
for (index2, person2) in people.enumerated() {
if index != index2 {
var count = 0
for (key, value) in person {
if value == person2[key] {
count += 1
}
}
let key = "\(people[index]["Name"] ?? "John Doe"), \(people[index2]["Name"] ?? "Stan Smith")"
teammates[key] = count
}
}
}
return teammates
}
func exportJSON(_ data: [[String: Any]], to file: String) throws {
let jsonData = try JSONSerialization.data(withJSONObject: data, options: .prettyPrinted)
let fileURL = URL(fileURLWithPath: file)
try jsonData.write(to: fileURL)
print("Successfully written to \(file)")
}
// No duplicates (i.e. John Doe, Stan Smith is the same as Stan Smith, John Doe)
var filteredTeammates = mostLikelyTeammates(parseCSV(openFile("data.csv")), 2).filter { $0.value > 0 }
let sortedTeammates = filteredTeammates.filter { $0.value > 0 }.sorted { $0.value > $1.value }
let jsonExportData = sortedTeammates.map { ["pair": $0.key, "count": $0.value] }
do {
try exportJSON(jsonExportData, to: "mostLikelyTeammates.json")
} catch {
print("Error exporting JSON: \(error)")
}

View File

@ -0,0 +1,104 @@
Name,ID,Email,P1,P2,P3,P4,P5
David Bacinschi,s5498279,D.Bacinschi@student.rug.nl,1,4,13,10,
Ioana Badea,s5216184,I.M.Badea@student.rug.nl,13,10,7,4,1
Tudor Badici,s5546389,T.Badici@student.rug.nl,8,7,1,14,17
Kealan Barry,s5137578,K.Barry@student.rug.nl,1,16,17,7,4
Gabriele Berardi,s4878728,G.Berardi@student.rug.nl,19,8,21,3,23
Sjoerd Blom,s5620856,S.Blom.7@student.rug.nl,16,19,7,23,14
Marco Boasso,s6230725,M.Boasso@student.rug.nl,2,9,7,8,11
Virag Bognár,s5492645,V.Bognar@student.rug.nl,6,15,16,14,7
Matteo Bongiovanni,s5560349,M.Bongiovanni.1@student.rug.nl,6,8,16,17,19
Milan Boomsma,s4810945,M.Boomsma.3@student.rug.nl,1,7,14,19,16
Sven Brüning,s5615135,S.Bruning.1@student.rug.nl,,,,,
Mihnea Burac,s5613418,M.Burac@student.rug.nl,16,17,7,6,8
Jerome Canard,s5603870,j.j.canard@student.rug.nl,1,6,15,14,8
Catalin Cândea,s5539439,D.Candea@student.rug.nl,20,15,6,22,19
Gorkem Çek,s5479185,G.Cek@student.rug.nl,7,19,1,5,11
Alexandru Cernat,s5190584,A.Cernat.1@student.rug.nl,6,13,2,1,10
Guru Chelliah,s5557852,G.Chelliah.Nayagam@student.rug.nl,1,6,13,23,9
Vlad Coicea,s5562465,V.Coicea@student.rug.nl,6,20,16,8,14
Vlad Cotiga Vladescu,s5580781,V.Cotiga-Vladescu@student.rug.nl,19,16,3,23,15
Martine Damstra,s5463092,M.D.Damstra@student.rug.nl,1,20,23,14,6
Guido Danhof,s4421612,G.J.Danhof@student.rug.nl,6,13,9,,
Alp Darmar,s5069262,A.H.Darmar@student.rug.nl,6,24,9,11,12
Robert Dascalu,s5223385,R.C.Dascalu.1@student.rug.nl,6,15,16,20,21
Bo de Vries,s5552796,B.S.de.Vries.1@student.rug.nl,1,9,14,2,20
Youri de Vrije,s5520452,Y.de.Vrije@student.rug.nl,4,10,14,,
Maria Diaz Bover,s5581001,M.Diaz.Bover@student.rug.nl,15,6,13,,
Foppe Dijkstra,s5582202,F.J.Dijkstra.5@student.rug.nl,1,14,4,12,17
Nemo Ding,s5606276,H.Y.Ding@student.rug.nl,6,19,11,7,20
Dalia Dinu,s5465761,D.Dinu@student.rug.nl,6,15,16,14,7
Richard Even,s5226147,R.W.Even@student.rug.nl,8,6,1,16,
Andrei Foitos,s5233836,A.Foitos@student.rug.nl,10,11,6,3,12
Adam Fomin,s5559189,A.Fomin@student.rug.nl,,,,,
Sorana Gavril,s5552672,S.Gavril@student.rug.nl,11,7,8,14,13
Roman Gazarek,s5599717,R.Gazarek@student.rug.nl,16,1,6,15,17
Mostafa Ghorbani,s5621321,M.Ghorbani.1@student.rug.nl,6,15,1,7,19
Andries Gommers,s5517222,A.H.Gommers@student.rug.nl,1,20,16,4,14
Celia Gutiérrez Otero,s5709377,C.Gutierrez.Otero@student.rug.nl,15,20,16,21,25
Belen Hidalgo Odria,s5562821,B.Hidalgo.Odria@student.rug.nl,6,15,16,14,7
Jelger Hulshoff,s5462975,J.H.Hulshoff@student.rug.nl,19,20,8,17,6
Sabina Iliuta,s5617618,B.Iliuta@student.rug.nl,7,1,8,14,4
Ana-Maria Izbas,s5575974,A.Izbas@student.rug.nl,11,6,13,7,8
Ola Janikowska,s5539552,A.Janikowska@student.rug.nl,4,13,8,6,11
Mechy Janssen,s4314115,M.C.S.Janssen@student.rug.nl,22,14,17,3,16
Berk Kara,s5558727,J.B.Kara@student.rug.nl,7,19,1,5,11
Hristo Karagyozov,s4796683,H.Karagyozov@student.rug.nl,3,19,12,14,11
Boyan Karakostov,s5230837,B.Karakostov@student.rug.nl,3,23,16,5,19
Alex Kardash,s5541883,A.Kardash@student.rug.nl,10,2,13,4,7
Ken Kasai,s5498856,K.Kasai@student.rug.nl,19,20,14,17,
Guneet Khalsa,s6212905,G.S.Khalsa@student.rug.nl,19,20,16,6,1
Ata Kircadag,s5573289,A.Kircadag@student.rug.nl,20,19,7,1,16
Corné Koppies,s6069193,C.J.Koppies@student.rug.nl,,,,oh,
Andrei Lentu,s5508223,A.Lentu@student.rug.nl,7,1,15,2,4
Nathan Lesman,s5703948,N.Lesman@student.rug.nl,8,5,,21,
Iustin Lungu,s4787641,I.Lungu.2@student.rug.nl,1,12,16,24,15
Sergiu Macra,s5524032,S.Macra@student.rug.nl,4,16,9,14,1
Alexandros Manis,s5550432,A.Manis@student.rug.nl,20,1,7,15,16
Kieran McGeehan,s5624126,K.A.McGeehan@student.rug.nl,13,22,14,4,21
Joseph Micallef,s5532388,J.Micallef@student.rug.nl,8,6,15,14,3
Florian Molanus,s5596327,F.Molanus@student.rug.nl,4,10,7,14,17
Berke Musellim,s4773179,B.Musellim@student.rug.nl,1,2,6,11,19
Sepehr Nikshohrat,s5567076,S.Nikshohrat@student.rug.nl,1,17,6,23,19
Sarlote Odzina,s5584752,S.L.Odzina@student.rug.nl,8,7,6,9,16
Jort Oosterveld,s5545781,J.J.Oosterveld@student.rug.nl,7,6,19,14,16
Wilmer Oostindjer,s5602475,W.B.Oostindjer@student.rug.nl,19,20,3,14,8
Arya Mira Özdemir,s5065038,D.O.Ozdemir@student.rug.nl,6,1,4,10,15
Mardo Parlayan,s5578566,M.Parlayan@student.rug.nl,,,,,
Teodor Patache,s4787137,P.T.Patache@student.rug.nl,21,19,24,23,10
Thijs Periam,s4764919,T.E.W.Periam@student.rug.nl,6,18,15,23,16
Michal Petruf,s4715160,M.Petruf@student.rug.nl,16,22,19,21,8
Elena Pîrjolea,s5550084,E.Pirjolea@student.rug.nl,1,6,7,15,10
Eduard Pliuta,s5161908,E.Pliuta@student.rug.nl,4,6,10,15,7
Alexandra Popescu,s5177995,A.Popescu.13@student.rug.nl,6,13,4,1,16
Luca Popescu,s4741544,L.Popescu.1@student.rug.nl,,,,,
Florin Raceanu,s5575982,F.Raceanu@student.rug.nl,6,7,16,15,11
Miguel Reyes Suarez,s5497604,M.A.Reyes.Suarez@student.rug.nl,6,15,16,14,7
Jelte Rijks,s5638437,J.Rijks@student.rug.nl,19,20,6,7,1
Menno Schipper,s4795369,M.Schipper.6@student.rug.nl,20,19,14,10,7
Jan Seton,s4762029,J.M.Seton.1@student.rug.nl,15,5,23,18,16
Majd Shuqeir,s4903838,M.Shuqeir@student.rug.nl,6,7,11,1,23
Vitalii Sikorski,s5622360,V.Sikorski@student.rug.nl,,,,,
Arend Spijker,s5619734,A.Spijker@student.rug.nl,1,4,10,14,16
Jelmer Spoor,s5466598,J.S.Spoor@student.rug.nl,19,20,6,8,23
Teodora Stanca,s5468124,I.Stanca@student.rug.nl,8,7,1,14,17
Valentin Stefanescu,s5510341,V.Stefanescu@student.rug.nl,8,7,1,15,6
Gijs-Izaac Stevens,s5565421,G.O.Stevens@student.rug.nl,,,,,
Herre Torensma,s5629969,H.D.R.Torensma@student.rug.nl,14,19,1,4,17
Tudor Trandafir,s5079063,T.Trandafir@student.rug.nl,20,21,,,
Georgios Tsitlakidis,s6222196,G.Tsitlakidis@student.rug.nl,14,12,20,17,19
Ioannis Tziantopoulos,s6222218,I.Tziantopoulos@student.rug.nl,13,6,9,3,8
Cindy Um,s6149707,C.I.Um@student.rug.nl,,,,,
Alexandru Vallimarescu,s5574552,A.Vallimarescu@student.rug.nl,20,19,16,,7
Tjalle-Durk van der Eems,s5616816,T.van.der.Eems@student.rug.nl,16,23,18,14,7
Mark van der Veen,s5054397,M.van.der.Veen.38@student.rug.nl,4,1,6,19,14
Pepijn van der Zee,s5496284,P.J.van.der.Zee@student.rug.nl,20,19,16,4,1
Diko van Rosmalen,s5577896,D.van.Rosmalen@student.rug.nl,7,6,19,14,16
Vlad Vasile,s5217687,V.Vasile.1@student.rug.nl,7,10,2,16,19
Wietse Verstraete,s3752135,W.Verstraete@student.rug.nl,,,,,
Thomas Vlonk,s5606985,T.Vlonk@student.rug.nl,6,1,16,8,17
Maria Voicu,s5585635,M.Voicu.2@student.rug.nl,11,7,8,14,13
Bianca Vraci,s5532337,B.Vraci@student.rug.nl,11,6,8,15,14
Oscar Weimann,s5634555,O.L.Weimann@student.rug.nl,16,6,19,15,23
Ferre Woltjer,s5463130,F.K.Woltjer@student.rug.nl,4,10,14,,
Sophie Schoerner,s4136594,s.schorner@student.rug.nl,6,5,,,
1 Name ID Email P1 P2 P3 P4 P5
2 David Bacinschi s5498279 D.Bacinschi@student.rug.nl 1 4 13 10
3 Ioana Badea s5216184 I.M.Badea@student.rug.nl 13 10 7 4 1
4 Tudor Badici s5546389 T.Badici@student.rug.nl 8 7 1 14 17
5 Kealan Barry s5137578 K.Barry@student.rug.nl 1 16 17 7 4
6 Gabriele Berardi s4878728 G.Berardi@student.rug.nl 19 8 21 3 23
7 Sjoerd Blom s5620856 S.Blom.7@student.rug.nl 16 19 7 23 14
8 Marco Boasso s6230725 M.Boasso@student.rug.nl 2 9 7 8 11
9 Virag Bognár s5492645 V.Bognar@student.rug.nl 6 15 16 14 7
10 Matteo Bongiovanni s5560349 M.Bongiovanni.1@student.rug.nl 6 8 16 17 19
11 Milan Boomsma s4810945 M.Boomsma.3@student.rug.nl 1 7 14 19 16
12 Sven Brüning s5615135 S.Bruning.1@student.rug.nl
13 Mihnea Burac s5613418 M.Burac@student.rug.nl 16 17 7 6 8
14 Jerome Canard s5603870 j.j.canard@student.rug.nl 1 6 15 14 8
15 Catalin Cândea s5539439 D.Candea@student.rug.nl 20 15 6 22 19
16 Gorkem Çek s5479185 G.Cek@student.rug.nl 7 19 1 5 11
17 Alexandru Cernat s5190584 A.Cernat.1@student.rug.nl 6 13 2 1 10
18 Guru Chelliah s5557852 G.Chelliah.Nayagam@student.rug.nl 1 6 13 23 9
19 Vlad Coicea s5562465 V.Coicea@student.rug.nl 6 20 16 8 14
20 Vlad Cotiga Vladescu s5580781 V.Cotiga-Vladescu@student.rug.nl 19 16 3 23 15
21 Martine Damstra s5463092 M.D.Damstra@student.rug.nl 1 20 23 14 6
22 Guido Danhof s4421612 G.J.Danhof@student.rug.nl 6 13 9
23 Alp Darmar s5069262 A.H.Darmar@student.rug.nl 6 24 9 11 12
24 Robert Dascalu s5223385 R.C.Dascalu.1@student.rug.nl 6 15 16 20 21
25 Bo de Vries s5552796 B.S.de.Vries.1@student.rug.nl 1 9 14 2 20
26 Youri de Vrije s5520452 Y.de.Vrije@student.rug.nl 4 10 14
27 Maria Diaz Bover s5581001 M.Diaz.Bover@student.rug.nl 15 6 13
28 Foppe Dijkstra s5582202 F.J.Dijkstra.5@student.rug.nl 1 14 4 12 17
29 Nemo Ding s5606276 H.Y.Ding@student.rug.nl 6 19 11 7 20
30 Dalia Dinu s5465761 D.Dinu@student.rug.nl 6 15 16 14 7
31 Richard Even s5226147 R.W.Even@student.rug.nl 8 6 1 16
32 Andrei Foitos s5233836 A.Foitos@student.rug.nl 10 11 6 3 12
33 Adam Fomin s5559189 A.Fomin@student.rug.nl
34 Sorana Gavril s5552672 S.Gavril@student.rug.nl 11 7 8 14 13
35 Roman Gazarek s5599717 R.Gazarek@student.rug.nl 16 1 6 15 17
36 Mostafa Ghorbani s5621321 M.Ghorbani.1@student.rug.nl 6 15 1 7 19
37 Andries Gommers s5517222 A.H.Gommers@student.rug.nl 1 20 16 4 14
38 Celia Gutiérrez Otero s5709377 C.Gutierrez.Otero@student.rug.nl 15 20 16 21 25
39 Belen Hidalgo Odria s5562821 B.Hidalgo.Odria@student.rug.nl 6 15 16 14 7
40 Jelger Hulshoff s5462975 J.H.Hulshoff@student.rug.nl 19 20 8 17 6
41 Sabina Iliuta s5617618 B.Iliuta@student.rug.nl 7 1 8 14 4
42 Ana-Maria Izbas s5575974 A.Izbas@student.rug.nl 11 6 13 7 8
43 Ola Janikowska s5539552 A.Janikowska@student.rug.nl 4 13 8 6 11
44 Mechy Janssen s4314115 M.C.S.Janssen@student.rug.nl 22 14 17 3 16
45 Berk Kara s5558727 J.B.Kara@student.rug.nl 7 19 1 5 11
46 Hristo Karagyozov s4796683 H.Karagyozov@student.rug.nl 3 19 12 14 11
47 Boyan Karakostov s5230837 B.Karakostov@student.rug.nl 3 23 16 5 19
48 Alex Kardash s5541883 A.Kardash@student.rug.nl 10 2 13 4 7
49 Ken Kasai s5498856 K.Kasai@student.rug.nl 19 20 14 17
50 Guneet Khalsa s6212905 G.S.Khalsa@student.rug.nl 19 20 16 6 1
51 Ata Kircadag s5573289 A.Kircadag@student.rug.nl 20 19 7 1 16
52 Corné Koppies s6069193 C.J.Koppies@student.rug.nl oh
53 Andrei Lentu s5508223 A.Lentu@student.rug.nl 7 1 15 2 4
54 Nathan Lesman s5703948 N.Lesman@student.rug.nl 8 5 21
55 Iustin Lungu s4787641 I.Lungu.2@student.rug.nl 1 12 16 24 15
56 Sergiu Macra s5524032 S.Macra@student.rug.nl 4 16 9 14 1
57 Alexandros Manis s5550432 A.Manis@student.rug.nl 20 1 7 15 16
58 Kieran McGeehan s5624126 K.A.McGeehan@student.rug.nl 13 22 14 4 21
59 Joseph Micallef s5532388 J.Micallef@student.rug.nl 8 6 15 14 3
60 Florian Molanus s5596327 F.Molanus@student.rug.nl 4 10 7 14 17
61 Berke Musellim s4773179 B.Musellim@student.rug.nl 1 2 6 11 19
62 Sepehr Nikshohrat s5567076 S.Nikshohrat@student.rug.nl 1 17 6 23 19
63 Sarlote Odzina s5584752 S.L.Odzina@student.rug.nl 8 7 6 9 16
64 Jort Oosterveld s5545781 J.J.Oosterveld@student.rug.nl 7 6 19 14 16
65 Wilmer Oostindjer s5602475 W.B.Oostindjer@student.rug.nl 19 20 3 14 8
66 Arya Mira Özdemir s5065038 D.O.Ozdemir@student.rug.nl 6 1 4 10 15
67 Mardo Parlayan s5578566 M.Parlayan@student.rug.nl
68 Teodor Patache s4787137 P.T.Patache@student.rug.nl 21 19 24 23 10
69 Thijs Periam s4764919 T.E.W.Periam@student.rug.nl 6 18 15 23 16
70 Michal Petruf s4715160 M.Petruf@student.rug.nl 16 22 19 21 8
71 Elena Pîrjolea s5550084 E.Pirjolea@student.rug.nl 1 6 7 15 10
72 Eduard Pliuta s5161908 E.Pliuta@student.rug.nl 4 6 10 15 7
73 Alexandra Popescu s5177995 A.Popescu.13@student.rug.nl 6 13 4 1 16
74 Luca Popescu s4741544 L.Popescu.1@student.rug.nl
75 Florin Raceanu s5575982 F.Raceanu@student.rug.nl 6 7 16 15 11
76 Miguel Reyes Suarez s5497604 M.A.Reyes.Suarez@student.rug.nl 6 15 16 14 7
77 Jelte Rijks s5638437 J.Rijks@student.rug.nl 19 20 6 7 1
78 Menno Schipper s4795369 M.Schipper.6@student.rug.nl 20 19 14 10 7
79 Jan Seton s4762029 J.M.Seton.1@student.rug.nl 15 5 23 18 16
80 Majd Shuqeir s4903838 M.Shuqeir@student.rug.nl 6 7 11 1 23
81 Vitalii Sikorski s5622360 V.Sikorski@student.rug.nl
82 Arend Spijker s5619734 A.Spijker@student.rug.nl 1 4 10 14 16
83 Jelmer Spoor s5466598 J.S.Spoor@student.rug.nl 19 20 6 8 23
84 Teodora Stanca s5468124 I.Stanca@student.rug.nl 8 7 1 14 17
85 Valentin Stefanescu s5510341 V.Stefanescu@student.rug.nl 8 7 1 15 6
86 Gijs-Izaac Stevens s5565421 G.O.Stevens@student.rug.nl
87 Herre Torensma s5629969 H.D.R.Torensma@student.rug.nl 14 19 1 4 17
88 Tudor Trandafir s5079063 T.Trandafir@student.rug.nl 20 21
89 Georgios Tsitlakidis s6222196 G.Tsitlakidis@student.rug.nl 14 12 20 17 19
90 Ioannis Tziantopoulos s6222218 I.Tziantopoulos@student.rug.nl 13 6 9 3 8
91 Cindy Um s6149707 C.I.Um@student.rug.nl
92 Alexandru Vallimarescu s5574552 A.Vallimarescu@student.rug.nl 20 19 16 7
93 Tjalle-Durk van der Eems s5616816 T.van.der.Eems@student.rug.nl 16 23 18 14 7
94 Mark van der Veen s5054397 M.van.der.Veen.38@student.rug.nl 4 1 6 19 14
95 Pepijn van der Zee s5496284 P.J.van.der.Zee@student.rug.nl 20 19 16 4 1
96 Diko van Rosmalen s5577896 D.van.Rosmalen@student.rug.nl 7 6 19 14 16
97 Vlad Vasile s5217687 V.Vasile.1@student.rug.nl 7 10 2 16 19
98 Wietse Verstraete s3752135 W.Verstraete@student.rug.nl
99 Thomas Vlonk s5606985 T.Vlonk@student.rug.nl 6 1 16 8 17
100 Maria Voicu s5585635 M.Voicu.2@student.rug.nl 11 7 8 14 13
101 Bianca Vraci s5532337 B.Vraci@student.rug.nl 11 6 8 15 14
102 Oscar Weimann s5634555 O.L.Weimann@student.rug.nl 16 6 19 15 23
103 Ferre Woltjer s5463130 F.K.Woltjer@student.rug.nl 4 10 14
104 Sophie Schoerner s4136594 s.schorner@student.rug.nl 6 5

File diff suppressed because it is too large Load Diff