0 Replies - 661 Views - Last Post: 04 April 2015 - 12:07 PM

#1 JoziNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 20-April 14

Rubik's World - Scheme

Posted 04 April 2015 - 12:07 PM

I have to write a functions to twist my 2x2x2 world state along the x, y, z, X, Y, and Z directions. In this case,
the upper case letters denote a 90 degree twist in the negative direction, whereas the lower case
letters denote a 90 degree twist in the positive direction

;; ;helper function for rotating the cube. Recalculates the various orientations
;; ;of the sub-cubes

(define (recalculateOrientation orientation axis)
    (cond
        [(= axis 0)
            (if (> orientation 4)
                orientation
                (if(= orientation 4)
                    1
                    (+ orientation 1)
                )
            )
        ]
        [(= axis 1)
            (if (or (= orientation 1) (= orientation 3))
                orientation
                (cond
                    [(= orientation 2) 6]
                    [(= orientation 4) 5]
                    [(= orientation 5) 2]
                    [(= orientation 6) 4]
                )
            )
        ]
        [(= axis 2)
            (if (or (= orientation 2) (= orientation 4))
                orientation
                (cond
                    [(= orientation 1) 5]
                    [(= orientation 3) 6]
                    [(= orientation 5) 3]
                    [(= orientation 6) 1]
                )
            )
        ]
    )
)
[code/]

;; ;TESTS
;; ; (print (= 2 (recalculateOrientation 1 0)) "\n")

Can someone please explain the logic of this? As I want to hard code a solution

I have to write a  functions to twist my 2x2x2 world state along the x, y, z, X, Y, and Z directions. In this case,
the upper case letters denote a 90 degree twist in the negative direction, whereas the lower case
letters denote a 90 degree twist in the positive direction

[code]
;; ;helper function for rotating the cube. Recalculates the various orientations
;; ;of the sub-cubes

(define (recalculateOrientation orientation axis)
    (cond
        [(= axis 0)
            (if (> orientation 4)
                orientation
                (if(= orientation 4)
                    1
                    (+ orientation 1)
                )
            )
        ]
        [(= axis 1)
            (if (or (= orientation 1) (= orientation 3))
                orientation
                (cond
                    [(= orientation 2) 6]
                    [(= orientation 4) 5]
                    [(= orientation 5) 2]
                    [(= orientation 6) 4]
                )
            )
        ]
        [(= axis 2)
            (if (or (= orientation 2) (= orientation 4))
                orientation
                (cond
                    [(= orientation 1) 5]
                    [(= orientation 3) 6]
                    [(= orientation 5) 3]
                    [(= orientation 6) 1]
                )
            )
        ]
    )
)



;; ;TESTS
;; ; (print (= 2 (recalculateOrientation 1 0)) "\n")

Can someone please explain the logic of this? As I want to hard code a solution

Is This A Good Question/Topic? 0
  • +

Page 1 of 1