Python Forum
How to eliminate magic squares formed by the same numbers, but permuted
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to eliminate magic squares formed by the same numbers, but permuted
#7
Add this method to the square class. Then normalize the produced squares and remove repetitions
    def normalize(self):
        if self.mat[0][0] > self.mat[2][2]:
            self.mat = [row[::-1] for row in self.mat[::-1]]
        if self.mat[2][0] > self.mat[0][2]:
            self.mat = [list(row) for row in zip(*self.mat)]
        if self.mat[0][0] > self.mat[2][0]:
            self.mat = self.mat[::-1]
alternately, you can use
def is_magic_and_cool(self):
    return (self.is_magic() and
                self.mat[0][0] < min(self.mat[2][0], self.mat[2][2]) and self.mat[2][0] < self.mat[0][2])
and generate only magic and cool squares.
Reply


Messages In This Thread
RE: How to eliminate magic squares formed by the same numbers, but permuted - by Gribouillis - May-09-2019, 09:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Eliminate entering QR - Whatsapp web automated by selenium akanowhere 1 3,157 Jan-21-2024, 01:12 PM
Last Post: owalahtole
  Why does newly-formed dict only consist of last row of each year? Mark17 6 903 Nov-17-2023, 05:28 PM
Last Post: Mark17
  magic related field in Django model sonh 1 1,306 Apr-24-2022, 12:37 PM
Last Post: sonh
  Need a little help with numpy array magic. pmf71 0 1,211 Dec-01-2021, 02:51 AM
Last Post: pmf71
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,390 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  How to eliminate unwanted spaces Mohan 5 2,979 Jun-04-2020, 08:34 AM
Last Post: buran
  [gpxpy] "Error parsing XML: not well-formed (invalid token): line 1, column 1" Winfried 5 6,824 Jan-26-2020, 01:09 AM
Last Post: Winfried
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,842 May-09-2019, 12:19 PM
Last Post: Pleiades
  Magic method __str__ dan789 16 7,521 Dec-23-2018, 03:59 PM
Last Post: ichabod801
  [split] Bad magic number. What is it ? Douglas 2 5,346 Oct-22-2018, 10:38 AM
Last Post: Douglas

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020