Skip to content

Commit a01a614

Browse files
committed
Added - ProblemSet7/Fiftyville
1 parent 63980a8 commit a01a614

File tree

2 files changed

+128
-0
lines changed

2 files changed

+128
-0
lines changed
Lines changed: 3 additions & 0 deletions
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.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
https://cs50.harvard.edu/x/2023/psets/7/fiftyville/
3+
*/
4+
5+
-- We know the theft took place on Humphrey St., on July 28 2021.
6+
7+
SELECT *
8+
FROM crime_scene_reports
9+
WHERE street = "Humphrey Street" AND year = 2021 AND month = 7 AND day = 28;
10+
11+
-- By checking the crime scene reports we found out that it took place at 10:15 AM at the bakery.
12+
-- Three witnesses were present each mentioning the bakery.
13+
14+
SELECT *
15+
FROM interviews
16+
WHERE year = 2021 AND month = 7 AND day = 28;
17+
18+
-- By checking the interviews that took place on that day, we found out after 10 minutes of the theft,
19+
-- the thief got into a car in the bakery parking lot and drove away.
20+
-- Also someone mentioned that he recognized the thief because earlier that morning he saw the thief withdrawing some money on Leggett Street.
21+
-- The thief called someone after leaving the bakery and talked to them for less than a minute.
22+
-- The thief said on the phone that they were planning to take the earliest flight out of Fiftyville tomorrow and asked the person he was talking to to buy the tickets.
23+
24+
SELECT *
25+
FROM people
26+
WHERE license_plate IN (
27+
SELECT license_plate
28+
FROM bakery_security_logs
29+
WHERE activity = "exit" AND year = 2021 AND month = 7 AND day = 28 AND hour = 10 AND minute BETWEEN 15 AND 40
30+
)
31+
AND phone_number IN (
32+
SELECT caller
33+
FROM phone_calls
34+
WHERE year = 2021 AND month = 7 AND day = 28 AND duration < 60
35+
)
36+
AND people.id IN (
37+
SELECT person_id
38+
FROM bank_accounts
39+
WHERE bank_accounts.account_number IN (
40+
SELECT account_number
41+
FROM atm_transactions
42+
WHERE year = 2021 AND month = 7 AND day = 28 AND atm_location = "Leggett Street" AND transaction_type = "withdraw"
43+
)
44+
);
45+
46+
-- Following the leads about the bakery parking and the ATM withdrawal and the call, we get back 3 suspects.
47+
-- Taylor, Diana and Bruce.
48+
49+
SELECT *
50+
FROM people
51+
WHERE phone_number IN (
52+
SELECT receiver
53+
FROM phone_calls
54+
WHERE year = 2021 AND month = 7 AND day = 28 AND duration < 60 AND caller IN ("(286) 555-6063", "(770) 555-1861", "(367) 555-5533")
55+
);
56+
57+
-- If we check the receivers of those phone calls against the 3 suspects phone numbers, we get 3 names that might be the accomplices.
58+
-- James, Philip and Robin.
59+
60+
SELECT *
61+
FROM phone_calls
62+
WHERE year = 2021 AND month = 7 AND day = 28 AND duration < 60
63+
AND caller IN ("(286) 555-6063", "(770) 555-1861", "(367) 555-5533")
64+
AND receiver IN ("(676) 555-6554", "(725) 555-3243", "(375) 555-8161");
65+
66+
-- Knowing the names of the possible suspects and accomplices we can check who called who.
67+
-- Taylor called James, Diana called Philip and Bruce called Robin.
68+
69+
SELECT *
70+
FROM flights
71+
JOIN airports
72+
ON airports.id = flights.origin_airport_id
73+
WHERE flights.year = 2021 AND flights.month = 7 AND flights.day = 29 AND flights.hour BETWEEN 00 AND 12 AND airports.city = "Fiftyville"
74+
ORDER BY flights.hour, flights.minute;
75+
76+
SELECT full_name, city
77+
FROM airports
78+
WHERE id IN (1, 4, 11);
79+
80+
-- The thief said he wants to leave as early as possible tomorrow.
81+
-- Checking the earliest flights we get back 3 flights: to New York at 8:20 AM, to Chicago at 9:30 AM and to San Francisco at 12:15 PM.
82+
83+
SELECT name, passport_number
84+
FROM people
85+
WHERE people.name IN ("Bruce", "Taylor", "Diana", "James", "Philip", "Robin")
86+
AND passport_number IN (
87+
SELECT passport_number
88+
FROM passengers
89+
JOIN flights
90+
ON flights.id = passengers.flight_id
91+
JOIN airports
92+
ON airports.id = flights.origin_airport_id
93+
WHERE flights.year = 2021 AND flights.month = 7 AND flights.day = 29 AND flights.hour BETWEEN 00 AND 12
94+
AND flights.origin_airport_id IN (
95+
SELECT airports.id
96+
FROM airports
97+
WHERE airports.city = "Fiftyville"
98+
)
99+
AND flights.destination_airport_id IN (
100+
SELECT airports.id
101+
FROM airports
102+
WHERE airports.city IN ("New York City", "Chicago", "San Francisco")
103+
)
104+
);
105+
106+
-- From the three suspects, Bruce and Taylor flew on the 29th on one of the three aforementioned flights.
107+
108+
SELECT full_name, city, passport_number, flights.destination_airport_id, flights.hour, flights.minute
109+
FROM airports
110+
JOIN flights
111+
ON flights.origin_airport_id = airports.id
112+
JOIN passengers
113+
ON passengers.flight_id = flights.id
114+
WHERE flights.year = 2021 AND flights.month = 7 AND flights.day = 29 AND hour BETWEEN 00 AND 12
115+
AND passengers.passport_number IN (
116+
SELECT passport_number
117+
FROM people
118+
WHERE people.name IN ("Bruce", "Taylor", "Diana", "James", "Philip", "Robin")
119+
);
120+
121+
-- Both of them flew to New York without the accomplices.
122+
123+
-- From the information gathered so far there are two options:
124+
-- Thief: Taylor | Accomplice: James | Flew to: New York.
125+
-- Thief: Bruce | Accomplice: Robin | Flew to: New York.

0 commit comments

Comments
 (0)