package kLoops.examples

typealias Point = Pair<Int, Int>

data class World(val landPoints: Set<Point>, val height: Int, val width: Int) {
    fun print() {
        (0 until height).forEach { row ->
            (0 until width).forEach { column ->
                val value = if (landPoints.contains(Point(row, column))) 1 else 0
                print("$value ")
            }
            println()
        }
    }

    fun neighbours(point: Point): List<Point> {
        val neighbours = mutableListOf<Point>()
        if (point.first > 0) neighbours.add(point.copy(first = point.first - 1))
        if (point.first < height - 1) neighbours.add(point.copy(first = point.first + 1))
        if (point.second > 0) neighbours.add(point.copy(second = point.second - 1))
        if (point.second > width - 1) neighbours.add(point.copy(second = point.second + 1))
        return neighbours.toList()
    }
}

fun isPerfectIsland(world: World): Boolean {
    val visitedPoint = mutableListOf(world.landPoints.first())
    fun traverseIsland() {
        world.neighbours(visitedPoint.last()).forEach { neighbour ->
            if (world.landPoints.contains(neighbour) && !visitedPoint.contains(neighbour)) {
                visitedPoint.add(neighbour)
                traverseIsland()
            }
        }
    }
    traverseIsland()
    return visitedPoint.containsAll(world.landPoints)
}

val memmoization = mutableMapOf<World, Int>()
fun findNumberOfSwitches(world: World, path: List<World>): Int {
    memmoization[world] = -1
    if (memmoization[world]?: -1 > 0 ) {
        return memmoization[world]!!
    }
    val numberOfSwitches = if (isPerfectIsland(world)) {

        0
    } else {
        1 + world.landPoints.flatMap { point ->
            world.neighbours(point).map { neighbour ->
                world.copy(landPoints = world.landPoints - point + neighbour)
            }.filter {newWorld ->
                !path.contains(newWorld)
            }.map { newWorld ->
                val sw = findNumberOfSwitches(newWorld, path + world)
                sw
            }
        }.min()!!
    }
    memmoization.put(world, numberOfSwitches)
    return numberOfSwitches
}

fun main() {
    val worldArray = listOf(
            listOf(0, 1, 0),
            listOf(0, 0, 1),
            listOf(1, 0, 0)
    )

    val height = worldArray.size
    val width = worldArray[0].size
    val landPoints = (0 until height).flatMap { row ->
        (0 until width).flatMap { column ->
            if (worldArray[row][column] == 1) listOf(Point(row, column)) else listOf()
        }
    }.toSet()
    val world = World(landPoints, height, width)
    world.print()

    println("Fuck ${findNumberOfSwitches(world, listOf())}")
    println("Fuck ${findNumberOfSwitches(world, listOf())}")
}

Compiled from "island.kt"
public final class kLoops.examples.IslandKt {
  private static final java.util.Map<kLoops.examples.World, java.lang.Integer> memmoization;

  public static final boolean isPerfectIsland(kLoops.examples.World);
    Code:
       0: aload_0
       1: ldc           #9                  // String world
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: anewarray     #17                 // class kotlin/Pair
      10: astore_2
      11: aload_2
      12: iconst_0
      13: aload_0
      14: invokevirtual #23                 // Method kLoops/examples/World.getLandPoints:()Ljava/util/Set;
      17: checkcast     #25                 // class java/lang/Iterable
      20: invokestatic  #31                 // Method kotlin/collections/CollectionsKt.first:(Ljava/lang/Iterable;)Ljava/lang/Object;
      23: aastore
      24: aload_2
      25: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      28: astore_1
      29: aload_0
      30: aload_1
      31: invokestatic  #39                 // Method isPerfectIsland$traverseIsland:(LkLoops/examples/World;Ljava/util/List;)V
      34: aload_1
      35: aload_0
      36: invokevirtual #23                 // Method kLoops/examples/World.getLandPoints:()Ljava/util/Set;
      39: checkcast     #41                 // class java/util/Collection
      42: invokeinterface #47,  2           // InterfaceMethod java/util/List.containsAll:(Ljava/util/Collection;)Z
      47: ireturn

  public static final java.util.Map<kLoops.examples.World, java.lang.Integer> getMemmoization();
    Code:
       0: getstatic     #57                 // Field memmoization:Ljava/util/Map;
       3: areturn

  public static final int findNumberOfSwitches(kLoops.examples.World, java.util.List<kLoops.examples.World>);
    Code:
       0: aload_0
       1: ldc           #9                  // String world
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #62                 // String path
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: getstatic     #57                 // Field memmoization:Ljava/util/Map;
      15: aload_0
      16: iconst_m1
      17: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      20: invokeinterface #74,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      25: pop
      26: getstatic     #57                 // Field memmoization:Ljava/util/Map;
      29: aload_0
      30: invokeinterface #78,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      35: checkcast     #64                 // class java/lang/Integer
      38: dup
      39: ifnull        48
      42: invokevirtual #82                 // Method java/lang/Integer.intValue:()I
      45: goto          50
      48: pop
      49: iconst_m1
      50: ifle          73
      53: getstatic     #57                 // Field memmoization:Ljava/util/Map;
      56: aload_0
      57: invokeinterface #78,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      62: dup
      63: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      66: checkcast     #88                 // class java/lang/Number
      69: invokevirtual #89                 // Method java/lang/Number.intValue:()I
      72: ireturn
      73: aload_0
      74: invokestatic  #91                 // Method isPerfectIsland:(LkLoops/examples/World;)Z
      77: ifeq          84
      80: iconst_0
      81: goto          542
      84: iconst_1
      85: aload_0
      86: invokevirtual #23                 // Method kLoops/examples/World.getLandPoints:()Ljava/util/Set;
      89: checkcast     #25                 // class java/lang/Iterable
      92: astore_3
      93: istore        23
      95: iconst_0
      96: istore        4
      98: aload_3
      99: astore        5
     101: new           #93                 // class java/util/ArrayList
     104: dup
     105: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     108: checkcast     #41                 // class java/util/Collection
     111: astore        6
     113: iconst_0
     114: istore        7
     116: aload         5
     118: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     123: astore        8
     125: aload         8
     127: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          513
     135: aload         8
     137: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: astore        9
     144: aload         9
     146: checkcast     #17                 // class kotlin/Pair
     149: astore        10
     151: iconst_0
     152: istore        11
     154: aload_0
     155: aload         10
     157: invokevirtual #115                // Method kLoops/examples/World.neighbours:(Lkotlin/Pair;)Ljava/util/List;
     160: checkcast     #25                 // class java/lang/Iterable
     163: astore        12
     165: iconst_0
     166: istore        13
     168: aload         12
     170: astore        14
     172: new           #93                 // class java/util/ArrayList
     175: dup
     176: aload         12
     178: bipush        10
     180: invokestatic  #119                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     183: invokespecial #122                // Method java/util/ArrayList."<init>":(I)V
     186: checkcast     #41                 // class java/util/Collection
     189: astore        15
     191: iconst_0
     192: istore        16
     194: aload         14
     196: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     201: astore        17
     203: aload         17
     205: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     210: ifeq          271
     213: aload         17
     215: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     220: astore        18
     222: aload         15
     224: aload         18
     226: checkcast     #17                 // class kotlin/Pair
     229: astore        19
     231: astore        20
     233: iconst_0
     234: istore        21
     236: aload_0
     237: aload_0
     238: invokevirtual #23                 // Method kLoops/examples/World.getLandPoints:()Ljava/util/Set;
     241: aload         10
     243: invokestatic  #128                // Method kotlin/collections/SetsKt.minus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     246: aload         19
     248: invokestatic  #131                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     251: iconst_0
     252: iconst_0
     253: bipush        6
     255: aconst_null
     256: invokestatic  #135                // Method kLoops/examples/World.copy$default:(LkLoops/examples/World;Ljava/util/Set;IIILjava/lang/Object;)LkLoops/examples/World;
     259: aload         20
     261: swap
     262: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     267: pop
     268: goto          203
     271: aload         15
     273: checkcast     #43                 // class java/util/List
     276: nop
     277: checkcast     #25                 // class java/lang/Iterable
     280: astore        12
     282: nop
     283: iconst_0
     284: istore        13
     286: aload         12
     288: astore        14
     290: new           #93                 // class java/util/ArrayList
     293: dup
     294: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     297: checkcast     #41                 // class java/util/Collection
     300: astore        15
     302: iconst_0
     303: istore        16
     305: aload         14
     307: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     312: astore        17
     314: aload         17
     316: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     321: ifeq          375
     324: aload         17
     326: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     331: astore        18
     333: aload         18
     335: checkcast     #19                 // class kLoops/examples/World
     338: astore        19
     340: iconst_0
     341: istore        21
     343: aload_1
     344: aload         19
     346: invokeinterface #142,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     351: ifne          358
     354: iconst_1
     355: goto          359
     358: iconst_0
     359: ifeq          314
     362: aload         15
     364: aload         18
     366: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     371: pop
     372: goto          314
     375: aload         15
     377: checkcast     #43                 // class java/util/List
     380: nop
     381: checkcast     #25                 // class java/lang/Iterable
     384: astore        12
     386: nop
     387: iconst_0
     388: istore        13
     390: aload         12
     392: astore        14
     394: new           #93                 // class java/util/ArrayList
     397: dup
     398: aload         12
     400: bipush        10
     402: invokestatic  #119                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     405: invokespecial #122                // Method java/util/ArrayList."<init>":(I)V
     408: checkcast     #41                 // class java/util/Collection
     411: astore        15
     413: iconst_0
     414: istore        16
     416: aload         14
     418: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     423: astore        17
     425: aload         17
     427: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     432: ifeq          490
     435: aload         17
     437: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     442: astore        18
     444: aload         15
     446: aload         18
     448: checkcast     #19                 // class kLoops/examples/World
     451: astore        19
     453: astore        20
     455: iconst_0
     456: istore        21
     458: aload         19
     460: aload_1
     461: checkcast     #41                 // class java/util/Collection
     464: aload_0
     465: invokestatic  #145                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     468: invokestatic  #147                // Method findNumberOfSwitches:(LkLoops/examples/World;Ljava/util/List;)I
     471: istore        22
     473: iload         22
     475: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     478: aload         20
     480: swap
     481: invokeinterface #139,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     486: pop
     487: goto          425
     490: aload         15
     492: checkcast     #43                 // class java/util/List
     495: nop
     496: checkcast     #25                 // class java/lang/Iterable
     499: nop
     500: astore        10
     502: aload         6
     504: aload         10
     506: invokestatic  #151                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     509: pop
     510: goto          125
     513: aload         6
     515: checkcast     #43                 // class java/util/List
     518: nop
     519: astore        24
     521: iload         23
     523: aload         24
     525: checkcast     #25                 // class java/lang/Iterable
     528: invokestatic  #155                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     531: dup
     532: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     535: checkcast     #88                 // class java/lang/Number
     538: invokevirtual #89                 // Method java/lang/Number.intValue:()I
     541: iadd
     542: istore_2
     543: getstatic     #57                 // Field memmoization:Ljava/util/Map;
     546: aload_0
     547: iload_2
     548: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     551: invokeinterface #74,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     556: pop
     557: iload_2
     558: ireturn

  public static final void main();
    Code:
       0: iconst_3
       1: anewarray     #43                 // class java/util/List
       4: astore_1
       5: aload_1
       6: iconst_0
       7: iconst_3
       8: anewarray     #64                 // class java/lang/Integer
      11: astore_2
      12: aload_2
      13: iconst_0
      14: iconst_0
      15: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore
      19: aload_2
      20: iconst_1
      21: iconst_1
      22: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: aastore
      26: aload_2
      27: iconst_2
      28: iconst_0
      29: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: aastore
      33: aload_2
      34: invokestatic  #189                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      37: aastore
      38: aload_1
      39: iconst_1
      40: iconst_3
      41: anewarray     #64                 // class java/lang/Integer
      44: astore_2
      45: aload_2
      46: iconst_0
      47: iconst_0
      48: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: aastore
      52: aload_2
      53: iconst_1
      54: iconst_0
      55: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: aastore
      59: aload_2
      60: iconst_2
      61: iconst_1
      62: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: aastore
      66: aload_2
      67: invokestatic  #189                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      70: aastore
      71: aload_1
      72: iconst_2
      73: iconst_3
      74: anewarray     #64                 // class java/lang/Integer
      77: astore_2
      78: aload_2
      79: iconst_0
      80: iconst_1
      81: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      84: aastore
      85: aload_2
      86: iconst_1
      87: iconst_0
      88: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: aastore
      92: aload_2
      93: iconst_2
      94: iconst_0
      95: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: aastore
      99: aload_2
     100: invokestatic  #189                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     103: aastore
     104: aload_1
     105: invokestatic  #189                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     108: astore_0
     109: aload_0
     110: invokeinterface #192,  1          // InterfaceMethod java/util/List.size:()I
     115: istore_1
     116: aload_0
     117: iconst_0
     118: invokeinterface #195,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     123: checkcast     #43                 // class java/util/List
     126: invokeinterface #192,  1          // InterfaceMethod java/util/List.size:()I
     131: istore_2
     132: iconst_0
     133: iload_1
     134: invokestatic  #201                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     137: checkcast     #25                 // class java/lang/Iterable
     140: astore        4
     142: iconst_0
     143: istore        5
     145: aload         4
     147: astore        6
     149: new           #93                 // class java/util/ArrayList
     152: dup
     153: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     156: checkcast     #41                 // class java/util/Collection
     159: astore        7
     161: iconst_0
     162: istore        8
     164: aload         6
     166: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     171: astore        9
     173: aload         9
     175: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     180: ifeq          362
     183: aload         9
     185: checkcast     #203                // class kotlin/collections/IntIterator
     188: invokevirtual #206                // Method kotlin/collections/IntIterator.nextInt:()I
     191: istore        10
     193: iload         10
     195: istore        11
     197: iconst_0
     198: istore        12
     200: iconst_0
     201: iload_2
     202: invokestatic  #201                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     205: checkcast     #25                 // class java/lang/Iterable
     208: astore        13
     210: iconst_0
     211: istore        14
     213: aload         13
     215: astore        15
     217: new           #93                 // class java/util/ArrayList
     220: dup
     221: invokespecial #97                 // Method java/util/ArrayList."<init>":()V
     224: checkcast     #41                 // class java/util/Collection
     227: astore        16
     229: iconst_0
     230: istore        17
     232: aload         15
     234: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     239: astore        18
     241: aload         18
     243: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     248: ifeq          339
     251: aload         18
     253: checkcast     #203                // class kotlin/collections/IntIterator
     256: invokevirtual #206                // Method kotlin/collections/IntIterator.nextInt:()I
     259: istore        19
     261: iload         19
     263: istore        20
     265: iconst_0
     266: istore        21
     268: aload_0
     269: iload         11
     271: invokeinterface #195,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     276: checkcast     #43                 // class java/util/List
     279: iload         20
     281: invokeinterface #195,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     286: checkcast     #88                 // class java/lang/Number
     289: invokevirtual #89                 // Method java/lang/Number.intValue:()I
     292: iconst_1
     293: if_icmpne     319
     296: new           #17                 // class kotlin/Pair
     299: dup
     300: iload         11
     302: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     305: iload         20
     307: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     310: invokespecial #209                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     313: invokestatic  #212                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     316: goto          322
     319: invokestatic  #216                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     322: checkcast     #25                 // class java/lang/Iterable
     325: nop
     326: astore        20
     328: aload         16
     330: aload         20
     332: invokestatic  #151                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     335: pop
     336: goto          241
     339: aload         16
     341: checkcast     #43                 // class java/util/List
     344: nop
     345: checkcast     #25                 // class java/lang/Iterable
     348: nop
     349: astore        11
     351: aload         7
     353: aload         11
     355: invokestatic  #151                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     358: pop
     359: goto          173
     362: aload         7
     364: checkcast     #43                 // class java/util/List
     367: nop
     368: checkcast     #25                 // class java/lang/Iterable
     371: invokestatic  #220                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     374: astore_3
     375: new           #19                 // class kLoops/examples/World
     378: dup
     379: aload_3
     380: iload_1
     381: iload_2
     382: invokespecial #223                // Method kLoops/examples/World."<init>":(Ljava/util/Set;II)V
     385: astore        4
     387: aload         4
     389: invokevirtual #226                // Method kLoops/examples/World.print:()V
     392: new           #228                // class java/lang/StringBuilder
     395: dup
     396: invokespecial #229                // Method java/lang/StringBuilder."<init>":()V
     399: ldc           #231                // String Fuck
     401: invokevirtual #235                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     404: aload         4
     406: invokestatic  #216                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     409: invokestatic  #147                // Method findNumberOfSwitches:(LkLoops/examples/World;Ljava/util/List;)I
     412: invokevirtual #238                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     415: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     418: getstatic     #248                // Field java/lang/System.out:Ljava/io/PrintStream;
     421: swap
     422: invokevirtual #253                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     425: new           #228                // class java/lang/StringBuilder
     428: dup
     429: invokespecial #229                // Method java/lang/StringBuilder."<init>":()V
     432: ldc           #231                // String Fuck
     434: invokevirtual #235                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     437: aload         4
     439: invokestatic  #216                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     442: invokestatic  #147                // Method findNumberOfSwitches:(LkLoops/examples/World;Ljava/util/List;)I
     445: invokevirtual #238                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     448: invokevirtual #242                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     451: getstatic     #248                // Field java/lang/System.out:Ljava/io/PrintStream;
     454: swap
     455: invokevirtual #253                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     458: return

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

  private static final void isPerfectIsland$traverseIsland(kLoops.examples.World, java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #272                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
       5: checkcast     #17                 // class kotlin/Pair
       8: invokevirtual #115                // Method kLoops/examples/World.neighbours:(Lkotlin/Pair;)Ljava/util/List;
      11: checkcast     #25                 // class java/lang/Iterable
      14: astore_2
      15: iconst_0
      16: istore_3
      17: aload_2
      18: invokeinterface #101,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      23: astore        4
      25: aload         4
      27: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      32: ifeq          98
      35: aload         4
      37: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        5
      44: aload         5
      46: checkcast     #17                 // class kotlin/Pair
      49: astore        6
      51: iconst_0
      52: istore        7
      54: aload_0
      55: invokevirtual #23                 // Method kLoops/examples/World.getLandPoints:()Ljava/util/Set;
      58: aload         6
      60: invokeinterface #275,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      65: ifeq          93
      68: aload_1
      69: aload         6
      71: invokeinterface #142,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
      76: ifne          93
      79: aload_1
      80: aload         6
      82: invokeinterface #276,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      87: pop
      88: aload_0
      89: aload_1
      90: invokestatic  #39                 // Method isPerfectIsland$traverseIsland:(LkLoops/examples/World;Ljava/util/List;)V
      93: nop
      94: nop
      95: goto          25
      98: nop
      99: return

  static {};
    Code:
       0: new           #284                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #285                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #70                 // class java/util/Map
      10: putstatic     #57                 // Field memmoization:Ljava/util/Map;
      13: return
}


package graph

import java.util.*
import kotlin.collections.HashMap
import kotlin.collections.HashSet

class Graph {
    companion object {
        @JvmStatic
        fun createAdjacencyList(edges: Array<Pair<String, String>>): Map<String, Set<String>> {
            val graph = HashMap<String, MutableSet<String>>()
            for (edge in edges) {
                if (!graph.containsKey(edge.first)) {
                    graph[edge.first] = HashSet()
                }
                if (!graph.containsKey(edge.second)) {
                    graph[edge.second] = HashSet()
                }
                graph[edge.first]?.add(edge.second)
                graph[edge.second]?.add(edge.first)
            }
            return graph
        }

        @JvmStatic
        fun main(args: Array<String>) {
            val graph = Graph()
//            graph.breadthFirst()

//            graph.findPath()

//            println(graph.findPathUndirected())

            println(graph.connectedComponents())
        }
    }

    private fun connectedComponents(): Int {
//        val edges = arrayOf(Pair("1", "2"), Pair("4", "6"), Pair("5", "6"), Pair("6", "7"), Pair("6", "8"), Pair("3"))
        val graph = HashMap<String, Set<String>>()
        graph["1"] = setOf("2")
        graph["2"] = setOf("1")
        graph["3"] = emptySet()
        graph["4"] = setOf("6")
        graph["5"] = setOf("6")
        graph["6"] = setOf("4", "5", "7", "8")
        graph["7"] = setOf("6")
        graph["8"] = setOf("6")

        val visited = HashSet<String>()
        return connectedComponents(graph, visited)
    }

    private fun connectedComponents(
        graph: HashMap<String, Set<String>>,
        visited: HashSet<String>
    ): Int {
        var connectedComponents = 0
        for (node in graph.keys) {
            if (!visited.contains(node)) {
                connectedComponents++
                explore(graph, node, visited)
            }
        }
        return connectedComponents
    }

    private fun explore(
        graph: HashMap<String, Set<String>>,
        node: String,
        visited: HashSet<String>
    ) {
        if (!visited.contains(node)) {
            visited.add(node)
            graph[node]?.let {
                for (neighbor in it) {
                    explore(graph, neighbor, visited)
                }
            }
        }
    }

    fun findPathUndirected(): Boolean {
        val edges = arrayOf(Pair("i", "j"), Pair("k", "i"), Pair("m", "k"), Pair("k", "l"), Pair("o", "n"))
        val graph = createAdjacencyList(edges)
        println(graph.toString())
        return findPathUndirected(graph, "i", "j")
    }

    private fun findPathUndirected(graph: Map<String, Set<String>>, src: String, dst: String): Boolean {
        val queue: Queue<String> = LinkedList()
        queue.add(src)
        val visited = HashSet<String>()
        while (queue.isNotEmpty()) {
            val current = queue.poll()

            if (current.equals(dst)) {
                return true
            }
            if (!visited.contains(current)) {
                visited.add(current)
                graph[current]?.let {
                    for (neighbor in graph[current]!!) {
                        queue.add(neighbor)
                    }
                }
            }
        }
        return false
    }

    fun depthFirst(graph: HashMap<String, Set<String>>, source: String) {
        val stack = Stack<String>()
        stack.push(source)
        while (stack.isNotEmpty()) {
            val current = stack.pop()
            println(current)
            graph[current]?.let {
                for (neighbor in graph[current]!!) {
                    stack.push(neighbor)
                }
            }
        }
    }

    fun breadthFirst() {
        val graph = HashMap<String, Set<String>>()
        graph["a"] = setOf("b", "c")
        graph["b"] = setOf("d")
        graph["c"] = setOf("e")
        graph["d"] = setOf("f")
        graph["e"] = emptySet()
        graph["f"] = emptySet()

        breadthFirst(graph, "a")
    }

    fun breadthFirst(graph: HashMap<String, Set<String>>, source: String) {
        val queue: Queue<String> = LinkedList()
        queue.add(source)
        while (queue.isNotEmpty()) {
            val current = queue.poll()
            println(current)
            graph[current]?.let {
                for (neighbor in graph[current]!!) {
                    queue.add(neighbor)
                }
            }
        }
    }

    private fun findPath() {
        val graph = HashMap<String, Set<String>>()
        graph["f"] = setOf("g", "i")
        graph["g"] = setOf("h")
        graph["h"] = emptySet()
        graph["i"] = setOf("g", "k")
        graph["j"] = setOf("i")
        graph["k"] = emptySet()

        println(this.findPath(graph, "j", "h"))

    }

    private fun findPath(graph: java.util.HashMap<String, Set<String>>, src: String, dst: String): Boolean {
        val queue: Queue<String> = LinkedList()
        queue.add(src)
        while (queue.isNotEmpty()) {
            val current = queue.poll()

            if (current.equals(dst)) {
                return true
            }
            graph[current]?.let {
                for (neighbor in graph[current]!!) {
                    queue.add(neighbor)
                }
            }
        }

        return false
    }
}

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

  public final java.util.Map<java.lang.String, java.util.Set<java.lang.String>> createAdjacencyList(kotlin.Pair<java.lang.String, java.lang.String>[]);
    Code:
       0: aload_1
       1: ldc           #17                 // String edges
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #25                 // class java/util/HashMap
       9: dup
      10: invokespecial #26                 // Method java/util/HashMap."<init>":()V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_1
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     167
      26: aload_1
      27: iload_3
      28: aaload
      29: astore        5
      31: aload_2
      32: aload         5
      34: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      37: invokevirtual #36                 // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
      40: ifne          65
      43: aload_2
      44: checkcast     #38                 // class java/util/Map
      47: aload         5
      49: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      52: new           #40                 // class java/util/HashSet
      55: dup
      56: invokespecial #41                 // Method java/util/HashSet."<init>":()V
      59: invokeinterface #45,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      64: pop
      65: aload_2
      66: aload         5
      68: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      71: invokevirtual #36                 // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
      74: ifne          99
      77: aload_2
      78: checkcast     #38                 // class java/util/Map
      81: aload         5
      83: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      86: new           #40                 // class java/util/HashSet
      89: dup
      90: invokespecial #41                 // Method java/util/HashSet."<init>":()V
      93: invokeinterface #45,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      98: pop
      99: aload_2
     100: aload         5
     102: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     105: invokevirtual #52                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     108: checkcast     #54                 // class java/util/Set
     111: dup
     112: ifnull        129
     115: aload         5
     117: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     120: invokeinterface #57,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     125: pop
     126: goto          130
     129: pop
     130: aload_2
     131: aload         5
     133: invokevirtual #48                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     136: invokevirtual #52                 // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     139: checkcast     #54                 // class java/util/Set
     142: dup
     143: ifnull        160
     146: aload         5
     148: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     151: invokeinterface #57,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          161
     160: pop
     161: iinc          3, 1
     164: goto          20
     167: aload_2
     168: checkcast     #38                 // class java/util/Map
     171: areturn

  public final void main(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #66                 // String args
       3: invokestatic  #23                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #68                 // class graph/Graph
       9: dup
      10: invokespecial #69                 // Method graph/Graph."<init>":()V
      13: astore_2
      14: aload_2
      15: invokestatic  #73                 // Method graph/Graph.access$connectedComponents:(Lgraph/Graph;)I
      18: istore_3
      19: getstatic     #79                 // Field java/lang/System.out:Ljava/io/PrintStream;
      22: iload_3
      23: invokevirtual #85                 // Method java/io/PrintStream.println:(I)V
      26: return

  public graph.Graph$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #89                 // Method "<init>":()V
       4: return
}

Compiled from "Graph.kt"
public final class graph.Graph {
  public static final graph.Graph$Companion Companion;

  public graph.Graph();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final int connectedComponents();
    Code:
       0: new           #14                 // class java/util/HashMap
       3: dup
       4: invokespecial #15                 // Method java/util/HashMap."<init>":()V
       7: astore_1
       8: aload_1
       9: checkcast     #17                 // class java/util/Map
      12: ldc           #19                 // String 1
      14: ldc           #21                 // String 2
      16: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      19: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      24: pop
      25: aload_1
      26: checkcast     #17                 // class java/util/Map
      29: ldc           #21                 // String 2
      31: ldc           #19                 // String 1
      33: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      36: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      41: pop
      42: aload_1
      43: checkcast     #17                 // class java/util/Map
      46: ldc           #33                 // String 3
      48: invokestatic  #37                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      51: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      56: pop
      57: aload_1
      58: checkcast     #17                 // class java/util/Map
      61: ldc           #39                 // String 4
      63: ldc           #41                 // String 6
      65: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      68: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      73: pop
      74: aload_1
      75: checkcast     #17                 // class java/util/Map
      78: ldc           #43                 // String 5
      80: ldc           #41                 // String 6
      82: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      85: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      90: pop
      91: aload_1
      92: checkcast     #17                 // class java/util/Map
      95: astore_2
      96: ldc           #41                 // String 6
      98: astore_3
      99: iconst_4
     100: anewarray     #45                 // class java/lang/String
     103: astore        4
     105: aload         4
     107: iconst_0
     108: ldc           #39                 // String 4
     110: aastore
     111: aload         4
     113: iconst_1
     114: ldc           #43                 // String 5
     116: aastore
     117: aload         4
     119: iconst_2
     120: ldc           #47                 // String 7
     122: aastore
     123: aload         4
     125: iconst_3
     126: ldc           #49                 // String 8
     128: aastore
     129: aload         4
     131: invokestatic  #52                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     134: astore        4
     136: aload_2
     137: aload_3
     138: aload         4
     140: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     145: pop
     146: aload_1
     147: checkcast     #17                 // class java/util/Map
     150: ldc           #47                 // String 7
     152: ldc           #41                 // String 6
     154: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
     157: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     162: pop
     163: aload_1
     164: checkcast     #17                 // class java/util/Map
     167: ldc           #49                 // String 8
     169: ldc           #41                 // String 6
     171: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
     174: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     179: pop
     180: new           #54                 // class java/util/HashSet
     183: dup
     184: invokespecial #55                 // Method java/util/HashSet."<init>":()V
     187: astore_2
     188: aload_0
     189: aload_1
     190: aload_2
     191: invokespecial #58                 // Method connectedComponents:(Ljava/util/HashMap;Ljava/util/HashSet;)I
     194: ireturn

  private final int connectedComponents(java.util.HashMap<java.lang.String, java.util.Set<java.lang.String>>, java.util.HashSet<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_3
       2: aload_1
       3: invokevirtual #66                 // Method java/util/HashMap.keySet:()Ljava/util/Set;
       6: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      11: astore        4
      13: aload         4
      15: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      20: ifeq          58
      23: aload         4
      25: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      30: checkcast     #45                 // class java/lang/String
      33: astore        5
      35: aload_2
      36: aload         5
      38: invokevirtual #86                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      41: ifne          13
      44: iinc          3, 1
      47: aload_0
      48: aload_1
      49: aload         5
      51: aload_2
      52: invokespecial #90                 // Method explore:(Ljava/util/HashMap;Ljava/lang/String;Ljava/util/HashSet;)V
      55: goto          13
      58: iload_3
      59: ireturn

  private final void explore(java.util.HashMap<java.lang.String, java.util.Set<java.lang.String>>, java.lang.String, java.util.HashSet<java.lang.String>);
    Code:
       0: aload_3
       1: aload_2
       2: invokevirtual #86                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
       5: ifne          79
       8: aload_3
       9: aload_2
      10: invokevirtual #97                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      13: pop
      14: aload_1
      15: aload_2
      16: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      19: checkcast     #68                 // class java/util/Set
      22: dup
      23: ifnull        77
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload         4
      33: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      38: astore        6
      40: aload         6
      42: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          73
      50: aload         6
      52: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: checkcast     #45                 // class java/lang/String
      60: astore        7
      62: aload_0
      63: aload_1
      64: aload         7
      66: aload_3
      67: invokespecial #90                 // Method explore:(Ljava/util/HashMap;Ljava/lang/String;Ljava/util/HashSet;)V
      70: goto          40
      73: nop
      74: goto          79
      77: pop
      78: nop
      79: return

  public final boolean findPathUndirected();
    Code:
       0: iconst_5
       1: anewarray     #108                // class kotlin/Pair
       4: astore_2
       5: aload_2
       6: iconst_0
       7: new           #108                // class kotlin/Pair
      10: dup
      11: ldc           #110                // String i
      13: ldc           #112                // String j
      15: invokespecial #115                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      18: aastore
      19: aload_2
      20: iconst_1
      21: new           #108                // class kotlin/Pair
      24: dup
      25: ldc           #117                // String k
      27: ldc           #110                // String i
      29: invokespecial #115                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      32: aastore
      33: aload_2
      34: iconst_2
      35: new           #108                // class kotlin/Pair
      38: dup
      39: ldc           #119                // String m
      41: ldc           #117                // String k
      43: invokespecial #115                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      46: aastore
      47: aload_2
      48: iconst_3
      49: new           #108                // class kotlin/Pair
      52: dup
      53: ldc           #117                // String k
      55: ldc           #121                // String l
      57: invokespecial #115                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      60: aastore
      61: aload_2
      62: iconst_4
      63: new           #108                // class kotlin/Pair
      66: dup
      67: ldc           #123                // String o
      69: ldc           #125                // String n
      71: invokespecial #115                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      74: aastore
      75: aload_2
      76: astore_1
      77: getstatic     #129                // Field Companion:Lgraph/Graph$Companion;
      80: aload_1
      81: invokevirtual #135                // Method graph/Graph$Companion.createAdjacencyList:([Lkotlin/Pair;)Ljava/util/Map;
      84: astore_2
      85: aload_2
      86: invokevirtual #139                // Method java/lang/Object.toString:()Ljava/lang/String;
      89: getstatic     #145                // Field java/lang/System.out:Ljava/io/PrintStream;
      92: swap
      93: invokevirtual #151                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      96: aload_0
      97: aload_2
      98: ldc           #110                // String i
     100: ldc           #112                // String j
     102: invokespecial #154                // Method findPathUndirected:(Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Z
     105: ireturn

  private final boolean findPathUndirected(java.util.Map<java.lang.String, ? extends java.util.Set<java.lang.String>>, java.lang.String, java.lang.String);
    Code:
       0: new           #160                // class java/util/LinkedList
       3: dup
       4: invokespecial #161                // Method java/util/LinkedList."<init>":()V
       7: checkcast     #163                // class java/util/Queue
      10: astore        4
      12: aload         4
      14: aload_2
      15: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
      20: pop
      21: new           #54                 // class java/util/HashSet
      24: dup
      25: invokespecial #55                 // Method java/util/HashSet."<init>":()V
      28: astore        5
      30: aload         4
      32: checkcast     #166                // class java/util/Collection
      35: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      40: ifne          47
      43: iconst_1
      44: goto          48
      47: iconst_0
      48: ifeq          178
      51: aload         4
      53: invokeinterface #172,  1          // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
      58: checkcast     #45                 // class java/lang/String
      61: astore        6
      63: aload         6
      65: aload_3
      66: invokevirtual #175                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      69: ifeq          74
      72: iconst_1
      73: ireturn
      74: aload         5
      76: aload         6
      78: invokevirtual #86                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      81: ifne          30
      84: aload         5
      86: aload         6
      88: invokevirtual #97                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      91: pop
      92: aload_1
      93: aload         6
      95: invokeinterface #176,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     100: checkcast     #68                 // class java/util/Set
     103: dup
     104: ifnull        173
     107: astore        7
     109: iconst_0
     110: istore        8
     112: aload_1
     113: aload         6
     115: invokeinterface #176,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     120: dup
     121: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     124: checkcast     #68                 // class java/util/Set
     127: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     132: astore        9
     134: aload         9
     136: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     141: ifeq          169
     144: aload         9
     146: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     151: checkcast     #45                 // class java/lang/String
     154: astore        10
     156: aload         4
     158: aload         10
     160: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     165: pop
     166: goto          134
     169: nop
     170: goto          30
     173: pop
     174: nop
     175: goto          30
     178: iconst_0
     179: ireturn

  public final void depthFirst(java.util.HashMap<java.lang.String, java.util.Set<java.lang.String>>, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #192                // String graph
       3: invokestatic  #196                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #198                // String source
       9: invokestatic  #196                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #200                // class java/util/Stack
      15: dup
      16: invokespecial #201                // Method java/util/Stack."<init>":()V
      19: astore_3
      20: aload_3
      21: aload_2
      22: invokevirtual #204                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
      25: pop
      26: aload_3
      27: checkcast     #166                // class java/util/Collection
      30: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      35: ifne          42
      38: iconst_1
      39: goto          43
      42: iconst_0
      43: ifeq          142
      46: aload_3
      47: invokevirtual #207                // Method java/util/Stack.pop:()Ljava/lang/Object;
      50: checkcast     #45                 // class java/lang/String
      53: astore        4
      55: getstatic     #145                // Field java/lang/System.out:Ljava/io/PrintStream;
      58: aload         4
      60: invokevirtual #151                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      63: aload_1
      64: aload         4
      66: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      69: checkcast     #68                 // class java/util/Set
      72: dup
      73: ifnull        137
      76: astore        5
      78: iconst_0
      79: istore        6
      81: aload_1
      82: aload         4
      84: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      87: dup
      88: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      91: checkcast     #68                 // class java/util/Set
      94: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      99: astore        7
     101: aload         7
     103: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     108: ifeq          133
     111: aload         7
     113: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     118: checkcast     #45                 // class java/lang/String
     121: astore        8
     123: aload_3
     124: aload         8
     126: invokevirtual #204                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     129: pop
     130: goto          101
     133: nop
     134: goto          26
     137: pop
     138: nop
     139: goto          26
     142: return

  public final void breadthFirst();
    Code:
       0: new           #14                 // class java/util/HashMap
       3: dup
       4: invokespecial #15                 // Method java/util/HashMap."<init>":()V
       7: astore_1
       8: aload_1
       9: checkcast     #17                 // class java/util/Map
      12: astore_2
      13: ldc           #213                // String a
      15: astore_3
      16: iconst_2
      17: anewarray     #45                 // class java/lang/String
      20: astore        4
      22: aload         4
      24: iconst_0
      25: ldc           #215                // String b
      27: aastore
      28: aload         4
      30: iconst_1
      31: ldc           #217                // String c
      33: aastore
      34: aload         4
      36: invokestatic  #52                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      39: astore        4
      41: aload_2
      42: aload_3
      43: aload         4
      45: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      50: pop
      51: aload_1
      52: checkcast     #17                 // class java/util/Map
      55: ldc           #215                // String b
      57: ldc           #219                // String d
      59: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      62: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      67: pop
      68: aload_1
      69: checkcast     #17                 // class java/util/Map
      72: ldc           #217                // String c
      74: ldc           #221                // String e
      76: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      79: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      84: pop
      85: aload_1
      86: checkcast     #17                 // class java/util/Map
      89: ldc           #219                // String d
      91: ldc           #223                // String f
      93: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      96: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     101: pop
     102: aload_1
     103: checkcast     #17                 // class java/util/Map
     106: ldc           #221                // String e
     108: invokestatic  #37                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
     111: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     116: pop
     117: aload_1
     118: checkcast     #17                 // class java/util/Map
     121: ldc           #223                // String f
     123: invokestatic  #37                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
     126: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     131: pop
     132: aload_0
     133: aload_1
     134: ldc           #213                // String a
     136: invokevirtual #225                // Method breadthFirst:(Ljava/util/HashMap;Ljava/lang/String;)V
     139: return

  public final void breadthFirst(java.util.HashMap<java.lang.String, java.util.Set<java.lang.String>>, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #192                // String graph
       3: invokestatic  #196                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #198                // String source
       9: invokestatic  #196                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #160                // class java/util/LinkedList
      15: dup
      16: invokespecial #161                // Method java/util/LinkedList."<init>":()V
      19: checkcast     #163                // class java/util/Queue
      22: astore_3
      23: aload_3
      24: aload_2
      25: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
      30: pop
      31: aload_3
      32: checkcast     #166                // class java/util/Collection
      35: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      40: ifne          47
      43: iconst_1
      44: goto          48
      47: iconst_0
      48: ifeq          151
      51: aload_3
      52: invokeinterface #172,  1          // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
      57: checkcast     #45                 // class java/lang/String
      60: astore        4
      62: getstatic     #145                // Field java/lang/System.out:Ljava/io/PrintStream;
      65: aload         4
      67: invokevirtual #151                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      70: aload_1
      71: aload         4
      73: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      76: checkcast     #68                 // class java/util/Set
      79: dup
      80: ifnull        146
      83: astore        5
      85: iconst_0
      86: istore        6
      88: aload_1
      89: aload         4
      91: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      94: dup
      95: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      98: checkcast     #68                 // class java/util/Set
     101: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     106: astore        7
     108: aload         7
     110: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     115: ifeq          142
     118: aload         7
     120: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     125: checkcast     #45                 // class java/lang/String
     128: astore        8
     130: aload_3
     131: aload         8
     133: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     138: pop
     139: goto          108
     142: nop
     143: goto          31
     146: pop
     147: nop
     148: goto          31
     151: return

  private final void findPath();
    Code:
       0: new           #14                 // class java/util/HashMap
       3: dup
       4: invokespecial #15                 // Method java/util/HashMap."<init>":()V
       7: astore_1
       8: aload_1
       9: checkcast     #17                 // class java/util/Map
      12: astore_2
      13: ldc           #223                // String f
      15: astore_3
      16: iconst_2
      17: anewarray     #45                 // class java/lang/String
      20: astore        4
      22: aload         4
      24: iconst_0
      25: ldc           #229                // String g
      27: aastore
      28: aload         4
      30: iconst_1
      31: ldc           #110                // String i
      33: aastore
      34: aload         4
      36: invokestatic  #52                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      39: astore        4
      41: aload_2
      42: aload_3
      43: aload         4
      45: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      50: pop
      51: aload_1
      52: checkcast     #17                 // class java/util/Map
      55: ldc           #229                // String g
      57: ldc           #231                // String h
      59: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      62: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      67: pop
      68: aload_1
      69: checkcast     #17                 // class java/util/Map
      72: ldc           #231                // String h
      74: invokestatic  #37                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      77: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      82: pop
      83: aload_1
      84: checkcast     #17                 // class java/util/Map
      87: astore_2
      88: ldc           #110                // String i
      90: astore_3
      91: iconst_2
      92: anewarray     #45                 // class java/lang/String
      95: astore        4
      97: aload         4
      99: iconst_0
     100: ldc           #229                // String g
     102: aastore
     103: aload         4
     105: iconst_1
     106: ldc           #117                // String k
     108: aastore
     109: aload         4
     111: invokestatic  #52                 // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     114: astore        4
     116: aload_2
     117: aload_3
     118: aload         4
     120: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     125: pop
     126: aload_1
     127: checkcast     #17                 // class java/util/Map
     130: ldc           #112                // String j
     132: ldc           #110                // String i
     134: invokestatic  #27                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
     137: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     142: pop
     143: aload_1
     144: checkcast     #17                 // class java/util/Map
     147: ldc           #117                // String k
     149: invokestatic  #37                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
     152: invokeinterface #31,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     157: pop
     158: aload_0
     159: aload_1
     160: ldc           #112                // String j
     162: ldc           #231                // String h
     164: invokespecial #234                // Method findPath:(Ljava/util/HashMap;Ljava/lang/String;Ljava/lang/String;)Z
     167: istore_2
     168: getstatic     #145                // Field java/lang/System.out:Ljava/io/PrintStream;
     171: iload_2
     172: invokevirtual #237                // Method java/io/PrintStream.println:(Z)V
     175: return

  private final boolean findPath(java.util.HashMap<java.lang.String, java.util.Set<java.lang.String>>, java.lang.String, java.lang.String);
    Code:
       0: new           #160                // class java/util/LinkedList
       3: dup
       4: invokespecial #161                // Method java/util/LinkedList."<init>":()V
       7: checkcast     #163                // class java/util/Queue
      10: astore        4
      12: aload         4
      14: aload_2
      15: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
      20: pop
      21: aload         4
      23: checkcast     #166                // class java/util/Collection
      26: invokeinterface #169,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      31: ifne          38
      34: iconst_1
      35: goto          39
      38: iconst_0
      39: ifeq          147
      42: aload         4
      44: invokeinterface #172,  1          // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
      49: checkcast     #45                 // class java/lang/String
      52: astore        5
      54: aload         5
      56: aload_3
      57: invokevirtual #175                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      60: ifeq          65
      63: iconst_1
      64: ireturn
      65: aload_1
      66: aload         5
      68: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      71: checkcast     #68                 // class java/util/Set
      74: dup
      75: ifnull        142
      78: astore        6
      80: iconst_0
      81: istore        7
      83: aload_1
      84: aload         5
      86: invokevirtual #101                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      89: dup
      90: invokestatic  #181                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      93: checkcast     #68                 // class java/util/Set
      96: invokeinterface #72,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     101: astore        8
     103: aload         8
     105: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     110: ifeq          138
     113: aload         8
     115: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     120: checkcast     #45                 // class java/lang/String
     123: astore        9
     125: aload         4
     127: aload         9
     129: invokeinterface #164,  2          // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     134: pop
     135: goto          103
     138: nop
     139: goto          21
     142: pop
     143: nop
     144: goto          21
     147: iconst_0
     148: ireturn

  public static final java.util.Map<java.lang.String, java.util.Set<java.lang.String>> createAdjacencyList(kotlin.Pair<java.lang.String, java.lang.String>[]);
    Code:
       0: getstatic     #129                // Field Companion:Lgraph/Graph$Companion;
       3: aload_0
       4: invokevirtual #135                // Method graph/Graph$Companion.createAdjacencyList:([Lkotlin/Pair;)Ljava/util/Map;
       7: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: getstatic     #129                // Field Companion:Lgraph/Graph$Companion;
       3: aload_0
       4: invokevirtual #245                // Method graph/Graph$Companion.main:([Ljava/lang/String;)V
       7: return

  public static final int access$connectedComponents(graph.Graph);
    Code:
       0: aload_0
       1: invokespecial #251                // Method connectedComponents:()I
       4: ireturn

  static {};
    Code:
       0: new           #131                // class graph/Graph$Companion
       3: dup
       4: aconst_null
       5: invokespecial #256                // Method graph/Graph$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #129                // Field Companion:Lgraph/Graph$Companion;
      11: return
}


package arrays

import java.util.LinkedList
import java.util.Queue

class NumberOfIslands {

    data class Coordinate(val row: Int, val col: Int)

    fun numIslands(grid: Array<CharArray>): Int {
        val visited = HashSet<Coordinate>()
        var islandsFound = 0
        for (row in grid.indices) {
            for (col in grid[row].indices) {
                val current = grid[row][col]
                if (current == '0' || visited.contains(Coordinate(row, col))) {
                    continue
                }
                exploreIterative(grid, row, col, visited)
                islandsFound++
            }
        }
        return islandsFound
    }

    private fun exploreRecursive(grid: Array<CharArray>, row: Int, col: Int, visited: java.util.HashSet<Coordinate>) {
        if (visited.contains(Coordinate(row, col))) {
            return
        }
        visited.add(Coordinate(row, col))
        val dr = arrayOf(0, 1, 0, -1)
        val dc = arrayOf(1, 0, -1, 0)
        for (i in dr.indices) {
            val newRow = row + dr[i]
            val newCol = col + dc[i]
            if (isValid(grid, newRow, newCol)) {
                exploreRecursive(grid, newRow, newCol, visited)
            }
        }
    }

    private fun exploreIterative(grid: Array<CharArray>, row: Int, col: Int, visited: java.util.HashSet<Coordinate>) {
        val queue: Queue<Coordinate> = LinkedList()
        queue.add(Coordinate(row, col))
        while (queue.isNotEmpty()) {
            val current = queue.poll()
            if (visited.contains(current)) {
                continue
            }
            visited.add(current)
            val dr = arrayOf(0, 1, 0, -1)
            val dc = arrayOf(1, 0, -1, 0)
            for (i in dr.indices) {
                val newRow = current.row + dr[i]
                val newCol = current.col + dc[i]
                if (isValid(grid, newRow, newCol)) {
                    queue.add(Coordinate(newRow, newCol))
                }
            }
        }
    }

    private fun isValid(grid: Array<CharArray>, row: Int, col: Int): Boolean {
        return row >= 0 && row < grid.size && col >= 0 && col < grid[row].size && grid[row][col] == '1'
    }
}

fun main() {
    println(
        NumberOfIslands().numIslands(
            arrayOf(
                charArrayOf('1', '1', '0', '0', '0'),
                charArrayOf('1', '1', '0', '0', '0'),
                charArrayOf('0', '0', '1', '0', '0'),
                charArrayOf('0', '0', '0', '1', '1')
            )
        )
    )
}

Compiled from "NumberOfIslands.kt"
public final class arrays.NumberOfIslands {
  public arrays.NumberOfIslands();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int numIslands(char[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class java/util/HashSet
       9: dup
      10: invokespecial #24                 // Method java/util/HashSet."<init>":()V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: iconst_0
      17: istore        4
      19: aload_1
      20: checkcast     #26                 // class "[Ljava/lang/Object;"
      23: arraylength
      24: istore        5
      26: iload         4
      28: iload         5
      30: if_icmpge     112
      33: iconst_0
      34: istore        6
      36: aload_1
      37: iload         4
      39: aaload
      40: arraylength
      41: istore        7
      43: iload         6
      45: iload         7
      47: if_icmpge     106
      50: aload_1
      51: iload         4
      53: aaload
      54: iload         6
      56: caload
      57: istore        8
      59: iload         8
      61: bipush        48
      63: if_icmpeq     84
      66: aload_2
      67: new           #28                 // class arrays/NumberOfIslands$Coordinate
      70: dup
      71: iload         4
      73: iload         6
      75: invokespecial #31                 // Method arrays/NumberOfIslands$Coordinate."<init>":(II)V
      78: invokevirtual #35                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      81: ifeq          87
      84: goto          100
      87: aload_0
      88: aload_1
      89: iload         4
      91: iload         6
      93: aload_2
      94: invokespecial #39                 // Method exploreIterative:([[CIILjava/util/HashSet;)V
      97: iinc          3, 1
     100: iinc          6, 1
     103: goto          43
     106: iinc          4, 1
     109: goto          26
     112: iload_3
     113: ireturn

  private final void exploreRecursive(char[][], int, int, java.util.HashSet<arrays.NumberOfIslands$Coordinate>);
    Code:
       0: aload         4
       2: new           #28                 // class arrays/NumberOfIslands$Coordinate
       5: dup
       6: iload_2
       7: iload_3
       8: invokespecial #31                 // Method arrays/NumberOfIslands$Coordinate."<init>":(II)V
      11: invokevirtual #35                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      14: ifeq          18
      17: return
      18: aload         4
      20: new           #28                 // class arrays/NumberOfIslands$Coordinate
      23: dup
      24: iload_2
      25: iload_3
      26: invokespecial #31                 // Method arrays/NumberOfIslands$Coordinate."<init>":(II)V
      29: invokevirtual #54                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      32: pop
      33: iconst_4
      34: anewarray     #56                 // class java/lang/Integer
      37: astore        6
      39: aload         6
      41: iconst_0
      42: iconst_0
      43: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aastore
      47: aload         6
      49: iconst_1
      50: iconst_1
      51: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: aastore
      55: aload         6
      57: iconst_2
      58: iconst_0
      59: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: aastore
      63: aload         6
      65: iconst_3
      66: iconst_m1
      67: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      70: aastore
      71: aload         6
      73: astore        5
      75: iconst_4
      76: anewarray     #56                 // class java/lang/Integer
      79: astore        7
      81: aload         7
      83: iconst_0
      84: iconst_1
      85: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      88: aastore
      89: aload         7
      91: iconst_1
      92: iconst_0
      93: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: aastore
      97: aload         7
      99: iconst_2
     100: iconst_m1
     101: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: aastore
     105: aload         7
     107: iconst_3
     108: iconst_0
     109: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aastore
     113: aload         7
     115: astore        6
     117: iconst_0
     118: istore        7
     120: aload         5
     122: arraylength
     123: istore        8
     125: iload         7
     127: iload         8
     129: if_icmpge     185
     132: iload_2
     133: aload         5
     135: iload         7
     137: aaload
     138: invokevirtual #64                 // Method java/lang/Integer.intValue:()I
     141: iadd
     142: istore        9
     144: iload_3
     145: aload         6
     147: iload         7
     149: aaload
     150: invokevirtual #64                 // Method java/lang/Integer.intValue:()I
     153: iadd
     154: istore        10
     156: aload_0
     157: aload_1
     158: iload         9
     160: iload         10
     162: invokespecial #68                 // Method isValid:([[CII)Z
     165: ifeq          179
     168: aload_0
     169: aload_1
     170: iload         9
     172: iload         10
     174: aload         4
     176: invokespecial #70                 // Method exploreRecursive:([[CIILjava/util/HashSet;)V
     179: iinc          7, 1
     182: goto          125
     185: return

  private final void exploreIterative(char[][], int, int, java.util.HashSet<arrays.NumberOfIslands$Coordinate>);
    Code:
       0: new           #79                 // class java/util/LinkedList
       3: dup
       4: invokespecial #80                 // Method java/util/LinkedList."<init>":()V
       7: checkcast     #82                 // class java/util/Queue
      10: astore        5
      12: aload         5
      14: new           #28                 // class arrays/NumberOfIslands$Coordinate
      17: dup
      18: iload_2
      19: iload_3
      20: invokespecial #31                 // Method arrays/NumberOfIslands$Coordinate."<init>":(II)V
      23: invokeinterface #83,  2           // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
      28: pop
      29: aload         5
      31: checkcast     #85                 // class java/util/Collection
      34: invokeinterface #89,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      39: ifne          46
      42: iconst_1
      43: goto          47
      46: iconst_0
      47: ifeq          251
      50: aload         5
      52: invokeinterface #93,  1           // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
      57: checkcast     #28                 // class arrays/NumberOfIslands$Coordinate
      60: astore        6
      62: aload         4
      64: aload         6
      66: invokevirtual #35                 // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      69: ifeq          75
      72: goto          29
      75: aload         4
      77: aload         6
      79: invokevirtual #54                 // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      82: pop
      83: iconst_4
      84: anewarray     #56                 // class java/lang/Integer
      87: astore        8
      89: aload         8
      91: iconst_0
      92: iconst_0
      93: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: aastore
      97: aload         8
      99: iconst_1
     100: iconst_1
     101: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: aastore
     105: aload         8
     107: iconst_2
     108: iconst_0
     109: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: aastore
     113: aload         8
     115: iconst_3
     116: iconst_m1
     117: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: aastore
     121: aload         8
     123: astore        7
     125: iconst_4
     126: anewarray     #56                 // class java/lang/Integer
     129: astore        9
     131: aload         9
     133: iconst_0
     134: iconst_1
     135: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: aastore
     139: aload         9
     141: iconst_1
     142: iconst_0
     143: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: aastore
     147: aload         9
     149: iconst_2
     150: iconst_m1
     151: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aastore
     155: aload         9
     157: iconst_3
     158: iconst_0
     159: invokestatic  #60                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     162: aastore
     163: aload         9
     165: astore        8
     167: iconst_0
     168: istore        9
     170: aload         7
     172: arraylength
     173: istore        10
     175: iload         9
     177: iload         10
     179: if_icmpge     29
     182: aload         6
     184: invokevirtual #96                 // Method arrays/NumberOfIslands$Coordinate.getRow:()I
     187: aload         7
     189: iload         9
     191: aaload
     192: invokevirtual #64                 // Method java/lang/Integer.intValue:()I
     195: iadd
     196: istore        11
     198: aload         6
     200: invokevirtual #99                 // Method arrays/NumberOfIslands$Coordinate.getCol:()I
     203: aload         8
     205: iload         9
     207: aaload
     208: invokevirtual #64                 // Method java/lang/Integer.intValue:()I
     211: iadd
     212: istore        12
     214: aload_0
     215: aload_1
     216: iload         11
     218: iload         12
     220: invokespecial #68                 // Method isValid:([[CII)Z
     223: ifeq          245
     226: aload         5
     228: new           #28                 // class arrays/NumberOfIslands$Coordinate
     231: dup
     232: iload         11
     234: iload         12
     236: invokespecial #31                 // Method arrays/NumberOfIslands$Coordinate."<init>":(II)V
     239: invokeinterface #83,  2           // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     244: pop
     245: iinc          9, 1
     248: goto          175
     251: return

  private final boolean isValid(char[][], int, int);
    Code:
       0: iload_2
       1: iflt          39
       4: iload_2
       5: aload_1
       6: checkcast     #26                 // class "[Ljava/lang/Object;"
       9: arraylength
      10: if_icmpge     39
      13: iload_3
      14: iflt          39
      17: iload_3
      18: aload_1
      19: iload_2
      20: aaload
      21: arraylength
      22: if_icmpge     39
      25: aload_1
      26: iload_2
      27: aaload
      28: iload_3
      29: caload
      30: bipush        49
      32: if_icmpne     39
      35: iconst_1
      36: goto          40
      39: iconst_0
      40: ireturn
}

Compiled from "NumberOfIslands.kt"
public final class arrays.NumberOfIslands$Coordinate {
  private final int row;

  private final int col;

  public arrays.NumberOfIslands$Coordinate(int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field row:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field col:I
      14: return

  public final int getRow();
    Code:
       0: aload_0
       1: getfield      #13                 // Field row:I
       4: ireturn

  public final int getCol();
    Code:
       0: aload_0
       1: getfield      #16                 // Field col:I
       4: ireturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field row:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field col:I
       4: ireturn

  public final arrays.NumberOfIslands$Coordinate copy(int, int);
    Code:
       0: new           #2                  // class arrays/NumberOfIslands$Coordinate
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #28                 // Method "<init>":(II)V
       9: areturn

  public static arrays.NumberOfIslands$Coordinate copy$default(arrays.NumberOfIslands$Coordinate, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field row:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field col:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #32                 // Method copy:(II)Larrays/NumberOfIslands$Coordinate;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #36                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #39                 // String Coordinate(row=
       9: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field row:I
      16: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #48                 // String , col=
      21: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field col:I
      28: invokevirtual #46                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #51                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #53                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field row:I
       4: invokestatic  #59                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field col:I
      16: invokestatic  #59                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class arrays/NumberOfIslands$Coordinate
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class arrays/NumberOfIslands$Coordinate
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field row:I
      25: aload_2
      26: getfield      #13                 // Field row:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field col:I
      38: aload_2
      39: getfield      #16                 // Field col:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "NumberOfIslands.kt"
public final class arrays.NumberOfIslandsKt {
  public static final void main();
    Code:
       0: new           #8                  // class arrays/NumberOfIslands
       3: dup
       4: invokespecial #11                 // Method arrays/NumberOfIslands."<init>":()V
       7: iconst_4
       8: anewarray     #13                 // class "[C"
      11: astore_0
      12: aload_0
      13: iconst_0
      14: iconst_5
      15: newarray       char
      17: astore_1
      18: aload_1
      19: iconst_0
      20: bipush        49
      22: castore
      23: aload_1
      24: iconst_1
      25: bipush        49
      27: castore
      28: aload_1
      29: iconst_2
      30: bipush        48
      32: castore
      33: aload_1
      34: iconst_3
      35: bipush        48
      37: castore
      38: aload_1
      39: iconst_4
      40: bipush        48
      42: castore
      43: aload_1
      44: aastore
      45: aload_0
      46: iconst_1
      47: iconst_5
      48: newarray       char
      50: astore_1
      51: aload_1
      52: iconst_0
      53: bipush        49
      55: castore
      56: aload_1
      57: iconst_1
      58: bipush        49
      60: castore
      61: aload_1
      62: iconst_2
      63: bipush        48
      65: castore
      66: aload_1
      67: iconst_3
      68: bipush        48
      70: castore
      71: aload_1
      72: iconst_4
      73: bipush        48
      75: castore
      76: aload_1
      77: aastore
      78: aload_0
      79: iconst_2
      80: iconst_5
      81: newarray       char
      83: astore_1
      84: aload_1
      85: iconst_0
      86: bipush        48
      88: castore
      89: aload_1
      90: iconst_1
      91: bipush        48
      93: castore
      94: aload_1
      95: iconst_2
      96: bipush        49
      98: castore
      99: aload_1
     100: iconst_3
     101: bipush        48
     103: castore
     104: aload_1
     105: iconst_4
     106: bipush        48
     108: castore
     109: aload_1
     110: aastore
     111: aload_0
     112: iconst_3
     113: iconst_5
     114: newarray       char
     116: astore_1
     117: aload_1
     118: iconst_0
     119: bipush        48
     121: castore
     122: aload_1
     123: iconst_1
     124: bipush        48
     126: castore
     127: aload_1
     128: iconst_2
     129: bipush        48
     131: castore
     132: aload_1
     133: iconst_3
     134: bipush        49
     136: castore
     137: aload_1
     138: iconst_4
     139: bipush        49
     141: castore
     142: aload_1
     143: aastore
     144: aload_0
     145: invokevirtual #17                 // Method arrays/NumberOfIslands.numIslands:([[C)I
     148: istore_0
     149: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     152: iload_0
     153: invokevirtual #29                 // Method java/io/PrintStream.println:(I)V
     156: return

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