From 679bc2676998719d66731eb3139af35df5aaff24 Mon Sep 17 00:00:00 2001 From: Andrew Franklin Date: Fri, 23 Oct 2020 12:05:24 -0500 Subject: [PATCH 1/2] Workaround/simplification of code in simple_cube.py. This change makes simple_cube.py work in python 3. It is necessary since the class scope is inaccessible from functions, list comprehensions or generator expressions enclosed in that scope; they act as if that scope does not exist. see: https://stackoverflow.com/questions/13905741/accessing-class-variables-from-a-list-comprehension-in-the-class-definition This code was tested and worked in 3.8.4 & 2.7.14 --- code/simple_cube.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/simple_cube.py b/code/simple_cube.py index f909f96..213e297 100644 --- a/code/simple_cube.py +++ b/code/simple_cube.py @@ -133,13 +133,17 @@ class CubeAxes(Axes): The cube has side-length 2, and the observer is a distance zloc away along the z-axis. """ - face = np.array([[1, 1], [1, -1], [-1, -1], [-1, 1], [1, 1]]) - faces = np.array([np.hstack([face[:, :i], + + def faces(): + face = np.array([[1, 1], [1, -1], [-1, -1], [-1, 1], [1, 1]]) + return np.array([np.hstack([face[:, :i], np.ones((5, 1)), face[:, i:]]) for i in range(3)] + [np.hstack([face[:, :i], -np.ones((5, 1)), face[:, i:]]) for i in range(3)]) + faces = faces() + stickercolors = ["#ffffff", "#00008f", "#ff6f00", "#ffcf00", "#009f0f", "#cf0000"] From 23d1b93df481cc702cc4b95d7490794ed268bab3 Mon Sep 17 00:00:00 2001 From: Andrew Franklin Date: Fri, 23 Oct 2020 12:13:29 -0500 Subject: [PATCH 2/2] Adjusted printing in cube.py. The code now works in python2 and python3. --- code/cube.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/cube.py b/code/cube.py index 428e6b7..a1d4b1c 100644 --- a/code/cube.py +++ b/code/cube.py @@ -46,6 +46,7 @@ """ +from __future__ import print_function import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Rectangle @@ -145,7 +146,7 @@ def move(self, f, l, d): self.stickers[i] = np.rot90(self.stickers[i], 3) if l == self.N - 1: self.stickers[i2] = np.rot90(self.stickers[i2], 1) - print "moved", f, l, len(ds) + print("moved", f, l, len(ds)) return None def _rotate(self, args):