package io.github.konfork.predicates

fun isMod10(evenWeight: Int, oddWeight: Int): (String) -> Boolean {
    val weightSequence = alternatingSequence(evenWeight, oddWeight)
    return { isMod10(it, weightSequence, Int::times) }
}

fun isEan(length: Int): (String) -> Boolean {
    val mod10Fn = isMod10(1, 3)
    return { it.length == length && mod10Fn(it) }
}

fun isLuhn(s: String): Boolean =
    isAllDigits(s) && validateMod10Checksum(s, alternatingSequence(1, 2)) { l, r ->
        (l * r).let { (it / 10) + (it % 10) }
    }

private fun isAllDigits(s: String): Boolean = s.all(Char::isDigit)

private val MOD11_DIGITS = Regex("[0-9]+[xX]?")
fun isMod11(weightSequence: Sequence<Int>): (String) -> Boolean = {
    it.matches(MOD11_DIGITS) && validateMod11Checksum(it.map(Char::toMod11Int), weightSequence)
}

fun isMod11(startWeight: Int, endWeight: Int): (String) -> Boolean =
    isMod11(repeatingCounterSequence(startWeight, endWeight))

private val isMod11Isbn10 = isMod11(9, 1)
fun isIsbn10(s: String): Boolean =
    s.replace(Regex("[ -]"), "")
        .let { it.length == 10 && isMod11Isbn10(it) }

private val isEan13 = isEan(13)
fun isIsbn13(s: String): Boolean = isEan13(s.replace(Regex("[ -]"), ""))

fun isIsbn(s: String): Boolean = isIsbn10(s) || isIsbn13(s)

private fun isMod10(s: String, weightSequence: Sequence<Int>, map: (Int, Int) -> Int): Boolean =
    isAllDigits(s) && validateMod10Checksum(s, weightSequence, map)

private fun validateMod10Checksum(s: String, weightSequence: Sequence<Int>, map: (Int, Int) -> Int): Boolean =
    weightedSum(s.map(Char::digitToInt).reversed(), weightSequence, map)
        .let { it % 10 == 0 }

private fun alternatingSequence(even: Int, odd: Int): Sequence<Int> =
    generateIndexedSequence { it % 2 == 0 }
        .map { if (it) even else odd }

private fun <T : Any> generateIndexedSequence(generator: (Int) -> T): Sequence<T> =
    generateSequence(0) { index -> index + 1 }
        .map(generator)

private fun repeatingCounterSequence(start: Int, end: Int): Sequence<Int> =
    if (start <= end) {
        generateIndexedSequence { index -> start + index % (end - start + 1) }
    } else {
        generateIndexedSequence { index -> start - index % (start - end + 1) }
    }

private fun validateMod11Checksum(s: List<Int>, weightSequence: Sequence<Int>): Boolean =
    weightedSum(s.dropLast(1).reversed(), weightSequence, Int::times)
        .let { it % 11 == s.last() }

private fun weightedSum(list: List<Int>, weightSequence: Sequence<Int>, map: (Int, Int) -> Int): Int =
    list.asSequence()
        .zip(weightSequence, map)
        .sum()

private fun Char.toMod11Int(): Int =
    when (this) {
        'x' -> 10
        'X' -> 10
        else -> this.digitToInt()
    }

Compiled from "CheckDigits.kt"
public final class io.github.konfork.predicates.CheckDigitsKt {
  private static final kotlin.text.Regex MOD11_DIGITS;

  private static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isMod11Isbn10;

  private static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isEan13;

  public static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isMod10(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: invokestatic  #12                 // Method alternatingSequence:(II)Lkotlin/sequences/Sequence;
       5: astore_2
       6: aload_2
       7: invokedynamic #32,  0             // InvokeDynamic #0:invoke:(Lkotlin/sequences/Sequence;)Lkotlin/jvm/functions/Function1;
      12: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isEan(int);
    Code:
       0: iconst_1
       1: iconst_3
       2: invokestatic  #42                 // Method isMod10:(II)Lkotlin/jvm/functions/Function1;
       5: astore_1
       6: iload_0
       7: aload_1
       8: invokedynamic #50,  0             // InvokeDynamic #1:invoke:(ILkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
      13: areturn

  public static final boolean isLuhn(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #57                 // String s
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #66                 // Method isAllDigits:(Ljava/lang/String;)Z
      10: ifeq          34
      13: aload_0
      14: iconst_1
      15: iconst_2
      16: invokestatic  #12                 // Method alternatingSequence:(II)Lkotlin/sequences/Sequence;
      19: invokedynamic #78,  0             // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function2;
      24: invokestatic  #82                 // Method validateMod10Checksum:(Ljava/lang/String;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Z
      27: ifeq          34
      30: iconst_1
      31: goto          35
      34: iconst_0
      35: ireturn

  private static final boolean isAllDigits(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #85                 // class java/lang/CharSequence
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: iload_3
      10: aload_1
      11: invokeinterface #88,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      16: if_icmpge     54
      19: aload_1
      20: iload_3
      21: invokeinterface #92,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      26: istore        4
      28: iload         4
      30: istore        5
      32: iconst_0
      33: istore        6
      35: iload         5
      37: invokestatic  #98                 // Method java/lang/Character.isDigit:(C)Z
      40: nop
      41: ifne          48
      44: iconst_0
      45: goto          55
      48: iinc          3, 1
      51: goto          9
      54: iconst_1
      55: ireturn

  public static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isMod11(kotlin.sequences.Sequence<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #108                // String weightSequence
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokedynamic #113,  0            // InvokeDynamic #3:invoke:(Lkotlin/sequences/Sequence;)Lkotlin/jvm/functions/Function1;
      12: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.String, java.lang.Boolean> isMod11(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: invokestatic  #116                // Method repeatingCounterSequence:(II)Lkotlin/sequences/Sequence;
       5: invokestatic  #118                // Method isMod11:(Lkotlin/sequences/Sequence;)Lkotlin/jvm/functions/Function1;
       8: areturn

  public static final boolean isIsbn10(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #57                 // String s
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #85                 // class java/lang/CharSequence
      10: astore_1
      11: new           #123                // class kotlin/text/Regex
      14: dup
      15: ldc           #125                // String [ -]
      17: invokespecial #129                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      20: astore_2
      21: ldc           #131                // String
      23: astore_3
      24: aload_2
      25: aload_1
      26: aload_3
      27: invokevirtual #135                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      30: astore_2
      31: iconst_0
      32: istore_3
      33: aload_2
      34: invokevirtual #138                // Method java/lang/String.length:()I
      37: bipush        10
      39: if_icmpne     64
      42: getstatic     #141                // Field isMod11Isbn10:Lkotlin/jvm/functions/Function1;
      45: aload_2
      46: invokeinterface #145,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      51: checkcast     #147                // class java/lang/Boolean
      54: invokevirtual #151                // Method java/lang/Boolean.booleanValue:()Z
      57: ifeq          64
      60: iconst_1
      61: goto          65
      64: iconst_0
      65: nop
      66: ireturn

  public static final boolean isIsbn13(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #57                 // String s
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: getstatic     #157                // Field isEan13:Lkotlin/jvm/functions/Function1;
       9: aload_0
      10: checkcast     #85                 // class java/lang/CharSequence
      13: astore_1
      14: new           #123                // class kotlin/text/Regex
      17: dup
      18: ldc           #125                // String [ -]
      20: invokespecial #129                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      23: astore_2
      24: ldc           #131                // String
      26: astore_3
      27: aload_2
      28: aload_1
      29: aload_3
      30: invokevirtual #135                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      33: invokeinterface #145,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      38: checkcast     #147                // class java/lang/Boolean
      41: invokevirtual #151                // Method java/lang/Boolean.booleanValue:()Z
      44: ireturn

  public static final boolean isIsbn(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #57                 // String s
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #160                // Method isIsbn10:(Ljava/lang/String;)Z
      10: ifne          20
      13: aload_0
      14: invokestatic  #162                // Method isIsbn13:(Ljava/lang/String;)Z
      17: ifeq          24
      20: iconst_1
      21: goto          25
      24: iconst_0
      25: ireturn

  private static final boolean isMod10(java.lang.String, kotlin.sequences.Sequence<java.lang.Integer>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokestatic  #66                 // Method isAllDigits:(Ljava/lang/String;)Z
       4: ifeq          20
       7: aload_0
       8: aload_1
       9: aload_2
      10: invokestatic  #82                 // Method validateMod10Checksum:(Ljava/lang/String;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Z
      13: ifeq          20
      16: iconst_1
      17: goto          21
      20: iconst_0
      21: ireturn

  private static final boolean validateMod10Checksum(java.lang.String, kotlin.sequences.Sequence<java.lang.Integer>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: checkcast     #85                 // class java/lang/CharSequence
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #167                // class java/util/ArrayList
      14: dup
      15: aload_3
      16: invokeinterface #88,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      21: invokespecial #170                // Method java/util/ArrayList."<init>":(I)V
      24: checkcast     #172                // class java/util/Collection
      27: astore        6
      29: iconst_0
      30: istore        7
      32: iconst_0
      33: istore        8
      35: iload         8
      37: aload         5
      39: invokeinterface #88,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      44: if_icmpge     92
      47: aload         5
      49: iload         8
      51: invokeinterface #92,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      56: istore        9
      58: aload         6
      60: iload         9
      62: istore        10
      64: astore        12
      66: iconst_0
      67: istore        11
      69: iload         10
      71: invokestatic  #178                // Method kotlin/text/CharsKt.digitToInt:(C)I
      74: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: aload         12
      79: swap
      80: invokeinterface #188,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      85: pop
      86: iinc          8, 1
      89: goto          35
      92: aload         6
      94: checkcast     #190                // class java/util/List
      97: nop
      98: checkcast     #192                // class java/lang/Iterable
     101: invokestatic  #198                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     104: aload_1
     105: aload_2
     106: invokestatic  #202                // Method weightedSum:(Ljava/util/List;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)I
     109: istore        4
     111: iconst_0
     112: istore        5
     114: iload         4
     116: bipush        10
     118: irem
     119: ifne          126
     122: iconst_1
     123: goto          127
     126: iconst_0
     127: nop
     128: ireturn

  private static final kotlin.sequences.Sequence<java.lang.Integer> alternatingSequence(int, int);
    Code:
       0: invokedynamic #226,  0            // InvokeDynamic #4:invoke:()Lkotlin/jvm/functions/Function1;
       5: invokestatic  #230                // Method generateIndexedSequence:(Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
       8: iload_0
       9: iload_1
      10: invokedynamic #239,  0            // InvokeDynamic #5:invoke:(II)Lkotlin/jvm/functions/Function1;
      15: invokestatic  #244                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      18: areturn

  private static final <T> kotlin.sequences.Sequence<T> generateIndexedSequence(kotlin.jvm.functions.Function1<? super java.lang.Integer, ? extends T>);
    Code:
       0: iconst_0
       1: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: invokedynamic #254,  0            // InvokeDynamic #6:invoke:()Lkotlin/jvm/functions/Function1;
       9: invokestatic  #258                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      12: aload_0
      13: invokestatic  #244                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      16: areturn

  private static final kotlin.sequences.Sequence<java.lang.Integer> repeatingCounterSequence(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpgt     18
       5: iload_0
       6: iload_1
       7: invokedynamic #265,  0            // InvokeDynamic #7:invoke:(II)Lkotlin/jvm/functions/Function1;
      12: invokestatic  #230                // Method generateIndexedSequence:(Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: goto          28
      18: iload_0
      19: iload_1
      20: invokedynamic #270,  0            // InvokeDynamic #8:invoke:(II)Lkotlin/jvm/functions/Function1;
      25: invokestatic  #230                // Method generateIndexedSequence:(Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      28: areturn

  private static final boolean validateMod11Checksum(java.util.List<java.lang.Integer>, kotlin.sequences.Sequence<java.lang.Integer>);
    Code:
       0: aload_0
       1: iconst_1
       2: invokestatic  #279                // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
       5: checkcast     #192                // class java/lang/Iterable
       8: invokestatic  #198                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
      11: aload_1
      12: getstatic     #285                // Field io/github/konfork/predicates/CheckDigitsKt$validateMod11Checksum$1.INSTANCE:Lio/github/konfork/predicates/CheckDigitsKt$validateMod11Checksum$1;
      15: checkcast     #215                // class kotlin/jvm/functions/Function2
      18: invokestatic  #202                // Method weightedSum:(Ljava/util/List;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)I
      21: istore_2
      22: iconst_0
      23: istore_3
      24: iload_2
      25: bipush        11
      27: irem
      28: aload_0
      29: invokestatic  #289                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      32: checkcast     #291                // class java/lang/Number
      35: invokevirtual #294                // Method java/lang/Number.intValue:()I
      38: if_icmpne     45
      41: iconst_1
      42: goto          46
      45: iconst_0
      46: nop
      47: ireturn

  private static final int weightedSum(java.util.List<java.lang.Integer>, kotlin.sequences.Sequence<java.lang.Integer>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: checkcast     #192                // class java/lang/Iterable
       4: invokestatic  #301                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: aload_1
       8: aload_2
       9: invokestatic  #305                // Method kotlin/sequences/SequencesKt.zip:(Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence;
      12: invokestatic  #309                // Method kotlin/sequences/SequencesKt.sumOfInt:(Lkotlin/sequences/Sequence;)I
      15: ireturn

  private static final int toMod11Int(char);
    Code:
       0: iload_0
       1: lookupswitch  { // 2
                    88: 33
                   120: 28
               default: 38
          }
      28: bipush        10
      30: goto          42
      33: bipush        10
      35: goto          42
      38: iload_0
      39: invokestatic  #178                // Method kotlin/text/CharsKt.digitToInt:(C)I
      42: ireturn

  private static final boolean isMod10$lambda$0(kotlin.sequences.Sequence, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #313                // String it
       4: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: aload_0
       9: getstatic     #318                // Field io/github/konfork/predicates/CheckDigitsKt$isMod10$1$1.INSTANCE:Lio/github/konfork/predicates/CheckDigitsKt$isMod10$1$1;
      12: checkcast     #215                // class kotlin/jvm/functions/Function2
      15: invokestatic  #320                // Method isMod10:(Ljava/lang/String;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function2;)Z
      18: ireturn

  private static final boolean isEan$lambda$1(int, kotlin.jvm.functions.Function1, java.lang.String);
    Code:
       0: aload_2
       1: ldc_w         #313                // String it
       4: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: invokevirtual #138                // Method java/lang/String.length:()I
      11: iload_0
      12: if_icmpne     35
      15: aload_1
      16: aload_2
      17: invokeinterface #145,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      22: checkcast     #147                // class java/lang/Boolean
      25: invokevirtual #151                // Method java/lang/Boolean.booleanValue:()Z
      28: ifeq          35
      31: iconst_1
      32: goto          36
      35: iconst_0
      36: ireturn

  private static final int isLuhn$lambda$3(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: imul
       3: istore_2
       4: iconst_0
       5: istore_3
       6: iload_2
       7: bipush        10
       9: idiv
      10: iload_2
      11: bipush        10
      13: irem
      14: iadd
      15: nop
      16: ireturn

  private static final boolean isMod11$lambda$5(kotlin.sequences.Sequence, java.lang.String);
    Code:
       0: aload_1
       1: ldc_w         #313                // String it
       4: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: checkcast     #85                 // class java/lang/CharSequence
      11: astore_2
      12: getstatic     #330                // Field MOD11_DIGITS:Lkotlin/text/Regex;
      15: aload_2
      16: invokevirtual #334                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      19: ifeq          130
      22: aload_1
      23: checkcast     #85                 // class java/lang/CharSequence
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: astore        4
      32: new           #167                // class java/util/ArrayList
      35: dup
      36: aload_2
      37: invokeinterface #88,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      42: invokespecial #170                // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #172                // class java/util/Collection
      48: astore        5
      50: iconst_0
      51: istore        6
      53: iconst_0
      54: istore        7
      56: iload         7
      58: aload         4
      60: invokeinterface #88,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      65: if_icmpge     113
      68: aload         4
      70: iload         7
      72: invokeinterface #92,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      77: istore        8
      79: aload         5
      81: iload         8
      83: istore        9
      85: astore        11
      87: iconst_0
      88: istore        10
      90: iload         9
      92: invokestatic  #336                // Method toMod11Int:(C)I
      95: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      98: aload         11
     100: swap
     101: invokeinterface #188,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: iinc          7, 1
     110: goto          56
     113: aload         5
     115: checkcast     #190                // class java/util/List
     118: nop
     119: aload_0
     120: invokestatic  #338                // Method validateMod11Checksum:(Ljava/util/List;Lkotlin/sequences/Sequence;)Z
     123: ifeq          130
     126: iconst_1
     127: goto          131
     130: iconst_0
     131: ireturn

  private static final boolean alternatingSequence$lambda$9(int);
    Code:
       0: iload_0
       1: iconst_2
       2: irem
       3: ifne          10
       6: iconst_1
       7: goto          11
      10: iconst_0
      11: ireturn

  private static final int alternatingSequence$lambda$10(int, int, boolean);
    Code:
       0: iload_2
       1: ifeq          8
       4: iload_0
       5: goto          9
       8: iload_1
       9: ireturn

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

  private static final int repeatingCounterSequence$lambda$12(int, int, int);
    Code:
       0: iload_0
       1: iload_2
       2: iload_1
       3: iload_0
       4: isub
       5: iconst_1
       6: iadd
       7: irem
       8: iadd
       9: ireturn

  private static final int repeatingCounterSequence$lambda$13(int, int, int);
    Code:
       0: iload_0
       1: iload_2
       2: iload_0
       3: iload_1
       4: isub
       5: iconst_1
       6: iadd
       7: irem
       8: isub
       9: ireturn

  static {};
    Code:
       0: new           #123                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #349                // String [0-9]+[xX]?
       7: invokespecial #129                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #330                // Field MOD11_DIGITS:Lkotlin/text/Regex;
      13: bipush        9
      15: iconst_1
      16: invokestatic  #351                // Method isMod11:(II)Lkotlin/jvm/functions/Function1;
      19: putstatic     #141                // Field isMod11Isbn10:Lkotlin/jvm/functions/Function1;
      22: bipush        13
      24: invokestatic  #353                // Method isEan:(I)Lkotlin/jvm/functions/Function1;
      27: putstatic     #157                // Field isEan13:Lkotlin/jvm/functions/Function1;
      30: return
}

Compiled from "CheckDigits.kt"
final class io.github.konfork.predicates.CheckDigitsKt$validateMod11Checksum$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, java.lang.Integer> {
  public static final io.github.konfork.predicates.CheckDigitsKt$validateMod11Checksum$1 INSTANCE;

  io.github.konfork.predicates.CheckDigitsKt$validateMod11Checksum$1();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Integer.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String times
       7: ldc           #19                 // String times(I)I
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Integer invoke(int, int);
    Code:
       0: iload_1
       1: iload_2
       2: imul
       3: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.intValue:()I
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      15: invokevirtual #42                 // Method invoke:(II)Ljava/lang/Integer;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class io/github/konfork/predicates/CheckDigitsKt$validateMod11Checksum$1
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:Lio/github/konfork/predicates/CheckDigitsKt$validateMod11Checksum$1;
      10: return
}

Compiled from "CheckDigits.kt"
final class io.github.konfork.predicates.CheckDigitsKt$isMod10$1$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, java.lang.Integer> {
  public static final io.github.konfork.predicates.CheckDigitsKt$isMod10$1$1 INSTANCE;

  io.github.konfork.predicates.CheckDigitsKt$isMod10$1$1();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Integer.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String times
       7: ldc           #19                 // String times(I)I
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Integer invoke(int, int);
    Code:
       0: iload_1
       1: iload_2
       2: imul
       3: invokestatic  #30                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.intValue:()I
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.intValue:()I
      15: invokevirtual #42                 // Method invoke:(II)Ljava/lang/Integer;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class io/github/konfork/predicates/CheckDigitsKt$isMod10$1$1
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:Lio/github/konfork/predicates/CheckDigitsKt$isMod10$1$1;
      10: return
}


package com.exponential_groth.calculator.result

import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sign
import kotlin.math.sqrt

private val Double.mantissa get() = toBits() and 0x000fffffffffffffL/* or 0x0010000000000000L*/
private val Double.exponent get() = (toBits() and 0x7ff0000000000000 ushr  52) - 1023

fun reduceFraction(numerator: Long, denominator: Long): Pair<Long, Long> {
    val sign = if ((numerator > 0) xor (denominator > 0)) -1 else 1
    val gcd = gcd(abs(numerator), abs(denominator))
    return Pair(
        sign * abs(numerator) / gcd,
        abs(denominator) / gcd
    )
}

private fun gcd(a: Long, b: Long): Long { // binary gcd algorithm is faster than the euclidean one
    require(a > 0 && b > 0)
    if (a == 0L) return b
    if (b == 0L) return a

    val shift = (a or b).countTrailingZeroBits()
    var u = a
    var v = b
    u = u shr u.countTrailingZeroBits()

    do {
        v = v shr  v.countTrailingZeroBits()
        v -= u
        val m = v shr  63
        u += v and m
        v = (v + m) xor m
    } while (v != 0L)

    return u shl shift
}

fun fractionToDecimal(numerator: Long, denominator: Long): String {
    val nume = abs(numerator)
    val deno = abs(denominator)
    val sign = if ((numerator < 0) xor (denominator < 0)) "-" else ""
    if (deno == 0L) {
        return ""
    } else if (nume == 0L) {
        return "0"
    } else if (nume % deno == 0L) {
        return "$sign${nume / deno}"
    }
    val map = HashMap<Long, Int>()
    val rst = StringBuffer("$sign${nume/deno}.")
    var end = nume % deno * 10
    var i = 0
    while (end != 0L) {
        if (map.containsKey(end)) {
            rst.insert(rst.indexOf(".") + map[end]!! + 1, "\\overline{")
            rst.append("}")
            return rst.toString()
        }
        rst.append(end / deno)
        map[end] = i++
        end = end % deno * 10
    }
    return rst.toString()
}

fun Double.toFraction(): Pair<Long, Long>? {
    val sign = this.sign.toInt()
    val exponent = this.exponent
    var mantissa = this.mantissa shl 12

/*    val maxExponent = 31  // it would work as long as exponent < 52 but that can take long
    if (exponent > maxExponent && this <= Long.MAX_VALUE)
        return toLong() to 1L
    else if (exponent > maxExponent)
        return null
    else if (exponent == -1023L)  // Subnormal numbers are not supported
        return null*/

    if (abs(exponent) >= 32)
        return null

    asRepeatingDecimalToFraction()?.let { return it }

    if (mantissa.countTrailingZeroBits() < 12 + 5) return null  // should have at least 5 zeros to make sure that it is not repeating with a bigger repeating length
    var numerator = 1L
    var denominator = 1L
    var leadingZeros = mantissa.countLeadingZeroBits()
    while (leadingZeros != 64) {
        numerator = (numerator shl (leadingZeros+1)) + 1
        denominator = denominator shl (leadingZeros+1)
        mantissa = mantissa shl (leadingZeros + 1)
        leadingZeros = mantissa.countLeadingZeroBits()
    }
    if (exponent >= 0)
        numerator = numerator shl exponent.toInt()
    else
        denominator = denominator shl -exponent.toInt()

    return reduceFraction(sign * numerator, denominator)
}

private fun Double.asRepeatingDecimalToFraction(): Pair<Long, Long>? {
    val exp = exponent.toInt()
    val numOfDigitsToCheck = 52 - max(exp, 0) - 2 // don't check last two digits and the ones that account for the integer part
    val digitsToCheck = (mantissa and (0L.inv() shl 2)) shl (62 - numOfDigitsToCheck) // remove the bits mentioned above and trim start
    if ((digitsToCheck ushr  (64 - numOfDigitsToCheck)).countTrailingZeroBits() > numOfDigitsToCheck / 2) return null
    var currentlyCheckedRepetendLength = numOfDigitsToCheck / 2
    var minRepeatingPartLength = numOfDigitsToCheck
    var smallestRepetendLength: Int? = null
    val alreadyChecked = mutableListOf<Int>()
    while (currentlyCheckedRepetendLength > 0) {
        var isRecurringWithCurrentLength = true
        for (i in (64 - numOfDigitsToCheck + currentlyCheckedRepetendLength) until (64 - (numOfDigitsToCheck - minRepeatingPartLength))) {
            if ((digitsToCheck and (1L shl (i - currentlyCheckedRepetendLength)) == 0L) != (digitsToCheck and (1L shl i) == 0L)) {
                isRecurringWithCurrentLength = false
                break
            }
        }
        if (!isRecurringWithCurrentLength && smallestRepetendLength != null) {
            if (currentlyCheckedRepetendLength == 1) break
            alreadyChecked.add(currentlyCheckedRepetendLength)
            do {
                currentlyCheckedRepetendLength = smallestRepetendLength / smallestDivisor(smallestRepetendLength, smallestRepetendLength / currentlyCheckedRepetendLength)
            } while (currentlyCheckedRepetendLength > 1 && alreadyChecked.any { it % currentlyCheckedRepetendLength == 0 })
            if (currentlyCheckedRepetendLength == 1) break
        } else if (!isRecurringWithCurrentLength) {
            currentlyCheckedRepetendLength--
            if (currentlyCheckedRepetendLength != 0) minRepeatingPartLength--
        } else {
            smallestRepetendLength = currentlyCheckedRepetendLength
            if (currentlyCheckedRepetendLength == 1) break
            currentlyCheckedRepetendLength /= smallestPrimeFactor(currentlyCheckedRepetendLength)
            alreadyChecked.clear()
        }
    }

    if (smallestRepetendLength == null) return null
    val repetend = ((((1L shl smallestRepetendLength) - 1) shl (minRepeatingPartLength - smallestRepetendLength)) and (digitsToCheck ushr (64-numOfDigitsToCheck))) ushr (minRepeatingPartLength - smallestRepetendLength)
    var shiftRepetitionStart = 0
    val allDigits = mantissa
    for (i in (2 + minRepeatingPartLength) until (52 - max(exp, 0))) {
        if ((allDigits and (1L shl (i - smallestRepetendLength)) == 0L) != (allDigits and (1L shl i) == 0L)) break
        shiftRepetitionStart++
    }

//    I.APPP... = (IAP - IA) / ((2^n - 1) * 2^k)   with n = repetendLength, k = digits between . and first P
    val p = repetend.rotateRight(shiftRepetitionStart, smallestRepetendLength)
    val ia = (mantissa or 0x0010000000000000L) ushr  (2 + minRepeatingPartLength + shiftRepetitionStart)
    val numerator = ((ia shl smallestRepetendLength) or p) - ia  // Do I need to check for overflow here and the line below?
    val denominator = ((1L shl smallestRepetendLength) - 1) shl (50 - minRepeatingPartLength - shiftRepetitionStart - exp)
    return reduceFraction(sign.toInt() * numerator, denominator)
}

/**returns the smallest divisor of [n] that is bigger than [k]*/
private fun smallestDivisor(n: Int, k: Int): Int {
    for (i in k+1 until n) {
        if (n % i == 0) return i
    }
    return n
}

private fun smallestPrimeFactor(n: Int): Int { // fast enough, because n is never bigger than 50
    if (n % 2 == 0) return 2
    var i = 3
    while (i <= sqrt(n.toDouble())) {
        if (n % i == 0) return i
        i += 2
    }
    return n
}

fun primeFactors(num: Long): Map<Long, Int> {
    var n = num
    val factors = mutableMapOf<Long, Int>()
    var i = 2L
    while (i * i <= n) {
        while (n % i == 0L) {
            val occurrences = factors[i]?:0
            factors[i] = occurrences + 1
            n /= i
        }
        i++
    }
    if (n > 1) {
        val occurrences = factors[i]?:0
        factors[n] = occurrences + 1
    }
    return factors.toMap()
}

private fun Long.rotateRight(n: Int, size: Int) = (((1L shl n) - 1) shl (size - n)) and
        (this shl (size - n)) or
        (this ushr n)

Compiled from "Util.kt"
public final class com.exponential_groth.calculator.result.UtilKt {
  private static final long getMantissa(double);
    Code:
       0: dload_0
       1: invokestatic  #11                 // Method java/lang/Double.doubleToLongBits:(D)J
       4: ldc2_w        #12                 // long 4503599627370495l
       7: land
       8: lreturn

  private static final long getExponent(double);
    Code:
       0: dload_0
       1: invokestatic  #11                 // Method java/lang/Double.doubleToLongBits:(D)J
       4: ldc2_w        #17                 // long 9218868437227405312l
       7: land
       8: bipush        52
      10: lushr
      11: sipush        1023
      14: i2l
      15: lsub
      16: lreturn

  public static final kotlin.Pair<java.lang.Long, java.lang.Long> reduceFraction(long, long);
    Code:
       0: lload_0
       1: lconst_0
       2: lcmp
       3: ifle          10
       6: iconst_1
       7: goto          11
      10: iconst_0
      11: lload_2
      12: lconst_0
      13: lcmp
      14: ifle          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ixor
      23: ifeq          30
      26: iconst_m1
      27: goto          31
      30: iconst_1
      31: istore        4
      33: lload_0
      34: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      37: lload_2
      38: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      41: invokestatic  #33                 // Method gcd:(JJ)J
      44: lstore        5
      46: new           #35                 // class kotlin/Pair
      49: dup
      50: iload         4
      52: i2l
      53: lload_0
      54: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      57: lmul
      58: lload         5
      60: ldiv
      61: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      64: lload_2
      65: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      68: lload         5
      70: ldiv
      71: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      74: invokespecial #45                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      77: areturn

  private static final long gcd(long, long);
    Code:
       0: lload_0
       1: lconst_0
       2: lcmp
       3: ifle          16
       6: lload_2
       7: lconst_0
       8: lcmp
       9: ifle          16
      12: iconst_1
      13: goto          17
      16: iconst_0
      17: ifne          37
      20: ldc           #52                 // String Failed requirement.
      22: astore        5
      24: new           #54                 // class java/lang/IllegalArgumentException
      27: dup
      28: aload         5
      30: invokevirtual #58                 // Method java/lang/Object.toString:()Ljava/lang/String;
      33: invokespecial #61                 // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      36: athrow
      37: lload_0
      38: lconst_0
      39: lcmp
      40: ifne          45
      43: lload_2
      44: lreturn
      45: lload_2
      46: lconst_0
      47: lcmp
      48: ifne          53
      51: lload_0
      52: lreturn
      53: lload_0
      54: lload_2
      55: lor
      56: invokestatic  #65                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      59: istore        4
      61: lload_0
      62: lstore        5
      64: lload_2
      65: lstore        7
      67: lload         5
      69: lload         5
      71: invokestatic  #65                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      74: lshr
      75: lstore        5
      77: lload         7
      79: lload         7
      81: invokestatic  #65                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      84: lshr
      85: lstore        7
      87: lload         7
      89: lload         5
      91: lsub
      92: lstore        7
      94: lload         7
      96: bipush        63
      98: lshr
      99: lstore        9
     101: lload         5
     103: lload         7
     105: lload         9
     107: land
     108: ladd
     109: lstore        5
     111: lload         7
     113: lload         9
     115: ladd
     116: lload         9
     118: lxor
     119: lstore        7
     121: lload         7
     123: lconst_0
     124: lcmp
     125: ifne          77
     128: lload         5
     130: iload         4
     132: lshl
     133: lreturn

  public static final java.lang.String fractionToDecimal(long, long);
    Code:
       0: lload_0
       1: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
       4: lstore        4
       6: lload_2
       7: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      10: lstore        6
      12: lload_0
      13: lconst_0
      14: lcmp
      15: ifge          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: lload_2
      24: lconst_0
      25: lcmp
      26: ifge          33
      29: iconst_1
      30: goto          34
      33: iconst_0
      34: ixor
      35: ifeq          43
      38: ldc           #75                 // String -
      40: goto          45
      43: ldc           #77                 // String
      45: astore        8
      47: lload         6
      49: lconst_0
      50: lcmp
      51: ifne          57
      54: ldc           #77                 // String
      56: areturn
      57: lload         4
      59: lconst_0
      60: lcmp
      61: ifne          67
      64: ldc           #79                 // String 0
      66: areturn
      67: lload         4
      69: lload         6
      71: lrem
      72: lconst_0
      73: lcmp
      74: ifne          101
      77: new           #81                 // class java/lang/StringBuilder
      80: dup
      81: invokespecial #84                 // Method java/lang/StringBuilder."<init>":()V
      84: aload         8
      86: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      89: lload         4
      91: lload         6
      93: ldiv
      94: invokevirtual #91                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      97: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: areturn
     101: new           #94                 // class java/util/HashMap
     104: dup
     105: invokespecial #95                 // Method java/util/HashMap."<init>":()V
     108: astore        9
     110: new           #97                 // class java/lang/StringBuffer
     113: dup
     114: new           #81                 // class java/lang/StringBuilder
     117: dup
     118: invokespecial #84                 // Method java/lang/StringBuilder."<init>":()V
     121: aload         8
     123: invokevirtual #88                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     126: lload         4
     128: lload         6
     130: ldiv
     131: invokevirtual #91                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     134: bipush        46
     136: invokevirtual #100                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     139: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     142: invokespecial #101                // Method java/lang/StringBuffer."<init>":(Ljava/lang/String;)V
     145: astore        10
     147: lload         4
     149: lload         6
     151: lrem
     152: bipush        10
     154: i2l
     155: lmul
     156: lstore        11
     158: iconst_0
     159: istore        13
     161: lload         11
     163: lconst_0
     164: lcmp
     165: ifeq          292
     168: aload         9
     170: lload         11
     172: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     175: invokevirtual #105                // Method java/util/HashMap.containsKey:(Ljava/lang/Object;)Z
     178: ifeq          239
     181: aload         10
     183: aload         10
     185: ldc           #107                // String .
     187: invokevirtual #111                // Method java/lang/StringBuffer.indexOf:(Ljava/lang/String;)I
     190: aload         9
     192: lload         11
     194: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     197: invokevirtual #115                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     200: dup
     201: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     204: checkcast     #123                // class java/lang/Number
     207: invokevirtual #127                // Method java/lang/Number.intValue:()I
     210: iadd
     211: iconst_1
     212: iadd
     213: ldc           #129                // String \\overline{
     215: invokevirtual #133                // Method java/lang/StringBuffer.insert:(ILjava/lang/String;)Ljava/lang/StringBuffer;
     218: pop
     219: aload         10
     221: ldc           #135                // String }
     223: invokevirtual #138                // Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
     226: pop
     227: aload         10
     229: invokevirtual #139                // Method java/lang/StringBuffer.toString:()Ljava/lang/String;
     232: dup
     233: ldc           #141                // String toString(...)
     235: invokestatic  #145                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     238: areturn
     239: aload         10
     241: lload         11
     243: lload         6
     245: ldiv
     246: invokevirtual #148                // Method java/lang/StringBuffer.append:(J)Ljava/lang/StringBuffer;
     249: pop
     250: lload         11
     252: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     255: astore        14
     257: aload         9
     259: checkcast     #150                // class java/util/Map
     262: aload         14
     264: iload         13
     266: iinc          13, 1
     269: invokestatic  #155                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     272: invokeinterface #159,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     277: pop
     278: lload         11
     280: lload         6
     282: lrem
     283: bipush        10
     285: i2l
     286: lmul
     287: lstore        11
     289: goto          161
     292: aload         10
     294: invokevirtual #139                // Method java/lang/StringBuffer.toString:()Ljava/lang/String;
     297: dup
     298: ldc           #141                // String toString(...)
     300: invokestatic  #145                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     303: areturn

  public static final kotlin.Pair<java.lang.Long, java.lang.Long> toFraction(double);
    Code:
       0: dload_0
       1: invokestatic  #178                // Method java/lang/Math.signum:(D)D
       4: d2i
       5: istore_2
       6: dload_0
       7: invokestatic  #180                // Method getExponent:(D)J
      10: lstore_3
      11: dload_0
      12: invokestatic  #182                // Method getMantissa:(D)J
      15: bipush        12
      17: lshl
      18: lstore        5
      20: lload_3
      21: invokestatic  #29                 // Method java/lang/Math.abs:(J)J
      24: ldc2_w        #183                // long 32l
      27: lcmp
      28: iflt          33
      31: aconst_null
      32: areturn
      33: dload_0
      34: invokestatic  #187                // Method asRepeatingDecimalToFraction:(D)Lkotlin/Pair;
      37: astore        7
      39: aload         7
      41: ifnull        54
      44: aload         7
      46: astore        9
      48: iconst_0
      49: istore        10
      51: aload         9
      53: areturn
      54: lload         5
      56: invokestatic  #65                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      59: bipush        17
      61: if_icmpge     66
      64: aconst_null
      65: areturn
      66: lconst_1
      67: lstore        7
      69: lconst_1
      70: lstore        9
      72: lload         5
      74: invokestatic  #190                // Method java/lang/Long.numberOfLeadingZeros:(J)I
      77: istore        11
      79: iload         11
      81: bipush        64
      83: if_icmpeq     125
      86: lload         7
      88: iload         11
      90: iconst_1
      91: iadd
      92: lshl
      93: lconst_1
      94: ladd
      95: lstore        7
      97: lload         9
      99: iload         11
     101: iconst_1
     102: iadd
     103: lshl
     104: lstore        9
     106: lload         5
     108: iload         11
     110: iconst_1
     111: iadd
     112: lshl
     113: lstore        5
     115: lload         5
     117: invokestatic  #190                // Method java/lang/Long.numberOfLeadingZeros:(J)I
     120: istore        11
     122: goto          79
     125: lload_3
     126: lconst_0
     127: lcmp
     128: iflt          141
     131: lload         7
     133: lload_3
     134: l2i
     135: lshl
     136: lstore        7
     138: goto          149
     141: lload         9
     143: lload_3
     144: l2i
     145: ineg
     146: lshl
     147: lstore        9
     149: iload_2
     150: i2l
     151: lload         7
     153: lmul
     154: lload         9
     156: invokestatic  #192                // Method reduceFraction:(JJ)Lkotlin/Pair;
     159: areturn

  private static final kotlin.Pair<java.lang.Long, java.lang.Long> asRepeatingDecimalToFraction(double);
    Code:
       0: dload_0
       1: invokestatic  #180                // Method getExponent:(D)J
       4: l2i
       5: istore_2
       6: bipush        52
       8: iload_2
       9: iconst_0
      10: invokestatic  #203                // Method java/lang/Math.max:(II)I
      13: isub
      14: iconst_2
      15: isub
      16: istore_3
      17: dload_0
      18: invokestatic  #182                // Method getMantissa:(D)J
      21: ldc2_w        #204                // long -4l
      24: land
      25: bipush        62
      27: iload_3
      28: isub
      29: lshl
      30: lstore        4
      32: lload         4
      34: bipush        64
      36: iload_3
      37: isub
      38: lushr
      39: invokestatic  #65                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      42: iload_3
      43: iconst_2
      44: idiv
      45: if_icmple     50
      48: aconst_null
      49: areturn
      50: iconst_0
      51: istore        6
      53: iload_3
      54: iconst_2
      55: idiv
      56: istore        6
      58: iload_3
      59: istore        7
      61: aconst_null
      62: astore        8
      64: new           #207                // class java/util/ArrayList
      67: dup
      68: invokespecial #208                // Method java/util/ArrayList."<init>":()V
      71: checkcast     #210                // class java/util/List
      74: astore        9
      76: iload         6
      78: ifle          388
      81: iconst_1
      82: istore        10
      84: bipush        64
      86: iload_3
      87: isub
      88: iload         6
      90: iadd
      91: istore        11
      93: bipush        64
      95: iload_3
      96: iload         7
      98: isub
      99: isub
     100: istore        12
     102: iload         11
     104: iload         12
     106: if_icmpge     161
     109: lload         4
     111: lconst_1
     112: iload         11
     114: iload         6
     116: isub
     117: lshl
     118: land
     119: lconst_0
     120: lcmp
     121: ifne          128
     124: iconst_1
     125: goto          129
     128: iconst_0
     129: lload         4
     131: lconst_1
     132: iload         11
     134: lshl
     135: land
     136: lconst_0
     137: lcmp
     138: ifne          145
     141: iconst_1
     142: goto          146
     145: iconst_0
     146: if_icmpeq     155
     149: iconst_0
     150: istore        10
     152: goto          161
     155: iinc          11, 1
     158: goto          102
     161: iload         10
     163: ifne          329
     166: aload         8
     168: ifnull        329
     171: iload         6
     173: iconst_1
     174: if_icmpeq     388
     177: aload         9
     179: iload         6
     181: invokestatic  #155                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: invokeinterface #213,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     189: pop
     190: aload         8
     192: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     195: aload         8
     197: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     200: aload         8
     202: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     205: iload         6
     207: idiv
     208: invokestatic  #217                // Method smallestDivisor:(II)I
     211: idiv
     212: istore        6
     214: iload         6
     216: iconst_1
     217: if_icmple     320
     220: aload         9
     222: checkcast     #219                // class java/lang/Iterable
     225: astore        11
     227: iconst_0
     228: istore        12
     230: aload         11
     232: instanceof    #221                // class java/util/Collection
     235: ifeq          255
     238: aload         11
     240: checkcast     #221                // class java/util/Collection
     243: invokeinterface #225,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     248: ifeq          255
     251: iconst_0
     252: goto          317
     255: aload         11
     257: invokeinterface #229,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     262: astore        13
     264: aload         13
     266: invokeinterface #234,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     271: ifeq          316
     274: aload         13
     276: invokeinterface #238,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     281: astore        14
     283: aload         14
     285: checkcast     #123                // class java/lang/Number
     288: invokevirtual #127                // Method java/lang/Number.intValue:()I
     291: istore        15
     293: iconst_0
     294: istore        16
     296: iload         15
     298: iload         6
     300: irem
     301: ifne          308
     304: iconst_1
     305: goto          309
     308: iconst_0
     309: ifeq          264
     312: iconst_1
     313: goto          317
     316: iconst_0
     317: ifne          190
     320: iload         6
     322: iconst_1
     323: if_icmpne     76
     326: goto          388
     329: iload         10
     331: ifne          355
     334: iload         6
     336: istore        11
     338: iload         11
     340: iconst_m1
     341: iadd
     342: istore        6
     344: iload         6
     346: ifeq          76
     349: iinc          7, -1
     352: goto          76
     355: iload         6
     357: invokestatic  #155                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     360: astore        8
     362: iload         6
     364: iconst_1
     365: if_icmpeq     388
     368: iload         6
     370: iload         6
     372: invokestatic  #242                // Method smallestPrimeFactor:(I)I
     375: idiv
     376: istore        6
     378: aload         9
     380: invokeinterface #245,  1          // InterfaceMethod java/util/List.clear:()V
     385: goto          76
     388: aload         8
     390: ifnonnull     395
     393: aconst_null
     394: areturn
     395: lconst_1
     396: aload         8
     398: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     401: lshl
     402: lconst_1
     403: lsub
     404: iload         7
     406: aload         8
     408: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     411: isub
     412: lshl
     413: lload         4
     415: bipush        64
     417: iload_3
     418: isub
     419: lushr
     420: land
     421: iload         7
     423: aload         8
     425: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     428: isub
     429: lushr
     430: lstore        10
     432: iconst_0
     433: istore        12
     435: dload_0
     436: invokestatic  #182                // Method getMantissa:(D)J
     439: lstore        13
     441: iconst_2
     442: iload         7
     444: iadd
     445: istore        15
     447: bipush        52
     449: iload_2
     450: iconst_0
     451: invokestatic  #203                // Method java/lang/Math.max:(II)I
     454: isub
     455: istore        16
     457: iload         15
     459: iload         16
     461: if_icmpge     516
     464: lload         13
     466: lconst_1
     467: iload         15
     469: aload         8
     471: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     474: isub
     475: lshl
     476: land
     477: lconst_0
     478: lcmp
     479: ifne          486
     482: iconst_1
     483: goto          487
     486: iconst_0
     487: lload         13
     489: lconst_1
     490: iload         15
     492: lshl
     493: land
     494: lconst_0
     495: lcmp
     496: ifne          503
     499: iconst_1
     500: goto          504
     503: iconst_0
     504: if_icmpne     516
     507: iinc          12, 1
     510: iinc          15, 1
     513: goto          457
     516: lload         10
     518: iload         12
     520: aload         8
     522: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     525: invokestatic  #249                // Method rotateRight:(JII)J
     528: lstore        15
     530: dload_0
     531: invokestatic  #182                // Method getMantissa:(D)J
     534: ldc2_w        #250                // long 4503599627370496l
     537: lor
     538: iconst_2
     539: iload         7
     541: iadd
     542: iload         12
     544: iadd
     545: lushr
     546: lstore        17
     548: lload         17
     550: aload         8
     552: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     555: lshl
     556: lload         15
     558: lor
     559: lload         17
     561: lsub
     562: lstore        19
     564: lconst_1
     565: aload         8
     567: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     570: lshl
     571: lconst_1
     572: lsub
     573: bipush        50
     575: iload         7
     577: isub
     578: iload         12
     580: isub
     581: iload_2
     582: isub
     583: lshl
     584: lstore        21
     586: dload_0
     587: invokestatic  #178                // Method java/lang/Math.signum:(D)D
     590: d2i
     591: i2l
     592: lload         19
     594: lmul
     595: lload         21
     597: invokestatic  #192                // Method reduceFraction:(JJ)Lkotlin/Pair;
     600: areturn

  private static final int smallestDivisor(int, int);
    Code:
       0: iload_1
       1: iconst_1
       2: iadd
       3: istore_2
       4: iload_2
       5: iload_0
       6: if_icmpge     23
       9: iload_0
      10: iload_2
      11: irem
      12: ifne          17
      15: iload_2
      16: ireturn
      17: iinc          2, 1
      20: goto          4
      23: iload_0
      24: ireturn

  private static final int smallestPrimeFactor(int);
    Code:
       0: iload_0
       1: iconst_2
       2: irem
       3: ifne          8
       6: iconst_2
       7: ireturn
       8: iconst_3
       9: istore_1
      10: iload_1
      11: i2d
      12: iload_0
      13: i2d
      14: invokestatic  #279                // Method java/lang/Math.sqrt:(D)D
      17: dcmpg
      18: ifgt          35
      21: iload_0
      22: iload_1
      23: irem
      24: ifne          29
      27: iload_1
      28: ireturn
      29: iinc          1, 2
      32: goto          10
      35: iload_0
      36: ireturn

  public static final java.util.Map<java.lang.Long, java.lang.Integer> primeFactors(long);
    Code:
       0: lload_0
       1: lstore_2
       2: new           #284                // class java/util/LinkedHashMap
       5: dup
       6: invokespecial #285                // Method java/util/LinkedHashMap."<init>":()V
       9: checkcast     #150                // class java/util/Map
      12: astore        4
      14: ldc2_w        #286                // long 2l
      17: lstore        5
      19: lload         5
      21: lload         5
      23: lmul
      24: lload_2
      25: lcmp
      26: ifgt          112
      29: lload_2
      30: lload         5
      32: lrem
      33: lconst_0
      34: lcmp
      35: ifne          99
      38: aload         4
      40: lload         5
      42: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      45: invokeinterface #288,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      50: checkcast     #152                // class java/lang/Integer
      53: dup
      54: ifnull        63
      57: invokevirtual #214                // Method java/lang/Integer.intValue:()I
      60: goto          65
      63: pop
      64: iconst_0
      65: istore        7
      67: lload         5
      69: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      72: astore        9
      74: aload         4
      76: aload         9
      78: iload         7
      80: iconst_1
      81: iadd
      82: invokestatic  #155                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: invokeinterface #159,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      90: pop
      91: lload_2
      92: lload         5
      94: ldiv
      95: lstore_2
      96: goto          29
      99: lload         5
     101: lstore        7
     103: lload         7
     105: lconst_1
     106: ladd
     107: lstore        5
     109: goto          19
     112: lload_2
     113: lconst_1
     114: lcmp
     115: ifle          170
     118: aload         4
     120: lload         5
     122: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     125: invokeinterface #288,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     130: checkcast     #152                // class java/lang/Integer
     133: dup
     134: ifnull        143
     137: invokevirtual #214                // Method java/lang/Integer.intValue:()I
     140: goto          145
     143: pop
     144: iconst_0
     145: istore        7
     147: lload_2
     148: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     151: astore        9
     153: aload         4
     155: aload         9
     157: iload         7
     159: iconst_1
     160: iadd
     161: invokestatic  #155                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     164: invokeinterface #159,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     169: pop
     170: aload         4
     172: invokestatic  #294                // Method kotlin/collections/MapsKt.toMap:(Ljava/util/Map;)Ljava/util/Map;
     175: areturn

  private static final long rotateRight(long, int, int);
    Code:
       0: lconst_1
       1: iload_2
       2: lshl
       3: lconst_1
       4: lsub
       5: iload_3
       6: iload_2
       7: isub
       8: lshl
       9: lload_0
      10: iload_3
      11: iload_2
      12: isub
      13: lshl
      14: land
      15: lload_0
      16: iload_2
      17: lushr
      18: lor
      19: lreturn
}


package day09

import java.io.File

data class Knot(var x: Int, var y: Int)

val fileList = File("puzzle_input/day09.txt").readLines()

fun moveHead(head: Knot, direction: Char) = when (direction) {
    'U'  -> Knot(head.x, head.y + 1)
    'L'  -> Knot(head.x - 1, head.y)
    'R'  -> Knot(head.x + 1, head.y)
    'D'  -> Knot(head.x, head.y - 1)
    else -> Knot(0, 0)
  }

fun moveTail(head: Knot, tail: Knot) = when {
  head.x > tail.x + 1 && head.y > tail.y + 1 -> Knot(head.x - 1, head.y - 1)
  head.x < tail.x - 1 && head.y > tail.y + 1 -> Knot(head.x + 1, head.y - 1)
  head.x > tail.x + 1 && head.y < tail.y - 1 -> Knot(head.x - 1, head.y + 1)
  head.x < tail.x - 1 && head.y < tail.y - 1 -> Knot(head.x + 1, head.y + 1)
  head.x > tail.x + 1 -> Knot(head.x - 1, head.y)
  head.x < tail.x - 1 -> Knot(head.x + 1, head.y)
  head.y > tail.y + 1 -> Knot(head.x, head.y - 1)
  head.y < tail.y - 1 -> Knot(head.x, head.y + 1)
  else                -> tail
}

fun a(): Int {
  val visited = mutableSetOf(Knot(0, 0))

  var head = Knot(0, 0)
  var tail = Knot(0, 0)

  for (line in fileList) {
    val direction = line[0]
    val steps = line.slice(2 until line.length).toInt()

    repeat(steps) {
      head = moveHead(head, direction)
      tail = moveTail(head, tail)
      visited += tail
    }
  }

  return visited.size
}

fun b(): Int {
  val visited = mutableSetOf(Knot(0, 0))

  val rope = Array(10) { Knot(0,0) }

  for (line in fileList) {
    val direction = line[0]
    val steps = line.slice(2 until line.length).toInt()

    repeat(steps) {
      rope[0] = moveHead(rope[0], direction)
      for (i in rope.indices.filter { it > 0 }) rope[i] = moveTail(rope[i - 1], rope[i])
      visited += rope[9]
    }
  }

  return visited.size
}

Compiled from "DayNine.kt"
public final class day09.DayNineKt {
  private static final java.util.List<java.lang.String> fileList;

  public static final java.util.List<java.lang.String> getFileList();
    Code:
       0: getstatic     #12                 // Field fileList:Ljava/util/List;
       3: areturn

  public static final day09.Knot moveHead(day09.Knot, char);
    Code:
       0: aload_0
       1: ldc           #16                 // String head
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: lookupswitch  { // 4
                    68: 108
                    76: 68
                    82: 88
                    85: 48
               default: 128
          }
      48: new           #24                 // class day09/Knot
      51: dup
      52: aload_0
      53: invokevirtual #28                 // Method day09/Knot.getX:()I
      56: aload_0
      57: invokevirtual #31                 // Method day09/Knot.getY:()I
      60: iconst_1
      61: iadd
      62: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      65: goto          137
      68: new           #24                 // class day09/Knot
      71: dup
      72: aload_0
      73: invokevirtual #28                 // Method day09/Knot.getX:()I
      76: iconst_1
      77: isub
      78: aload_0
      79: invokevirtual #31                 // Method day09/Knot.getY:()I
      82: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      85: goto          137
      88: new           #24                 // class day09/Knot
      91: dup
      92: aload_0
      93: invokevirtual #28                 // Method day09/Knot.getX:()I
      96: iconst_1
      97: iadd
      98: aload_0
      99: invokevirtual #31                 // Method day09/Knot.getY:()I
     102: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     105: goto          137
     108: new           #24                 // class day09/Knot
     111: dup
     112: aload_0
     113: invokevirtual #28                 // Method day09/Knot.getX:()I
     116: aload_0
     117: invokevirtual #31                 // Method day09/Knot.getY:()I
     120: iconst_1
     121: isub
     122: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     125: goto          137
     128: new           #24                 // class day09/Knot
     131: dup
     132: iconst_0
     133: iconst_0
     134: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     137: areturn

  public static final day09.Knot moveTail(day09.Knot, day09.Knot);
    Code:
       0: aload_0
       1: ldc           #16                 // String head
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #42                 // String tail
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: nop
      13: aload_0
      14: invokevirtual #28                 // Method day09/Knot.getX:()I
      17: aload_1
      18: invokevirtual #28                 // Method day09/Knot.getX:()I
      21: iconst_1
      22: iadd
      23: if_icmple     61
      26: aload_0
      27: invokevirtual #31                 // Method day09/Knot.getY:()I
      30: aload_1
      31: invokevirtual #31                 // Method day09/Knot.getY:()I
      34: iconst_1
      35: iadd
      36: if_icmple     61
      39: new           #24                 // class day09/Knot
      42: dup
      43: aload_0
      44: invokevirtual #28                 // Method day09/Knot.getX:()I
      47: iconst_1
      48: isub
      49: aload_0
      50: invokevirtual #31                 // Method day09/Knot.getY:()I
      53: iconst_1
      54: isub
      55: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      58: goto          338
      61: aload_0
      62: invokevirtual #28                 // Method day09/Knot.getX:()I
      65: aload_1
      66: invokevirtual #28                 // Method day09/Knot.getX:()I
      69: iconst_1
      70: isub
      71: if_icmpge     109
      74: aload_0
      75: invokevirtual #31                 // Method day09/Knot.getY:()I
      78: aload_1
      79: invokevirtual #31                 // Method day09/Knot.getY:()I
      82: iconst_1
      83: iadd
      84: if_icmple     109
      87: new           #24                 // class day09/Knot
      90: dup
      91: aload_0
      92: invokevirtual #28                 // Method day09/Knot.getX:()I
      95: iconst_1
      96: iadd
      97: aload_0
      98: invokevirtual #31                 // Method day09/Knot.getY:()I
     101: iconst_1
     102: isub
     103: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     106: goto          338
     109: aload_0
     110: invokevirtual #28                 // Method day09/Knot.getX:()I
     113: aload_1
     114: invokevirtual #28                 // Method day09/Knot.getX:()I
     117: iconst_1
     118: iadd
     119: if_icmple     157
     122: aload_0
     123: invokevirtual #31                 // Method day09/Knot.getY:()I
     126: aload_1
     127: invokevirtual #31                 // Method day09/Knot.getY:()I
     130: iconst_1
     131: isub
     132: if_icmpge     157
     135: new           #24                 // class day09/Knot
     138: dup
     139: aload_0
     140: invokevirtual #28                 // Method day09/Knot.getX:()I
     143: iconst_1
     144: isub
     145: aload_0
     146: invokevirtual #31                 // Method day09/Knot.getY:()I
     149: iconst_1
     150: iadd
     151: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     154: goto          338
     157: aload_0
     158: invokevirtual #28                 // Method day09/Knot.getX:()I
     161: aload_1
     162: invokevirtual #28                 // Method day09/Knot.getX:()I
     165: iconst_1
     166: isub
     167: if_icmpge     205
     170: aload_0
     171: invokevirtual #31                 // Method day09/Knot.getY:()I
     174: aload_1
     175: invokevirtual #31                 // Method day09/Knot.getY:()I
     178: iconst_1
     179: isub
     180: if_icmpge     205
     183: new           #24                 // class day09/Knot
     186: dup
     187: aload_0
     188: invokevirtual #28                 // Method day09/Knot.getX:()I
     191: iconst_1
     192: iadd
     193: aload_0
     194: invokevirtual #31                 // Method day09/Knot.getY:()I
     197: iconst_1
     198: iadd
     199: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     202: goto          338
     205: aload_0
     206: invokevirtual #28                 // Method day09/Knot.getX:()I
     209: aload_1
     210: invokevirtual #28                 // Method day09/Knot.getX:()I
     213: iconst_1
     214: iadd
     215: if_icmple     238
     218: new           #24                 // class day09/Knot
     221: dup
     222: aload_0
     223: invokevirtual #28                 // Method day09/Knot.getX:()I
     226: iconst_1
     227: isub
     228: aload_0
     229: invokevirtual #31                 // Method day09/Knot.getY:()I
     232: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     235: goto          338
     238: aload_0
     239: invokevirtual #28                 // Method day09/Knot.getX:()I
     242: aload_1
     243: invokevirtual #28                 // Method day09/Knot.getX:()I
     246: iconst_1
     247: isub
     248: if_icmpge     271
     251: new           #24                 // class day09/Knot
     254: dup
     255: aload_0
     256: invokevirtual #28                 // Method day09/Knot.getX:()I
     259: iconst_1
     260: iadd
     261: aload_0
     262: invokevirtual #31                 // Method day09/Knot.getY:()I
     265: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     268: goto          338
     271: aload_0
     272: invokevirtual #31                 // Method day09/Knot.getY:()I
     275: aload_1
     276: invokevirtual #31                 // Method day09/Knot.getY:()I
     279: iconst_1
     280: iadd
     281: if_icmple     304
     284: new           #24                 // class day09/Knot
     287: dup
     288: aload_0
     289: invokevirtual #28                 // Method day09/Knot.getX:()I
     292: aload_0
     293: invokevirtual #31                 // Method day09/Knot.getY:()I
     296: iconst_1
     297: isub
     298: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     301: goto          338
     304: aload_0
     305: invokevirtual #31                 // Method day09/Knot.getY:()I
     308: aload_1
     309: invokevirtual #31                 // Method day09/Knot.getY:()I
     312: iconst_1
     313: isub
     314: if_icmpge     337
     317: new           #24                 // class day09/Knot
     320: dup
     321: aload_0
     322: invokevirtual #28                 // Method day09/Knot.getX:()I
     325: aload_0
     326: invokevirtual #31                 // Method day09/Knot.getY:()I
     329: iconst_1
     330: iadd
     331: invokespecial #35                 // Method day09/Knot."<init>":(II)V
     334: goto          338
     337: aload_1
     338: areturn

  public static final int a();
    Code:
       0: iconst_1
       1: anewarray     #24                 // class day09/Knot
       4: astore_1
       5: aload_1
       6: iconst_0
       7: new           #24                 // class day09/Knot
      10: dup
      11: iconst_0
      12: iconst_0
      13: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      16: aastore
      17: aload_1
      18: invokestatic  #49                 // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      21: astore_0
      22: aconst_null
      23: astore_1
      24: new           #24                 // class day09/Knot
      27: dup
      28: iconst_0
      29: iconst_0
      30: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      33: astore_1
      34: aconst_null
      35: astore_2
      36: new           #24                 // class day09/Knot
      39: dup
      40: iconst_0
      41: iconst_0
      42: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      45: astore_2
      46: getstatic     #12                 // Field fileList:Ljava/util/List;
      49: invokeinterface #55,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      54: astore_3
      55: aload_3
      56: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          150
      64: aload_3
      65: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: checkcast     #67                 // class java/lang/String
      73: astore        4
      75: aload         4
      77: iconst_0
      78: invokevirtual #71                 // Method java/lang/String.charAt:(I)C
      81: istore        5
      83: aload         4
      85: iconst_2
      86: aload         4
      88: invokevirtual #74                 // Method java/lang/String.length:()I
      91: invokestatic  #80                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      94: invokestatic  #86                 // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      97: invokestatic  #92                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     100: istore        6
     102: iconst_0
     103: istore        7
     105: iload         7
     107: iload         6
     109: if_icmpge     55
     112: iload         7
     114: istore        8
     116: iconst_0
     117: istore        9
     119: aload_1
     120: iload         5
     122: invokestatic  #94                 // Method moveHead:(Lday09/Knot;C)Lday09/Knot;
     125: astore_1
     126: aload_1
     127: aload_2
     128: invokestatic  #96                 // Method moveTail:(Lday09/Knot;Lday09/Knot;)Lday09/Knot;
     131: astore_2
     132: aload_0
     133: checkcast     #98                 // class java/util/Collection
     136: aload_2
     137: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     142: pop
     143: nop
     144: iinc          7, 1
     147: goto          105
     150: aload_0
     151: invokeinterface #107,  1          // InterfaceMethod java/util/Set.size:()I
     156: ireturn

  public static final int b();
    Code:
       0: iconst_1
       1: anewarray     #24                 // class day09/Knot
       4: astore_1
       5: aload_1
       6: iconst_0
       7: new           #24                 // class day09/Knot
      10: dup
      11: iconst_0
      12: iconst_0
      13: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      16: aastore
      17: aload_1
      18: invokestatic  #49                 // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      21: astore_0
      22: iconst_0
      23: istore_2
      24: bipush        10
      26: anewarray     #24                 // class day09/Knot
      29: astore_3
      30: iload_2
      31: bipush        10
      33: if_icmpge     58
      36: iload_2
      37: istore        4
      39: aload_3
      40: iload         4
      42: new           #24                 // class day09/Knot
      45: dup
      46: iconst_0
      47: iconst_0
      48: invokespecial #35                 // Method day09/Knot."<init>":(II)V
      51: aastore
      52: iinc          2, 1
      55: goto          30
      58: aload_3
      59: astore_1
      60: getstatic     #12                 // Field fileList:Ljava/util/List;
      63: invokeinterface #55,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      68: astore_2
      69: aload_2
      70: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      75: ifeq          317
      78: aload_2
      79: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: checkcast     #67                 // class java/lang/String
      87: astore_3
      88: aload_3
      89: iconst_0
      90: invokevirtual #71                 // Method java/lang/String.charAt:(I)C
      93: istore        4
      95: aload_3
      96: iconst_2
      97: aload_3
      98: invokevirtual #74                 // Method java/lang/String.length:()I
     101: invokestatic  #80                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     104: invokestatic  #86                 // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     107: invokestatic  #92                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     110: istore        5
     112: iconst_0
     113: istore        6
     115: iload         6
     117: iload         5
     119: if_icmpge     69
     122: iload         6
     124: istore        7
     126: iconst_0
     127: istore        8
     129: aload_1
     130: iconst_0
     131: aload_1
     132: iconst_0
     133: aaload
     134: iload         4
     136: invokestatic  #94                 // Method moveHead:(Lday09/Knot;C)Lday09/Knot;
     139: aastore
     140: aload_1
     141: invokestatic  #123                // Method kotlin/collections/ArraysKt.getIndices:([Ljava/lang/Object;)Lkotlin/ranges/IntRange;
     144: checkcast     #125                // class java/lang/Iterable
     147: astore        9
     149: iconst_0
     150: istore        10
     152: aload         9
     154: astore        11
     156: new           #127                // class java/util/ArrayList
     159: dup
     160: invokespecial #130                // Method java/util/ArrayList."<init>":()V
     163: checkcast     #98                 // class java/util/Collection
     166: astore        12
     168: iconst_0
     169: istore        13
     171: aload         11
     173: invokeinterface #131,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     178: astore        14
     180: aload         14
     182: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     187: ifeq          238
     190: aload         14
     192: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     197: astore        15
     199: aload         15
     201: checkcast     #133                // class java/lang/Number
     204: invokevirtual #136                // Method java/lang/Number.intValue:()I
     207: istore        16
     209: iconst_0
     210: istore        17
     212: iload         16
     214: ifle          221
     217: iconst_1
     218: goto          222
     221: iconst_0
     222: ifeq          180
     225: aload         12
     227: aload         15
     229: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     234: pop
     235: goto          180
     238: aload         12
     240: checkcast     #51                 // class java/util/List
     243: nop
     244: invokeinterface #55,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     249: astore        18
     251: aload         18
     253: invokeinterface #61,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     258: ifeq          296
     261: aload         18
     263: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     268: checkcast     #133                // class java/lang/Number
     271: invokevirtual #136                // Method java/lang/Number.intValue:()I
     274: istore        9
     276: aload_1
     277: iload         9
     279: aload_1
     280: iload         9
     282: iconst_1
     283: isub
     284: aaload
     285: aload_1
     286: iload         9
     288: aaload
     289: invokestatic  #96                 // Method moveTail:(Lday09/Knot;Lday09/Knot;)Lday09/Knot;
     292: aastore
     293: goto          251
     296: aload_0
     297: checkcast     #98                 // class java/util/Collection
     300: aload_1
     301: bipush        9
     303: aaload
     304: invokeinterface #102,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     309: pop
     310: nop
     311: iinc          6, 1
     314: goto          115
     317: aload_0
     318: invokeinterface #107,  1          // InterfaceMethod java/util/Set.size:()I
     323: ireturn

  static {};
    Code:
       0: new           #153                // class java/io/File
       3: dup
       4: ldc           #155                // String puzzle_input/day09.txt
       6: invokespecial #158                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #164                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: putstatic     #12                 // Field fileList:Ljava/util/List;
      18: return
}