Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var list = new Set()
- /* Variant:
- 0--1
- | |
- 3--2
- */
- function flipHor(variant) {
- return [
- variant[1],
- variant[0],
- variant[3],
- variant[2],
- ]
- }
- function flipVer(variant) {
- return [
- variant[3],
- variant[2],
- variant[1],
- variant[0],
- ]
- }
- function rotVar(variant, rot = 0) {
- return variant.map((e, i) => variant[(i + rot) % variant.length])
- }
- function hash(variant) {
- return variant.join('-')
- }
- function inList(variant, {flipH = false, flipV = false, rotate = false}) {
- const orig = [variant]
- const rot = rotate
- ? orig.reduce((prev, curr) => ([
- ...prev,
- curr,
- rotVar(curr, 1),
- rotVar(curr, 2),
- rotVar(curr, 3),
- ]), [])
- : [...orig]
- const flip = flipH
- ? rot.reduce((prev, curr) => ([...prev, curr, flipHor(curr)]), [])
- : [...rot]
- const opts = flipV
- ? flip.reduce((prev, curr) => ([...prev, curr, flipVer(curr)]), [])
- : [...flip]
- return opts.map(e => hash(e)).some(e => list.has(e))
- }
- function combine(src = [], vars = [], depth = 0) {
- depth = depth - 1
- const res = [...src]
- let out = []
- vars.forEach(v => {
- const upd = res.map(r => [...r, v])
- out = res.length
- ? [...out, ...upd]
- : [...out, [v]]
- })
- return (depth > 0)
- ? combine(out, vars, depth)
- : out
- }
- function iterate(depth = 4, vars = [], options = {}) {
- list = new Set()
- const res = combine([], vars, depth)
- res.map(v => v.reverse()).forEach(v => {
- if (!inList(v, options)) {
- list.add(hash(v))
- }
- })
- return list
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement