Skip to content

Commit 8a0e07e

Browse files
committed
CS50 January 2024
- week 07 problem set
1 parent b0338f8 commit 8a0e07e

36 files changed

+704
-0
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The THIEF is: Bruce
2+
The city the thief ESCAPED TO: New York City
3+
The ACCOMPLICE is: Robin
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
-- Keep a log of any SQL queries you execute as you solve the mystery.
2+
-- Use: cat log.sql | sqlite3 fiftyville.db > output.txt
3+
4+
-- Check reports for when and where the crime happened.
5+
SELECT *
6+
FROM crime_scene_reports
7+
WHERE street = "Humphrey Street"
8+
AND year = 2021
9+
AND month = 7
10+
AND day = 28;
11+
12+
-- Theft happened at 10:15 a.m.
13+
-- Above report mentions three witness interview transcripts mentioning bakery.
14+
SELECT *
15+
FROM interviews
16+
WHERE year = 2021
17+
AND month = 7
18+
AND day = 28
19+
AND transcript LIKE "%bakery%";
20+
21+
-- Ruth says within ten minutes of theft, thief drove from bakery parking lot.
22+
-- ** LEAD 1 ** Check bakery security camera footage of that time.
23+
-- Eugene says thief withdrew money from Leggett Street ATM earlier in morning.
24+
-- ** LEAD 2 ** Check ATM transactions that morning.
25+
-- Raymond says thief talked to someone on the phone less than 1 minute, told to
26+
-- buy a plane ticket for earliest flight out of Fiftyville the next day.
27+
-- ** LEAD 3 ** Check flights the next day.
28+
-- ** LEAD 4 ** Check phone calls that are less than 1 minute (60 seconds).
29+
-- Emma says someone talked on the phone for half an hour.
30+
-- This is not relevant to the case.
31+
32+
-- ** LEAD 1 ** check bakery security footage, 2021-7-28 10:15-10:25 a.m.
33+
SELECT *
34+
FROM bakery_security_logs
35+
WHERE year = 2021
36+
AND month = 7
37+
AND day = 28
38+
AND hour = 10
39+
AND minute >= 15
40+
AND minute <= 25;
41+
42+
-- This gives us 8 possible license plates.
43+
-- ** LEAD 5 ** Check license plates.
44+
45+
-- ** LEAD 2 ** check ATM transactions on Leggett Street, 2021-7-28.
46+
SELECT *
47+
FROM atm_transactions
48+
WHERE year = 2021
49+
AND month = 7
50+
AND day = 28
51+
AND atm_location = "Leggett Street"
52+
AND transaction_type = "withdraw";
53+
54+
-- This gives us 8 possible account numbers.
55+
-- ** LEAD 6 ** Check bank account numbers.
56+
57+
-- ** LEAD 3 ** check earliest flight out of Fiftyville on 2021-7-29.
58+
SELECT *
59+
FROM flights
60+
JOIN airports
61+
ON airports.id = flights.origin_airport_id
62+
WHERE airports.city = "Fiftyville"
63+
AND flights.year = 2021
64+
AND flights.month = 7
65+
AND flights.day = 29
66+
ORDER BY flights.hour
67+
LIMIT 1;
68+
69+
-- The thief escaped to city with destination_airport_id = 4.
70+
SELECT city
71+
FROM airports
72+
WHERE id = 4;
73+
74+
-- That's New York City. SECOND QUESTION ANSWERED!
75+
-- ** LEAD 7 ** check passengers for that flight.
76+
77+
-- ** LEAD 4 ** Check phone records 2021-7-28, for less than 60 seconds call.
78+
SELECT *
79+
FROM phone_calls
80+
WHERE year = 2021
81+
AND month = 7
82+
AND day = 28
83+
AND duration <= 60;
84+
85+
-- This gives 10 phone calls.
86+
-- ** LEAD 8 ** check the phone numbers.
87+
88+
-- ** LEAD 5** The 8 license plates can be used on the people table.
89+
-- ** LEAD 6** The 8 bank accounts have a person_id field referencing people.id
90+
-- ** LEAD 7** Passengers have passport_number which can be used on people table
91+
-- ** LEAD 8** The phone numbers can be used on the people table.
92+
93+
-- ** LEAD 5 ** One of these 8 people is the thief.
94+
SELECT *
95+
FROM people
96+
WHERE license_plate = "5P2BI95" OR license_plate = "94KL13X"
97+
OR license_plate = "6P58WS2" OR license_plate = "4328GD8"
98+
OR license_plate = "G412CB7" OR license_plate = "L93JTIZ"
99+
OR license_plate = "322W7JE" OR license_plate = "0NTHK55";
100+
101+
-- ** LEAD 6 ** One of these 8 people is the thief.
102+
SELECT *
103+
FROM people
104+
JOIN bank_accounts
105+
ON bank_accounts.person_id = people.id
106+
WHERE bank_accounts.account_number = 28500762
107+
OR bank_accounts.account_number = 28296815
108+
OR bank_accounts.account_number = 76054385
109+
OR bank_accounts.account_number = 49610011
110+
OR bank_accounts.account_number = 16153065
111+
OR bank_accounts.account_number = 25506511
112+
OR bank_accounts.account_number = 81061156
113+
OR bank_accounts.account_number = 26013199;
114+
115+
-- ** LEAD 7 ** One of these 8 people is the thief.
116+
SELECT *
117+
FROM passengers
118+
JOIN people
119+
ON passengers.passport_number = people.passport_number
120+
WHERE passengers.flight_id = 36;
121+
122+
-- ** LEAD 8 (callers) ** One of these is the thief.
123+
SELECT *
124+
FROM people
125+
WHERE phone_number = "(130) 555-0289" OR phone_number = "(499) 555-9472"
126+
OR phone_number = "(367) 555-5533" OR phone_number = "(609) 555-5876"
127+
OR phone_number = "(499) 555-9472" OR phone_number = "(286) 555-6063"
128+
OR phone_number = "(770) 555-1861" OR phone_number = "(031) 555-6622"
129+
OR phone_number = "(826) 555-1652" OR phone_number = "(338) 555-6650";
130+
131+
-- ** LEAD 8 (receivers) ** One of these is the accomplice.
132+
SELECT *
133+
FROM people
134+
WHERE phone_number = "(996) 555-8899" OR phone_number = "(892) 555-8872"
135+
OR phone_number = "(375) 555-8161" OR phone_number = "(389) 555-5198"
136+
OR phone_number = "(717) 555-1342" OR phone_number = "(676) 555-6554"
137+
OR phone_number = "(725) 555-3243" OR phone_number = "(910) 555-3251"
138+
OR phone_number = "(066) 555-9701" OR phone_number = "(704) 555-2131";
139+
140+
-- Looks like Bruce is the thief, and he called Robin on the phone.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
+-----+------+-------+-----+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2+
| id | year | month | day | street | description |
3+
+-----+------+-------+-----+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4+
| 295 | 2021 | 7 | 28 | Humphrey Street | Theft of the CS50 duck took place at 10:15am at the Humphrey Street bakery. Interviews were conducted today with three witnesses who were present at the time – each of their interview transcripts mentions the bakery. |
5+
| 297 | 2021 | 7 | 28 | Humphrey Street | Littering took place at 16:36. No known witnesses. |
6+
+-----+------+-------+-----+-----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
7+
+-----+---------+------+-------+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
8+
| id | name | year | month | day | transcript |
9+
+-----+---------+------+-------+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
10+
| 161 | Ruth | 2021 | 7 | 28 | Sometime within ten minutes of the theft, I saw the thief get into a car in the bakery parking lot and drive away. If you have security footage from the bakery parking lot, you might want to look for cars that left the parking lot in that time frame. |
11+
| 162 | Eugene | 2021 | 7 | 28 | I don't know the thief's name, but it was someone I recognized. Earlier this morning, before I arrived at Emma's bakery, I was walking by the ATM on Leggett Street and saw the thief there withdrawing some money. |
12+
| 163 | Raymond | 2021 | 7 | 28 | As the thief was leaving the bakery, they called someone who talked to them for less than a minute. In the call, I heard the thief say that they were planning to take the earliest flight out of Fiftyville tomorrow. The thief then asked the person on the other end of the phone to purchase the flight ticket. |
13+
| 193 | Emma | 2021 | 7 | 28 | I'm the bakery owner, and someone came in, suspiciously whispering into a phone for about half an hour. They never bought anything. |
14+
+-----+---------+------+-------+-----+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
15+
+-----+------+-------+-----+------+--------+----------+---------------+
16+
| id | year | month | day | hour | minute | activity | license_plate |
17+
+-----+------+-------+-----+------+--------+----------+---------------+
18+
| 260 | 2021 | 7 | 28 | 10 | 16 | exit | 5P2BI95 |
19+
| 261 | 2021 | 7 | 28 | 10 | 18 | exit | 94KL13X |
20+
| 262 | 2021 | 7 | 28 | 10 | 18 | exit | 6P58WS2 |
21+
| 263 | 2021 | 7 | 28 | 10 | 19 | exit | 4328GD8 |
22+
| 264 | 2021 | 7 | 28 | 10 | 20 | exit | G412CB7 |
23+
| 265 | 2021 | 7 | 28 | 10 | 21 | exit | L93JTIZ |
24+
| 266 | 2021 | 7 | 28 | 10 | 23 | exit | 322W7JE |
25+
| 267 | 2021 | 7 | 28 | 10 | 23 | exit | 0NTHK55 |
26+
+-----+------+-------+-----+------+--------+----------+---------------+
27+
+-----+----------------+------+-------+-----+----------------+------------------+--------+
28+
| id | account_number | year | month | day | atm_location | transaction_type | amount |
29+
+-----+----------------+------+-------+-----+----------------+------------------+--------+
30+
| 246 | 28500762 | 2021 | 7 | 28 | Leggett Street | withdraw | 48 |
31+
| 264 | 28296815 | 2021 | 7 | 28 | Leggett Street | withdraw | 20 |
32+
| 266 | 76054385 | 2021 | 7 | 28 | Leggett Street | withdraw | 60 |
33+
| 267 | 49610011 | 2021 | 7 | 28 | Leggett Street | withdraw | 50 |
34+
| 269 | 16153065 | 2021 | 7 | 28 | Leggett Street | withdraw | 80 |
35+
| 288 | 25506511 | 2021 | 7 | 28 | Leggett Street | withdraw | 20 |
36+
| 313 | 81061156 | 2021 | 7 | 28 | Leggett Street | withdraw | 30 |
37+
| 336 | 26013199 | 2021 | 7 | 28 | Leggett Street | withdraw | 35 |
38+
+-----+----------------+------+-------+-----+----------------+------------------+--------+
39+
+----+-------------------+------------------------+------+-------+-----+------+--------+----+--------------+-----------------------------+------------+
40+
| id | origin_airport_id | destination_airport_id | year | month | day | hour | minute | id | abbreviation | full_name | city |
41+
+----+-------------------+------------------------+------+-------+-----+------+--------+----+--------------+-----------------------------+------------+
42+
| 36 | 8 | 4 | 2021 | 7 | 29 | 8 | 20 | 8 | CSF | Fiftyville Regional Airport | Fiftyville |
43+
+----+-------------------+------------------------+------+-------+-----+------+--------+----+--------------+-----------------------------+------------+
44+
+---------------+
45+
| city |
46+
+---------------+
47+
| New York City |
48+
+---------------+
49+
+-----+----------------+----------------+------+-------+-----+----------+
50+
| id | caller | receiver | year | month | day | duration |
51+
+-----+----------------+----------------+------+-------+-----+----------+
52+
| 221 | (130) 555-0289 | (996) 555-8899 | 2021 | 7 | 28 | 51 |
53+
| 224 | (499) 555-9472 | (892) 555-8872 | 2021 | 7 | 28 | 36 |
54+
| 233 | (367) 555-5533 | (375) 555-8161 | 2021 | 7 | 28 | 45 |
55+
| 234 | (609) 555-5876 | (389) 555-5198 | 2021 | 7 | 28 | 60 |
56+
| 251 | (499) 555-9472 | (717) 555-1342 | 2021 | 7 | 28 | 50 |
57+
| 254 | (286) 555-6063 | (676) 555-6554 | 2021 | 7 | 28 | 43 |
58+
| 255 | (770) 555-1861 | (725) 555-3243 | 2021 | 7 | 28 | 49 |
59+
| 261 | (031) 555-6622 | (910) 555-3251 | 2021 | 7 | 28 | 38 |
60+
| 279 | (826) 555-1652 | (066) 555-9701 | 2021 | 7 | 28 | 55 |
61+
| 281 | (338) 555-6650 | (704) 555-2131 | 2021 | 7 | 28 | 54 |
62+
+-----+----------------+----------------+------+-------+-----+----------+
63+
+--------+---------+----------------+-----------------+---------------+
64+
| id | name | phone_number | passport_number | license_plate |
65+
+--------+---------+----------------+-----------------+---------------+
66+
| 221103 | Vanessa | (725) 555-4692 | 2963008352 | 5P2BI95 |
67+
| 243696 | Barry | (301) 555-4174 | 7526138472 | 6P58WS2 |
68+
| 396669 | Iman | (829) 555-5269 | 7049073643 | L93JTIZ |
69+
| 398010 | Sofia | (130) 555-0289 | 1695452385 | G412CB7 |
70+
| 467400 | Luca | (389) 555-5198 | 8496433585 | 4328GD8 |
71+
| 514354 | Diana | (770) 555-1861 | 3592750733 | 322W7JE |
72+
| 560886 | Kelsey | (499) 555-9472 | 8294398571 | 0NTHK55 |
73+
| 686048 | Bruce | (367) 555-5533 | 5773159633 | 94KL13X |
74+
+--------+---------+----------------+-----------------+---------------+
75+
+--------+---------+----------------+-----------------+---------------+----------------+-----------+---------------+
76+
| id | name | phone_number | passport_number | license_plate | account_number | person_id | creation_year |
77+
+--------+---------+----------------+-----------------+---------------+----------------+-----------+---------------+
78+
| 686048 | Bruce | (367) 555-5533 | 5773159633 | 94KL13X | 49610011 | 686048 | 2010 |
79+
| 514354 | Diana | (770) 555-1861 | 3592750733 | 322W7JE | 26013199 | 514354 | 2012 |
80+
| 458378 | Brooke | (122) 555-4581 | 4408372428 | QX4YZN3 | 16153065 | 458378 | 2012 |
81+
| 395717 | Kenny | (826) 555-1652 | 9878712108 | 30G67EN | 28296815 | 395717 | 2014 |
82+
| 396669 | Iman | (829) 555-5269 | 7049073643 | L93JTIZ | 25506511 | 396669 | 2014 |
83+
| 467400 | Luca | (389) 555-5198 | 8496433585 | 4328GD8 | 28500762 | 467400 | 2014 |
84+
| 449774 | Taylor | (286) 555-6063 | 1988161715 | 1106N58 | 76054385 | 449774 | 2015 |
85+
| 438727 | Benista | (338) 555-6650 | 9586786673 | 8X428L0 | 81061156 | 438727 | 2018 |
86+
+--------+---------+----------------+-----------------+---------------+----------------+-----------+---------------+
87+
+-----------+-----------------+------+--------+--------+----------------+-----------------+---------------+
88+
| flight_id | passport_number | seat | id | name | phone_number | passport_number | license_plate |
89+
+-----------+-----------------+------+--------+--------+----------------+-----------------+---------------+
90+
| 36 | 7214083635 | 2A | 953679 | Doris | (066) 555-9701 | 7214083635 | M51FA04 |
91+
| 36 | 1695452385 | 3B | 398010 | Sofia | (130) 555-0289 | 1695452385 | G412CB7 |
92+
| 36 | 5773159633 | 4A | 686048 | Bruce | (367) 555-5533 | 5773159633 | 94KL13X |
93+
| 36 | 1540955065 | 5C | 651714 | Edward | (328) 555-1152 | 1540955065 | 130LD9Z |
94+
| 36 | 8294398571 | 6C | 560886 | Kelsey | (499) 555-9472 | 8294398571 | 0NTHK55 |
95+
| 36 | 1988161715 | 6D | 449774 | Taylor | (286) 555-6063 | 1988161715 | 1106N58 |
96+
| 36 | 9878712108 | 7A | 395717 | Kenny | (826) 555-1652 | 9878712108 | 30G67EN |
97+
| 36 | 8496433585 | 7B | 467400 | Luca | (389) 555-5198 | 8496433585 | 4328GD8 |
98+
+-----------+-----------------+------+--------+--------+----------------+-----------------+---------------+
99+
+--------+---------+----------------+-----------------+---------------+
100+
| id | name | phone_number | passport_number | license_plate |
101+
+--------+---------+----------------+-----------------+---------------+
102+
| 395717 | Kenny | (826) 555-1652 | 9878712108 | 30G67EN |
103+
| 398010 | Sofia | (130) 555-0289 | 1695452385 | G412CB7 |
104+
| 438727 | Benista | (338) 555-6650 | 9586786673 | 8X428L0 |
105+
| 449774 | Taylor | (286) 555-6063 | 1988161715 | 1106N58 |
106+
| 514354 | Diana | (770) 555-1861 | 3592750733 | 322W7JE |
107+
| 560886 | Kelsey | (499) 555-9472 | 8294398571 | 0NTHK55 |
108+
| 561160 | Kathryn | (609) 555-5876 | 6121106406 | 4ZY7I8T |
109+
| 686048 | Bruce | (367) 555-5533 | 5773159633 | 94KL13X |
110+
| 907148 | Carina | (031) 555-6622 | 9628244268 | Q12B3Z3 |
111+
+--------+---------+----------------+-----------------+---------------+
112+
+--------+------------+----------------+-----------------+---------------+
113+
| id | name | phone_number | passport_number | license_plate |
114+
+--------+------------+----------------+-----------------+---------------+
115+
| 250277 | James | (676) 555-6554 | 2438825627 | Q13SVG6 |
116+
| 251693 | Larry | (892) 555-8872 | 2312901747 | O268ZZ0 |
117+
| 467400 | Luca | (389) 555-5198 | 8496433585 | 4328GD8 |
118+
| 484375 | Anna | (704) 555-2131 | | |
119+
| 567218 | Jack | (996) 555-8899 | 9029462229 | 52R0Y8U |
120+
| 626361 | Melissa | (717) 555-1342 | 7834357192 | |
121+
| 712712 | Jacqueline | (910) 555-3251 | | 43V0R5D |
122+
| 847116 | Philip | (725) 555-3243 | 3391710505 | GW362R6 |
123+
| 864400 | Robin | (375) 555-8161 | | 4V16VO0 |
124+
| 953679 | Doris | (066) 555-9701 | 7214083635 | M51FA04 |
125+
+--------+------------+----------------+-----------------+---------------+
26.8 KB
Loading

0 commit comments

Comments
 (0)