Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
MCS 275 Spring 2023 Homework 6
생성일
3년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
14 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
36 행
복사
22 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
42 행
복사
복사
복사됨
복사
복사됨
def
depth_first_maze_solution
(M,
path=None,verbose=False):
def
can_be_solved_maxlen
(M,
k,
path=None,verbose=False):
"""
"""
복사
복사됨
복사
복사됨
Find
solution to
Maze
`M`
that begins with
`path`
(
if given)
,
Returns True if a
solution to
`M`
can be found which is of length
returning either that solution as a list of Point2 objects or
at most `k` (starting from
`path`
,
if given)
. Else, returns False.
None if no such solution exists.
"""
"""
복사
복사됨
복사
복사됨
if path == None:
if path == None:
# no path was specified, initialize it with [M.start]
# no path was specified, initialize it with [M.start]
path = [ M.start ]
path = [ M.start ]
if verbose:
if verbose:
print("Considering:",path)
print("Considering:",path)
if path[-1] == M.goal:
if path[-1] == M.goal:
# path ends with goal, meaning it's a solution
# path ends with goal, meaning it's a solution
복사
복사됨
복사
복사됨
return
path
return
True
# If there are no more steps to take and we haven't reached the goal,
# then don't make another recursive call
if k == 0:
return False
possible_next_locations = M.free_neighbors(path[-1])
possible_next_locations = M.free_neighbors(path[-1])
for x in possible_next_locations:
for x in possible_next_locations:
if x in path:
if x in path:
# skip x
# skip x
continue # do not execute the rest of the loop body
continue # do not execute the rest of the loop body
# immediately begin the next iteration.
# immediately begin the next iteration.
# x should be considered
# x should be considered
new_path = path + [x]
new_path = path + [x]
복사
복사됨
복사
복사됨
# Ask for a solution that continues from new_path
# Ask for a solution that continues from new_path
solution =
depth_first_maze_solution
(M,
new_path,verbose)
# Reduce `k` by 1 because we've now made another move.
if solution:
# None is falsy, while a nonempty list is truthy
solution =
can_be_solved_maxlen
(M,
k-1,
new_path,verbose)
return
solution
if solution:
# If we've found `True` at any point in our search, return True.
return
True
# What now? If we end up here, it means no next step leads to a solution
# What now? If we end up here, it means no next step leads to a solution
# Hence `path` leads to only dead ends
# Hence `path` leads to only dead ends
# We therefore BACKTRACK
# We therefore BACKTRACK
if verbose:
if verbose:
print("GIVING UP ON:",path)
print("GIVING UP ON:",path)
복사
복사됨
복사
복사됨
return
None
return
False
저장된 비교 결과
원본
파일 열기
def depth_first_maze_solution(M,path=None,verbose=False): """ Find solution to Maze `M` that begins with `path` (if given), returning either that solution as a list of Point2 objects or None if no such solution exists. """ if path == None: # no path was specified, initialize it with [M.start] path = [ M.start ] if verbose: print("Considering:",path) if path[-1] == M.goal: # path ends with goal, meaning it's a solution return path possible_next_locations = M.free_neighbors(path[-1]) for x in possible_next_locations: if x in path: # skip x continue # do not execute the rest of the loop body # immediately begin the next iteration. # x should be considered new_path = path + [x] # Ask for a solution that continues from new_path solution = depth_first_maze_solution(M,new_path,verbose) if solution: # None is falsy, while a nonempty list is truthy return solution # What now? If we end up here, it means no next step leads to a solution # Hence `path` leads to only dead ends # We therefore BACKTRACK if verbose: print("GIVING UP ON:",path) return None
수정본
파일 열기
def can_be_solved_maxlen(M, k, path=None,verbose=False): """ Returns True if a solution to `M` can be found which is of length at most `k` (starting from `path`, if given). Else, returns False. """ if path == None: # no path was specified, initialize it with [M.start] path = [ M.start ] if verbose: print("Considering:",path) if path[-1] == M.goal: # path ends with goal, meaning it's a solution return True # If there are no more steps to take and we haven't reached the goal, # then don't make another recursive call if k == 0: return False possible_next_locations = M.free_neighbors(path[-1]) for x in possible_next_locations: if x in path: # skip x continue # do not execute the rest of the loop body # immediately begin the next iteration. # x should be considered new_path = path + [x] # Ask for a solution that continues from new_path # Reduce `k` by 1 because we've now made another move. solution = can_be_solved_maxlen(M, k-1, new_path,verbose) if solution: # If we've found `True` at any point in our search, return True. return True # What now? If we end up here, it means no next step leads to a solution # Hence `path` leads to only dead ends # We therefore BACKTRACK if verbose: print("GIVING UP ON:",path) return False
비교하기