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
L, S = input().split() L = int(L) max_captured = 0 for i in range(L): if S[i] != '.': continue new_S = S[:i] + 'W' + S[i+1:] chains = [] n = len(new_S) if n == 0: continue current_char = new_S[0] start = 0 for j in range(1, n): if new_S[j] != current_char: chains.append((current_char, start, j-1)) current_char = new_S[j] start = j chains.append((current_char, start, n-1)) valid = True for (color, s_pos, e_pos) in chains: if color == 'W': left = s_pos - 1 left_color = new_S[left] if left >= 0 else None right = e_pos + 1 right_color = new_S[right] if right < L else None if left_color == 'B' and right_color == 'B': valid = False break if not valid: continue captured = 0 for (color, s_pos, e_pos) in chains: if color == 'B': left = s_pos - 1 left_color = new_S[left] if left >= 0 else None right = e_pos + 1 right_color = new_S[right] if right < L else None if left_color == 'W' and right_color == 'W': captured += (e_pos - s_pos + 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.