Talk:A-level Computing/AQA/Paper 1/Skeleton program/2024

Pattern format
The Shakeel spiral™:

Patterns in the text file can be decoded using a spiral like this

→_ →_ →

↑__→___↓

←__←__↓

QQ**Q**QQ becomes

Q| Q|  *

Q| Q|  *

* |   *  |  Q

91.195.183.200 (discuss) 13:58, 12 September 2023 (UTC)

Question 10
For question 10, I'm having trouble doing part D, "ensure any changes made to a cell’s symbolsNotAllowed list are undone as required". The answer provided in python does not cover this in any way- I'm just thinking how it would be done? the only time the method AddToNotAllowedSymbols is mentioned is in MatchPattern, which can't be edited to do the reverse/simply store the output incase you do want to reverse it. I'm thinking that you could just revert the self.__SymbolsNotAllowed list to be blank, but then this would create weird edge cases where, for example, you have a completed T pattern, place a Q inside the 3x3 area, then revert the change, you can now place a T inside that 3x3 area again.

Can anyone help? I'll update this post if I figure out a solution.

--LivYRBY (discuss • contribs) 09:35, 13 May 2024 (UTC)

Update: I did it! ended up creating a new method in the puzzle and cell class, as well as editing the attemptpuzzle method. The two new methods, SaveForUndo and RemoveFromNotAllowedSymbols:

def SaveForUndo(self,Symbol, Cell, Row, Column): List = [] List.append(str(self.__SymbolsLeft)) List.append(str(Symbol)) List.append(str(Cell._Symbol)) List.append(str(self.__Score)) for n in range(0, len(self.__Grid)): List.append(self.__Grid[n]._Cell__SymbolsNotAllowed) return List

def RemoveFromNotAllowedSymbols(self, SymbolToRemove): self.__SymbolsNotAllowed.remove(SymbolToRemove)

and the amended AttemptPuzzle (Edits are marked with %):

def AttemptPuzzle(self): Finished = False while not Finished: self.DisplayPuzzle print("Current score: " + str(self.__Score)) Row = -1 Valid = False while not Valid: try: Row = int(input("Enter row number: ")) Valid = True except: pass Column = -1 Valid = False while not Valid: try: Column = int(input("Enter column number: ")) Valid = True except: pass Symbol = self.__GetSymbolFromUser CurrentCell = self.__GetCell(Row, Column) %  UndoList = self.SaveForUndo(Symbol, CurrentCell, Row, Column) if CurrentCell.CheckSymbolAllowed(Symbol): %    self.__SymbolsLeft -= 1 CurrentCell.ChangeSymbolInCell(Symbol) AmountToAddToScore = self.CheckforMatchWithPattern(Row, Column) if AmountToAddToScore > 0: self.__Score += AmountToAddToScore %   print %   self.DisplayPuzzle %   print %   Choice = input("Would you like to undo last move? (Y/N) ").lower %   if Choice.lower == "y": %   self.__SymbolsLeft = int(UndoList[0]) %   CurrentCell._Symbol = UndoList[2] %   self.__Score = int(UndoList[3]) - 3 %   for n in range(0, (len(self.__Grid)-1)): %       if UndoList[1] in self.__Grid[n]._Cell__SymbolsNotAllowed: %           self.__Grid[n].RemoveFromNotAllowedSymbols(UndoList[1]) if self.__SymbolsLeft == 0: Finished = True

I'll add it as a seperate solution to question 10- as it's rather complex.

--LivYRBY (discuss • contribs) 12:21, 13 May 2024 (UTC)