Sha256: 9d2f7c5fd23c8524951e388d533bdc5953d03fa136da0978448ec4d5f229e6d3

Contents?: true

Size: 645 Bytes

Versions: 188

Compression:

Stored size: 645 Bytes

Contents

import java.math.BigInteger

private const val SQUARE_COUNT = 64
private const val INVALID_SQUARE_NUMBER_MESSAGE = "Only integers between 1 and $SQUARE_COUNT (inclusive) are allowed"

object Board {

    fun getGrainCountForSquare(number: Int): BigInteger {
        require(number > 0)             { INVALID_SQUARE_NUMBER_MESSAGE }
        require(number <= SQUARE_COUNT) { INVALID_SQUARE_NUMBER_MESSAGE }

        return BigInteger.valueOf(2).pow(number - 1)
    }

    fun getTotalGrainCount(): BigInteger {
        return (1..SQUARE_COUNT)
            .map { getGrainCountForSquare(it) }
            .reduce { i1, i2 -> i1.add(i2) }
    }

}

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.138 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.137 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.136 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.135 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.134 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.133 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.132 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.131 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.130 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.129 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.128 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.127 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.126 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.125 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.124 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.123 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.122 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.121 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt
trackler-2.2.1.120 tracks/kotlin/exercises/grains/.meta/src/reference/kotlin/Board.kt