Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * This is a JavaScript Scratchpad.
  3.  *
  4.  * Enter some JavaScript, then Right Click or choose from the Execute Menu:
  5.  * 1. Run to evaluate the selected text (Ctrl+R),
  6.  * 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,
  7.  * 3. Display to insert the result in a comment after the selection. (Ctrl+L)
  8.  */
  9.  
  10. g=['g']
  11. r=['r']
  12. y=['y']
  13. c=['c']
  14. b=['b']
  15. p=['p']
  16.  
  17. g.push(r,y)
  18. r.push(c,b)
  19. y.push(r,c)
  20. c.push(p,b)
  21. p.push(g,y)
  22. b.push(p,g)
  23.  
  24. const isC = (c) => ([color]) => c === color ? 1 : 0
  25.  
  26. function s (_arr = [], i = 0) {
  27.   const arr = [..._arr]
  28.   const [c, a, b] = arr[i]
  29.   arr.splice(i, 1)
  30.   arr.splice(i, 0, a, b)
  31.   return arr
  32. }
  33.  
  34. function count (arr, c) {
  35.   return arr.reduce((acc, [color]) => acc + isC(c)(color), 0)
  36. }
  37.  
  38. function x (arr = [g], hist = []) {
  39.   if (arr.length === 10) {
  40.     const [r, y] = [count(arr, 'r'), count(arr, 'y')]
  41.     if (r === y && r === 5) {
  42.       return [hist]
  43.     } else {
  44.       return []
  45.     }
  46.   } else {
  47.     return arr.flatMap((_, i) => x(s(arr, i), hist.concat([i]))[0])
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement