Post History
Python 3.8+, 219 bytes Short version: from itertools import combinations as c def m(w): for k in range(n:=len(w)): for y in c(range(n),k+1): s=[0]*n for x in y: for r in range(...
Answer
#4: Post edited
Python 3.8+,192 bytesShort version without import:- ```python
- def m(w):
- for k in range(n:=len(w)):
for xs in combinations(range(n),k+1):- s=[0]*n
for x in xs:- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
- Python 3.8+, 219 bytes
- Short version:
- ```python
- from itertools import combinations as c
- def m(w):
- for k in range(n:=len(w)):
- for y in c(range(n),k+1):
- s=[0]*n
- for x in y:
- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
#3: Post edited
- Python 3.8+,192 bytes
- Short version without import:
- ```python
- def m(w):
- for k in range(n:=len(w)):
- for xs in combinations(range(n),k+1):
- s=[0]*n
- for x in xs:
- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
def get_list(string):return [int(ch) for ch in string]- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
- Python 3.8+,192 bytes
- Short version without import:
- ```python
- def m(w):
- for k in range(n:=len(w)):
- for xs in combinations(range(n),k+1):
- s=[0]*n
- for x in xs:
- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
#2: Post edited
Python 3.8+ **192 bytes**- Short version without import:
- ```python
- def m(w):
- for k in range(n:=len(w)):
- for xs in combinations(range(n),k+1):
- s=[0]*n
- for x in xs:
- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
- def get_list(string):
- return [int(ch) for ch in string]
- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
- Python 3.8+,192 bytes
- Short version without import:
- ```python
- def m(w):
- for k in range(n:=len(w)):
- for xs in combinations(range(n),k+1):
- s=[0]*n
- for x in xs:
- for r in range(w[x]):
- s[max(0,x-r)]=s[min(n-1,x+r)]=1
- if all(s):return k+1
- ```
- Longer version with the tests.
- ```python
- from itertools import combinations
- def umbrellas(values):
- n = len(values)
- for k in range(n):
- for xs in combinations(range(n), k+1):
- shadow = [False] * n
- for x in xs:
- for r in range(values[x]):
- shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True
- if all(shadow):
- return k + 1
- known_results = [
- ("214141131", 2),
- ("92132421", 1),
- ("11111111", 8),
- ("513131116", 2),
- ]
- def get_list(string):
- return [int(ch) for ch in string]
- for nums, result in known_results:
- res = min_shield([int(ch) for ch in nums])
- print(nums, result, res)
- ```
#1: Initial revision
Python 3.8+ **192 bytes** Short version without import: ```python def m(w): for k in range(n:=len(w)): for xs in combinations(range(n),k+1): s=[0]*n for x in xs: for r in range(w[x]): s[max(0,x-r)]=s[min(n-1,x+r)]=1 if all(s):return k+1 ``` Longer version with the tests. ```python from itertools import combinations def umbrellas(values): n = len(values) for k in range(n): for xs in combinations(range(n), k+1): shadow = [False] * n for x in xs: for r in range(values[x]): shadow[max(0, x-r)] = shadow[min(n-1, x+r)] = True if all(shadow): return k + 1 known_results = [ ("214141131", 2), ("92132421", 1), ("11111111", 8), ("513131116", 2), ] def get_list(string): return [int(ch) for ch in string] for nums, result in known_results: res = min_shield([int(ch) for ch in nums]) print(nums, result, res) ```