rotator

.py

School

Drexel University *

*We aren’t endorsed by this school

Course

380

Subject

Computer Science

Date

Oct 30, 2023

Type

py

Pages

3

Uploaded by DeanMetalChimpanzee3

Report
import sys DEFAULT_STATE = '12345|1234 |12354' class Action: def __init__(self, type, x1, y1, x2, y2, dx): self.type = type self.x1 = int(x1) self.y1 = int(y1) self.x2 = int(x2) self.y2 = int(y2) self.dx = int(dx) def __str__(self): if self.type == "rotate": return f"rotate({self.x1},{self.dx})" else: return f"slide({self.x1},{self.y1},{self.x2},{self.y2})" class State: def __init__(self, string): self.state_string = string self.rows = self.state_string.split("|") def __str__(self): return "|".join(self.rows) def __eq__(self, state): return str(state) == "|".join(self.rows) def clone(self): return State(str(self)) def is_goal(self): for i in range (len(self.rows[0])): for j in range (1, len(self.rows)): if self.rows[0][i] == " " or self.rows[j][i] == " ": continue if self.rows[0][i] != self.rows[j][i]: return False return True def actions(self): actions = [] for x in range(len(self.rows)): actions.append(Action("rotate", x, -1, -1, -1, -1)) actions.append(Action("rotate", x, -1, -1, -1, 1)) for x in range(len(self.rows)): for y in range(len(self.rows[0])): if self.rows[x][y] == " ": if (x - 1) >= 0: actions.append(Action("slide", y, x-1, y, x, -1)) if (x + 1) < len(self.rows): actions.append(Action("slide", y, x+1, y, x,
-1)) return actions def execute(self, action): if action.type == "slide": value1 = self.rows[action.y1][action.x1] value2 = self.rows[action.y2][action.x2] s1 = list(self.rows[action.y1]) s1[action.x1] = value2 s2 = list(self.rows[action.y2]) s2[action.x2] = value1 self.rows[action.y1] = "".join(s1) self.rows[action.y2] = "".join(s2) else: if action.dx == 1: s = list(self.rows[action.x1]) s = [s[-1]] + s[:-1] self.rows[action.x1] = "".join(s) else: s = list(self.rows[action.x1]) s = s[1:] + [s[0]] self.rows[action.x1] = "".join(s) if __name__ == "__main__": cmd = sys.argv[1] if cmd: state_string = sys.argv[2] if len(sys.argv) > 2 else DEFAULT_STATE state = State(state_string) if cmd == "print": print(str(state)) elif cmd == "goal": print(state.is_goal()) elif cmd == "actions": for actions in state.actions(): print(str(actions)) elif cmd.startswith("walk"): states = [] done = False x = 1 curr_state = state.clone() while x: for state in states: if curr_state == state: done = True break if done == True: break print(curr_state) states.append(curr_state) new = curr_state.clone()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Consider the following functions. f(x) = x² and g(x) = √√x +3 Step 2 of 2: Find the formula for…
Q: In each of the following, find the equation of theplane normal to the given vector N and…
Q: How many isomers of the formula C4H8C12 are there? a. 4 b. 6 2 3 c. 8 d. 9
Q: A 500-N force is applied to a bent plate as shown. Determine (a) an equivalent force-couple system…
Q: Gary and Georgeann have the following objectives: If Gary predeceases Georgeann, to provide her…
Q: Listed below are the conference designations of teams that won a certain annual​ tournament, where…
Q: THIS IS THE FORMULA - b ± √b²-4ac 2a your work for X = 2 - 2x²+3x = 2 THIS IS THE EQUATION
Q: Freefight Airlines is presently operating at 70 percent of capacity. Management of the airline is…
Q: The following chemical reaction takes place in aqueous solution: FeSO4(aq)+Na₂S(aq) →…
Q: 24' 24' I- 30' -I B A ーエー 26' -I -I -1 WDL = 100 psf WLL = 50 psf. Use LRFD 4p50
Q: 7. Given quarter-circular gate AB is 9-ft wide is hinged at A. Determine the contact force between…
Q: What is the goal of circuit theory?
Q: CH2CH2CH2CH2 I OH I OH Н С + H2O
Q: Suppose that the total revenue function is given by R(x) = 47x and that the total cost function is…
Q: 2. The clamp of the given figure is used to hold a cover in place. The screw of the clamp has a…
Q: I Consider an analog signal xa(t) = sin(250πt) + sin(400πt) + sin(750πt). (a) What is the Nyquist…
Q: can you write part b out and attach a photo it is unreadable in this format. also please address…
Q: (a) Determine the total area under the standard normal curve to the left of z= -2 or to the right of…
Q: Find the remainder when 819054 is divided by 13.
Q: Find a vector equation with parameter tt for the line of intersection of the planes x+y+z=4x+y+z=4…
Q: 4.67 Determine the reactions at B and D when b = .C hp 80 N A D 75 mm 250 mm C 90 mm- B 60 mm.
Q: I a) Design a noninverting amplifier with a gain of 100 using ideal op amps and practical values of…