package org.mjurisic.aoc2020.day7

import java.io.File
import java.util.function.Consumer

class Day7 {

    companion object {
        @JvmStatic
        fun main(args: Array<String>) = try {
            val nodes = HashMap<String, Node>()
            val vertices = ArrayList<Vertex>()

            File(ClassLoader.getSystemResource("resources/input7.txt").file).forEachLine {
                val bagColor = it.substring(0, it.indexOf("bags") - 1)

                val bagContent = it.substring(it.indexOf("contain") + 8, it.length - 1)
                val edges = ArrayList<Vertex>()
                if (bagContent != "no other bags") {
                    bagContent.split(",").forEach(Consumer {
                        val bag = it.trim()
                        val strength = bag.substring(0, bag.indexOf(" "))
                        val color = bag.substring(bag.indexOf(" ") + 1, bag.lastIndexOf(" "))
                        val vertex = Vertex(bagColor, color, strength.toInt())
                        edges.add(vertex)
                        vertices.add(vertex)
                    })
                }
                nodes.put(bagColor, Node(bagColor, edges))
            }
//          part 1
//          println(nodes.filter { isContained(it.value, vertices, nodes, "shiny gold") }.size)
            val sourceNode = nodes["shiny gold"]
            println(countBags(sourceNode!!, nodes, vertices))

        } catch (e: Exception) {
            e.printStackTrace()
        }

        // part 1
        private fun isContained(
            bag: Node,
            vertices: java.util.ArrayList<Vertex>,
            nodes: HashMap<String, Node>,
            color: String
        ): Boolean {
            if (bag.color == color) {
                return false
            }

            if (contains(bag, vertices, nodes, color)) {
                return true
            }

            return false
        }

        private fun contains(
            bag: Node,
            vertices: java.util.ArrayList<Vertex>,
            nodes: HashMap<String, Node>,
            color: String
        ): Boolean {
            if (bag.color == color) {
                return false
            }
            if (vertices.any { it.source == bag.color && it.destination == color }) {
                return true
            }

            if (vertices.filter { it.source == bag.color }.map { nodes[it.destination] }.any {
                    contains(
                        it!!,
                        vertices,
                        nodes,
                        color
                    )
                }) {
                return true
            }
            return false
        }

        // part 2
        private fun countBags(
            sourceNode: Node,
            nodes: java.util.HashMap<String, Node>,
            vertices: java.util.ArrayList<Vertex>
        ): Int {
            var count = 0
            sourceNode.vertices.forEach {
                count += it.strength
                val childNode = nodes[it.destination]!!
                count += it.strength * countBags(childNode, nodes, vertices)
            }

            return count
        }

    }
}

class Node(var color: String, var vertices: List<Vertex>) {
    override fun toString(): String {
        return "Node(color='$color', vertices=$vertices)"
    }
}

class Vertex(var source: String, var destination: String, var strength: Int) {
    override fun toString(): String {
        return "Vertex(source='$source', destination='$destination', strength=$strength)"
    }
}

Compiled from "Day7.kt"
public final class org.mjurisic.aoc2020.day7.Day7 {
  public static final org.mjurisic.aoc2020.day7.Day7$Companion Companion;

  public org.mjurisic.aoc2020.day7.Day7();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public static final void main(java.lang.String[]);
    Code:
       0: getstatic     #18                 // Field Companion:Lorg/mjurisic/aoc2020/day7/Day7$Companion;
       3: aload_0
       4: invokevirtual #22                 // Method org/mjurisic/aoc2020/day7/Day7$Companion.main:([Ljava/lang/String;)V
       7: return

  static {};
    Code:
       0: new           #20                 // class org/mjurisic/aoc2020/day7/Day7$Companion
       3: dup
       4: aconst_null
       5: invokespecial #28                 // Method org/mjurisic/aoc2020/day7/Day7$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #18                 // Field Companion:Lorg/mjurisic/aoc2020/day7/Day7$Companion;
      11: return
}

Compiled from "Day7.kt"
public final class org.mjurisic.aoc2020.day7.Day7$Companion {
  private org.mjurisic.aoc2020.day7.Day7$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void main(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #18                 // String args
       3: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: new           #26                 // class java/util/HashMap
      10: dup
      11: invokespecial #27                 // Method java/util/HashMap."<init>":()V
      14: astore_2
      15: new           #29                 // class java/util/ArrayList
      18: dup
      19: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      22: astore_3
      23: new           #32                 // class java/io/File
      26: dup
      27: ldc           #34                 // String resources/input7.txt
      29: invokestatic  #40                 // Method java/lang/ClassLoader.getSystemResource:(Ljava/lang/String;)Ljava/net/URL;
      32: invokevirtual #46                 // Method java/net/URL.getFile:()Ljava/lang/String;
      35: invokespecial #49                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      38: aconst_null
      39: aload_2
      40: aload_3
      41: invokedynamic #69,  0             // InvokeDynamic #0:invoke:(Ljava/util/HashMap;Ljava/util/ArrayList;)Lkotlin/jvm/functions/Function1;
      46: iconst_1
      47: aconst_null
      48: invokestatic  #75                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      51: aload_2
      52: ldc           #77                 // String shiny gold
      54: invokevirtual #80                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      57: checkcast     #82                 // class org/mjurisic/aoc2020/day7/Node
      60: astore        4
      62: aload_0
      63: aload         4
      65: dup
      66: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      69: aload_2
      70: aload_3
      71: invokespecial #90                 // Method countBags:(Lorg/mjurisic/aoc2020/day7/Node;Ljava/util/HashMap;Ljava/util/ArrayList;)I
      74: istore        5
      76: getstatic     #96                 // Field java/lang/System.out:Ljava/io/PrintStream;
      79: iload         5
      81: invokevirtual #102                // Method java/io/PrintStream.println:(I)V
      84: goto          92
      87: astore_2
      88: aload_2
      89: invokevirtual #105                // Method java/lang/Exception.printStackTrace:()V
      92: return
    Exception table:
       from    to  target type
           6    84    87   Class java/lang/Exception

  private final boolean isContained(org.mjurisic.aoc2020.day7.Node, java.util.ArrayList<org.mjurisic.aoc2020.day7.Vertex>, java.util.HashMap<java.lang.String, org.mjurisic.aoc2020.day7.Node>, java.lang.String);
    Code:
       0: aload_1
       1: invokevirtual #120                // Method org/mjurisic/aoc2020/day7/Node.getColor:()Ljava/lang/String;
       4: aload         4
       6: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       9: ifeq          14
      12: iconst_0
      13: ireturn
      14: aload_0
      15: aload_1
      16: aload_2
      17: aload_3
      18: aload         4
      20: invokespecial #127                // Method contains:(Lorg/mjurisic/aoc2020/day7/Node;Ljava/util/ArrayList;Ljava/util/HashMap;Ljava/lang/String;)Z
      23: ifeq          28
      26: iconst_1
      27: ireturn
      28: iconst_0
      29: ireturn

  private final boolean contains(org.mjurisic.aoc2020.day7.Node, java.util.ArrayList<org.mjurisic.aoc2020.day7.Vertex>, java.util.HashMap<java.lang.String, org.mjurisic.aoc2020.day7.Node>, java.lang.String);
    Code:
       0: aload_1
       1: invokevirtual #120                // Method org/mjurisic/aoc2020/day7/Node.getColor:()Ljava/lang/String;
       4: aload         4
       6: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       9: ifeq          14
      12: iconst_0
      13: ireturn
      14: aload_2
      15: checkcast     #132                // class java/lang/Iterable
      18: astore        5
      20: iconst_0
      21: istore        6
      23: aload         5
      25: instanceof    #134                // class java/util/Collection
      28: ifeq          48
      31: aload         5
      33: checkcast     #134                // class java/util/Collection
      36: invokeinterface #138,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      41: ifeq          48
      44: iconst_0
      45: goto          127
      48: aload         5
      50: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        7
      57: aload         7
      59: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          126
      67: aload         7
      69: invokeinterface #151,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        8
      76: aload         8
      78: checkcast     #153                // class org/mjurisic/aoc2020/day7/Vertex
      81: astore        9
      83: iconst_0
      84: istore        10
      86: aload         9
      88: invokevirtual #156                // Method org/mjurisic/aoc2020/day7/Vertex.getSource:()Ljava/lang/String;
      91: aload_1
      92: invokevirtual #120                // Method org/mjurisic/aoc2020/day7/Node.getColor:()Ljava/lang/String;
      95: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      98: ifeq          118
     101: aload         9
     103: invokevirtual #159                // Method org/mjurisic/aoc2020/day7/Vertex.getDestination:()Ljava/lang/String;
     106: aload         4
     108: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     111: ifeq          118
     114: iconst_1
     115: goto          119
     118: iconst_0
     119: ifeq          57
     122: iconst_1
     123: goto          127
     126: iconst_0
     127: ifeq          132
     130: iconst_1
     131: ireturn
     132: aload_2
     133: checkcast     #132                // class java/lang/Iterable
     136: astore        5
     138: iconst_0
     139: istore        6
     141: aload         5
     143: astore        7
     145: new           #29                 // class java/util/ArrayList
     148: dup
     149: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
     152: checkcast     #134                // class java/util/Collection
     155: astore        8
     157: iconst_0
     158: istore        9
     160: aload         7
     162: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     167: astore        10
     169: aload         10
     171: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          226
     179: aload         10
     181: invokeinterface #151,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: astore        11
     188: aload         11
     190: checkcast     #153                // class org/mjurisic/aoc2020/day7/Vertex
     193: astore        12
     195: iconst_0
     196: istore        13
     198: aload         12
     200: invokevirtual #156                // Method org/mjurisic/aoc2020/day7/Vertex.getSource:()Ljava/lang/String;
     203: aload_1
     204: invokevirtual #120                // Method org/mjurisic/aoc2020/day7/Node.getColor:()Ljava/lang/String;
     207: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     210: ifeq          169
     213: aload         8
     215: aload         11
     217: invokeinterface #163,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     222: pop
     223: goto          169
     226: aload         8
     228: checkcast     #165                // class java/util/List
     231: nop
     232: checkcast     #132                // class java/lang/Iterable
     235: astore        5
     237: iconst_0
     238: istore        6
     240: aload         5
     242: astore        7
     244: new           #29                 // class java/util/ArrayList
     247: dup
     248: aload         5
     250: bipush        10
     252: invokestatic  #171                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     255: invokespecial #173                // Method java/util/ArrayList."<init>":(I)V
     258: checkcast     #134                // class java/util/Collection
     261: astore        8
     263: iconst_0
     264: istore        9
     266: aload         7
     268: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     273: astore        10
     275: aload         10
     277: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          332
     285: aload         10
     287: invokeinterface #151,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: astore        11
     294: aload         8
     296: aload         11
     298: checkcast     #153                // class org/mjurisic/aoc2020/day7/Vertex
     301: astore        12
     303: astore        14
     305: iconst_0
     306: istore        13
     308: aload_3
     309: aload         12
     311: invokevirtual #159                // Method org/mjurisic/aoc2020/day7/Vertex.getDestination:()Ljava/lang/String;
     314: invokevirtual #80                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     317: checkcast     #82                 // class org/mjurisic/aoc2020/day7/Node
     320: aload         14
     322: swap
     323: invokeinterface #163,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     328: pop
     329: goto          275
     332: aload         8
     334: checkcast     #165                // class java/util/List
     337: nop
     338: checkcast     #132                // class java/lang/Iterable
     341: astore        5
     343: iconst_0
     344: istore        6
     346: aload         5
     348: instanceof    #134                // class java/util/Collection
     351: ifeq          371
     354: aload         5
     356: checkcast     #134                // class java/util/Collection
     359: invokeinterface #138,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     364: ifeq          371
     367: iconst_0
     368: goto          434
     371: aload         5
     373: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     378: astore        7
     380: aload         7
     382: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     387: ifeq          433
     390: aload         7
     392: invokeinterface #151,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     397: astore        8
     399: aload         8
     401: checkcast     #82                 // class org/mjurisic/aoc2020/day7/Node
     404: astore        9
     406: iconst_0
     407: istore        10
     409: getstatic     #178                // Field org/mjurisic/aoc2020/day7/Day7.Companion:Lorg/mjurisic/aoc2020/day7/Day7$Companion;
     412: aload         9
     414: dup
     415: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     418: aload_2
     419: aload_3
     420: aload         4
     422: invokespecial #127                // Method contains:(Lorg/mjurisic/aoc2020/day7/Node;Ljava/util/ArrayList;Ljava/util/HashMap;Ljava/lang/String;)Z
     425: nop
     426: ifeq          380
     429: iconst_1
     430: goto          434
     433: iconst_0
     434: ifeq          439
     437: iconst_1
     438: ireturn
     439: iconst_0
     440: ireturn

  private final int countBags(org.mjurisic.aoc2020.day7.Node, java.util.HashMap<java.lang.String, org.mjurisic.aoc2020.day7.Node>, java.util.ArrayList<org.mjurisic.aoc2020.day7.Vertex>);
    Code:
       0: iconst_0
       1: istore        4
       3: aload_1
       4: invokevirtual #209                // Method org/mjurisic/aoc2020/day7/Node.getVertices:()Ljava/util/List;
       7: checkcast     #132                // class java/lang/Iterable
      10: astore        5
      12: iconst_0
      13: istore        6
      15: aload         5
      17: invokeinterface #142,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        7
      24: aload         7
      26: invokeinterface #147,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          107
      34: aload         7
      36: invokeinterface #151,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        8
      43: aload         8
      45: checkcast     #153                // class org/mjurisic/aoc2020/day7/Vertex
      48: astore        9
      50: iconst_0
      51: istore        10
      53: iload         4
      55: aload         9
      57: invokevirtual #213                // Method org/mjurisic/aoc2020/day7/Vertex.getStrength:()I
      60: iadd
      61: istore        4
      63: aload_2
      64: aload         9
      66: invokevirtual #159                // Method org/mjurisic/aoc2020/day7/Vertex.getDestination:()Ljava/lang/String;
      69: invokevirtual #80                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      72: dup
      73: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      76: checkcast     #82                 // class org/mjurisic/aoc2020/day7/Node
      79: astore        11
      81: iload         4
      83: aload         9
      85: invokevirtual #213                // Method org/mjurisic/aoc2020/day7/Vertex.getStrength:()I
      88: getstatic     #178                // Field org/mjurisic/aoc2020/day7/Day7.Companion:Lorg/mjurisic/aoc2020/day7/Day7$Companion;
      91: aload         11
      93: aload_2
      94: aload_3
      95: invokespecial #90                 // Method countBags:(Lorg/mjurisic/aoc2020/day7/Node;Ljava/util/HashMap;Ljava/util/ArrayList;)I
      98: imul
      99: iadd
     100: istore        4
     102: nop
     103: nop
     104: goto          24
     107: nop
     108: iload         4
     110: ireturn

  private static final void main$lambda$1$lambda$0(java.lang.String, java.util.ArrayList, java.util.ArrayList, java.lang.String);
    Code:
       0: aload_3
       1: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       4: aload_3
       5: checkcast     #222                // class java/lang/CharSequence
       8: invokestatic  #228                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      11: invokevirtual #231                // Method java/lang/Object.toString:()Ljava/lang/String;
      14: astore        4
      16: aload         4
      18: iconst_0
      19: aload         4
      21: checkcast     #222                // class java/lang/CharSequence
      24: ldc           #233                // String
      26: iconst_0
      27: iconst_0
      28: bipush        6
      30: aconst_null
      31: invokestatic  #237                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      34: invokevirtual #241                // Method java/lang/String.substring:(II)Ljava/lang/String;
      37: dup
      38: ldc           #243                // String substring(...)
      40: invokestatic  #246                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      43: astore        5
      45: aload         4
      47: aload         4
      49: checkcast     #222                // class java/lang/CharSequence
      52: ldc           #233                // String
      54: iconst_0
      55: iconst_0
      56: bipush        6
      58: aconst_null
      59: invokestatic  #237                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      62: iconst_1
      63: iadd
      64: aload         4
      66: checkcast     #222                // class java/lang/CharSequence
      69: ldc           #233                // String
      71: iconst_0
      72: iconst_0
      73: bipush        6
      75: aconst_null
      76: invokestatic  #249                // Method kotlin/text/StringsKt.lastIndexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      79: invokevirtual #241                // Method java/lang/String.substring:(II)Ljava/lang/String;
      82: dup
      83: ldc           #243                // String substring(...)
      85: invokestatic  #246                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      88: astore        6
      90: new           #153                // class org/mjurisic/aoc2020/day7/Vertex
      93: dup
      94: aload_0
      95: aload         6
      97: aload         5
      99: invokestatic  #255                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     102: invokespecial #258                // Method org/mjurisic/aoc2020/day7/Vertex."<init>":(Ljava/lang/String;Ljava/lang/String;I)V
     105: astore        7
     107: aload_1
     108: aload         7
     110: invokevirtual #259                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     113: pop
     114: aload_2
     115: aload         7
     117: invokevirtual #259                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     120: pop
     121: return

  private static final kotlin.Unit main$lambda$1(java.util.HashMap, java.util.ArrayList, java.lang.String);
    Code:
       0: aload_2
       1: ldc_w         #265                // String it
       4: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: iconst_0
       9: aload_2
      10: checkcast     #222                // class java/lang/CharSequence
      13: ldc_w         #267                // String bags
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #237                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      24: iconst_1
      25: isub
      26: invokevirtual #241                // Method java/lang/String.substring:(II)Ljava/lang/String;
      29: dup
      30: ldc           #243                // String substring(...)
      32: invokestatic  #246                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      35: astore_3
      36: aload_2
      37: aload_2
      38: checkcast     #222                // class java/lang/CharSequence
      41: ldc_w         #269                // String contain
      44: iconst_0
      45: iconst_0
      46: bipush        6
      48: aconst_null
      49: invokestatic  #237                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      52: bipush        8
      54: iadd
      55: aload_2
      56: invokevirtual #272                // Method java/lang/String.length:()I
      59: iconst_1
      60: isub
      61: invokevirtual #241                // Method java/lang/String.substring:(II)Ljava/lang/String;
      64: dup
      65: ldc           #243                // String substring(...)
      67: invokestatic  #246                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      70: astore        4
      72: new           #29                 // class java/util/ArrayList
      75: dup
      76: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      79: astore        5
      81: aload         4
      83: ldc_w         #274                // String no other bags
      86: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      89: ifne          134
      92: aload         4
      94: checkcast     #222                // class java/lang/CharSequence
      97: iconst_1
      98: anewarray     #204                // class java/lang/String
     101: astore        6
     103: aload         6
     105: iconst_0
     106: ldc_w         #276                // String ,
     109: aastore
     110: aload         6
     112: iconst_0
     113: iconst_0
     114: bipush        6
     116: aconst_null
     117: invokestatic  #280                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     120: aload_3
     121: aload         5
     123: aload_1
     124: invokedynamic #289,  0            // InvokeDynamic #1:accept:(Ljava/lang/String;Ljava/util/ArrayList;Ljava/util/ArrayList;)Ljava/util/function/Consumer;
     129: invokeinterface #293,  2          // InterfaceMethod java/util/List.forEach:(Ljava/util/function/Consumer;)V
     134: aload_0
     135: aload_3
     136: new           #82                 // class org/mjurisic/aoc2020/day7/Node
     139: dup
     140: aload_3
     141: aload         5
     143: checkcast     #165                // class java/util/List
     146: invokespecial #296                // Method org/mjurisic/aoc2020/day7/Node."<init>":(Ljava/lang/String;Ljava/util/List;)V
     149: invokevirtual #300                // Method java/util/HashMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     152: pop
     153: getstatic     #306                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     156: areturn

  public org.mjurisic.aoc2020.day7.Day7$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #312                // Method "<init>":()V
       4: return
}


package combinatorics

import java.util.LinkedList

interface Circular<out T> : Iterable<T> {
    fun state(): T
    fun inc()
    fun isZero(): Boolean   // `true` in exactly one state
    fun hasNext(): Boolean  // `false` if the next state `isZero()`

    override fun iterator() : Iterator<T> {
        return object : Iterator<T> {
            var started = false

            override fun next(): T {
                if(started) {
                    inc()
                } else {
                    started = true
                }

                return state()
            }

            override fun hasNext() = this@Circular.hasNext()
        }
    }
}

class Ring(val size: Int) : Circular<Int> {
    private var state = 0

    override fun state() = state
    override fun inc() {state = (1 + state) % size}
    override fun isZero() = (state == 0)
    override fun hasNext() = (state != size - 1)

    init {
        assert(size > 0)
    }
}

abstract class CircularList<out E, out H: Circular<E>>(val size: Int) : Circular<List<E>> {
    protected abstract val state: List<H>  // state.size == size

    override fun inc() {
        state.forEach {
            it.inc()
            if(! it.isZero()) return
        }
    }

    override fun isZero() = state.all {it.isZero()}
    override fun hasNext() = state.any {it.hasNext()}
}

abstract class IntCombinations(size: Int) : CircularList<Int, Ring>(size)

class BinaryBits(N: Int) : IntCombinations(N) {
    override val state = Array(N, {Ring(2)}).toList()
    override fun state() = state.map {it.state()}.reversed()
}

class Permutations(N: Int) : IntCombinations(N) {
    override val state = mutableListOf<Ring>()

    init {
        for(i in N downTo 1) {
            state += Ring(i)
        }
    }

    override fun state(): List<Int> {
        val items = (0..size - 1).toCollection(LinkedList())
        return state.map {ring -> items.removeAt(ring.state())}
    }
}

fun main(args: Array<String>) {
    val n = 100
    val sumNumbers = Ring(n).sum()
    println("In theory, the sum of numbers 0..${n - 1} is ${n * (n - 1) / 2}.")
    println("Which is consistent with a practical result of $sumNumbers.\n")

    BinaryBits(5).asSequence().filter {it.sum() == 2}.take(5).forEach { println(it) }

    println("\npermutations of 3 elements:")
    for(configuration in Permutations(3)) {
        println(configuration)
    }
}

Compiled from "Permutations.kt"
public final class combinatorics.Permutations extends combinatorics.IntCombinations {
  private final java.util.List<combinatorics.Ring> state;

  public combinatorics.Permutations(int);
    Code:
       0: aload_0
       1: iload_1
       2: invokespecial #8                  // Method combinatorics/IntCombinations."<init>":(I)V
       5: aload_0
       6: new           #10                 // class java/util/ArrayList
       9: dup
      10: invokespecial #13                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #15                 // class java/util/List
      16: putfield      #19                 // Field state:Ljava/util/List;
      19: nop
      20: iload_1
      21: istore_2
      22: iconst_0
      23: iload_2
      24: if_icmpge     54
      27: aload_0
      28: invokevirtual #23                 // Method getState:()Ljava/util/List;
      31: checkcast     #25                 // class java/util/Collection
      34: new           #27                 // class combinatorics/Ring
      37: dup
      38: iload_2
      39: invokespecial #28                 // Method combinatorics/Ring."<init>":(I)V
      42: invokeinterface #32,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      47: pop
      48: iinc          2, -1
      51: goto          22
      54: nop
      55: return

  protected java.util.List<combinatorics.Ring> getState();
    Code:
       0: aload_0
       1: getfield      #19                 // Field state:Ljava/util/List;
       4: areturn

  public java.util.List<java.lang.Integer> state();
    Code:
       0: new           #42                 // class kotlin/ranges/IntRange
       3: dup
       4: iconst_0
       5: aload_0
       6: invokevirtual #46                 // Method getSize:()I
       9: iconst_1
      10: isub
      11: invokespecial #49                 // Method kotlin/ranges/IntRange."<init>":(II)V
      14: checkcast     #51                 // class java/lang/Iterable
      17: new           #53                 // class java/util/LinkedList
      20: dup
      21: invokespecial #54                 // Method java/util/LinkedList."<init>":()V
      24: checkcast     #25                 // class java/util/Collection
      27: invokestatic  #60                 // Method kotlin/collections/CollectionsKt.toCollection:(Ljava/lang/Iterable;Ljava/util/Collection;)Ljava/util/Collection;
      30: checkcast     #53                 // class java/util/LinkedList
      33: astore_1
      34: aload_0
      35: invokevirtual #23                 // Method getState:()Ljava/util/List;
      38: checkcast     #51                 // class java/lang/Iterable
      41: astore_2
      42: iconst_0
      43: istore_3
      44: aload_2
      45: astore        4
      47: new           #10                 // class java/util/ArrayList
      50: dup
      51: aload_2
      52: bipush        10
      54: invokestatic  #64                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      57: invokespecial #65                 // Method java/util/ArrayList."<init>":(I)V
      60: checkcast     #25                 // class java/util/Collection
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         4
      70: invokeinterface #69,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      75: astore        7
      77: aload         7
      79: invokeinterface #75,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      84: ifeq          137
      87: aload         7
      89: invokeinterface #79,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      94: astore        8
      96: aload         5
      98: aload         8
     100: checkcast     #27                 // class combinatorics/Ring
     103: astore        9
     105: astore        11
     107: iconst_0
     108: istore        10
     110: aload_1
     111: aload         9
     113: invokevirtual #82                 // Method combinatorics/Ring.state:()Ljava/lang/Integer;
     116: invokevirtual #87                 // Method java/lang/Integer.intValue:()I
     119: invokevirtual #91                 // Method java/util/LinkedList.remove:(I)Ljava/lang/Object;
     122: checkcast     #84                 // class java/lang/Integer
     125: aload         11
     127: swap
     128: invokeinterface #32,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     133: pop
     134: goto          77
     137: aload         5
     139: checkcast     #15                 // class java/util/List
     142: nop
     143: areturn

  public java.lang.Object state();
    Code:
       0: aload_0
       1: invokevirtual #107                // Method state:()Ljava/util/List;
       4: areturn
}

Compiled from "Permutations.kt"
public final class combinatorics.PermutationsKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        100
       8: istore_1
       9: new           #17                 // class combinatorics/Ring
      12: dup
      13: iload_1
      14: invokespecial #21                 // Method combinatorics/Ring."<init>":(I)V
      17: checkcast     #23                 // class java/lang/Iterable
      20: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      23: istore_2
      24: new           #31                 // class java/lang/StringBuilder
      27: dup
      28: invokespecial #34                 // Method java/lang/StringBuilder."<init>":()V
      31: ldc           #36                 // String In theory, the sum of numbers 0..
      33: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: iload_1
      37: iconst_1
      38: isub
      39: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      42: ldc           #45                 // String  is
      44: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      47: iload_1
      48: iload_1
      49: iconst_1
      50: isub
      51: imul
      52: iconst_2
      53: idiv
      54: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      57: bipush        46
      59: invokevirtual #48                 // Method java/lang/StringBuilder.append:(C)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: new           #31                 // class java/lang/StringBuilder
      75: dup
      76: invokespecial #34                 // Method java/lang/StringBuilder."<init>":()V
      79: ldc           #66                 // String Which is consistent with a practical result of
      81: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      84: iload_2
      85: invokevirtual #43                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      88: ldc           #68                 // String .\n
      90: invokevirtual #40                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: new           #70                 // class combinatorics/BinaryBits
     106: dup
     107: iconst_5
     108: invokespecial #71                 // Method combinatorics/BinaryBits."<init>":(I)V
     111: checkcast     #23                 // class java/lang/Iterable
     114: invokestatic  #75                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     117: invokedynamic #95,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     122: invokestatic  #101                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     125: iconst_5
     126: invokestatic  #105                // Method kotlin/sequences/SequencesKt.take:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     129: astore_3
     130: iconst_0
     131: istore        4
     133: aload_3
     134: invokeinterface #111,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     139: astore        5
     141: aload         5
     143: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     148: ifeq          183
     151: aload         5
     153: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     158: astore        6
     160: aload         6
     162: checkcast     #123                // class java/util/List
     165: astore        7
     167: iconst_0
     168: istore        8
     170: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     173: aload         7
     175: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     178: nop
     179: nop
     180: goto          141
     183: nop
     184: ldc           #125                // String \npermutations of 3 elements:
     186: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     189: swap
     190: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     193: new           #127                // class combinatorics/Permutations
     196: dup
     197: iconst_3
     198: invokespecial #128                // Method combinatorics/Permutations."<init>":(I)V
     201: invokevirtual #129                // Method combinatorics/Permutations.iterator:()Ljava/util/Iterator;
     204: astore_3
     205: aload_3
     206: invokeinterface #117,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     211: ifeq          236
     214: aload_3
     215: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     220: checkcast     #123                // class java/util/List
     223: astore        4
     225: getstatic     #58                 // Field java/lang/System.out:Ljava/io/PrintStream;
     228: aload         4
     230: invokevirtual #64                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     233: goto          205
     236: return

  private static final boolean main$lambda$0(java.util.List);
    Code:
       0: aload_0
       1: ldc           #144                // String it
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #23                 // class java/lang/Iterable
      10: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      13: iconst_2
      14: if_icmpne     21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn
}


package boj.week02.recursive_function

import java.util.*

/**
 *
 * no.10870
 * https://www.acmicpc.net/problem/10870
 *
 * 피보나치 수는 0과 1로 시작한다. 0번째 피보나치 수는 0이고, 1번째 피보나치 수는 1이다. 그 다음 2번째 부터는 바로 앞 두 피보나치 수의 합이 된다.
 * 이를 식으로 써보면 Fn = Fn-1 + Fn-2 (n ≥ 2)가 된다.
 * n=17일때 까지 피보나치 수를 써보면 다음과 같다.
 * 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597
 * n이 주어졌을 때, n번째 피보나치 수를 구하는 프로그램을 작성하시오.
 *
 * 입력
 * 첫째 줄에 n이 주어진다. n은 20보다 작거나 같은 자연수 또는 0이다.
 *
 * 출력
 * 첫째 줄에 n번째 피보나치 수를 출력한다.
 */

fun main() {
    val inputValue = Scanner(System.`in`)
    println("${fibonacci(inputValue.nextInt())}")
}

fun fibonacci(n: Int): Int {
    if (n <= 1) {
        return n
    }
    return fibonacci(n - 1) + fibonacci(n - 2)
}

Compiled from "FibonacciSequence5.kt"
public final class boj.week02.recursive_function.FibonacciSequence5Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/util/Scanner
       3: dup
       4: getstatic     #14                 // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #18                 // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #22                 // Method java/util/Scanner.nextInt:()I
      15: invokestatic  #26                 // Method fibonacci:(I)I
      18: invokestatic  #32                 // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      21: getstatic     #36                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: swap
      25: invokevirtual #42                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      28: return

  public static final int fibonacci(int);
    Code:
       0: iload_0
       1: iconst_1
       2: if_icmpgt     7
       5: iload_0
       6: ireturn
       7: iload_0
       8: iconst_1
       9: isub
      10: invokestatic  #26                 // Method fibonacci:(I)I
      13: iload_0
      14: iconst_2
      15: isub
      16: invokestatic  #26                 // Method fibonacci:(I)I
      19: iadd
      20: ireturn

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


package programmers.lv02

/**
 *
 * no.12939
 * 최댓값과 최솟값
 * https://school.programmers.co.kr/learn/courses/30/lessons/12939
 *
 * 문제 설명
 * 문자열 s에는 공백으로 구분된 숫자들이 저장되어 있습니다.
 * str에 나타나는 숫자 중 최소값과 최대값을 찾아 이를 "(최소값) (최대값)"형태의 문자열을 반환하는 함수, solution을 완성하세요.
 * 예를들어 s가 "1 2 3 4"라면 "1 4"를 리턴하고, "-1 -2 -3 -4"라면 "-4 -1"을 리턴하면 됩니다.
 *
 * 제한 조건
 * s에는 둘 이상의 정수가 공백으로 구분되어 있습니다.
 * 입출력 예
 * s	            return
 * "1 2 3 4"	    "1 4"
 * "-1 -2 -3 -4"	"-4 -1"
 * "-1 -1"	        "-1 -1"
 *
 */

fun main() {
    println(solution("1 2 3 4"))
    println(solution("-1 -2 -3 -4"))
}

private fun solution(s: String): String {
    var answer = ""
    val splitString = s.split(" ")
    answer = splitString.minOf { it.toInt() }.toString() + " " + splitString.maxOf { it.toInt() }.toString()
    return answer
}

Compiled from "Lv2_12939_최댓값과최솟값.kt"
public final class programmers.lv02.Lv2_12939_최댓값과최솟값Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String 1 2 3 4
       2: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
       5: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       8: swap
       9: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      12: ldc           #26                 // String -1 -2 -3 -4
      14: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
      17: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      20: swap
      21: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: return

  private static final java.lang.String solution(java.lang.String);
    Code:
       0: ldc           #28                 // String
       2: astore_1
       3: aload_0
       4: checkcast     #30                 // class java/lang/CharSequence
       7: iconst_1
       8: anewarray     #32                 // class java/lang/String
      11: astore_3
      12: aload_3
      13: iconst_0
      14: ldc           #34                 // String
      16: aastore
      17: aload_3
      18: iconst_0
      19: iconst_0
      20: bipush        6
      22: aconst_null
      23: invokestatic  #40                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      26: astore_2
      27: new           #42                 // class java/lang/StringBuilder
      30: dup
      31: invokespecial #45                 // Method java/lang/StringBuilder."<init>":()V
      34: aload_2
      35: checkcast     #47                 // class java/lang/Iterable
      38: astore_3
      39: astore        8
      41: aload_3
      42: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      47: astore        4
      49: aload         4
      51: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifne          67
      59: new           #59                 // class java/util/NoSuchElementException
      62: dup
      63: invokespecial #60                 // Method java/util/NoSuchElementException."<init>":()V
      66: athrow
      67: aload         4
      69: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: checkcast     #32                 // class java/lang/String
      77: astore        5
      79: iconst_0
      80: istore        6
      82: aload         5
      84: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      87: nop
      88: istore        5
      90: aload         4
      92: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      97: ifeq          137
     100: aload         4
     102: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     107: checkcast     #32                 // class java/lang/String
     110: astore        6
     112: iconst_0
     113: istore        7
     115: aload         6
     117: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     120: nop
     121: istore        6
     123: iload         5
     125: iload         6
     127: if_icmple     90
     130: iload         6
     132: istore        5
     134: goto          90
     137: iload         5
     139: istore        9
     141: aload         8
     143: iload         9
     145: invokevirtual #74                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     148: bipush        32
     150: invokevirtual #77                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     153: aload_2
     154: checkcast     #47                 // class java/lang/Iterable
     157: astore_3
     158: astore        8
     160: aload_3
     161: invokeinterface #51,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     166: astore        4
     168: aload         4
     170: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     175: ifne          186
     178: new           #59                 // class java/util/NoSuchElementException
     181: dup
     182: invokespecial #60                 // Method java/util/NoSuchElementException."<init>":()V
     185: athrow
     186: aload         4
     188: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     193: checkcast     #32                 // class java/lang/String
     196: astore        5
     198: iconst_0
     199: istore        6
     201: aload         5
     203: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     206: nop
     207: istore        5
     209: aload         4
     211: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     216: ifeq          256
     219: aload         4
     221: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     226: checkcast     #32                 // class java/lang/String
     229: astore        6
     231: iconst_0
     232: istore        7
     234: aload         6
     236: invokestatic  #70                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     239: nop
     240: istore        6
     242: iload         5
     244: iload         6
     246: if_icmpge     209
     249: iload         6
     251: istore        5
     253: goto          209
     256: iload         5
     258: istore        9
     260: aload         8
     262: iload         9
     264: invokevirtual #74                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     267: invokevirtual #81                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     270: astore_1
     271: aload_1
     272: areturn

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


package programmers.lv02

/**
 *
 * no.12951
 * JadenCase 문자열 만들기
 * https://school.programmers.co.kr/learn/courses/30/lessons/12951
 *
 * JadenCase란 모든 단어의 첫 문자가 대문자이고, 그 외의 알파벳은 소문자인 문자열입니다.
 * 단, 첫 문자가 알파벳이 아닐 때에는 이어지는 알파벳은 소문자로 쓰면 됩니다. (첫 번째 입출력 예 참고)
 * 문자열 s가 주어졌을 때, s를 JadenCase로 바꾼 문자열을 리턴하는 함수, solution을 완성해주세요.
 *
 * 제한 조건
 * s는 길이 1 이상 200 이하인 문자열입니다.
 * s는 알파벳과 숫자, 공백문자(" ")로 이루어져 있습니다.
 * 숫자는 단어의 첫 문자로만 나옵니다.
 * 숫자로만 이루어진 단어는 없습니다.
 * 공백문자가 연속해서 나올 수 있습니다.
 * 입출력 예
 * s	                        return
 * "3people unFollowed me"	    "3people Unfollowed Me"
 * "for the last week"	        "For The Last Week"
 */

fun main() {
    println(solution("3people unFollowed me"))
    println(solution("for the last week"))
}

private fun solution(s: String): String {
    var answer = ""

    val sArray = s.toCharArray()
    sArray.forEachIndexed { index, c ->
        if (index == 0) {
            sArray[index] = sArray[index].uppercaseChar()
        }

        if (c.isLetter() && index != 0) {
            if (sArray[index -1].toString() != " ") {
                sArray[index] = sArray[index].lowercaseChar()
            } else {
                sArray[index] = sArray[index].uppercaseChar()
            }
        }

    }

    answer = String(sArray)
    return answer

}

Compiled from "Lv2_12951_JadenCase문자열만들기.kt"
public final class programmers.lv02.Lv2_12951_JadenCase문자열만들기Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String 3people unFollowed me
       2: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
       5: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
       8: swap
       9: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      12: ldc           #26                 // String for the last week
      14: invokestatic  #12                 // Method solution:(Ljava/lang/String;)Ljava/lang/String;
      17: getstatic     #18                 // Field java/lang/System.out:Ljava/io/PrintStream;
      20: swap
      21: invokevirtual #24                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: return

  private static final java.lang.String solution(java.lang.String);
    Code:
       0: ldc           #28                 // String
       2: astore_1
       3: aload_0
       4: invokevirtual #34                 // Method java/lang/String.toCharArray:()[C
       7: dup
       8: ldc           #36                 // String toCharArray(...)
      10: invokestatic  #42                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: astore_2
      14: aload_2
      15: astore_3
      16: iconst_0
      17: istore        4
      19: iconst_0
      20: istore        5
      22: iconst_0
      23: istore        6
      25: aload_3
      26: arraylength
      27: istore        7
      29: iload         6
      31: iload         7
      33: if_icmpge     135
      36: aload_3
      37: iload         6
      39: caload
      40: istore        8
      42: iload         5
      44: iinc          5, 1
      47: iload         8
      49: istore        9
      51: istore        10
      53: iconst_0
      54: istore        11
      56: iload         10
      58: ifne          72
      61: aload_2
      62: iload         10
      64: aload_2
      65: iload         10
      67: caload
      68: invokestatic  #48                 // Method java/lang/Character.toUpperCase:(C)C
      71: castore
      72: iload         9
      74: invokestatic  #52                 // Method java/lang/Character.isLetter:(C)Z
      77: ifeq          127
      80: iload         10
      82: ifeq          127
      85: aload_2
      86: iload         10
      88: iconst_1
      89: isub
      90: caload
      91: invokestatic  #56                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      94: ldc           #58                 // String
      96: invokestatic  #62                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      99: ifne          116
     102: aload_2
     103: iload         10
     105: aload_2
     106: iload         10
     108: caload
     109: invokestatic  #65                 // Method java/lang/Character.toLowerCase:(C)C
     112: castore
     113: goto          127
     116: aload_2
     117: iload         10
     119: aload_2
     120: iload         10
     122: caload
     123: invokestatic  #48                 // Method java/lang/Character.toUpperCase:(C)C
     126: castore
     127: nop
     128: nop
     129: iinc          6, 1
     132: goto          29
     135: nop
     136: new           #30                 // class java/lang/String
     139: dup
     140: aload_2
     141: invokespecial #69                 // Method java/lang/String."<init>":([C)V
     144: astore_1
     145: aload_1
     146: areturn

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


package programmers.lv01

/**
 * no.68644
 *  두 개 뽑아서 더하기
 * https://school.programmers.co.kr/learn/courses/30/lessons/68644
 *
 * 문제 설명
 * 정수 배열 numbers가 주어집니다.
 * numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를
 * 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요.
 *
 * 제한사항
 * numbers의 길이는 2 이상 100 이하입니다.
 * numbers의 모든 수는 0 이상 100 이하입니다.
 *
 * 입출력 예
 * numbers	    result
 * [2,1,3,4,1]	[2,3,4,5,6,7]
 * [5,0,2,7]	[2,5,7,9,12]
 *
 * 입출력 예 설명
 * 입출력 예 #1
 * 2 = 1 + 1 입니다. (1이 numbers에 두 개 있습니다.)
 * 3 = 2 + 1 입니다.
 * 4 = 1 + 3 입니다.
 * 5 = 1 + 4 = 2 + 3 입니다.
 * 6 = 2 + 4 입니다.
 * 7 = 3 + 4 입니다.
 * 따라서 [2,3,4,5,6,7] 을 return 해야 합니다.
 *
 * 입출력 예 #2
 * 2 = 0 + 2 입니다.
 * 5 = 5 + 0 입니다.
 * 7 = 0 + 7 = 5 + 2 입니다.
 * 9 = 2 + 7 입니다.
 * 12 = 5 + 7 입니다.
 * 따라서 [2,5,7,9,12] 를 return 해야 합니다.
 */

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

private fun solution(numbers: IntArray): IntArray {
    val resultList = mutableListOf<Int>()

    for (i in numbers.indices) {
        for (j in i + 1 until  numbers.size) {
            val sum = numbers[i] + numbers[j]
            if (!resultList.contains(sum)) {
                resultList.add(sum)
            }
        }
    }

    return resultList.sorted().toIntArray()
}

Compiled from "Lv1_68644.kt"
public final class programmers.lv01.Lv1_68644Kt {
  public static final void main();
    Code:
       0: iconst_5
       1: newarray       int
       3: astore_0
       4: aload_0
       5: iconst_0
       6: iconst_2
       7: iastore
       8: aload_0
       9: iconst_1
      10: iconst_1
      11: iastore
      12: aload_0
      13: iconst_2
      14: iconst_3
      15: iastore
      16: aload_0
      17: iconst_3
      18: iconst_4
      19: iastore
      20: aload_0
      21: iconst_4
      22: iconst_1
      23: iastore
      24: aload_0
      25: invokestatic  #10                 // Method solution:([I)[I
      28: pop
      29: return

  private static final int[] solution(int[]);
    Code:
       0: new           #12                 // class java/util/ArrayList
       3: dup
       4: invokespecial #15                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #17                 // class java/util/List
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_0
      14: arraylength
      15: istore_3
      16: iload_2
      17: iload_3
      18: if_icmpge     85
      21: iload_2
      22: iconst_1
      23: iadd
      24: istore        4
      26: aload_0
      27: arraylength
      28: istore        5
      30: iload         4
      32: iload         5
      34: if_icmpge     79
      37: aload_0
      38: iload_2
      39: iaload
      40: aload_0
      41: iload         4
      43: iaload
      44: iadd
      45: istore        6
      47: aload_1
      48: iload         6
      50: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: invokeinterface #27,  2           // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
      58: ifne          73
      61: aload_1
      62: iload         6
      64: invokestatic  #23                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokeinterface #30,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      72: pop
      73: iinc          4, 1
      76: goto          30
      79: iinc          2, 1
      82: goto          16
      85: aload_1
      86: checkcast     #32                 // class java/lang/Iterable
      89: invokestatic  #38                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      92: checkcast     #40                 // class java/util/Collection
      95: invokestatic  #44                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
      98: areturn

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


package programmers.lv01

/**
 * no.12901
 * 2016년
 * https://school.programmers.co.kr/learn/courses/30/lessons/12901
 *
 * 2016년 1월 1일은 금요일입니다.
 * 2016년 a월 b일은 무슨 요일일까요?
 * 두 수 a ,b를 입력받아 2016년 a월 b일이 무슨 요일인지 리턴하는 함수, solution을 완성하세요.
 * 요일의 이름은 일요일부터 토요일까지 각각 SUN,MON,TUE,WED,THU,FRI,SAT 입니다.
 * 예를 들어 a=5, b=24라면 5월 24일은 화요일이므로 문자열 "TUE"를 반환하세요.
 *
 * 제한 조건
 * 2016년은 윤년입니다.
 * 2016년 a월 b일은 실제로 있는 날입니다. (13월 26일이나 2월 45일같은 날짜는 주어지지 않습니다)
 *
 * 입출력 예
 * a	b	result
 * 5	24	"TUE"
 */

fun main() {
    solution(5, 24)
}

private fun solution(a: Int, b: Int): String {
    var answer = ""

    val daysInMonth = listOf(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    val daysOfWeek = listOf("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", )

    var days = 0
    for (month in 1 until a) {
        days += daysInMonth[month]
    }
    days += b - 1

    answer = daysOfWeek[(days + 5) % 7]

    return answer
}

Compiled from "Lv1_12901.kt"
public final class programmers.lv01.Lv1_12901Kt {
  public static final void main();
    Code:
       0: iconst_5
       1: bipush        24
       3: invokestatic  #10                 // Method solution:(II)Ljava/lang/String;
       6: pop
       7: return

  private static final java.lang.String solution(int, int);
    Code:
       0: ldc           #12                 // String
       2: astore_2
       3: bipush        13
       5: anewarray     #14                 // class java/lang/Integer
       8: astore        4
      10: aload         4
      12: iconst_0
      13: iconst_0
      14: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: aastore
      18: aload         4
      20: iconst_1
      21: bipush        31
      23: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: aastore
      27: aload         4
      29: iconst_2
      30: bipush        29
      32: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aastore
      36: aload         4
      38: iconst_3
      39: bipush        31
      41: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: aastore
      45: aload         4
      47: iconst_4
      48: bipush        30
      50: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: aastore
      54: aload         4
      56: iconst_5
      57: bipush        31
      59: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: aastore
      63: aload         4
      65: bipush        6
      67: bipush        30
      69: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aastore
      73: aload         4
      75: bipush        7
      77: bipush        31
      79: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      82: aastore
      83: aload         4
      85: bipush        8
      87: bipush        31
      89: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: aastore
      93: aload         4
      95: bipush        9
      97: bipush        30
      99: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: aastore
     103: aload         4
     105: bipush        10
     107: bipush        31
     109: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aastore
     113: aload         4
     115: bipush        11
     117: bipush        30
     119: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: aastore
     123: aload         4
     125: bipush        12
     127: bipush        31
     129: invokestatic  #18                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: aastore
     133: aload         4
     135: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     138: astore_3
     139: bipush        7
     141: anewarray     #26                 // class java/lang/String
     144: astore        5
     146: aload         5
     148: iconst_0
     149: ldc           #28                 // String SUN
     151: aastore
     152: aload         5
     154: iconst_1
     155: ldc           #30                 // String MON
     157: aastore
     158: aload         5
     160: iconst_2
     161: ldc           #32                 // String TUE
     163: aastore
     164: aload         5
     166: iconst_3
     167: ldc           #34                 // String WED
     169: aastore
     170: aload         5
     172: iconst_4
     173: ldc           #36                 // String THU
     175: aastore
     176: aload         5
     178: iconst_5
     179: ldc           #38                 // String FRI
     181: aastore
     182: aload         5
     184: bipush        6
     186: ldc           #40                 // String SAT
     188: aastore
     189: aload         5
     191: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     194: astore        4
     196: iconst_0
     197: istore        5
     199: iconst_1
     200: istore        6
     202: iload         6
     204: iload_0
     205: if_icmpge     233
     208: iload         5
     210: aload_3
     211: iload         6
     213: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #48                 // class java/lang/Number
     221: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     224: iadd
     225: istore        5
     227: iinc          6, 1
     230: goto          202
     233: iload         5
     235: iload_1
     236: iconst_1
     237: isub
     238: iadd
     239: istore        5
     241: aload         4
     243: iload         5
     245: iconst_5
     246: iadd
     247: bipush        7
     249: irem
     250: invokeinterface #46,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     255: checkcast     #26                 // class java/lang/String
     258: astore_2
     259: aload_2
     260: areturn

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


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12935
 *
 * 문제 설명
 * 정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요.
 * 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요.
 * 예를들어 arr이 [4,3,2,1]인 경우는 [4,3,2]를 리턴 하고, [10]면 [-1]을 리턴 합니다.
 *
 * 제한 조건
 * arr은 길이 1 이상인 배열입니다.
 * 인덱스 i, j에 대해 i ≠ j이면 arr[i] ≠ arr[j] 입니다.
 * 입출력 예
 * arr	        return
 * [4,3,2,1]	[4,3,2]
 * [10]	        [-1]
 */

fun main() {
    solution(intArrayOf(4,3,2,1))
    solution(intArrayOf(10))
    solution(intArrayOf())
}

private fun solution(arr: IntArray): IntArray {
    if (arr.isEmpty()) return intArrayOf(-1)

    var answer = intArrayOf()
    var minValue = arr.first();

    arr.forEach {
        if (it < minValue) {
            minValue = it
        }
    }
    answer = arr.filter { it != minValue }.toIntArray()
    if (answer.isEmpty()) return intArrayOf(-1)
    return answer
}

//private fun solution_1(arr: IntArray): IntArray {
//    if (arr.size == 1) return intArrayOf(-1)
//    return arr.sorted().toIntArray().copyOfRange(1, arr.size);
//}

private fun solution_2(arr: IntArray): IntArray = if(arr.size == 1) intArrayOf(-1)
                                                else arr.filter { it != arr.min() }.toIntArray()

Compiled from "Lv1_12935.kt"
public final class main.kotlin.programmers.lv01.Lv1_12935Kt {
  public static final void main();
    Code:
       0: iconst_4
       1: newarray       int
       3: astore_0
       4: aload_0
       5: iconst_0
       6: iconst_4
       7: iastore
       8: aload_0
       9: iconst_1
      10: iconst_3
      11: iastore
      12: aload_0
      13: iconst_2
      14: iconst_2
      15: iastore
      16: aload_0
      17: iconst_3
      18: iconst_1
      19: iastore
      20: aload_0
      21: invokestatic  #10                 // Method solution:([I)[I
      24: pop
      25: iconst_1
      26: newarray       int
      28: astore_0
      29: aload_0
      30: iconst_0
      31: bipush        10
      33: iastore
      34: aload_0
      35: invokestatic  #10                 // Method solution:([I)[I
      38: pop
      39: iconst_0
      40: newarray       int
      42: invokestatic  #10                 // Method solution:([I)[I
      45: pop
      46: return

  private static final int[] solution(int[]);
    Code:
       0: aload_0
       1: arraylength
       2: ifne          9
       5: iconst_1
       6: goto          10
       9: iconst_0
      10: ifeq          23
      13: iconst_1
      14: newarray       int
      16: astore_1
      17: aload_1
      18: iconst_0
      19: iconst_m1
      20: iastore
      21: aload_1
      22: areturn
      23: iconst_0
      24: newarray       int
      26: astore_1
      27: iconst_0
      28: istore_2
      29: aload_0
      30: invokestatic  #16                 // Method kotlin/collections/ArraysKt.first:([I)I
      33: istore_2
      34: aload_0
      35: astore_3
      36: iconst_0
      37: istore        4
      39: iconst_0
      40: istore        5
      42: aload_3
      43: arraylength
      44: istore        6
      46: iload         5
      48: iload         6
      50: if_icmpge     83
      53: aload_3
      54: iload         5
      56: iaload
      57: istore        7
      59: iload         7
      61: istore        8
      63: iconst_0
      64: istore        9
      66: iload         8
      68: iload_2
      69: if_icmpge     75
      72: iload         8
      74: istore_2
      75: nop
      76: nop
      77: iinc          5, 1
      80: goto          46
      83: nop
      84: aload_0
      85: astore_3
      86: iconst_0
      87: istore        4
      89: aload_3
      90: astore        5
      92: new           #18                 // class java/util/ArrayList
      95: dup
      96: invokespecial #21                 // Method java/util/ArrayList."<init>":()V
      99: checkcast     #23                 // class java/util/Collection
     102: astore        6
     104: iconst_0
     105: istore        7
     107: iconst_0
     108: istore        8
     110: aload         5
     112: arraylength
     113: istore        9
     115: iload         8
     117: iload         9
     119: if_icmpge     169
     122: aload         5
     124: iload         8
     126: iaload
     127: istore        10
     129: iload         10
     131: istore        11
     133: iconst_0
     134: istore        12
     136: iload         11
     138: iload_2
     139: if_icmpeq     146
     142: iconst_1
     143: goto          147
     146: iconst_0
     147: ifeq          163
     150: aload         6
     152: iload         10
     154: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     157: invokeinterface #33,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: iinc          8, 1
     166: goto          115
     169: aload         6
     171: checkcast     #35                 // class java/util/List
     174: nop
     175: checkcast     #23                 // class java/util/Collection
     178: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     181: astore_1
     182: aload_1
     183: arraylength
     184: ifne          191
     187: iconst_1
     188: goto          192
     191: iconst_0
     192: ifeq          205
     195: iconst_1
     196: newarray       int
     198: astore_3
     199: aload_3
     200: iconst_0
     201: iconst_m1
     202: iastore
     203: aload_3
     204: areturn
     205: aload_1
     206: areturn

  private static final int[] solution_2(int[]);
    Code:
       0: aload_0
       1: arraylength
       2: iconst_1
       3: if_icmpne     18
       6: iconst_1
       7: newarray       int
       9: astore_1
      10: aload_1
      11: iconst_0
      12: iconst_m1
      13: iastore
      14: aload_1
      15: goto          114
      18: aload_0
      19: astore_1
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #18                 // class java/util/ArrayList
      27: dup
      28: invokespecial #21                 // Method java/util/ArrayList."<init>":()V
      31: checkcast     #23                 // class java/util/Collection
      34: astore        4
      36: iconst_0
      37: istore        5
      39: iconst_0
      40: istore        6
      42: aload_3
      43: arraylength
      44: istore        7
      46: iload         6
      48: iload         7
      50: if_icmpge     102
      53: aload_3
      54: iload         6
      56: iaload
      57: istore        8
      59: iload         8
      61: istore        9
      63: iconst_0
      64: istore        10
      66: iload         9
      68: aload_0
      69: invokestatic  #64                 // Method kotlin/collections/ArraysKt.minOrThrow:([I)I
      72: if_icmpeq     79
      75: iconst_1
      76: goto          80
      79: iconst_0
      80: ifeq          96
      83: aload         4
      85: iload         8
      87: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: invokeinterface #33,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: iinc          6, 1
      99: goto          46
     102: aload         4
     104: checkcast     #35                 // class java/util/List
     107: nop
     108: checkcast     #23                 // class java/util/Collection
     111: invokestatic  #41                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     114: areturn

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


package main.kotlin.programmers.lv01

import kotlin.math.sqrt

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/77884
 *
 * 약수의 개수와 덧셈
 * 문제 설명
 * 두 정수 left와 right가 매개변수로 주어집니다.
 * left부터 right까지의 모든 수들 중에서, 약수의 개수가 짝수인 수는 더하고, 약수의 개수가 홀수인 수는 뺀 수를 return 하도록 solution 함수를 완성해주세요.
 *
 * 제한사항
 * 1 ≤ left ≤ right ≤ 1,000
 * 입출력 예
 * left	right	result
 * 13	17	43
 * 24	27	52
 * 입출력 예 설명
 * 입출력 예 #1
 *
 * 다음 표는 13부터 17까지의 수들의 약수를 모두 나타낸 것입니다.
 * 수	약수	            약수의 개수
 * 13	1, 13	        2
 * 14	1, 2, 7, 14	    4
 * 15	1, 3, 5, 15	    4
 * 16	1, 2, 4, 8, 16	5
 * 17	1, 17	        2
 * 따라서, 13 + 14 + 15 - 16 + 17 = 43을 return 해야 합니다.
 * 입출력 예 #2
 *
 * 다음 표는 24부터 27까지의 수들의 약수를 모두 나타낸 것입니다.
 * 수	약수	                        약수의 개수
 * 24	1, 2, 3, 4, 6, 8, 12, 24	8
 * 25	1, 5, 25	                3
 * 26	1, 2, 13, 26	            4
 * 27	1, 3, 9, 27	                4
 * 따라서, 24 - 25 + 26 + 27 = 52를 return 해야 합니다.
 *
 */

fun main() {
    solution(13, 17)
}

private fun solution(left: Int, right: Int): Int {
    var answer: Int = 0

    for (i in left..right) {
        if (countDivisors(i) % 2 == 0) {
            answer += i
        } else {
            answer -= i
        }
    }

    println(answer)

    return answer
}

private fun countDivisors(n: Int): Int {
    var count = 0
    val sqrtN = sqrt(n.toDouble()).toInt()

    for (i in 1..sqrtN) {
        if (n % i == 0) {
            count += 2 // i와 n/i는 모두 약수이므로 2를 추가
        }
    }

    // 만약 n이 제곱수인 경우 중복으로 카운트된 약수를 제거
    if (sqrtN * sqrtN == n) {
        count--
    }

    return count
}

Compiled from "Lv1_77884.kt"
public final class main.kotlin.programmers.lv01.Lv1_77884Kt {
  public static final void main();
    Code:
       0: bipush        13
       2: bipush        17
       4: invokestatic  #10                 // Method solution:(II)I
       7: pop
       8: return

  private static final int solution(int, int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_0
       3: istore_3
       4: iload_3
       5: iload_1
       6: if_icmpgt     40
       9: iload_3
      10: invokestatic  #14                 // Method countDivisors:(I)I
      13: iconst_2
      14: irem
      15: ifne          25
      18: iload_2
      19: iload_3
      20: iadd
      21: istore_2
      22: goto          29
      25: iload_2
      26: iload_3
      27: isub
      28: istore_2
      29: iload_3
      30: iload_1
      31: if_icmpeq     40
      34: iinc          3, 1
      37: goto          9
      40: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      43: iload_2
      44: invokevirtual #26                 // Method java/io/PrintStream.println:(I)V
      47: iload_2
      48: ireturn

  private static final int countDivisors(int);
    Code:
       0: iconst_0
       1: istore_1
       2: iload_0
       3: i2d
       4: invokestatic  #37                 // Method java/lang/Math.sqrt:(D)D
       7: d2i
       8: istore_2
       9: iconst_1
      10: istore_3
      11: iload_3
      12: iload_2
      13: if_icmpgt     36
      16: iload_0
      17: iload_3
      18: irem
      19: ifne          25
      22: iinc          1, 2
      25: iload_3
      26: iload_2
      27: if_icmpeq     36
      30: iinc          3, 1
      33: goto          16
      36: iload_2
      37: iload_2
      38: imul
      39: iload_0
      40: if_icmpne     46
      43: iinc          1, -1
      46: iload_1
      47: ireturn

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


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/70128
 *
 * 문제 설명
 * 길이가 같은 두 1차원 정수 배열 a, b가 매개변수로 주어집니다.
 * a와 b의 내적을 return 하도록 solution 함수를 완성해주세요.
 *
 * 이때, a와 b의 내적은 a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] 입니다. (n은 a, b의 길이)
 *
 * 제한사항
 * a, b의 길이는 1 이상 1,000 이하입니다.
 * a, b의 모든 수는 -1,000 이상 1,000 이하입니다.
 * 입출력 예
 * a	        b	            result
 * [1,2,3,4]	[-3,-1,0,2]	    3
 * [-1,0,1]	    [1,0,-1]	    -2
 *
 * 입출력 예 설명
 * 입출력 예 #1
 * a와 b의 내적은 1*(-3) + 2*(-1) + 3*0 + 4*2 = 3 입니다.
 *
 * 입출력 예 #2
 * a와 b의 내적은 (-1)*1 + 0*0 + 1*(-1) = -2 입니다.
 */

fun main() {
    solution(intArrayOf(1,2,3,4), intArrayOf(-3,-1,0,2))
}

private fun solution(a: IntArray, b: IntArray): Int {
    var answer: Int = 0
    for (i in a.indices) {
        answer += a[i] * b[i]
    }
    return answer
}

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

  private static final int solution(int[], int[]);
    Code:
       0: iconst_0
       1: istore_2
       2: iconst_0
       3: istore_3
       4: aload_0
       5: arraylength
       6: istore        4
       8: iload_3
       9: iload         4
      11: if_icmpge     30
      14: iload_2
      15: aload_0
      16: iload_3
      17: iaload
      18: aload_1
      19: iload_3
      20: iaload
      21: imul
      22: iadd
      23: istore_2
      24: iinc          3, 1
      27: goto          8
      30: iload_2
      31: ireturn

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


package main.kotlin.programmers.lv01

/**
 *
 * https://school.programmers.co.kr/learn/courses/30/lessons/12912
 *
 * 두 정수 a, b가 주어졌을 때 a와 b 사이에 속한 모든 정수의 합을 리턴하는 함수, solution을 완성하세요.
 * 예를 들어 a = 3, b = 5인 경우, 3 + 4 + 5 = 12이므로 12를 리턴합니다.
 *
 * 제한 조건
 * a와 b가 같은 경우는 둘 중 아무 수나 리턴하세요.
 * a와 b는 -10,000,000 이상 10,000,000 이하인 정수입니다.
 * a와 b의 대소관계는 정해져있지 않습니다.
 * 입출력 예
 * a	b	return
 * 3	5	12
 * 3	3	3
 * 5	3	12
 *
 */

fun main() {
    solution(3, 5)
    solution(3, 3)
    solution(5, 3)

}

private fun solution(a: Int, b: Int): Long {
    var answer: Long = 0

    if (a > b) {
        for (i in b..a) {
            answer += i
        }
    } else {
        for (i in a..b) {
            answer += i
        }
    }
    return answer
}

private fun secondSolution(a: Int, b: Int): Long {
    val start : Long = (if(a>b) b else a).toLong()
    val end : Long = (if(a>b) a else b).toLong()
    return (start..end).sum()
}

Compiled from "Lv1_12912.kt"
public final class main.kotlin.programmers.lv01.Lv1_12912Kt {
  public static final void main();
    Code:
       0: iconst_3
       1: iconst_5
       2: invokestatic  #10                 // Method solution:(II)J
       5: pop2
       6: iconst_3
       7: iconst_3
       8: invokestatic  #10                 // Method solution:(II)J
      11: pop2
      12: iconst_5
      13: iconst_3
      14: invokestatic  #10                 // Method solution:(II)J
      17: pop2
      18: return

  private static final long solution(int, int);
    Code:
       0: lconst_0
       1: lstore_2
       2: iload_0
       3: iload_1
       4: if_icmple     34
       7: iload_1
       8: istore        4
      10: iload         4
      12: iload_0
      13: if_icmpgt     61
      16: lload_2
      17: iload         4
      19: i2l
      20: ladd
      21: lstore_2
      22: iload         4
      24: iload_0
      25: if_icmpeq     61
      28: iinc          4, 1
      31: goto          16
      34: iload_0
      35: istore        4
      37: iload         4
      39: iload_1
      40: if_icmpgt     61
      43: lload_2
      44: iload         4
      46: i2l
      47: ladd
      48: lstore_2
      49: iload         4
      51: iload_1
      52: if_icmpeq     61
      55: iinc          4, 1
      58: goto          43
      61: lload_2
      62: lreturn

  private static final long secondSolution(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmple     9
       5: iload_1
       6: goto          10
       9: iload_0
      10: i2l
      11: lstore_2
      12: iload_0
      13: iload_1
      14: if_icmple     21
      17: iload_0
      18: goto          22
      21: iload_1
      22: i2l
      23: lstore        4
      25: new           #19                 // class kotlin/ranges/LongRange
      28: dup
      29: lload_2
      30: lload         4
      32: invokespecial #23                 // Method kotlin/ranges/LongRange."<init>":(JJ)V
      35: checkcast     #25                 // class java/lang/Iterable
      38: invokestatic  #31                 // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
      41: lreturn

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