Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 0 = boys
- // 1 = girls
- const index = (i, n) => i < 0? (i + n) % n: i % n
- const conv = (int, n) => {
- arr = []
- for (let i = 0; i < n; i++) {
- let x = 1 << (n - i - 1) & +int? 1: 0
- arr.push(x)
- }
- return arr
- }
- const calc = (arr) => {
- let b = 0
- let g = 0
- let nb = 0
- let ng = 0
- let n = arr.length
- for (let i = 0; i < n; i++) {
- let prev, cur, next
- if (i === 0) {
- prev = arr[n - 1]
- cur = arr[i]
- next = arr[i + 1]
- } else if (i === n - 1) {
- prev = arr[i - 1]
- cur = arr[i]
- next = arr[0]
- } else {
- prev = arr[i - 1]
- cur = arr[i]
- next = arr[i + 1]
- }
- if (cur === 0) {
- nb += 1
- } else {
- ng += 1
- }
- if (prev === 0 || next === 0)
- b += 1
- if (prev === 1 || next === 1)
- g += 1
- }
- return {arr, nb, ng, b, g}
- }
- function check(n) {
- let upper = Math.pow(2, n) - 1
- for (let i = 0; i < upper; i++) {
- let x = calc(conv(i, n))
- if (x.g === 24 && x.b === 20) {
- console.log(JSON.stringify(x.arr))
- }
- }
- }
- check(30)
- /*
- [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]
- [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]
- [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]
- [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1]
- [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1]
- [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1]
- [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,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