This commit is contained in:
2023-09-22 09:41:53 -04:00
parent 0454a29f27
commit 4d75bca7c1
14 changed files with 561 additions and 0 deletions

37
9-foot-traffic/README.md Normal file
View File

@ -0,0 +1,37 @@
Foot Traffic Analysis
=====================
A very prestigious art gallery has contacted you regarding a job. Get to work!
Management wants to figure out how many people visit each room in the gallery, and for how long: this is to help improve the quality of the overall gallery in the future.
Your goal is to write a program that takes a formatted text file that describes the overall gallery's foot-traffic on a minute-to-minute basis. From this data you must compute the average time spent in each room, and how many visitors there were in each room.
###The Input
Each line in the text file represents either a visitor entering or leaving a room. It starts with an integer, representing a visitor's unique identifier. Next on this line is another integer, representing the room's number. Next is a single character, either 'I' (for "In") for this visitor entering the room, or 'O' (for "out") for the visitor leaving the room. Finally, at the end of this line, there is a time-stamp integer: it is an integer representing the minute the event occurred during the day. All of these elements are space-delimited.
You may assume that all input is logically well-formed: for each person entering a room, he or she will always leave it at some point in the future. A visitor will only be in one room at a time.
Note that the order of events in the log are not sorted in any way; it shouldn't matter, as you can solve this problem without sorting given data.
Sample Input:
0 0 I 540
1 0 I 540
0 0 O 560
1 0 O 560
###The Output
For each room that had log data associated with it, print the room number, then print the average length of time visitors have stayed as an integer, and then finally print the total number of visitors in the room. All of this should be on the same line and be space delimited; you may optionally include labels on this text, like in our sample output 1.
Sample Output:
Room 0, 20 minute average visit, 2 visitor(s) total
###Loading the Text File
You'll find a text file `traffic.txt` in this repo. Import this text file and parse it to get the results.
When you are done solving the problem, write your output to another text file and save it in the repo.

View File

192
9-foot-traffic/traffic.txt Normal file
View File

@ -0,0 +1,192 @@
0 5 I 330
1 15 I 1061
2 21 I 319
3 12 I 1067
4 35 I 989
5 20 I 704
6 32 I 558
7 4 I 719
8 21 I 880
9 12 I 964
10 32 I 337
11 28 I 889
12 21 I 817
13 21 I 543
14 9 I 357
15 34 I 927
16 31 I 339
17 37 I 1086
18 15 I 1041
19 4 I 460
20 21 I 344
21 16 I 363
22 1 I 1003
23 15 I 1013
24 30 I 958
25 22 I 354
26 8 I 954
27 1 I 556
28 13 I 760
29 11 I 458
30 3 I 646
31 38 I 505
0 5 O 383
1 15 O 1177
2 21 O 399
3 12 O 1098
4 35 O 1032
5 20 O 794
6 32 O 644
7 4 O 814
8 21 O 985
9 12 O 999
10 32 O 383
11 28 O 975
12 21 O 885
13 21 O 569
14 9 O 452
15 34 O 941
16 31 O 402
17 37 O 1128
18 15 O 1144
19 4 O 491
20 21 O 439
21 16 O 489
22 1 O 1025
23 15 O 1118
24 30 O 979
25 22 O 385
26 8 O 1054
27 1 O 618
28 13 O 881
29 11 O 569
30 3 O 687
31 38 O 531
0 37 I 788
1 12 I 750
2 9 I 397
3 19 I 1175
4 25 I 354
5 38 I 971
6 38 I 438
7 29 I 794
8 3 I 769
9 4 I 763
10 26 I 1067
11 4 I 359
12 14 I 680
13 22 I 387
14 25 I 1043
15 28 I 1030
16 14 I 382
17 4 I 1125
18 6 I 1015
19 28 I 1075
20 15 I 1134
21 21 I 1006
22 23 I 538
23 16 I 313
24 1 I 707
25 19 I 500
26 7 I 1038
27 30 I 331
28 8 I 399
29 15 I 680
30 29 I 801
31 31 I 545
0 37 O 910
1 12 O 822
2 9 O 498
3 19 O 1201
4 25 O 434
5 38 O 1014
6 38 O 507
7 29 O 878
8 3 O 861
9 4 O 775
10 26 O 1088
11 4 O 392
12 14 O 782
13 22 O 423
14 25 O 1111
15 28 O 1138
16 14 O 485
17 4 O 1155
18 6 O 1102
19 28 O 1143
20 15 O 1238
21 21 O 1055
22 23 O 551
23 16 O 416
24 1 O 719
25 19 O 549
26 7 O 1081
27 30 O 406
28 8 O 447
29 15 O 782
30 29 O 900
31 31 O 645
0 3 I 877
1 8 I 313
2 37 I 703
3 23 I 765
4 8 I 1024
5 15 I 968
6 9 I 316
7 34 I 919
8 17 I 1133
9 10 I 486
10 6 I 1018
11 7 I 428
12 16 I 782
13 32 I 541
14 25 I 1130
15 2 I 1065
16 9 I 979
17 20 I 500
18 35 I 529
19 23 I 631
20 25 I 454
21 30 I 641
22 30 I 1043
23 3 I 635
24 28 I 942
25 29 I 913
26 1 I 1198
27 25 I 441
28 9 I 1147
29 35 I 422
30 32 I 337
31 31 I 804
0 3 O 1005
1 8 O 339
2 37 O 736
3 23 O 849
4 8 O 1119
5 15 O 1080
6 9 O 446
7 34 O 980
8 17 O 1245
9 10 O 529
10 6 O 1032
11 7 O 454
12 16 O 861
13 32 O 602
14 25 O 1187
15 2 O 1103
16 9 O 1058
17 20 O 607
18 35 O 594
19 23 O 647
20 25 O 572
21 30 O 675
22 30 O 1162
23 3 O 691
24 28 O 1006
25 29 O 970
26 1 O 1246
27 25 O 467
28 9 O 1160
29 35 O 522
30 32 O 393
31 31 O 910