val dat = """ ここにdatを入れる! """ // この回数以上書き込んだIDを抽出 const val minCount = 2 fun main() { val lines = dat.trim().lines().drop(1) // 一般的な定時に書き込んでるIDを抽出 val mayMusyokuIdList = lines .mapNotNull { line -> val (hour, id) = Regex(""".*?<>.*?<>.*?(\d{2}):.*?(ID:.+)<>.*?<>""") .find(line.trim()) ?.destructured ?: return@mapNotNull null if (hour.toIntOrNull() in 9..11 || hour.toIntOrNull() in 13..17) { id } else { null } } // 出現回数 val musyokuIdList = mayMusyokuIdList .groupingBy { it } .eachCount() .filter { it.value >= minCount } .toList() .sortedByDescending { it.second } // テキストに val result = buildString { append("9時〜18時の書き込みID一覧($minCount 回以上):\n\n") musyokuIdList.forEach { (id, count) -> append("$count 回 $id\n") } } println(result) }