Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Hultan (SoftTeam AB)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Rubik's Cube in go-lang

Thoroughly-tested representation of the Rubik's Cube in `go-lang`. A naive and limited BFS solver is provided.
Thoroughly-tested package, called `Rubik`, that is a representation of the Rubik's Cube in `go-lang`. A naive and limited BFS solver is provided. It contains functions for all normal moves, slice moves, double moves and cube rotations.

It also contains a package `Rubik-alg` that can execute algorithms and reverse algorithms. `Rubik-alg` can also scramble cubes.

## The Cube

Expand All @@ -18,7 +20,7 @@ scrambled := rubik.NewCube("bwwbwwyyr orwogbygb gbbrrwrrw ooygbygbr oogoogyyb rr
```

Then move the faces. For instance, front face clockwise, upper face clockwise, right face clockwise,
and finally upper face counter clockwise:
and finally upper face counterclockwise:

```
moved := cube.F().U().R().Uc()
Expand All @@ -41,3 +43,55 @@ solved := rubik.Solve(cube)
See [better algorithms](https://en.wikipedia.org/wiki/Optimal_solutions_for_Rubik%27s_Cube) or
[Algorithms for solving the Rubik's cube - Harpreet Kaur](HarpreetKaur.pdf)
by Harpreet Kaur.

## PACKAGES

### Rubik

Contains the cube implementation, and functions for :

* Create a solved cube
* Check if the cube solved
* Check if a cube equals another cube
* Copy a cube
* Normal moves : R, R', L, L', U, U', D, D', F, F', B, B'
- Called R(), Rc()...
* Slice moves : M, M', S, S', E, E'
- Called M(), Mc()...
* Double moves : r, r', l, l', u, u', d, d', f, f', b, b'
- Called Rd(), Rdc()...
* Rotation moves : x, x', y, y', z, z'
- Called X(), Xc()...

It also contains a naive solver.

### Rubik-alg

Contains functions for :

* Execute an algorithm, ex "F' U' x L U' R d2 S'".
* Reversing an algorithms, ex "S d2 R' U L' x' U F".
* Get a scrambled cube, and the scramble algorithm.

Parentheses and brackets in the algorithms are ignored.

Tests are included for all public methods.

#### Examples using `Rubik-alg`

Example using the `PerformAlg` function:
```go
// Perform a T permutation
cube := PerformAlg(cube, "(R U R' U') (R' F R2 U') R' U' (R U R' F')")
fmt.Println(cube) // Prints : "wwwwwwwww ggrgggggg bogrrrrrr rbbbbbbbb orooooooo yyyyyyyyy"
```
You can reverse algorithms using the `ReverseAlg` function:
```go
alg := ReverseAlg("(R U R' U') (R' F R2 U') R' U' (R U R' F')")
fmt.Println(alg) // Prints "F R U' R' U R U R2 F' R U R U' R'"
```
Get a scrambled cube by using the `GetScrambledCube` function:
```go
cube, alg := GetScrambledCube()
fmt.Println(cube, alg)
```
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/hultan/go-rubik

go 1.17
Loading