diff --git a/Programming/Kotlin/DesignHitCounter/DesignHitCounter.kt b/Programming/Kotlin/DesignHitCounter/DesignHitCounter.kt new file mode 100644 index 0000000..3e00d27 --- /dev/null +++ b/Programming/Kotlin/DesignHitCounter/DesignHitCounter.kt @@ -0,0 +1,23 @@ +package com.example.testapp + +fun main(){ + //Making an input as the question suggests doesn't really make any sense. + val hitCounter = HitCounter() + hitCounter.hit(1) + hitCounter.hit(2) + hitCounter.hit(3) + println(hitCounter.getHits(4)) + hitCounter.hit(300) + println(hitCounter.getHits(300)) + println(hitCounter.getHits(301)) +} + +class HitCounter { + private val hits = arrayListOf() + + fun hit(timestamp: Int) = hits.add(timestamp) + + fun getHits(timestamp: Int) : Int = hits.count { + it in (timestamp - 300 + 1)..timestamp + } +} \ No newline at end of file