package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12926
 *
 * 시저 암호
 * 문제 설명
 * 어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식을 시저 암호라고 합니다.
 * 예를 들어 "AB"는 1만큼 밀면 "BC"가 되고, 3만큼 밀면 "DE"가 됩니다.
 * "z"는 1만큼 밀면 "a"가 됩니다.
 * 문자열 s와 거리 n을 입력받아 s를 n만큼 민 암호문을 만드는 함수, solution을 완성해 보세요.
 *
 * 제한 조건
 * 공백은 아무리 밀어도 공백입니다.
 * s는 알파벳 소문자, 대문자, 공백으로만 이루어져 있습니다.
 * s의 길이는 8000이하입니다.
 * n은 1 이상, 25이하인 자연수입니다.
 * 입출력 예
 * s	        n	    result
 * "AB"	        1	    "BC"
 * "z"	        1	    "a"
 * "a B z"	    4	    "e F d"
 */

fun main() {
//    println(solution("a b y Z", 2))
    solution("a b y Z", 2)
}

private fun solution(s: String, n: Int): String {
    var answer = ""
    // " " = 32
    // a = 97, z = 122
    // A = 65, Z = 90
    for (char in s) {
        println(" - - - - - start - - - - - ")
        println("char = $char, ascii = ${char.toInt()}")

        if (isLowerCase(char.toInt())) {
            println("isLowerCase")
            if (isLowerCase(char.toInt() + n)) {
                answer += (char.toInt() + n).toChar()
            } else {
                println("LowerCase err, char.toInt() + n = ${char.toInt() + n}, ${(char.toInt() + n).toChar()} ")
                println("char.toInt() + n = ${char.toInt() + n}")
                println("${(96 + (char.toInt() + n).toInt() - 122).toChar()}")
                answer += (96 + (char.toInt() + n).toInt() - 122).toChar()
            }
        }

        if (isUpperCase(char.toInt())) {
            println("isUpperCase")
            if (isUpperCase(char.toInt() + n)) {
                answer += (char.toInt() + n).toChar()
            } else {
                println("UpperCase err, char.toInt() + n = ${char.toInt() + n}, ${(char.toInt() + n).toChar()} ")
                println("char.toInt() + n = ${char.toInt() + n}")
                println("${(64 + (char.toInt() + n).toInt() - 90).toChar()}")
                answer += (64 + (char.toInt() + n).toInt() - 90).toChar()
            }
        }

        if (char.toInt() == 32) {
            println("is ")
            answer += " "
        }
        println("answer = $answer")
    }

    return answer
}

private fun isLowerCase(ascii: Int): Boolean {
    return ascii in 97 .. 122
}

private fun isUpperCase(ascii: Int): Boolean {
    return ascii in 65..90
}

Compiled from "Lv1_12926.kt"
public final class main.kotlin.programmers.lv01.Lv1_12926Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String a b y Z
       2: iconst_2
       3: invokestatic  #12                 // Method solution:(Ljava/lang/String;I)Ljava/lang/String;
       6: pop
       7: return

  private static final java.lang.String solution(java.lang.String, int);
    Code:
       0: ldc           #14                 // String
       2: astore_2
       3: iconst_0
       4: istore_3
       5: aload_0
       6: invokevirtual #20                 // Method java/lang/String.length:()I
       9: istore        4
      11: iload_3
      12: iload         4
      14: if_icmpge     496
      17: aload_0
      18: iload_3
      19: invokevirtual #24                 // Method java/lang/String.charAt:(I)C
      22: istore        5
      24: ldc           #26                 // String  - - - - - start - - - - -
      26: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
      29: swap
      30: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      33: new           #40                 // class java/lang/StringBuilder
      36: dup
      37: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
      40: ldc           #45                 // String char =
      42: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      45: iload         5
      47: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      50: ldc           #54                 // String , ascii =
      52: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      55: iload         5
      57: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      60: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
      66: swap
      67: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      70: iload         5
      72: invokestatic  #65                 // Method isLowerCase:(I)Z
      75: ifeq          249
      78: ldc           #66                 // String isLowerCase
      80: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: swap
      84: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      87: iload         5
      89: iload_1
      90: iadd
      91: invokestatic  #65                 // Method isLowerCase:(I)Z
      94: ifeq          123
      97: new           #40                 // class java/lang/StringBuilder
     100: dup
     101: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     104: aload_2
     105: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     108: iload         5
     110: iload_1
     111: iadd
     112: i2c
     113: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     116: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     119: astore_2
     120: goto          249
     123: new           #40                 // class java/lang/StringBuilder
     126: dup
     127: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     130: ldc           #68                 // String LowerCase err, char.toInt() + n =
     132: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     135: iload         5
     137: iload_1
     138: iadd
     139: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     142: ldc           #70                 // String ,
     144: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     147: iload         5
     149: iload_1
     150: iadd
     151: i2c
     152: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     155: bipush        32
     157: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     160: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     163: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     166: swap
     167: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     170: new           #40                 // class java/lang/StringBuilder
     173: dup
     174: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     177: ldc           #72                 // String char.toInt() + n =
     179: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     182: iload         5
     184: iload_1
     185: iadd
     186: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     189: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     192: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     195: swap
     196: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     199: bipush        96
     201: iload         5
     203: iload_1
     204: iadd
     205: iadd
     206: bipush        122
     208: isub
     209: i2c
     210: invokestatic  #76                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     213: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     216: swap
     217: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     220: new           #40                 // class java/lang/StringBuilder
     223: dup
     224: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     227: aload_2
     228: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     231: bipush        96
     233: iload         5
     235: iload_1
     236: iadd
     237: iadd
     238: bipush        122
     240: isub
     241: i2c
     242: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     245: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     248: astore_2
     249: iload         5
     251: invokestatic  #79                 // Method isUpperCase:(I)Z
     254: ifeq          428
     257: ldc           #80                 // String isUpperCase
     259: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     262: swap
     263: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     266: iload         5
     268: iload_1
     269: iadd
     270: invokestatic  #79                 // Method isUpperCase:(I)Z
     273: ifeq          302
     276: new           #40                 // class java/lang/StringBuilder
     279: dup
     280: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     283: aload_2
     284: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     287: iload         5
     289: iload_1
     290: iadd
     291: i2c
     292: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     295: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     298: astore_2
     299: goto          428
     302: new           #40                 // class java/lang/StringBuilder
     305: dup
     306: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     309: ldc           #82                 // String UpperCase err, char.toInt() + n =
     311: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     314: iload         5
     316: iload_1
     317: iadd
     318: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     321: ldc           #70                 // String ,
     323: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     326: iload         5
     328: iload_1
     329: iadd
     330: i2c
     331: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     334: bipush        32
     336: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     339: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     342: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     345: swap
     346: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     349: new           #40                 // class java/lang/StringBuilder
     352: dup
     353: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     356: ldc           #72                 // String char.toInt() + n =
     358: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     361: iload         5
     363: iload_1
     364: iadd
     365: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     368: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     371: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     374: swap
     375: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     378: bipush        64
     380: iload         5
     382: iload_1
     383: iadd
     384: iadd
     385: bipush        90
     387: isub
     388: i2c
     389: invokestatic  #76                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     392: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     395: swap
     396: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     399: new           #40                 // class java/lang/StringBuilder
     402: dup
     403: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     406: aload_2
     407: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     410: bipush        64
     412: iload         5
     414: iload_1
     415: iadd
     416: iadd
     417: bipush        90
     419: isub
     420: i2c
     421: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     424: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     427: astore_2
     428: iload         5
     430: bipush        32
     432: if_icmpne     464
     435: ldc           #84                 // String is
     437: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     440: swap
     441: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     444: new           #40                 // class java/lang/StringBuilder
     447: dup
     448: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     451: aload_2
     452: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     455: bipush        32
     457: invokevirtual #52                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     460: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     463: astore_2
     464: new           #40                 // class java/lang/StringBuilder
     467: dup
     468: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
     471: ldc           #86                 // String answer =
     473: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     476: aload_2
     477: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     480: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     483: getstatic     #32                 // Field java/lang/System.out:Ljava/io/PrintStream;
     486: swap
     487: invokevirtual #38                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     490: iinc          3, 1
     493: goto          11
     496: aload_2
     497: areturn

  private static final boolean isLowerCase(int);
    Code:
       0: bipush        97
       2: iload_0
       3: if_icmpgt     20
       6: iload_0
       7: bipush        123
       9: if_icmpge     16
      12: iconst_1
      13: goto          21
      16: iconst_0
      17: goto          21
      20: iconst_0
      21: ireturn

  private static final boolean isUpperCase(int);
    Code:
       0: bipush        65
       2: iload_0
       3: if_icmpgt     20
       6: iload_0
       7: bipush        91
       9: if_icmpge     16
      12: iconst_1
      13: goto          21
      16: iconst_0
      17: goto          21
      20: iconst_0
      21: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #97                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12918
 *
 * 문자열 다루기 기본
 * 문제 설명
 * 문자열 s의 길이가 4 혹은 6이고, 숫자로만 구성돼있는지 확인해주는 함수, solution을 완성하세요.
 * 예를 들어 s가 "a234"이면 False를 리턴하고 "1234"라면 True를 리턴하면 됩니다.
 *
 * 제한 사항
 * s는 길이 1 이상, 길이 8 이하인 문자열입니다.
 * s는 영문 알파벳 대소문자 또는 0부터 9까지 숫자로 이루어져 있습니다.
 * 입출력 예
 * s	return
 * "a234"	false
 * "1234"	true
 *
 */

fun main() {
    println(solution("a234"))
    println(solution("1234"))
}
private fun solution(s: String): Boolean {
    return (s.length == 4 || s.length == 6) && isNumericString(s)
}

private fun isNumericString(s: String): Boolean {
    val regex = Regex("""^\d+$""")
    return regex.matches(s)
}

private fun solution_1(s: String) = (s.length == 4 || s.length == 6) && s.toIntOrNull() != null

Compiled from "Lv1_12918.kt"
public final class main.kotlin.programmers.lv01.Lv1_12918Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String a234
       2: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Z
       5: istore_0
       6: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       9: iload_0
      10: invokevirtual #24                 // Method java/io/PrintStream.println:(Z)V
      13: ldc           #26                 // String 1234
      15: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Z
      18: istore_0
      19: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      22: iload_0
      23: invokevirtual #24                 // Method java/io/PrintStream.println:(Z)V
      26: return

  private static final boolean solution(java.lang.String);
    Code:
       0: aload_0
       1: invokevirtual #32                 // Method java/lang/String.length:()I
       4: iconst_4
       5: if_icmpeq     17
       8: aload_0
       9: invokevirtual #32                 // Method java/lang/String.length:()I
      12: bipush        6
      14: if_icmpne     28
      17: aload_0
      18: invokestatic  #35                 // Method isNumericString:(Ljava/lang/String;)Z
      21: ifeq          28
      24: iconst_1
      25: goto          29
      28: iconst_0
      29: ireturn

  private static final boolean isNumericString(java.lang.String);
    Code:
       0: new           #39                 // class kotlin/text/Regex
       3: dup
       4: ldc           #41                 // String ^\\d+$
       6: invokespecial #45                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: aload_1
      11: aload_0
      12: checkcast     #47                 // class java/lang/CharSequence
      15: invokevirtual #51                 // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      18: ireturn

  private static final boolean solution_1(java.lang.String);
    Code:
       0: aload_0
       1: invokevirtual #32                 // Method java/lang/String.length:()I
       4: iconst_4
       5: if_icmpeq     17
       8: aload_0
       9: invokevirtual #32                 // Method java/lang/String.length:()I
      12: bipush        6
      14: if_icmpne     28
      17: aload_0
      18: invokestatic  #60                 // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      21: ifnull        28
      24: iconst_1
      25: goto          29
      28: iconst_0
      29: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #63                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12950
 *
 * 행렬의 덧셈
 * 문제 설명
 * 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다.
 * 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요.
 *
 * 제한 조건
 * 행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않습니다.
 * 입출력 예
 * arr1	            arr2	        return
 * [[1,2],[2,3]]	[[3,4],[5,6]]	[[4,6],[7,9]]
 * [[1],[2]]	    [[3],[4]]	    [[4],[6]]
 */

fun main() {
    solution(arrayOf(intArrayOf(1,2), intArrayOf(2,3)), arrayOf(intArrayOf(3,4), intArrayOf(5,6)))
}

private fun solution(arr1: Array<IntArray>, arr2: Array<IntArray>): Array<IntArray> {
    val rowSize = arr1.size
    val colSize = arr1[0].size
    val answer = Array(rowSize) { IntArray(colSize) }

    for (i in 0 until rowSize) {
        for (j in 0 until colSize) {
            answer[i][j] = arr1[i][j] + arr2[i][j]
        }
    }

    return answer
}

Compiled from "Lv1_12950.kt"
public final class main.kotlin.programmers.lv01.Lv1_12950Kt {
  public static final void main();
    Code:
       0: iconst_2
       1: anewarray     #8                  // class "[I"
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_2
       8: newarray       int
      10: astore_1
      11: aload_1
      12: iconst_0
      13: iconst_1
      14: iastore
      15: aload_1
      16: iconst_1
      17: iconst_2
      18: iastore
      19: aload_1
      20: aastore
      21: aload_0
      22: iconst_1
      23: iconst_2
      24: newarray       int
      26: astore_1
      27: aload_1
      28: iconst_0
      29: iconst_2
      30: iastore
      31: aload_1
      32: iconst_1
      33: iconst_3
      34: iastore
      35: aload_1
      36: aastore
      37: aload_0
      38: iconst_2
      39: anewarray     #8                  // class "[I"
      42: astore_0
      43: aload_0
      44: iconst_0
      45: iconst_2
      46: newarray       int
      48: astore_1
      49: aload_1
      50: iconst_0
      51: iconst_3
      52: iastore
      53: aload_1
      54: iconst_1
      55: iconst_4
      56: iastore
      57: aload_1
      58: aastore
      59: aload_0
      60: iconst_1
      61: iconst_2
      62: newarray       int
      64: astore_1
      65: aload_1
      66: iconst_0
      67: iconst_5
      68: iastore
      69: aload_1
      70: iconst_1
      71: bipush        6
      73: iastore
      74: aload_1
      75: aastore
      76: aload_0
      77: invokestatic  #12                 // Method solution:([[I[[I)[[I
      80: pop
      81: return

  private static final int[][] solution(int[][], int[][]);
    Code:
       0: aload_0
       1: checkcast     #14                 // class "[Ljava/lang/Object;"
       4: arraylength
       5: istore_2
       6: aload_0
       7: iconst_0
       8: aaload
       9: arraylength
      10: istore_3
      11: iconst_0
      12: istore        5
      14: iload_2
      15: anewarray     #8                  // class "[I"
      18: astore        6
      20: iload         5
      22: iload_2
      23: if_icmpge     44
      26: iload         5
      28: istore        7
      30: aload         6
      32: iload         7
      34: iload_3
      35: newarray       int
      37: aastore
      38: iinc          5, 1
      41: goto          20
      44: aload         6
      46: astore        4
      48: iconst_0
      49: istore        5
      51: iload         5
      53: iload_2
      54: if_icmpge     101
      57: iconst_0
      58: istore        6
      60: iload         6
      62: iload_3
      63: if_icmpge     95
      66: aload         4
      68: iload         5
      70: aaload
      71: iload         6
      73: aload_0
      74: iload         5
      76: aaload
      77: iload         6
      79: iaload
      80: aload_1
      81: iload         5
      83: aaload
      84: iload         6
      86: iaload
      87: iadd
      88: iastore
      89: iinc          6, 1
      92: goto          60
      95: iinc          5, 1
      98: goto          51
     101: aload         4
     103: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #27                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12940
 *
 * 최대공약수와 최소공배수
 * 문제 설명
 * 두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요.
 * 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다.
 * 예를 들어 두 수 3, 12의 최대공약수는 3, 최소공배수는 12이므로 solution(3, 12)는 [3, 12]를 반환해야 합니다.
 *
 * 제한 사항
 * 두 수는 1이상 1000000이하의 자연수입니다.
 * 입출력 예
 * n	m	return
 * 3	12	[3, 12]
 * 2	5	[1, 10]
 * 입출력 예 설명
 * 입출력 예 #1
 * 위의 설명과 같습니다.
 *
 * 입출력 예 #2
 * 자연수 2와 5의 최대공약수는 1, 최소공배수는 10이므로 [1, 10]을 리턴해야 합니다.
 */

fun main() {
    solution(3, 12)
    println(" - - - - - - - - - - ")
    solution(2, 5)
}

private fun solution(n: Int, m: Int): IntArray {
    var answer = intArrayOf(0, 0)

    answer[0] = findGCD(n, m)
    answer[1] = findLCM(n, m)

    println(answer.toList())

    return answer
}

private fun findGCD(a: Int, b: Int): Int {
    return if (b == 0) {
        a
    } else {
        findGCD(b, a % b)
    }
}

private fun findLCM(a: Int, b: Int): Int {
    val gcd = findGCD(a, b)
    return a * b / gcd
}

Compiled from "Lv1_12940.kt"
public final class main.kotlin.programmers.lv01.Lv1_12940Kt {
  public static final void main();
    Code:
       0: iconst_3
       1: bipush        12
       3: invokestatic  #10                 // Method solution:(II)[I
       6: pop
       7: ldc           #12                 // String  - - - - - - - - - -
       9: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      12: swap
      13: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      16: iconst_2
      17: iconst_5
      18: invokestatic  #10                 // Method solution:(II)[I
      21: pop
      22: return

  private static final int[] solution(int, int);
    Code:
       0: iconst_2
       1: newarray       int
       3: astore_3
       4: aload_3
       5: iconst_0
       6: iconst_0
       7: iastore
       8: aload_3
       9: iconst_1
      10: iconst_0
      11: iastore
      12: aload_3
      13: astore_2
      14: aload_2
      15: iconst_0
      16: iload_0
      17: iload_1
      18: invokestatic  #28                 // Method findGCD:(II)I
      21: iastore
      22: aload_2
      23: iconst_1
      24: iload_0
      25: iload_1
      26: invokestatic  #31                 // Method findLCM:(II)I
      29: iastore
      30: aload_2
      31: invokestatic  #37                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
      34: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      37: swap
      38: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      41: aload_2
      42: areturn

  private static final int findGCD(int, int);
    Code:
       0: iload_1
       1: ifne          8
       4: iload_0
       5: goto          15
       8: iload_1
       9: iload_0
      10: iload_1
      11: irem
      12: invokestatic  #28                 // Method findGCD:(II)I
      15: ireturn

  private static final int findLCM(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: invokestatic  #28                 // Method findGCD:(II)I
       5: istore_2
       6: iload_0
       7: iload_1
       8: imul
       9: iload_2
      10: idiv
      11: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #48                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/68935
 *
 * 3진법 뒤집기
 * 문제 설명
 * 자연수 n이 매개변수로 주어집니다.
 * n을 3진법 상에서 앞뒤로 뒤집은 후, 이를 다시 10진법으로 표현한 수를 return 하도록 solution 함수를 완성해주세요.
 *
 * 제한사항
 * n은 1 이상 100,000,000 이하인 자연수입니다.
 * 입출력 예
 * n	result
 * 45	7
 * 125	229
 * 입출력 예 설명
 * 입출력 예 #1
 *
 * 답을 도출하는 과정은 다음과 같습니다.
 * n (10진법)	n (3진법)	앞뒤 반전(3진법)	10진법으로 표현
 * 45	        1200	    0021	        7
 * 따라서 7을 return 해야 합니다.
 * 입출력 예 #2
 *
 * 답을 도출하는 과정은 다음과 같습니다.
 * n (10진법)	n (3진법)	앞뒤 반전(3진법)	10진법으로 표현
 * 125	        11122	    22111	        229
 * 따라서 229를 return 해야 합니다.
 */

fun main() {
    solution(45)
}
private fun solution(n: Int): Int {
    return Integer.parseInt(n.toString(3).reversed(), 3)
}

private fun solution_1(n: Int): Int {
    return n.toString(3).reversed().toInt(10)
}

Compiled from "Lv1_68935.kt"
public final class main.kotlin.programmers.lv01.Lv1_68935Kt {
  public static final void main();
    Code:
       0: bipush        45
       2: invokestatic  #10                 // Method solution:(I)I
       5: pop
       6: return

  private static final int solution(int);
    Code:
       0: nop
       1: iload_0
       2: iconst_3
       3: invokestatic  #15                 // Method kotlin/text/CharsKt.checkRadix:(I)I
       6: invokestatic  #21                 // Method java/lang/Integer.toString:(II)Ljava/lang/String;
       9: dup
      10: ldc           #23                 // String toString(...)
      12: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      15: checkcast     #31                 // class java/lang/CharSequence
      18: invokestatic  #37                 // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      21: invokevirtual #40                 // Method java/lang/Object.toString:()Ljava/lang/String;
      24: iconst_3
      25: invokestatic  #44                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      28: ireturn

  private static final int solution_1(int);
    Code:
       0: nop
       1: iload_0
       2: iconst_3
       3: invokestatic  #15                 // Method kotlin/text/CharsKt.checkRadix:(I)I
       6: invokestatic  #21                 // Method java/lang/Integer.toString:(II)Ljava/lang/String;
       9: dup
      10: ldc           #23                 // String toString(...)
      12: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      15: checkcast     #31                 // class java/lang/CharSequence
      18: invokestatic  #37                 // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      21: invokevirtual #40                 // Method java/lang/Object.toString:()Ljava/lang/String;
      24: bipush        10
      26: invokestatic  #15                 // Method kotlin/text/CharsKt.checkRadix:(I)I
      29: invokestatic  #44                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      32: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #50                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/86051?language=kotlin
 *
 * 문제 설명
 * 0부터 9까지의 숫자 중 일부가 들어있는 정수 배열 numbers가 매개변수로 주어집니다.
 * numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요.
 *
 * 제한사항
 * 1 ≤ numbers의 길이 ≤ 9
 * 0 ≤ numbers의 모든 원소 ≤ 9
 * numbers의 모든 원소는 서로 다릅니다.
 * 입출력 예
 * numbers	result
 * [1,2,3,4,6,7,8,0]	14
 * [5,8,4,0,6,7,9]	6
 * 입출력 예 설명
 * 입출력 예 #1
 *
 * 5, 9가 numbers에 없으므로, 5 + 9 = 14를 return 해야 합니다.
 * 입출력 예 #2
 *
 * 1, 2, 3이 numbers에 없으므로, 1 + 2 + 3 = 6을 return 해야 합니다.
 *
 */

fun main() {
    solution(intArrayOf(1,2,3,4,6,7,8,0))
}

private fun solution(numbers: IntArray): Int {
    var answer: Int = 0

    for (i in 0..9) {
        if (!(numbers.contains(i))) {
            answer += i
        }
    }

    println("answer = $answer")

    return answer
}

private fun solution_1(numbers: IntArray): Int = (0..9).filterNot(numbers::contains).sum()

private fun solution_2(numbers: IntArray): Int  = 45 - numbers.sum()

Compiled from "Lv1_86051.kt"
public final class main.kotlin.programmers.lv01.Lv1_86051Kt {
  public static final void main();
    Code:
       0: bipush        8
       2: newarray       int
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_1
       8: iastore
       9: aload_0
      10: iconst_1
      11: iconst_2
      12: iastore
      13: aload_0
      14: iconst_2
      15: iconst_3
      16: iastore
      17: aload_0
      18: iconst_3
      19: iconst_4
      20: iastore
      21: aload_0
      22: iconst_4
      23: bipush        6
      25: iastore
      26: aload_0
      27: iconst_5
      28: bipush        7
      30: iastore
      31: aload_0
      32: bipush        6
      34: bipush        8
      36: iastore
      37: aload_0
      38: bipush        7
      40: iconst_0
      41: iastore
      42: aload_0
      43: invokestatic  #10                 // Method solution:([I)I
      46: pop
      47: return

  private static final int solution(int[]);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: iload_2
       5: bipush        10
       7: if_icmpge     28
      10: aload_0
      11: iload_2
      12: invokestatic  #16                 // Method kotlin/collections/ArraysKt.contains:([II)Z
      15: ifne          22
      18: iload_1
      19: iload_2
      20: iadd
      21: istore_1
      22: iinc          2, 1
      25: goto          4
      28: new           #18                 // class java/lang/StringBuilder
      31: dup
      32: invokespecial #21                 // Method java/lang/StringBuilder."<init>":()V
      35: ldc           #23                 // String answer =
      37: invokevirtual #27                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      40: iload_1
      41: invokevirtual #30                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      44: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      47: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      50: swap
      51: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      54: iload_1
      55: ireturn

  private static final int solution_1(int[]);
    Code:
       0: new           #54                 // class kotlin/ranges/IntRange
       3: dup
       4: iconst_0
       5: bipush        9
       7: invokespecial #57                 // Method kotlin/ranges/IntRange."<init>":(II)V
      10: checkcast     #59                 // class java/lang/Iterable
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_1
      17: astore_3
      18: new           #61                 // class java/util/ArrayList
      21: dup
      22: invokespecial #62                 // Method java/util/ArrayList."<init>":()V
      25: checkcast     #64                 // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          95
      51: aload         6
      53: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         7
      62: checkcast     #80                 // class java/lang/Number
      65: invokevirtual #84                 // Method java/lang/Number.intValue:()I
      68: istore        8
      70: iconst_0
      71: istore        9
      73: aload_0
      74: iload         8
      76: invokestatic  #16                 // Method kotlin/collections/ArraysKt.contains:([II)Z
      79: ifne          41
      82: aload         4
      84: aload         7
      86: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      91: pop
      92: goto          41
      95: aload         4
      97: checkcast     #90                 // class java/util/List
     100: nop
     101: checkcast     #59                 // class java/lang/Iterable
     104: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     107: ireturn

  private static final int solution_2(int[]);
    Code:
       0: bipush        45
       2: aload_0
       3: invokestatic  #112                // Method kotlin/collections/ArraysKt.sum:([I)I
       6: isub
       7: ireturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #115                // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

import kotlin.math.pow
import kotlin.math.sqrt

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12934
 *
 * 문제 설명
 * 임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다.
 * n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함수를 완성하세요.
 *
 * 제한 사항
 * n은 1이상, 50000000000000 이하인 양의 정수입니다.
 * 입출력 예
 * n	return
 * 121	144
 * 3	-1
 * 입출력 예 설명
 * 입출력 예#1
 * 121은 양의 정수 11의 제곱이므로, (11+1)를 제곱한 144를 리턴합니다.
 *
 * 입출력 예#2
 * 3은 양의 정수의 제곱이 아니므로, -1을 리턴합니다.
 *
 */

fun main() {
    println("result = ${solution(12)}")
    println("result = ${solution(13)}")
    println("result = ${solution(121)}")
    println("result = ${solution(3)}")
}

private fun solution(n: Long): Long{
    var answer:Long = 0
    val sqrt = sqrt(n.toDouble()).toLong()
    println("n = $n , sqrt = $sqrt")

    answer = if (sqrt * sqrt == n) {
        (sqrt + 1).toDouble().pow(2.0).toLong()
    } else {
        -1
    }
    return answer

}

Compiled from "Lv1_12934_square.kt"
public final class main.kotlin.programmers.lv01.Lv1_12934_squareKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/lang/StringBuilder
       3: dup
       4: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #13                 // String result =
       9: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: ldc2_w        #18                 // long 12l
      15: invokestatic  #23                 // Method solution:(J)J
      18: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      21: invokevirtual #30                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      24: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      27: swap
      28: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      31: new           #8                  // class java/lang/StringBuilder
      34: dup
      35: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
      38: ldc           #13                 // String result =
      40: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      43: ldc2_w        #43                 // long 13l
      46: invokestatic  #23                 // Method solution:(J)J
      49: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      52: invokevirtual #30                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      55: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      58: swap
      59: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      62: new           #8                  // class java/lang/StringBuilder
      65: dup
      66: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
      69: ldc           #13                 // String result =
      71: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      74: ldc2_w        #45                 // long 121l
      77: invokestatic  #23                 // Method solution:(J)J
      80: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      83: invokevirtual #30                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      86: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      89: swap
      90: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      93: new           #8                  // class java/lang/StringBuilder
      96: dup
      97: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
     100: ldc           #13                 // String result =
     102: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     105: ldc2_w        #47                 // long 3l
     108: invokestatic  #23                 // Method solution:(J)J
     111: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     114: invokevirtual #30                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     117: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
     120: swap
     121: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     124: return

  private static final long solution(long);
    Code:
       0: lconst_0
       1: lstore_2
       2: lload_0
       3: l2d
       4: invokestatic  #54                 // Method java/lang/Math.sqrt:(D)D
       7: d2l
       8: lstore        4
      10: new           #8                  // class java/lang/StringBuilder
      13: dup
      14: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
      17: ldc           #56                 // String n =
      19: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: lload_0
      23: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      26: ldc           #58                 // String  , sqrt =
      28: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      31: lload         4
      33: invokevirtual #26                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      36: invokevirtual #30                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      42: swap
      43: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      46: lload         4
      48: lload         4
      50: lmul
      51: lload_0
      52: lcmp
      53: ifne          71
      56: lload         4
      58: lconst_1
      59: ladd
      60: l2d
      61: ldc2_w        #59                 // double 2.0d
      64: invokestatic  #64                 // Method java/lang/Math.pow:(DD)D
      67: d2l
      68: goto          74
      71: ldc2_w        #65                 // long -1l
      74: lstore_2
      75: lload_2
      76: lreturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #72                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

import kotlin.math.ceil
import kotlin.math.sqrt

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12928
 *
 * 문제 설명
 * 정수 n을 입력받아 n의 약수를 모두 더한 값을 리턴하는 함수, solution을 완성해주세요.
 *
 * 제한 사항
 * n은 0 이상 3000이하인 정수입니다.
 * 입출력 예
 * n	return
 * 12	28
 * 5	6
 * 입출력 예 설명
 * 입출력 예 #1
 * 12의 약수는 1, 2, 3, 4, 6, 12입니다. 이를 모두 더하면 28입니다.
 *
 * 입출력 예 #2
 * 5의 약수는 1, 5입니다. 이를 모두 더하면 6입니다.
 */

private fun findDivisors(number: Int): List<Int> {
    val divisors = mutableListOf<Int>()
    if (number == 1) {
        divisors.add(1)
    }
    val sqrt = ceil(sqrt(number.toDouble())).toInt()
    println("get number = $number , sqrt = $sqrt")

    for (i in 1 until sqrt) {
        if (number % i == 0) {
            divisors.add(i)
            divisors.add(number / i)
        }
    }
    if(sqrt * sqrt == number) {
        divisors.add(sqrt)
    }

    return divisors
}

private fun solution(n: Int): Int {
    if (n == 1) return 1

    var answer = 0
    val sqrt = ceil(sqrt(n.toDouble())).toInt()

    for (i in 1 until sqrt) {
        if (n % i == 0) {
            answer += i
            answer += (n / i)
        }
    }

    if(sqrt * sqrt == n) {
        answer += sqrt
    }

    return answer
}

fun main() {
    println("findDivisors(0) = ${findDivisors(0).sorted()}")
    println("input = 0, result = ${solution(0)}")
    println(" * * * * * ")
    println("findDivisors(1) = ${findDivisors(1).sorted()}")
    println("input = 1, result = ${solution(1)}")
    println(" * * * * * ")
    println("findDivisors(2) = ${findDivisors(2).sorted()}")
    println("input = 2, result = ${solution(2)}")
    println(" * * * * * ")
    println("findDivisors(16) = ${findDivisors(16).sorted()}")
    println("input = 16, result = ${solution(16)}")
    println(" * * * * * ")
}

Compiled from "Lv1_12928_divisors.kt"
public final class main.kotlin.programmers.lv01.Lv1_12928_divisorsKt {
  private static final java.util.List<java.lang.Integer> findDivisors(int);
    Code:
       0: new           #9                  // class java/util/ArrayList
       3: dup
       4: invokespecial #13                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #15                 // class java/util/List
      10: astore_1
      11: iload_0
      12: iconst_1
      13: if_icmpne     27
      16: aload_1
      17: iconst_1
      18: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: invokeinterface #25,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      26: pop
      27: iload_0
      28: i2d
      29: invokestatic  #31                 // Method java/lang/Math.sqrt:(D)D
      32: invokestatic  #34                 // Method java/lang/Math.ceil:(D)D
      35: d2i
      36: istore_2
      37: new           #36                 // class java/lang/StringBuilder
      40: dup
      41: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      44: ldc           #39                 // String get number =
      46: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      49: iload_0
      50: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      53: ldc           #48                 // String  , sqrt =
      55: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      58: iload_2
      59: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      62: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      65: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
      68: swap
      69: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      72: iconst_1
      73: istore_3
      74: iload_3
      75: iload_2
      76: if_icmpge     115
      79: iload_0
      80: iload_3
      81: irem
      82: ifne          109
      85: aload_1
      86: iload_3
      87: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: invokeinterface #25,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      95: pop
      96: aload_1
      97: iload_0
      98: iload_3
      99: idiv
     100: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: invokeinterface #25,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     108: pop
     109: iinc          3, 1
     112: goto          74
     115: iload_2
     116: iload_2
     117: imul
     118: iload_0
     119: if_icmpne     133
     122: aload_1
     123: iload_2
     124: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     127: invokeinterface #25,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     132: pop
     133: aload_1
     134: areturn

  private static final int solution(int);
    Code:
       0: iload_0
       1: iconst_1
       2: if_icmpne     7
       5: iconst_1
       6: ireturn
       7: iconst_0
       8: istore_1
       9: iload_0
      10: i2d
      11: invokestatic  #31                 // Method java/lang/Math.sqrt:(D)D
      14: invokestatic  #34                 // Method java/lang/Math.ceil:(D)D
      17: d2i
      18: istore_2
      19: iconst_1
      20: istore_3
      21: iload_3
      22: iload_2
      23: if_icmpge     48
      26: iload_0
      27: iload_3
      28: irem
      29: ifne          42
      32: iload_1
      33: iload_3
      34: iadd
      35: istore_1
      36: iload_1
      37: iload_0
      38: iload_3
      39: idiv
      40: iadd
      41: istore_1
      42: iinc          3, 1
      45: goto          21
      48: iload_2
      49: iload_2
      50: imul
      51: iload_0
      52: if_icmpne     59
      55: iload_1
      56: iload_2
      57: iadd
      58: istore_1
      59: iload_1
      60: ireturn

  public static final void main();
    Code:
       0: new           #36                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #76                 // String findDivisors(0) =
       9: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: iconst_0
      13: invokestatic  #78                 // Method findDivisors:(I)Ljava/util/List;
      16: checkcast     #80                 // class java/lang/Iterable
      19: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      22: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      25: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #36                 // class java/lang/StringBuilder
      38: dup
      39: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      42: ldc           #91                 // String input = 0, result =
      44: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      47: iconst_0
      48: invokestatic  #93                 // Method solution:(I)I
      51: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      54: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      57: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
      60: swap
      61: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      64: ldc           #95                 // String  * * * * *
      66: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: swap
      70: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      73: new           #36                 // class java/lang/StringBuilder
      76: dup
      77: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      80: ldc           #97                 // String findDivisors(1) =
      82: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      85: iconst_1
      86: invokestatic  #78                 // Method findDivisors:(I)Ljava/util/List;
      89: checkcast     #80                 // class java/lang/Iterable
      92: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      95: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      98: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     101: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     104: swap
     105: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     108: new           #36                 // class java/lang/StringBuilder
     111: dup
     112: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
     115: ldc           #99                 // String input = 1, result =
     117: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     120: iconst_1
     121: invokestatic  #93                 // Method solution:(I)I
     124: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     127: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     130: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     133: swap
     134: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     137: ldc           #95                 // String  * * * * *
     139: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     142: swap
     143: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     146: new           #36                 // class java/lang/StringBuilder
     149: dup
     150: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
     153: ldc           #101                // String findDivisors(2) =
     155: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     158: iconst_2
     159: invokestatic  #78                 // Method findDivisors:(I)Ljava/util/List;
     162: checkcast     #80                 // class java/lang/Iterable
     165: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     168: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     171: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     174: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     177: swap
     178: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     181: new           #36                 // class java/lang/StringBuilder
     184: dup
     185: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
     188: ldc           #103                // String input = 2, result =
     190: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     193: iconst_2
     194: invokestatic  #93                 // Method solution:(I)I
     197: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     200: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     203: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     206: swap
     207: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     210: ldc           #95                 // String  * * * * *
     212: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     215: swap
     216: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     219: new           #36                 // class java/lang/StringBuilder
     222: dup
     223: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
     226: ldc           #105                // String findDivisors(16) =
     228: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     231: bipush        16
     233: invokestatic  #78                 // Method findDivisors:(I)Ljava/util/List;
     236: checkcast     #80                 // class java/lang/Iterable
     239: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     242: invokevirtual #89                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     245: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     248: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     251: swap
     252: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     255: new           #36                 // class java/lang/StringBuilder
     258: dup
     259: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
     262: ldc           #107                // String input = 16, result =
     264: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     267: bipush        16
     269: invokestatic  #93                 // Method solution:(I)I
     272: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     275: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     278: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     281: swap
     282: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     285: ldc           #95                 // String  * * * * *
     287: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     290: swap
     291: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     294: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #110                // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12954
 *
 * 문제 설명
 * 함수 solution은 정수 x와 자연수 n을 입력 받아, x부터 시작해 x씩 증가하는 숫자를 n개 지니는 리스트를 리턴해야 합니다.
 * 다음 제한 조건을 보고, 조건을 만족하는 함수, solution을 완성해주세요.
 *
 * 제한 조건
 * x는 -10000000 이상, 10000000 이하인 정수입니다.
 * n은 1000 이하인 자연수입니다.
 * 입출력 예
 * x	n	answer
 * 2	5	[2,4,6,8,10]
 * 4	3	[4,8,12]
 * -4	2	[-4, -8]
 */

fun main() {
    println("result = ${solution(2, 5).toList()}")
    println("result = ${secondSolution(4, 3).toList()}")
    println("result = ${solution(-4, 2).toList()}")
    println("result = ${secondSolution(0, 3).toList()}")
}

private fun solution(x: Int, n: Int): LongArray {
    val answer = LongArray(n)

    for (i in 0 until n) {
        answer[i] = x * (i.toLong() + 1);
    }

    return answer
}

private fun secondSolution(x: Int, n: Int): LongArray = LongArray(n) { i -> x.toLong() * (i+1) }

Compiled from "Lv1_12954_x_n.kt"
public final class main.kotlin.programmers.lv01.Lv1_12954_x_nKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/lang/StringBuilder
       3: dup
       4: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #13                 // String result =
       9: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: iconst_2
      13: iconst_5
      14: invokestatic  #21                 // Method solution:(II)[J
      17: invokestatic  #27                 // Method kotlin/collections/ArraysKt.toList:([J)Ljava/util/List;
      20: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      23: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      26: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      29: swap
      30: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      33: new           #8                  // class java/lang/StringBuilder
      36: dup
      37: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
      40: ldc           #13                 // String result =
      42: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      45: iconst_4
      46: iconst_3
      47: invokestatic  #49                 // Method secondSolution:(II)[J
      50: invokestatic  #27                 // Method kotlin/collections/ArraysKt.toList:([J)Ljava/util/List;
      53: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      56: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: new           #8                  // class java/lang/StringBuilder
      69: dup
      70: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
      73: ldc           #13                 // String result =
      75: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      78: bipush        -4
      80: iconst_2
      81: invokestatic  #21                 // Method solution:(II)[J
      84: invokestatic  #27                 // Method kotlin/collections/ArraysKt.toList:([J)Ljava/util/List;
      87: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      90: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      93: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      96: swap
      97: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     100: new           #8                  // class java/lang/StringBuilder
     103: dup
     104: invokespecial #11                 // Method java/lang/StringBuilder."<init>":()V
     107: ldc           #13                 // String result =
     109: invokevirtual #17                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     112: iconst_0
     113: iconst_3
     114: invokestatic  #49                 // Method secondSolution:(II)[J
     117: invokestatic  #27                 // Method kotlin/collections/ArraysKt.toList:([J)Ljava/util/List;
     120: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     123: invokevirtual #34                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     126: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
     129: swap
     130: invokevirtual #46                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     133: return

  private static final long[] solution(int, int);
    Code:
       0: iload_1
       1: newarray       long
       3: astore_2
       4: iconst_0
       5: istore_3
       6: iload_3
       7: iload_1
       8: if_icmpge     27
      11: aload_2
      12: iload_3
      13: iload_0
      14: i2l
      15: iload_3
      16: i2l
      17: lconst_1
      18: ladd
      19: lmul
      20: lastore
      21: iinc          3, 1
      24: goto          6
      27: aload_2
      28: areturn

  private static final long[] secondSolution(int, int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_1
       3: newarray       long
       5: astore_3
       6: iload_2
       7: iload_1
       8: if_icmpge     32
      11: iload_2
      12: istore        4
      14: aload_3
      15: iload         4
      17: iload_0
      18: i2l
      19: iload         4
      21: iconst_1
      22: iadd
      23: i2l
      24: lmul
      25: lastore
      26: iinc          2, 1
      29: goto          6
      32: aload_3
      33: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #59                 // Method main:()V
       3: return
}


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12948
 *
 * 문제 설명
 * 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
 * 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.
 *
 * 제한 조건
 * phone_number는 길이 4 이상, 20이하인 문자열입니다.
 * 입출력 예
 * phone_number	return
 * "01033334444"	"*******4444"
 * "027778888"	"*****8888"
 */

fun main() {
    solution("01033334444")
    solution("027778888")
}

private fun solution(phone_number: String): String {
    var answer = ""
    val numLength = phone_number.length
    for(i in 1..numLength - 4) {
        answer += "*"
    }
    val result = answer + phone_number.subSequence(numLength - 4, numLength)
    return result
}

private fun secondSolution(phone_number: String): String {
    return "${"".padStart(phone_number.length - 4, '*')}${phone_number.takeLast(4)}"
}

Compiled from "Lv1_12948_hide_number.kt"
public final class main.kotlin.programmers.lv01.Lv1_12948_hide_numberKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String 01033334444
       2: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
       5: pop
       6: ldc           #14                 // String 027778888
       8: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
      11: pop
      12: return

  private static final java.lang.String solution(java.lang.String);
    Code:
       0: ldc           #16                 // String
       2: astore_1
       3: aload_0
       4: invokevirtual #22                 // Method java/lang/String.length:()I
       7: istore_2
       8: iconst_1
       9: istore_3
      10: iload_2
      11: iconst_4
      12: isub
      13: istore        4
      15: iload_3
      16: iload         4
      18: if_icmpgt     53
      21: new           #24                 // class java/lang/StringBuilder
      24: dup
      25: invokespecial #27                 // Method java/lang/StringBuilder."<init>":()V
      28: aload_1
      29: invokevirtual #31                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      32: bipush        42
      34: invokevirtual #34                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      37: invokevirtual #38                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      40: astore_1
      41: iload_3
      42: iload         4
      44: if_icmpeq     53
      47: iinc          3, 1
      50: goto          21
      53: new           #24                 // class java/lang/StringBuilder
      56: dup
      57: invokespecial #27                 // Method java/lang/StringBuilder."<init>":()V
      60: aload_1
      61: invokevirtual #31                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      64: aload_0
      65: iload_2
      66: iconst_4
      67: isub
      68: iload_2
      69: invokevirtual #42                 // Method java/lang/String.subSequence:(II)Ljava/lang/CharSequence;
      72: invokevirtual #45                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      75: invokevirtual #38                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      78: astore_3
      79: aload_3
      80: areturn

  private static final java.lang.String secondSolution(java.lang.String);
    Code:
       0: new           #24                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #27                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #16                 // String
       9: aload_0
      10: invokevirtual #22                 // Method java/lang/String.length:()I
      13: iconst_4
      14: isub
      15: bipush        42
      17: invokestatic  #59                 // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
      20: invokevirtual #31                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      23: aload_0
      24: iconst_4
      25: invokestatic  #63                 // Method kotlin/text/StringsKt.takeLast:(Ljava/lang/String;I)Ljava/lang/String;
      28: invokevirtual #31                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      31: invokevirtual #38                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      34: areturn

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #66                 // Method main:()V
       3: return
}


package de.qwhon.aoc

import java.io.File

/** A simple helper class for keeping track of scanners.
 *
 */
data class ScannerRecord(val depth: Int, val range: Int)

/** parse the input file, and return a List of scanner records.
 *
 */
fun parseInputFile(fileName: String): List<ScannerRecord> {
    val file = File(fileName)
    val tmp = HashMap<Int, Int>()
    file.forEachLine {
        val contents = it.split(": ")
        tmp[contents[0].toInt()] = contents[1].toInt()
    }
    return tmp.map { ScannerRecord(depth = it.key, range = it.value) }
}

/** compute the minimum delay necessary to pass through the firewall without getting caught.
 *    we return the first number that fulfills:
 *       for every scanner N: scanner_N is not at position 0 at timestamp (depth_N + delay)
 *       since (depth_N + delay) is the timestamp at which our packet reaches level N, this solves our puzzle
 */
fun minimumDelayForInputFile(fileName: String): Int {
    val input = parseInputFile(fileName)
    return generateSequence(seed = 0) { i -> i + 1 }
            .find { i -> input.none { scanner -> (i + scanner.depth) % ((scanner.range - 1) * 2) == 0 } }!!
}

/** compute the severity of the violations for passing through the firewall without initial delay.
 *       we compute the severity as:
 *         for every scanner N: violation occurs iff scanner_N is at position 0 at timestamp (depth_N + delay)
 *         since (depth_N + delay) is the timestamp at which our packet reaches level N, this returns all scanners
 *         that catch our packet. Computing the severity is then a simple sum of depth*range, which can be computed by a fold.
 */
fun severityOfViolationsForInputFile(fileName: String): Int {
    val input = parseInputFile(fileName)
    return input.filter { scanner -> scanner.depth % ((scanner.range - 1) * 2) == 0 }
            .fold(initial = 0) { accu, scanner -> accu + scanner.depth * scanner.range }
}

Compiled from "PacketScanner.kt"
public final class de.qwhon.aoc.PacketScannerKt {
  public static final java.util.List<de.qwhon.aoc.ScannerRecord> parseInputFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/io/File
       9: dup
      10: aload_0
      11: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      14: astore_1
      15: new           #24                 // class java/util/HashMap
      18: dup
      19: invokespecial #27                 // Method java/util/HashMap."<init>":()V
      22: astore_2
      23: aload_1
      24: aconst_null
      25: aload_2
      26: invokedynamic #47,  0             // InvokeDynamic #0:invoke:(Ljava/util/HashMap;)Lkotlin/jvm/functions/Function1;
      31: iconst_1
      32: aconst_null
      33: invokestatic  #53                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      36: aload_2
      37: checkcast     #55                 // class java/util/Map
      40: astore_3
      41: iconst_0
      42: istore        4
      44: aload_3
      45: astore        5
      47: new           #57                 // class java/util/ArrayList
      50: dup
      51: aload_3
      52: invokeinterface #61,  1           // InterfaceMethod java/util/Map.size:()I
      57: invokespecial #64                 // Method java/util/ArrayList."<init>":(I)V
      60: checkcast     #66                 // class java/util/Collection
      63: astore        6
      65: iconst_0
      66: istore        7
      68: aload         5
      70: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      75: invokeinterface #76,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      80: astore        8
      82: aload         8
      84: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      89: ifeq          160
      92: aload         8
      94: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      99: checkcast     #88                 // class java/util/Map$Entry
     102: astore        9
     104: aload         6
     106: aload         9
     108: astore        10
     110: astore        12
     112: iconst_0
     113: istore        11
     115: new           #90                 // class de/qwhon/aoc/ScannerRecord
     118: dup
     119: aload         10
     121: invokeinterface #93,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     126: checkcast     #95                 // class java/lang/Number
     129: invokevirtual #98                 // Method java/lang/Number.intValue:()I
     132: aload         10
     134: invokeinterface #101,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     139: checkcast     #95                 // class java/lang/Number
     142: invokevirtual #98                 // Method java/lang/Number.intValue:()I
     145: invokespecial #104                // Method de/qwhon/aoc/ScannerRecord."<init>":(II)V
     148: aload         12
     150: swap
     151: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          82
     160: aload         6
     162: checkcast     #110                // class java/util/List
     165: nop
     166: areturn

  public static final int minimumDelayForInputFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #133                // Method parseInputFile:(Ljava/lang/String;)Ljava/util/List;
      10: astore_1
      11: iconst_0
      12: invokestatic  #139                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: invokedynamic #148,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      20: invokestatic  #154                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      23: astore_2
      24: aload_2
      25: invokeinterface #157,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      30: astore_3
      31: aload_3
      32: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          176
      40: aload_3
      41: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        4
      48: aload         4
      50: checkcast     #95                 // class java/lang/Number
      53: invokevirtual #98                 // Method java/lang/Number.intValue:()I
      56: istore        5
      58: iconst_0
      59: istore        6
      61: aload_1
      62: checkcast     #159                // class java/lang/Iterable
      65: astore        7
      67: iconst_0
      68: istore        8
      70: aload         7
      72: instanceof    #66                 // class java/util/Collection
      75: ifeq          95
      78: aload         7
      80: checkcast     #66                 // class java/util/Collection
      83: invokeinterface #162,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      88: ifeq          95
      91: iconst_1
      92: goto          167
      95: aload         7
      97: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     102: astore        9
     104: aload         9
     106: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          166
     114: aload         9
     116: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     121: astore        10
     123: aload         10
     125: checkcast     #90                 // class de/qwhon/aoc/ScannerRecord
     128: astore        11
     130: iconst_0
     131: istore        12
     133: iload         5
     135: aload         11
     137: invokevirtual #166                // Method de/qwhon/aoc/ScannerRecord.getDepth:()I
     140: iadd
     141: aload         11
     143: invokevirtual #169                // Method de/qwhon/aoc/ScannerRecord.getRange:()I
     146: iconst_1
     147: isub
     148: iconst_2
     149: imul
     150: irem
     151: ifne          158
     154: iconst_1
     155: goto          159
     158: iconst_0
     159: ifeq          104
     162: iconst_0
     163: goto          167
     166: iconst_1
     167: nop
     168: ifeq          31
     171: aload         4
     173: goto          177
     176: aconst_null
     177: dup
     178: invokestatic  #173                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     181: checkcast     #95                 // class java/lang/Number
     184: invokevirtual #98                 // Method java/lang/Number.intValue:()I
     187: ireturn

  public static final int severityOfViolationsForInputFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #133                // Method parseInputFile:(Ljava/lang/String;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: checkcast     #159                // class java/lang/Iterable
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: astore        4
      21: new           #57                 // class java/util/ArrayList
      24: dup
      25: invokespecial #187                // Method java/util/ArrayList."<init>":()V
      28: checkcast     #66                 // class java/util/Collection
      31: astore        5
      33: iconst_0
      34: istore        6
      36: aload         4
      38: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        7
      45: aload         7
      47: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          113
      55: aload         7
      57: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        8
      64: aload         8
      66: checkcast     #90                 // class de/qwhon/aoc/ScannerRecord
      69: astore        9
      71: iconst_0
      72: istore        10
      74: aload         9
      76: invokevirtual #166                // Method de/qwhon/aoc/ScannerRecord.getDepth:()I
      79: aload         9
      81: invokevirtual #169                // Method de/qwhon/aoc/ScannerRecord.getRange:()I
      84: iconst_1
      85: isub
      86: iconst_2
      87: imul
      88: irem
      89: ifne          96
      92: iconst_1
      93: goto          97
      96: iconst_0
      97: ifeq          45
     100: aload         5
     102: aload         8
     104: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     109: pop
     110: goto          45
     113: aload         5
     115: checkcast     #110                // class java/util/List
     118: nop
     119: checkcast     #159                // class java/lang/Iterable
     122: astore_2
     123: iconst_0
     124: istore_3
     125: iconst_0
     126: istore        4
     128: iload_3
     129: istore        5
     131: aload_2
     132: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     137: astore        6
     139: aload         6
     141: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifeq          191
     149: aload         6
     151: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     156: astore        7
     158: iload         5
     160: aload         7
     162: checkcast     #90                 // class de/qwhon/aoc/ScannerRecord
     165: astore        8
     167: istore        9
     169: iconst_0
     170: istore        10
     172: iload         9
     174: aload         8
     176: invokevirtual #166                // Method de/qwhon/aoc/ScannerRecord.getDepth:()I
     179: aload         8
     181: invokevirtual #169                // Method de/qwhon/aoc/ScannerRecord.getRange:()I
     184: imul
     185: iadd
     186: istore        5
     188: goto          139
     191: iload         5
     193: ireturn

  private static final kotlin.Unit parseInputFile$lambda$0(java.util.HashMap, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #200                // String it
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #202                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #129                // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #204                // String :
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #210                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_2
      30: nop
      31: aload_0
      32: checkcast     #55                 // class java/util/Map
      35: aload_2
      36: iconst_0
      37: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #129                // class java/lang/String
      45: invokestatic  #217                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      48: invokestatic  #139                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: aload_2
      52: iconst_1
      53: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      58: checkcast     #129                // class java/lang/String
      61: invokestatic  #217                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      64: invokestatic  #139                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokeinterface #221,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      72: pop
      73: getstatic     #227                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      76: areturn

  private static final java.lang.Integer minimumDelayForInputFile$lambda$2(int);
    Code:
       0: iload_0
       1: iconst_1
       2: iadd
       3: invokestatic  #139                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn
}