Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import _ from 'lodash'
- import loadData from '../../helpers/loadData.mjs'
- const inputData = loadData('./data.txt').map((line) => line.split('-'))
- // console.log(inputData)
- const net = new Map()
- for(const [a,b] of inputData) {
- if(!net.has(a)) net.set(a, [])
- if(!net.has(b)) net.set(b, [])
- net.get(a).push(b)
- net.get(b).push(a)
- }
- // console.log(net)
- let found = new Set()
- for(let [key1, conn1] of net.entries()) {
- const cc = [key1, ...conn1]
- const other = conn1.map((key2) => [key2, ...net.get(key2)])
- const w = other.map((s) => _.intersection(cc, s).length)
- const maxw = _.max(w)
- if(w.filter(v => v === maxw).length < maxw - 1) continue
- if(maxw < found.size) continue
- let base = [...cc]
- for(let i = 0; i < other.length && base.length >= maxw; i++) {
- if(w[i] !== maxw) continue
- base = _.intersection(base, other[i])
- }
- if(base.length < maxw) continue
- const res = new Set(base.sort())
- if(_.isEqual(found, res)) continue
- found = res
- }
- console.log(Array.from(found).join(','))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement