<commit_before>(ns scramblyzer.reid-parser
  [:use [clojure.string :only [join split blank?]]])

(defrecord Move 
  [edge-perm
   edge-orie
   corner-perm
   corner-orie])

(defrecord State
  [edges corners])

(def moves
  {
    "U" (Move. [1 2 3 0 4 5 6 7 8 9 10 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [1 2 3 0 4 5 6 7]
               [0 0 0 0 0 0 0 0])

    "D" (Move. [0 1 2 3 7 4 5 6 8 9 10 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [0 1 2 3 5 6 7 4]
               [0 0 0 0 0 0 0 0])

    "F" (Move. [9 1 2 3 8 5 6 7 0 4 10 11]
               [1 0 0 0 1 0 0 0 1 1 0 0]
               [3 1 2 5 0 4 6 7]
               [1 0 0 -1 -1 1 0 0])

    "B" (Move. [0 1 10 3 4 5 11 7 8 9 6 2]
               [0 0 1 0 0 0 1 0 0 0 1 1]
               [0 7 1 3 4 5 2 6]
               [0 -1 1 0 0 0 -1 1])

    "L" (Move. [0 1 2 11 4 5 6 9 8 3 10 7]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [0 1 6 2 4 3 5 7]
               [0 0 -1 1 0 -1 1 0])

    "R" (Move. [0 8 2 3 4 10 6 7 5 9 1 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [4 0 2 3 7 5 6 1]
               [-1 1 0 0 1 0 0 -1])})

(defn- scramble-moves
  [scramble]
  (remove blank?
          (seq (split scramble #"\s+"))))

(def move-type-counts
  {""  1
   "2" 2
   "'" 3})

(defn- expand-move
  [move]
  "Turn a move like R2 into clockwise turns like R R"
  (let [prefix (subs move 0 1)
        suffix (subs move 1)]
    (take (move-type-counts suffix)
          (cycle prefix)))) 

(defn- expand-scramble
  [scramble]
  "Turn all the moves into one of {U,D,L,R,F,B}"
  (let [moves (scramble-moves scramble)]
  (join " "
        (mapcat
          expand-move
          moves))))

(def solved-edges
  ; 0    1    2    3    4    5    6    7    8    9    10   11
  ["UF" "UR" "UB" "UL" "DF" "DR" "DB" "DL" "FR" "FL" "BR" "BL"])

(def solved-corners
  ; 0     1     2     3     4     5     6     7
  ["UFR" "URB" "UBL" "ULF" "DRF" "DFL" "DLB" "DBR"])

(def solved-state
  (State. solved-edges solved-corners))

(defn twist
  [piece-name amount]
  "Twist a piece by the amount given.
  e.g., UF twisted becomes FU"
  (let [sides (seq piece-name)
        times (mod amount (count sides))]
    (cond (= times 0) piece-name
          :else (twist
                  (join (concat (rest sides) (list (first sides))))
                  (dec times)))))

(defn- permute
  [base permutation]
  "Applies the permutation to the base"
  (vec (map base permutation)))

(defn- orient
  [base orientation]
  "Applies the orientation to the pieces"
  (vec (map twist base orientation)))<commit_msg>Made twist function cleaner<commit_after>(ns scramblyzer.reid-parser
  [:use [clojure.string :only [join split blank?]]])

(defrecord Move 
  [edge-perm
   edge-orie
   corner-perm
   corner-orie])

(defrecord State
  [edges corners])

(def moves
  {
    "U" (Move. [1 2 3 0 4 5 6 7 8 9 10 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [1 2 3 0 4 5 6 7]
               [0 0 0 0 0 0 0 0])

    "D" (Move. [0 1 2 3 7 4 5 6 8 9 10 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [0 1 2 3 5 6 7 4]
               [0 0 0 0 0 0 0 0])

    "F" (Move. [9 1 2 3 8 5 6 7 0 4 10 11]
               [1 0 0 0 1 0 0 0 1 1 0 0]
               [3 1 2 5 0 4 6 7]
               [1 0 0 -1 -1 1 0 0])

    "B" (Move. [0 1 10 3 4 5 11 7 8 9 6 2]
               [0 0 1 0 0 0 1 0 0 0 1 1]
               [0 7 1 3 4 5 2 6]
               [0 -1 1 0 0 0 -1 1])

    "L" (Move. [0 1 2 11 4 5 6 9 8 3 10 7]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [0 1 6 2 4 3 5 7]
               [0 0 -1 1 0 -1 1 0])

    "R" (Move. [0 8 2 3 4 10 6 7 5 9 1 11]
               [0 0 0 0 0 0 0 0 0 0 0 0]
               [4 0 2 3 7 5 6 1]
               [-1 1 0 0 1 0 0 -1])})

(defn- scramble-moves
  [scramble]
  (remove blank?
          (seq (split scramble #"\s+"))))

(def move-type-counts
  {""  1
   "2" 2
   "'" 3})

(defn- expand-move
  [move]
  "Turn a move like R2 into clockwise turns like R R"
  (let [prefix (subs move 0 1)
        suffix (subs move 1)]
    (take (move-type-counts suffix)
          (cycle prefix)))) 

(defn- expand-scramble
  [scramble]
  "Turn all the moves into one of {U,D,L,R,F,B}"
  (let [moves (scramble-moves scramble)]
  (join " "
        (mapcat
          expand-move
          moves))))

(def solved-edges
  ; 0    1    2    3    4    5    6    7    8    9    10   11
  ["UF" "UR" "UB" "UL" "DF" "DR" "DB" "DL" "FR" "FL" "BR" "BL"])

(def solved-corners
  ; 0     1     2     3     4     5     6     7
  ["UFR" "URB" "UBL" "ULF" "DRF" "DFL" "DLB" "DBR"])

(def solved-state
  (State. solved-edges solved-corners))

(defn twist
  [piece-name amount]
  (let [sides (vec (seq piece-name))
        size (count sides)]
    (join 
      (map sides 
           (map #(mod % size) 
                (range amount 
                       (+ size amount)))))))

(defn- permute
  [base permutation]
  "Applies the permutation to the base"
  (vec (map base permutation)))

(defn- orient
  [base orientation]
  "Applies the orientation to the pieces"
  (vec (map twist base orientation)))
{'fraction_non_alphanumeric': 0.1260520649833627, 'fraction_numerical': 0.1105891563906831, 'mean_word_length': 1.3867351704810835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263591', 'n_tokens_mistral': 2487, 'n_tokens_neox': 1970, 'n_words': 890}