Advertisement
Aqua_rar

Untitled

Dec 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function f (players, last) {
  2.   let list = [0]
  3.   let scores = Array(players).fill(0)
  4.   let target = 0
  5.   let turn = -1
  6.   for (let i = 1; i <= last; i++) {
  7.     turn = (turn + 1) % players
  8.     let length = list.length
  9.     if (i % 23 === 0) {
  10.       let nt = ((target - 8) % length) + 1
  11.       let score = list.splice(nt, 1)[0] + i
  12.       scores[turn] += score
  13.       target = nt
  14.     } else {
  15.       let nt = ((target + 1) % length) + 1
  16.       list.splice(nt, 0, i)
  17.       target = nt
  18.     }
  19.   }
  20.   return Math.max(...scores)
  21. }
  22.  
  23. console.log('Expect:', 32, 'Got:', f(9, 25)) // Correct
  24. console.log('Expect:', 8317, 'Got:', f(10, 1618)) // Correct
  25. console.log('Expect:', 146373, 'Got:', f(13, 7999)) // Wrong
  26. console.log('Expect:', 2764, 'Got:', f(17, 1104)) // Correct
  27. console.log('Expect:', 54718, 'Got:', f(21, 6111)) // Correct
  28. console.log('Expect:', 37305, 'Got:', f(30, 5807)) // Correct
  29. console.log('Expect:', 0, 'Got:', f(424, 71144)) // Wrong
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement