<commit_before>package leetcode

/**
 * https://leetcode.com/problems/count-lattice-points-inside-a-circle/
 */
class Problem2249 {
    fun countLatticePoints(circles: Array<IntArray>): Int {
        val points = mutableSetOf<Point>()
        for (circle in circles) {
            latticePoints(circle, points)
        }
        return points.size
    }

    private data class Point(val x: Int, val y: Int)

    private fun latticePoints(circle: IntArray, points: MutableSet<Point>) {
        val (x, y, r) = circle
        // Center
        for (i in x - r..x + r) {
            points += Point(i, y)
        }
        // Top
        var k = r - 1
        for (j in y + 1..y + r) {
            for (i in x - k..x + k) {
                points += Point(i, j)
            }
            k--
        }
        // Bottom
        k = r - 1
        for (j in y - 1 downTo y - r) {
            for (i in x - k..x + k) {
                points += Point(i, j)
            }
            k--
        }
    }
}

fun main() {
    val prob = Problem2249()
    println(prob.countLatticePoints(arrayOf(intArrayOf(2,2,1)))) // 5
    println(prob.countLatticePoints(arrayOf(intArrayOf(2,2,2), intArrayOf(3,4,1)))) // 16
    println(prob.countLatticePoints(arrayOf(intArrayOf(2,2,2), intArrayOf(3,5,1)))) // 18
    println(prob.countLatticePoints(arrayOf(
        intArrayOf(8,9,6),
        intArrayOf(9,8,4),
        intArrayOf(4,1,1),
        intArrayOf(8,5,1),
        intArrayOf(7,1,1),
        intArrayOf(6,7,5),
        intArrayOf(7,1,1),
        intArrayOf(7,1,1),
        intArrayOf(5,5,3)
    ))) // 141
}<commit_msg>Solve problem 2249<commit_after>package leetcode

/**
 * https://leetcode.com/problems/count-lattice-points-inside-a-circle/
 */
class Problem2249 {
    fun countLatticePoints(circles: Array<IntArray>): Int {
        data class Point(val x: Int, val y: Int)
        val points = mutableSetOf<Point>()
        for (circle in circles) {
            val (x, y, r) = circle
            for (i in -r..r) {
                for (j in -r..r) {
                    if (i * i + j * j <= r * r) {
                        points += Point(x + i, y + j)
                    }
                }
            }
        }
        return points.size
    }
}
{'fraction_non_alphanumeric': 0.1429207479964381, 'fraction_numerical': 0.031166518254674976, 'mean_word_length': 1.5621436716077537, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2479307', 'n_tokens_mistral': 802, 'n_tokens_neox': 761, 'n_words': 170}