Advertisement
NLinker

Roundelay task

Nov 19th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 0 = boys
  2. // 1 = girls
  3.  
  4. const index = (i, n) => i < 0? (i + n) % n: i % n
  5.  
  6. const conv = (int, n) => {
  7.   arr = []
  8.   for (let i = 0; i < n; i++) {
  9.     let x = 1 << (n - i - 1) & +int? 1: 0
  10.     arr.push(x)
  11.   }
  12.   return arr
  13. }
  14.  
  15. const calc = (arr) => {
  16.   let b = 0
  17.   let g = 0
  18.   let nb = 0
  19.   let ng = 0
  20.   let n = arr.length
  21.   for (let i = 0; i < n; i++) {
  22.     let prev, cur, next
  23.     if (i === 0) {
  24.       prev = arr[n - 1]
  25.       cur = arr[i]
  26.       next = arr[i + 1]
  27.     } else if (i === n - 1) {
  28.       prev = arr[i - 1]
  29.       cur = arr[i]
  30.       next = arr[0]
  31.     } else {
  32.       prev = arr[i - 1]
  33.       cur = arr[i]
  34.       next = arr[i + 1]
  35.     }
  36.     if (cur === 0) {
  37.       nb += 1
  38.     } else {
  39.       ng += 1
  40.     }
  41.     if (prev === 0 || next === 0)
  42.       b += 1
  43.     if (prev === 1 || next === 1)
  44.       g += 1
  45.   }
  46.   return {arr, nb, ng, b, g}
  47. }
  48.  
  49. function check(n) {
  50.   let upper = Math.pow(2, n) - 1
  51.   for (let i = 0; i < upper; i++) {
  52.     let x = calc(conv(i, n))
  53.     if (x.g === 24 && x.b === 20) {
  54.       console.log(JSON.stringify(x.arr))
  55.     }
  56.   }
  57. }
  58.  
  59. check(30)
  60.  
  61. /*
  62. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1]
  63. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1]
  64. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,0,1,1,1,1,1,1,1,1,1]
  65. [0,0,0,0,0,0,0,0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,1,1,0,1,1]
  160. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1]
  161. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1]
  162. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,0,1,1,1]
  163. [0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1]
  164. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement