Drawing Book

  • + 0 comments

    Scala

    def pageCount(n: Int, p: Int): Int = {
         //Sample book: 1 - 2 3 - 4 5 - 6 7 - 8 9 - 10 11
            val lastPage = if(n % 2 == 0) n+1 else n
            val firstPage = 0
            
            val fromFirst: Int = p/2
            val fromLast: Int = (lastPage - p)/2
            
            Array(fromFirst, fromLast).min
        }