diff --git a/README.md b/README.md index 8a68304..2ffca96 100644 --- a/README.md +++ b/README.md @@ -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:** ❓❓❓ diff --git a/march-2026/3-28-28-days-later/28-days-later.py b/march-2026/3-28-28-days-later/28-days-later.py new file mode 100644 index 0000000..d5d0fad --- /dev/null +++ b/march-2026/3-28-28-days-later/28-days-later.py @@ -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 \ No newline at end of file