Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Feel free to explore, learn, and share your own approaches.
- [x] **3/25:** Opening Day ⚾️
- [ ] **3/26:** Flatten Array 🪜
- [ ] **3/27:** Infinite Monkey Theorem 🐒
- [ ] **3/28:** 28 Days Later 🧟
- [x] **3/28:** [28 Days Later](https://github.com/codedex-io/daily-challenges/tree/main/march-2026/3-28-28-days-later) 🧟
- [ ] **3/29:** ❓❓❓
- [ ] **3/30:** ❓❓❓
- [ ] **3/31:** ❓❓❓
37 changes: 37 additions & 0 deletions march-2026/3-28-28-days-later/28-days-later.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def days_to_infect(city):
days = 0

while True:
# list to store who gets infected this round
newly_infected = []

# for each cell in the grid
for i in range(len(city)):
for j in range(len(city[i])):
if city[i][j] == '🧟':
# check the 4 neighbors
if i > 0 and city[i-1][j] == '👤':
newly_infected.append((i-1, j))
if i < len(city) - 1 and city[i+1][j] == '👤':
newly_infected.append((i+1, j))
if j > 0 and city[i][j-1] == '👤':
newly_infected.append((i, j-1))
if j < len(city[i]) - 1 and city[i][j+1] == '👤':
newly_infected.append((i, j+1))

# if nobody new go infected, spreading has stopped
if not newly_infected:
break

# infect everyone in the list at the same time
for i, j in newly_infected:
city[i][j] = '🧟'

days += 1

# if any healthy people are left, they can never be reached
for i in city:
if '👤' in i:
return -1

return days