Facebook
From Corrupt Marten, 2 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 50
  1. arr1 = [['#','#','#','#','#'],
  2. ['#','*','*','#','#'],
  3. ['#','#','#','*','#'],
  4. ['#','*','*','#','#'],
  5. ['#','#','#','#','#']]
  6.  
  7. arr2 = [['#','#','#','#','#','#','#','#','#','#'],
  8. ['#','-','-','-','*','-','-','*','#','#'],
  9. ['#','#','#','-','*','-','-','-','-','#'],
  10. ['#','*','*','#','#','#','#','#','#','#'],
  11. ['#','#','*','*','*','-','-','-','#','#'],
  12. ['#','#','#','#','#','#','#','#','#','#']]
  13.  
  14. def fun(n,m,arr):
  15.     persons = 0
  16.     rooms = 0
  17.     for i in range(n):
  18.         for j in range(m):
  19.             if arr[i][j] != '#':
  20.                 if arr[i][j] == "*":
  21.                     persons += 1
  22.                 if arr[i-1][j] != '#' or arr[i][j-1] != '#' or arr[i+1][j] != '#' or arr[i][j+1] != '#':
  23.                     arr[i][j] = '#'
  24.                 else:
  25.                     rooms += 1
  26.                     arr[i][j] = '#'
  27.     if rooms > 0:
  28.         return persons/rooms
  29.     else:
  30.         return False
  31.  
  32.  
  33. print(fun(5,5,arr1))
  34. print(fun(6,10,arr2))