Problem Statement Recently, AIs which play Go (a traditional board game) are well…
- User
Problem Statement
Recently, AIs which play Go (a traditional board game) are well investigated. Your friend Hikaru is planning to develop a new awesome Go AI named Sai and promote it to company F or company G in the future. As a first step, Hikaru has decided to develop an AI for 1D-Go, a restricted version of the original Go.
In both of the original Go and 1D-Go, capturing stones is an important strategy. Hikaru asked you to implement one of the functions of capturing.
In 1D-Go, the game board consists of grids lie in a row. A state of 1D-go is described by a string of length . The -th character of describes the -th grid as the following:
Assistant
def get_chains(s): chains = [] n = len(s) if n == 0: return chains current_char = s[0] start = 0 for i in range(1, n): if s[i] != current_char: chains.append((start, i-1, current_char)) current_char = s[i] start = i chains.append((start, n-1, current_char)) return chains L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue T = list(S) T[i] = 'W' T_str = ''.join(T) chains = get_chains(T_str) invalid = False for start, end, color in chains: if color != 'W': continue left_pos = start - 1 right_pos = end + 1 left_char = T_str[left_pos] if left_pos >= 0 else None right_char = T_str[right_pos] if right_pos < L else None if left_char == 'B' and right_char == 'B': invalid = True break if invalid: continue captured = 0 for start, end, color in chains: if color != 'B': continue left_pos = start - 1 right_pos = end + 1 left_char = T_str[left_pos] if left_pos >= 0 else None right_char = T_str[right_pos] if right_pos < L else None if left_char == 'W' and right_char == 'W': captured += (end - start + 1) if captured > max_captured: max_captured = captured print(max_captured)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.