Skip to content

Instantly share code, notes, and snippets.

@YoussefLagtab
Created July 12, 2018 04:00
Show Gist options
  • Save YoussefLagtab/81ab133e450f5e2bdc69dbe69cda77aa to your computer and use it in GitHub Desktop.
Save YoussefLagtab/81ab133e450f5e2bdc69dbe69cda77aa to your computer and use it in GitHub Desktop.
let campus = [
{
N: 4,
K: 1,
V: 3,
A: [
{ name: 'LikeSign', popularity: 4, visits: 0 },
{ name: 'Arcade', popularity: 3, visits: 0 },
{ name: 'SweetStop', popularity: 2, visits: 0 },
{ name: 'SwagStore', popularity: 1, visits: 0 }
]
},
{
N: 4,
K: 4,
V: 100,
A: [
{ name: 'FoxGazebo', popularity: 4, visits: 0 },
{ name: 'MPK20Roof', popularity: 3, visits: 0 },
{ name: 'WoodenSculpture', popularity: 2, visits: 0 },
{ name: 'Biryani', popularity: 1, visits: 0 }
]
},
{
N: 4,
K: 3,
V: 1,
A: [
{ name: 'LikeSign', popularity: 4, visits: 0 },
{ name: 'Arcade', popularity: 3, visits: 0 },
{ name: 'SweetStop', popularity: 2, visits: 0 },
{ name: 'SwagStore', popularity: 1, visits: 0 }
]
},
{
N: 4,
K: 3,
V: 3,
A: [
{ name: 'LikeSign', popularity: 4, visits: 0 },
{ name: 'Arcade', popularity: 3, visits: 0 },
{ name: 'SweetStop', popularity: 2, visits: 0 },
{ name: 'SwagStore', popularity: 1, visits: 0 }
]
},
{
N: 4,
K: 3,
V: 10,
A: [
{ name: 'LikeSign', popularity: 4, visits: 0 },
{ name: 'Arcade', popularity: 3, visits: 0 },
{ name: 'SweetStop', popularity: 2, visits: 0 },
{ name: 'SwagStore', popularity: 1, visits: 0 }
]
},
{
N: 2,
K: 1,
V: 1000000000000,
A: [
{ name: 'RainbowStairs', popularity: 2, visits: 0 },
{ name: 'WallOfPhones', popularity: 1, visits: 0 }
]
}
]
// console.log(campus.length)
for (let a in campus) {
let c = campus[a]
let kSelected = new Array(c.K)
let attrac = c.A
for (i = 1; i <= c.V; i++) {
attrac.sort((a, b) => {
if (a.visits === b.visits) return b.popularity - a.popularity
return a.visits - b.visits
})
for (j = 0; j < kSelected.length; j++) {
kSelected[j] = attrac[j].name
attrac[j].visits++
}
}
console.log('Case #' + (a+1) + ': ' + kSelected.join(' '))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment