Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package day19
- import collection.mutable.ArrayBuffer
- object Prog extends App {
- def solveSimple(n: Int) = {
- val value = n - Integer.highestOneBit(n);
- 2 * value + 1;
- }
- def solve(n: Int) = {
- val left = ArrayBuffer[Int]()
- val right = ArrayBuffer[Int]()
- for (i <- 1 to n) {
- if (i < (n / 2).toInt + 1) left += i
- else i +=: right
- }
- while (left.nonEmpty && right.nonEmpty) {
- if (left.length > right.length) {
- left.remove(left.length - 1)
- } else {
- right.remove(right.length - 1)
- }
- left.remove(0) +=: right
- left += right.remove(right.length-1)
- }
- if (left.nonEmpty) left.head else right.head
- }
- println(solveSimple(3012210))
- println(solve(3012210))
- }
Advertisement
Add Comment
Please, Sign In to add comment