Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This is a JavaScript Scratchpad.
- *
- * Enter some JavaScript, then Right Click or choose from the Execute Menu:
- * 1. Run to evaluate the selected text (Ctrl+R),
- * 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,
- * 3. Display to insert the result in a comment after the selection. (Ctrl+L)
- */
- g=['g']
- r=['r']
- y=['y']
- c=['c']
- b=['b']
- p=['p']
- g.push(r,y)
- r.push(c,b)
- y.push(r,c)
- c.push(p,b)
- p.push(g,y)
- b.push(p,g)
- const isC = (c) => ([color]) => c === color ? 1 : 0
- function s (_arr = [], i = 0) {
- const arr = [..._arr]
- const [c, a, b] = arr[i]
- arr.splice(i, 1)
- arr.splice(i, 0, a, b)
- return arr
- }
- function count (arr, c) {
- return arr.reduce((acc, [color]) => acc + isC(c)(color), 0)
- }
- function x (arr = [g], hist = []) {
- if (arr.length === 10) {
- const [r, y] = [count(arr, 'r'), count(arr, 'y')]
- if (r === y && r === 5) {
- return [hist]
- } else {
- return []
- }
- } else {
- return arr.flatMap((_, i) => x(s(arr, i), hist.concat([i]))[0])
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement