Skip to content

Instantly share code, notes, and snippets.

@Dex9999
Created July 2, 2023 19:43
Show Gist options
  • Save Dex9999/abc74f1ba7f28d34136fb3d4da3f9b1d to your computer and use it in GitHub Desktop.
Save Dex9999/abc74f1ba7f28d34136fb3d4da3f9b1d to your computer and use it in GitHub Desktop.
Get Puzzle Type from a Scramble
function whatPuzzle(scramble) {
const cubePattern2x2 = /^([UFR]'?|2? ?)+$/;
const cubePattern3x3 = /^([RLUDFB]'?|2? ?)+$/;
const cubePattern4x4or5x5 = /^([RLUDFBwxyz]'?|2? ?)+$/;
const cubePattern6x6or7x7 = /^([3RLUDFBw]'?|2? ?)+$/;
const clockPattern = /^([AURDLFBy0-9+\-*]+ ?)+$/;
const megaminxPattern = /^([RDU'+\-\s]+)+$/;
const pyraminxPattern = /^([LUBR'brlu\s]+)+$/;
const skewbPattern = /^(?:[LUBR'\s]+)$/;
const squanPattern = /^[\(\-\d,\)\/\s]+$/;
if (cubePattern2x2.test(scramble)) {
return "222";
} else if (cubePattern3x3.test(scramble)) {
if (skewbPattern.test(scramble)) {
return "skewb";
} else if (scramble.trim().startsWith("R' U' F") && scramble.trim().endsWith("R' U' F")) {
return "333fm";
} else {
return "333";
}
} else if (cubePattern4x4or5x5.test(scramble)) {
if (scramble.split("w").length - 1 <= 2) {
return "333bf";
} else if (scramble.split(" ").length === 60) {
return "555";
} else if (scramble.includes('x') || scramble.includes('y') || scramble.includes('z')) {
return "444bf";
} else {
return "444";
}
} else if (cubePattern6x6or7x7.test(scramble)) {
if (scramble.split("3").length - 1 <= 2) {
return "555bf";
} else if (scramble.split(" ").length === 100) {
return "777";
} else {
return "666";
}
} else if (clockPattern.test(scramble)) {
return "clock";
} else if (megaminxPattern.test(scramble)) {
return "minx";
} else if (pyraminxPattern.test(scramble)) {
return "pyram";
} else if (squanPattern.test(scramble)) {
return "sq1";
} else {
return "invalid";
}
}
// EXAMPLE USE:
// const scramble1 = ` (0,-4)/ (-2,-5)/ (-1,2)/ (0,-3)/ (-5,-5)/ (-3,0)/ (-4,0)/ (3,0)/ (6,0)/ (0,-1)/ (-2,0)/`;
// console.log(whatPuzzle(scramble1));
// Console Output: "sq1"
@Dex9999
Copy link
Author

Dex9999 commented Jul 2, 2023

Couldn't find any function like this on the internet so I made it :)

It will properly detect an event for any scramble given.
Only issue is since 3x3 and OH scrambles are generated the same, you obviously can't tell them apart.
Also be careful with multiple spaces between moves, though it should still work.

@abunickabhi
Copy link

abunickabhi commented Jul 25, 2023

Super interesting function and case structure.
5BLD scrambles will have 3Rw or 3Uw in the end.

MBLD is a standalone event, it does not need differentiation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment