diff --git a/docs/exPuzzlers/.idea/.name b/docs/exPuzzlers/.idea/.name deleted file mode 100644 index 140eaf3b823..00000000000 --- a/docs/exPuzzlers/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -exPuzzlers \ No newline at end of file diff --git a/docs/exPuzzlers/.idea/ant.xml b/docs/exPuzzlers/.idea/ant.xml deleted file mode 100644 index 2581ca3fe84..00000000000 --- a/docs/exPuzzlers/.idea/ant.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/docs/exPuzzlers/.idea/compiler.xml b/docs/exPuzzlers/.idea/compiler.xml deleted file mode 100644 index a1b41c52c72..00000000000 --- a/docs/exPuzzlers/.idea/compiler.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - diff --git a/docs/exPuzzlers/.idea/copyright/profiles_settings.xml b/docs/exPuzzlers/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 3572571ad83..00000000000 --- a/docs/exPuzzlers/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/docs/exPuzzlers/.idea/encodings.xml b/docs/exPuzzlers/.idea/encodings.xml deleted file mode 100644 index e206d70d859..00000000000 --- a/docs/exPuzzlers/.idea/encodings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/docs/exPuzzlers/.idea/modules.xml b/docs/exPuzzlers/.idea/modules.xml deleted file mode 100644 index f1b24b71fe3..00000000000 --- a/docs/exPuzzlers/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/docs/exPuzzlers/.idea/scopes/scope_settings.xml b/docs/exPuzzlers/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b8433..00000000000 --- a/docs/exPuzzlers/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/docs/exPuzzlers/.idea/uiDesigner.xml b/docs/exPuzzlers/.idea/uiDesigner.xml deleted file mode 100644 index 3b000203088..00000000000 --- a/docs/exPuzzlers/.idea/uiDesigner.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/exPuzzlers/.idea/vcs.xml b/docs/exPuzzlers/.idea/vcs.xml deleted file mode 100644 index def6a6a1845..00000000000 --- a/docs/exPuzzlers/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/docs/exPuzzlers/exPuzzlers.iml b/docs/exPuzzlers/exPuzzlers.iml deleted file mode 100644 index 2c1255b7f1e..00000000000 --- a/docs/exPuzzlers/exPuzzlers.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/docs/exPuzzlers/kotlin/std.kt b/docs/exPuzzlers/kotlin/std.kt deleted file mode 100644 index 31cd9bf4f8f..00000000000 --- a/docs/exPuzzlers/kotlin/std.kt +++ /dev/null @@ -1,36 +0,0 @@ -namespace std - -inline fun array(vararg array : T) = array -inline fun array(vararg array : Byte) = array -inline fun array(vararg array : Char) = array -inline fun array(vararg array : Short) = array -inline fun array(vararg array : Int) = array -inline fun array(vararg array : Long) = array -inline fun array(vararg array : Double) = array -inline fun array(vararg array : Float) = array - -//fun Any?.identityEquals(other : Any?) = this === other - -inline fun T?.sure() : T { - if (this == null) - throw NullPointerException() - return this; -} - -namespace string { - fun String.replaceAllSubstrings(pattern : String, replacement : String) : String { - return (this as java.lang.String).replace(pattern as CharSequence, replacement as CharSequence).sure() - } - - fun String.replaceAllWithRegex(pattern : String, replacement : String) : String { - return (this as java.lang.String).replaceAll(pattern, replacement).sure() - } -} - -namespace jutils { - - fun T.getJavaClass() : Class { - return ((this as Object).getClass()) as Class - } - -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_01_Oddity/Oddity.java b/docs/exPuzzlers/src/_02_expressive/_01_Oddity/Oddity.java deleted file mode 100644 index e18ac4118ca..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_01_Oddity/Oddity.java +++ /dev/null @@ -1,14 +0,0 @@ -package _02_expressive._01_Oddity; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 5). Pearson Education (USA). Kindle Edition. - */ -public class Oddity { - public static boolean isOdd(int i) { - return i % 2 == 1; - } - - public static void main(String[] args) { - System.out.println(isOdd(-1)); - } -} diff --git a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/BigDecimalSolution.kt b/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/BigDecimalSolution.kt deleted file mode 100644 index e01d247c9e4..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/BigDecimalSolution.kt +++ /dev/null @@ -1,19 +0,0 @@ -namespace change - -import java.math.BigDecimal -import kotlin.io.* - -fun main(args : Array) { - // Easy to make BigDecimals user-friendly - println( - "2.00".bd - "1.00" - ) -} - -val String.bd : BigDecimal get() = BigDecimal(this) - -fun BigDecimal.minus(other : BigDecimal) = this.subtract(other) -fun BigDecimal.minus(other : String) = subtract(other.bd) // this can be omitted - - - diff --git a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/Change.java b/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/Change.java deleted file mode 100644 index 882e193fbf9..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/Change.java +++ /dev/null @@ -1,11 +0,0 @@ -package _02_expressive._02_Time_for_a_Change; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 7). Pearson Education (USA). Kindle Edition. - */ -public class Change { - public static void main(String args[ ] ) { - System.out.println(2.00 - 1.10); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/ChangeSolutions.java b/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/ChangeSolutions.java deleted file mode 100644 index be1736a2d9f..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_02_Time_for_a_Change/ChangeSolutions.java +++ /dev/null @@ -1,20 +0,0 @@ -package _02_expressive._02_Time_for_a_Change; - -import java.math.BigDecimal; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 7). Pearson Education (USA). Kindle Edition. - */ -public class ChangeSolutions { - public static void main(String args[ ] ) { - // Poor solution - still uses binary floating-point! - System.out.printf("%.2f%n", 2.00 - 1.10); - - // Calculation in cents - System.out.println((200 - 110) + " cents"); - - // BigDecimal - System.out.println(new BigDecimal("2.00"). subtract(new BigDecimal("1.10"))); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.java b/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.java deleted file mode 100644 index e4de049aba5..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.java +++ /dev/null @@ -1,12 +0,0 @@ -package _02_expressive._03_Long_Division; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 9). Pearson Education (USA). Kindle Edition. - */ -public class LongDivision { - public static void main(String[] args) { - final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; - final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; - System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); - } -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.kt b/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.kt deleted file mode 100644 index bf4812daca9..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivision.kt +++ /dev/null @@ -1,15 +0,0 @@ -namespace long.division - -import kotlin.io.* - -fun main(args : Array) { - // Problematic case does not compile -// val MICROS_PER_DAY_ : Long = 24 * 60 * 60 * 1000 * 1000; -// val MILLIS_PER_DAY_ : Long = 24 * 60 * 60 * 1000 - - // Solution: - val MICROS_PER_DAY : Long = 24.toLong() * 60 * 60 * 1000 * 1000; - val MILLIS_PER_DAY : Long = 24.toLong() * 60 * 60 * 1000 - - println(MICROS_PER_DAY / MILLIS_PER_DAY) -} diff --git a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.java b/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.java deleted file mode 100644 index 24c8083f863..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.java +++ /dev/null @@ -1,12 +0,0 @@ -package _02_expressive._03_Long_Division; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 9). Pearson Education (USA). Kindle Edition. - */ -public class LongDivisionSolution { - public static void main(String[] args) { - final long MICROS_PER_DAY = 24L * 60 * 60 * 1000 * 1000; - final long MILLIS_PER_DAY = 24L * 60 * 60 * 1000; - System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); - } -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.kt b/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.kt deleted file mode 100644 index ebe4a17cc34..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_03_Long_Division/LongDivisionSolution.kt +++ /dev/null @@ -1,10 +0,0 @@ -namespace long.division.solution - -import kotlin.io.* - -fun main(args : Array) { - val MICROS_PER_DAY : Long = 24.toLong() * 60 * 60 * 1000 * 1000; - val MILLIS_PER_DAY : Long = 24.toLong() * 60 * 60 * 1000 - - println(MICROS_PER_DAY / MILLIS_PER_DAY) -} diff --git a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.java b/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.java deleted file mode 100644 index f81edefb51c..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.java +++ /dev/null @@ -1,11 +0,0 @@ -package _02_expressive._04_Elementary; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 11). Pearson Education (USA). Kindle Edition. - */ -public class Elementary { - public static void main(String[] args) { - System.out.println(12345 + 5432l); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.kt b/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.kt deleted file mode 100644 index b382a406e74..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/Elementary.kt +++ /dev/null @@ -1,11 +0,0 @@ -namespace elementary - -import kotlin.io.* - -fun main(args : Array) { - // Problematic case does not compile -// println(12345 + 5432l) - - // Correct syntax: - println(12345 + 5432.toLong()) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/ElementarySolution.java b/docs/exPuzzlers/src/_02_expressive/_04_Elementary/ElementarySolution.java deleted file mode 100644 index e1bc9464414..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_04_Elementary/ElementarySolution.java +++ /dev/null @@ -1,11 +0,0 @@ -package _02_expressive._04_Elementary; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 11). Pearson Education (USA). Kindle Edition. - */ -public class ElementarySolution { - public static void main(String[] args) { - System.out.println(12345 + 5432L); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_05_The_Joy_of_Hex/JoyOfHex.java b/docs/exPuzzlers/src/_02_expressive/_05_The_Joy_of_Hex/JoyOfHex.java deleted file mode 100644 index 93fbb99ee62..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_05_The_Joy_of_Hex/JoyOfHex.java +++ /dev/null @@ -1,11 +0,0 @@ -package _02_expressive._05_The_Joy_of_Hex; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 13). Pearson Education (USA). Kindle Edition. - */ -public class JoyOfHex { - public static void main(String[] args) { - System.out.println(Long.toHexString(0x100000000L + 0xcafebabe)); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Multicast.kt b/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Multicast.kt deleted file mode 100644 index 4ad429ebc6e..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Multicast.kt +++ /dev/null @@ -1,8 +0,0 @@ -namespace multicast - -import kotlin.io.* - -fun main(args : Array) { - println(-1.toByte().toChar().toInt()) - println((-1).toByte().toChar().toInt()) -} diff --git a/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Mutlicast.java b/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Mutlicast.java deleted file mode 100644 index 0813e988800..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_06_Multicast/Mutlicast.java +++ /dev/null @@ -1,8 +0,0 @@ -package _02_expressive._06_Multicast; - -public class Mutlicast { - public static void main(String[] args) { - System.out.println((int) (char) (byte) -1); - } -} - diff --git a/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.java b/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.java deleted file mode 100644 index 874747f3a3a..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.java +++ /dev/null @@ -1,16 +0,0 @@ -package _02_expressive._07_Swap_Meat; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 17). Pearson Education (USA). Kindle Edition. - */ -public class CleverSwap { - public static void main(String[] args) { - int x = 1984; // (0x7c0) - int y = 2001; // (0x7d1) - x ^= y ^= x ^= y; - System.out.println("x = " + x + "; y = " + y); - - // Solution: swap with a temp variable - // Do not assign to the same variable more than once in a single expression. - } -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.kt b/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.kt deleted file mode 100644 index 4d0062ffeee..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_07_Swap_Meat/CleverSwap.kt +++ /dev/null @@ -1,10 +0,0 @@ -namespace cleverswap - -import kotlin.io.* - -fun main(args : Array) { - var x = 1 - // Do not assign to the same variable more than once in a single expression. - // Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 19). Pearson Education (USA). Kindle Edition. -// x += (y += z) -} diff --git a/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.java b/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.java deleted file mode 100644 index 29658b3e2d1..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.java +++ /dev/null @@ -1,10 +0,0 @@ -package _02_expressive._08_Dos_Equis; - -public class DosEquis { - public static void main(String[] args) { - char x = 'X'; - int i = 0; - System.out.print(true ? x : 0); - System.out.print(false ? i : x); - } -} diff --git a/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.kt b/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.kt deleted file mode 100644 index 8dbef36d673..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_08_Dos_Equis/DosEquis.kt +++ /dev/null @@ -1,15 +0,0 @@ -namespace dos.equis - -import kotlin.io.* - -fun main(args : Array) { - // Problematic case does not compile - val x = 'X' - val i = 0 - print(if (true) x else 0) - print(if (false) 0 else x) - - // Mixed computations do not compile: -// val int : Int = if (true) x else 0 -// val char : Char = if (false) 0 else x -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_02_expressive/_09_Tweedledum/Tweedledum.java b/docs/exPuzzlers/src/_02_expressive/_09_Tweedledum/Tweedledum.java deleted file mode 100644 index 25485a6c2af..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_09_Tweedledum/Tweedledum.java +++ /dev/null @@ -1,10 +0,0 @@ -package _02_expressive._09_Tweedledum; - -public class Tweedledum { - public static void main(String[] args) { - byte x = 1; - byte i = 1; - x += i; -// x = x + i; - } -} diff --git a/docs/exPuzzlers/src/_02_expressive/_10_Tweedledee/Tweedledee.java b/docs/exPuzzlers/src/_02_expressive/_10_Tweedledee/Tweedledee.java deleted file mode 100644 index d7d3d9cd487..00000000000 --- a/docs/exPuzzlers/src/_02_expressive/_10_Tweedledee/Tweedledee.java +++ /dev/null @@ -1,10 +0,0 @@ -package _02_expressive._10_Tweedledee; - -public class Tweedledee { - public static void main(String[] args) { - Object x = 1; - String i = "1"; -// x += i; - x = x + i; - } -} diff --git a/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.java b/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.java deleted file mode 100644 index da25b2ad75b..00000000000 --- a/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.java +++ /dev/null @@ -1,12 +0,0 @@ -package _03_character._11_The_Last_Laugh; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 25). Pearson Education (USA). Kindle Edition. - */ -public class LastLaugh { - public static void main(String args[]) { - System.out.print("H" + "a"); - System.out.print('H' + 'a'); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.kt b/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.kt deleted file mode 100644 index 8a25fb84bca..00000000000 --- a/docs/exPuzzlers/src/_03_character/_11_The_Last_Laugh/LastLaugh.kt +++ /dev/null @@ -1,12 +0,0 @@ -namespace last.laugh - -import kotlin.io.* - -fun main(args : Array) { - print("H" + "a") - // Problematic case does not compile -// System.out?.print('H' + 'a') - - // Solution - print('H'.toString() + 'a') -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_03_character/_12_ABC/Abc.java b/docs/exPuzzlers/src/_03_character/_12_ABC/Abc.java deleted file mode 100644 index 5eef04a52f9..00000000000 --- a/docs/exPuzzlers/src/_03_character/_12_ABC/Abc.java +++ /dev/null @@ -1,19 +0,0 @@ -package _03_character._12_ABC; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 27). Pearson Education (USA). Kindle Edition. - */ -public class Abc { - public static void main(String[] args) { - String letters = "ABC"; - char[] numbers = {'1', '2', '3'}; - System.out.println(letters + " easy as " + numbers); - - // Solution: - System.out.println(letters + " easy as "); - System.out.println(numbers); - // or - System.out.println(letters + " easy as " + String.valueOf(numbers)); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.java b/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.java deleted file mode 100644 index d7c19aeecf5..00000000000 --- a/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.java +++ /dev/null @@ -1,18 +0,0 @@ -package _03_character._13_Animal_Farm; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 29). Pearson Education (USA). Kindle Edition. - */ -public class AnimalFarm { - public static void main(String[] args) { - final String pig = "length: 10"; - final String dog = "length: " + pig.length(); - System.out.println("Animals are equal: " + pig == dog); - - // Solution: - System.out.println("Animals are equal: " + pig.equals(dog)); - // or - System.out.println("Animals are equal: " + (pig.intern() == dog.intern())); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.kt b/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.kt deleted file mode 100644 index 8551bbcb5d7..00000000000 --- a/docs/exPuzzlers/src/_03_character/_13_Animal_Farm/AnimalFarm.kt +++ /dev/null @@ -1,16 +0,0 @@ -namespace animal.farm - -import kotlin.io.* -import kotlin.* - -fun main(args : Array) { - val pig = "length: 10"; - val dog = "length: " + pig.length; - println("Animals are equal: " + pig == dog); - - // Solution: - println("Animals are equal: " + (pig == dog)); - - // Note: - println("Animals are equal: " + (pig identityEquals dog)) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.java b/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.java deleted file mode 100644 index 76f8beca484..00000000000 --- a/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.java +++ /dev/null @@ -1,12 +0,0 @@ -package _03_character._14_Escape_Rout; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 31). Pearson Education (USA). Kindle Edition. - */ -public class EscapeRout { - public static void main(String[ ] args) { - // \u0022 is the Unicode escape for double quote (") - System.out.println("a\u0022.length( ) + \u0022b".length( )); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.kt b/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.kt deleted file mode 100644 index 545eecd5efd..00000000000 --- a/docs/exPuzzlers/src/_03_character/_14_Escape_Rout/EscapeRout.kt +++ /dev/null @@ -1,12 +0,0 @@ -namespace escape.rout - -import kotlin.io.* -import kotlin.* - -fun main(args : Array) { - // \u0022 is the Unicode escape for double quote (") - println("a\u0022.length( ) + \u0022b".length) - - // The actual string: - println("a\u0022.length( ) + \u0022b") -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.java b/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.java deleted file mode 100644 index 354241f8f26..00000000000 --- a/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.java +++ /dev/null @@ -1,16 +0,0 @@ -package _03_character._15_Hello_Whirled; - -// Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 33). Pearson Education (USA). Kindle Edition. - -/** - * Generated by the IBM IDL-to-Java compiler, version 1.0 - * from F:\TestRoot\apps\a1\ units\include\PolicyHome.idl <-- DELETE THE SPACE BEFORE 'u' - * Wednesday, June 17, 1998 6:44:40 o'clock AM GMT+00:00 - */ -public class Test { - public static void main(String[] args) { - System.out.print("Hell"); - System.out.println("o world"); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.kt b/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.kt deleted file mode 100644 index dd34e012730..00000000000 --- a/docs/exPuzzlers/src/_03_character/_15_Hello_Whirled/Test.kt +++ /dev/null @@ -1,14 +0,0 @@ -namespace hello.whirled - -import kotlin.io.* -import kotlin.* - -/** - * Generated by the IBM IDL-to-Java compiler, version 1.0 - * from F:\TestRoot\apps\a1\units\include\PolicyHome.idl - * Wednesday, June 17, 1998 6:44:40 o'clock AM GMT+00:00 - */ -fun main(args : Array) { - print("Hell"); - println("o world"); -} diff --git a/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.java b/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.java deleted file mode 100644 index bb38614c606..00000000000 --- a/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.java +++ /dev/null @@ -1,13 +0,0 @@ -package _03_character._16_Line_Printer; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 35). Pearson Education (USA). Kindle Edition. - */ -public class LinePrinter { - public static void main(String[] args) { - // Note: \ u000A is Unicode representation of linefeed (LF) <-- DELETE THE SPACE BEFORE 'u' - char c = 0x000A; - System.out.println(c); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.kt b/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.kt deleted file mode 100644 index 73df2a17ef8..00000000000 --- a/docs/exPuzzlers/src/_03_character/_16_Line_Printer/LinePrinter.kt +++ /dev/null @@ -1,10 +0,0 @@ -namespace line.printer - -import kotlin.io.* -import kotlin.* - -fun main(args : Array) { - // Note: \u000A is Unicode representation of linefeed (LF) - val c : Char = 0x000A .toChar(); - println(c); -} diff --git a/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.java b/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.java deleted file mode 100644 index 898bf2a4f3e..00000000000 --- a/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.java +++ /dev/null @@ -1,18 +0,0 @@ -package _03_character._17_Huh; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 37). Pearson Education (USA). Kindle Edition. - */ - -\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020 -\u0063\u006c\u0061\u0073\u0073\u0020\u0055\u0067\u006c\u0079 -\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020 -\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063 -\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028 -\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0020 -\u0020\u0020\u0020\u0020\u0061\u0072\u0067\u0073\u0029\u007b -\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074 -\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0020 -\u0022\u0048\u0065\u006c\u006c\u006f\u0020\u0077\u0022\u002b -\u0022\u006f\u0072\u006c\u0064\u0022\u0029\u003b\u007d\u007d - diff --git a/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.kt b/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.kt deleted file mode 100644 index a34d4848870..00000000000 --- a/docs/exPuzzlers/src/_03_character/_17_Huh/Ugly.kt +++ /dev/null @@ -1 +0,0 @@ -// You must be kidding \ No newline at end of file diff --git a/docs/exPuzzlers/src/_03_character/_18_String_Cheese/StringCheese.java b/docs/exPuzzlers/src/_03_character/_18_String_Cheese/StringCheese.java deleted file mode 100644 index f08c802b17c..00000000000 --- a/docs/exPuzzlers/src/_03_character/_18_String_Cheese/StringCheese.java +++ /dev/null @@ -1,16 +0,0 @@ -package _03_character._18_String_Cheese; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 39). Pearson Education (USA). Kindle Edition. - */ -public class StringCheese { - public static void main(String[] args) { - byte[] bytes = new byte[256]; - for (int i = 0; i < 256; i++) - bytes[i] = (byte) i; - String str = new String(bytes); - for (int i = 0, n = str.length(); i < n; i++) - System.out.print((int) str.charAt(i) + " "); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.java b/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.java deleted file mode 100644 index 80713a9d344..00000000000 --- a/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.java +++ /dev/null @@ -1,11 +0,0 @@ -package _03_character._20_Whats_My_Class; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 43). Pearson Education (USA). Kindle Edition. - */ -public class Me { - public static void main(String[] args) { - System.out.println(Me.class.getName().replaceAll(".", "/") + ".class"); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.kt b/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.kt deleted file mode 100644 index bd2f9849e31..00000000000 --- a/docs/exPuzzlers/src/_03_character/_20_Whats_My_Class/Me.kt +++ /dev/null @@ -1,18 +0,0 @@ -namespace whats.my.`class` - -import kotlin.io.* -import kotlin.string.* -import kotlin.jutils.* - -class Me() { - fun main() { - println(getJavaClass().getCanonicalName()?.replaceAllSubstrings(".", "/")) - - // Regex is denoted explicitly - println(getJavaClass().getCanonicalName()?.replaceAllWithRegex(".", "/")) - } -} - -fun main(args : Array) { - Me().main() -} diff --git a/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.java b/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.java deleted file mode 100644 index 6eb4ebe265b..00000000000 --- a/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.java +++ /dev/null @@ -1,13 +0,0 @@ -package _03_character._21_Whats_My_Class_Take_2; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 45). Pearson Education (USA). Kindle Edition. - */ - -public class MeToo { - public static void main(String[] args) { - System.out.println(MeToo.class.getName(). - replaceAll("\\.", /*File.separator*/"\\") + ".class"); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.kt b/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.kt deleted file mode 100644 index ae8458df5c9..00000000000 --- a/docs/exPuzzlers/src/_03_character/_21_Whats_My_Class_Take_2/MeToo.kt +++ /dev/null @@ -1,19 +0,0 @@ -namespace whats.my.`class`.take2 - -import kotlin.io.* -import kotlin.string.* -import kotlin.jutils.* -import java.io.File; - -class MeToo() { - fun main() { - println(getJavaClass().getCanonicalName()?.replaceAllSubstrings(".", /*File.separator.sure()*/"\\")) - - // Regex is denoted explicitly - println(getJavaClass().getCanonicalName()?.replaceAllWithRegex(".", "\\")) - } -} - -fun main(args : Array) { - MeToo().main() -} diff --git a/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.java b/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.java deleted file mode 100644 index 8cec49d3bdd..00000000000 --- a/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.java +++ /dev/null @@ -1,28 +0,0 @@ -package _03_character._23_No_Pain_No_Gain; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 49). Pearson Education (USA). Kindle Edition. - */ - -import java.util.Random; - -public class Rhymes { - private static Random rnd = new Random(); - - public static void main(String[] args) { - StringBuffer word = null; - switch (rnd.nextInt(2)) { - case 1: - word = new StringBuffer('P'); - case 2: - word = new StringBuffer('G'); - default: - word = new StringBuffer('M'); - } - word.append('a'); - word.append('i'); - word.append('n'); - System.out.println(word); - } -} - diff --git a/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.kt b/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.kt deleted file mode 100644 index b1ba2813157..00000000000 --- a/docs/exPuzzlers/src/_03_character/_23_No_Pain_No_Gain/Rhymes.kt +++ /dev/null @@ -1,33 +0,0 @@ -namespace no.pain.no.gain - -import kotlin.io.* - -val rnd = java.util.Random(); - -fun main(args : Array) { - // The erroneous code does not compile: -// var word : StringBuffer? = null -// when (rnd.nextInt(2)) { -// 1 => word = StringBuffer('P') -// 2 => word = StringBuffer('G') -// else => word = StringBuffer('M') -// } -// word?.append('a') -// word?.append('i') -// word?.append('n') -// println(word) - -// A natural implementation can't possibly have two problems out of three: -// * fall-through cases -// * StringBuffer(int) called with 'P' - val word = - when (rnd.nextInt(2)) { - 1 => StringBuffer().append('P') - 2 => StringBuffer().append('G') - else => StringBuffer().append('M') - } - word?.append('a') - word?.append('i') - word?.append('n') - println(word) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.java b/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.java deleted file mode 100644 index ee0d13a3695..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.java +++ /dev/null @@ -1,14 +0,0 @@ -package _04_loopy._24_Big_Delight_in_Every_Byte; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 53). Pearson Education (USA). Kindle Edition. - */ -public class BigDelight { - public static void main(String[] args) { - for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) { - if (b == 0x90) - System.out.print("Joy!"); - } - } -} - diff --git a/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.kt b/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.kt deleted file mode 100644 index 0eb9d09f97d..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_24_Big_Delight_in_Every_Byte/BigDelight.kt +++ /dev/null @@ -1,43 +0,0 @@ -namespace big.delight.in.every.byte - -import kotlin.io.* - -fun main(args : Array) { -// for (b : Byte in Byte.MIN_VALUE..Byte.MAX_VALUE) { -// // Problematic code does not compile -// if (b == 0x90 .toByte()) -// println("joy") -// } - for (b : Byte in Byte.MIN_VALUE to Byte.MAX_VALUE) { - // Problematic code does not compile - if (b == 0x90 .toByte()) - println("joy") - } -} - -trait IntCompatible { - fun valueOf(i : Int) : T - fun next(current : T) : T - fun compareToInt(t : T, int : Int) : Int -} - -class NumberRange>(val from : Int, val to : Int) : Range, Iterable - where class object T : IntCompatible { - - override fun contains(item: Int) : Boolean = from <= item && item <= to - fun contains(item: T) : Boolean = T.compareToInt(item, from) >= 0 && T.compareToInt(item, to) <= 0 - - override fun iterator(): Iterator = object : Iterator { - private var current : T = T.valueOf(from) - override fun next() : T { - if (!hasNext) throw java.util.NoSuchElementException() - val result = current - current = T.next(current) - return result - } - override val hasNext : Boolean - get() = T.compareToInt(current, to) < 0 - } -} - -fun Byte.to(to : Byte) = NumberRange(this.toInt(), to.toInt()) \ No newline at end of file diff --git a/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.java b/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.java deleted file mode 100644 index d73facdf338..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.java +++ /dev/null @@ -1,23 +0,0 @@ -package _04_loopy._25_In_the_Loop; - -/** - * Bloch, Joshua; Gafter, Neal (2005-06-24). Java™ Puzzlers: Traps, Pitfalls, and Corner Cases (p. 57). Pearson Education (USA). Kindle Edition. - */ -public class InTheLoop { - public static final int END = Integer.MAX_VALUE; - public static final int START = END - 100; - - public static void main(String[] args) { -// int count = 0; -// for (int i = START; i <= END; i++) -// count++; -// System.out.println(count); - final int end = Integer.MAX_VALUE; - int start = end - 100; - int count = 0; - for (int i = start; i <= end; i++) - count++; - System.out.println("count = " + count); - } -} - diff --git a/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.kt b/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.kt deleted file mode 100644 index 4ccded72063..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_25_In_the_Loop/InTheLoop.kt +++ /dev/null @@ -1,14 +0,0 @@ -namespace `in`.the.loop - -import kotlin.io.* - -val END = Integer.MAX_VALUE -val START = END - 100 - -fun main(args : Array) { - var count = 0 - // For-loop over integrals always terminates - for (i in START..END) - count++ - println(count) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.java b/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.java deleted file mode 100644 index 18b40c315b3..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.java +++ /dev/null @@ -1,10 +0,0 @@ -package _04_loopy._31_Ghost_of_Looper; - -public class GhostOfLooper { - public static void main(String[] args) { - short i = -1; - - while (i != 0) - i >>>= 1; - } -} diff --git a/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.kt b/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.kt deleted file mode 100644 index 1d4d229ae90..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_31_Ghost_of_Looper/GhostOfLooper.kt +++ /dev/null @@ -1,10 +0,0 @@ -namespace ghost.of.looper - -import kotlin.io.* - -fun main(args : Array) { - var i : Short = -1.toShort() - while (i != 1.toShort()) - // Lots of magic made explicit: - i = (i.toInt() ushr 1).toShort() -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.java b/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.java deleted file mode 100644 index 60761a9f775..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.java +++ /dev/null @@ -1,11 +0,0 @@ -package _04_loopy._32_Curse_of_Looper; - -public class CurseOfLooper { - public static void main(String[] args) { - // Place your declarations for i and j here - Integer i = 128; - Integer j = 128; - while (i <= j && j <= i && i != j) { - } - } -} diff --git a/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.kt b/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.kt deleted file mode 100644 index 2083c9f2f05..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/CurseOfLooper.kt +++ /dev/null @@ -1,19 +0,0 @@ -namespace curse.of.loooper // BUG!!! - -import kotlin.io.* - -class Curse>() { - fun curse(i : T, j : T) { - while (i <= j && j <= i && i != j) { - } - } -} - -fun main(args : Array) { -// BUG: -// val i : Integer = (128 : Int?) as Integer -// val j : Integer = (128 : Int?) as Integer -// while (i <= j && j <= i && i != j) { -// } - Curse.curse(128, 128) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/bug b/docs/exPuzzlers/src/_04_loopy/_32_Curse_of_Looper/bug deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.java b/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.java deleted file mode 100644 index fb3b30f8536..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.java +++ /dev/null @@ -1,11 +0,0 @@ -package _04_loopy._34_Down_for_the_Count; - -public class Count { - public static void main(String[] args) { - final int START = 2000000000; - int count = 0; - for (float f = START; f < START + 50; f++) - count++; - System.out.println(count); - } -} diff --git a/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.kt b/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.kt deleted file mode 100644 index 4273e092946..00000000000 --- a/docs/exPuzzlers/src/_04_loopy/_34_Down_for_the_Count/Count.kt +++ /dev/null @@ -1,11 +0,0 @@ -namespace down.`for`.the.count - -import kotlin.io.* - -fun main(args : Array) { -// Problematic code does not compile -// val START : Int = 2000000000 -// for (f : Float in START..(START + 50)) { -// -// } -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.java b/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.java deleted file mode 100644 index 6416be6146a..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.java +++ /dev/null @@ -1,15 +0,0 @@ -package _05_exceptional._36_Indecision; - -public class Indecisive { - public static void main(String[] args) { - System.out.println(decision()); - } - - static boolean decision() { - try { - return true; - } finally { - return false; - } - } -} diff --git a/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.kt b/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.kt deleted file mode 100644 index 8424586244a..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_36_Indecision/Indecisive.kt +++ /dev/null @@ -1,16 +0,0 @@ -namespace indecision - -import kotlin.io.* - -fun main(args : Array) { - println(decision()) -} - -fun decision() : Boolean { - try { -// Problematic code is illegal, as Java Puzzlers recommend: -// return true; - } finally { - return false; - } -} diff --git a/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/BUG b/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/BUG deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.java b/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.java deleted file mode 100644 index acc01cd88fe..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.java +++ /dev/null @@ -1,27 +0,0 @@ -package _05_exceptional._38_Unwelcome_Guest; - -public class UnwelcomeGuest { - public static final long GUEST_USER_ID = -1; - -// private static final long USER_ID; -// static { -// try { -// USER_ID = getUserIdFromEnvironment(); -// } catch (IdUnavailableException e) { -// USER_ID = GUEST_USER_ID; -// System.out.println("Logging in as guest"); -// } -// } - - private static long getUserIdFromEnvironment() - throws IdUnavailableException { - throw new IdUnavailableException(); // Simulate an error - } - - public static void main(String[] args) { -// System.out.println("User ID: " + USER_ID); - } -} - -class IdUnavailableException extends Exception { -} diff --git a/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.kt b/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.kt deleted file mode 100644 index 700ba1e1220..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_38_Unwelcome_Guest/UnwelcomeGuest.kt +++ /dev/null @@ -1,22 +0,0 @@ -namespace unwelcome.guest - -import kotlin.io.* - -val GUEST_USER_ID = -1 -val USER_ID = - try { - getUserIdFromEnvironment() - } - catch (e : UnsupportedOperationException) { -// catch (e : IdUnavailableException) { BUG - GUEST_USER_ID - } - -fun getUserIdFromEnvironment() = throw UnsupportedOperationException() -//fun getUserIdFromEnvironment() = throw IdUnavailableException() - -//class IdUnavailableException() : Ex() {} - -fun main(args : Array) { - println("User ID: " + USER_ID) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.java b/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.java deleted file mode 100644 index 5433d35b5a3..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.java +++ /dev/null @@ -1,18 +0,0 @@ -package _05_exceptional._39_The_Reluctant_Constructor; - -public class Reluctant { - private Reluctant internalInstance = new Reluctant(); - - public Reluctant() throws Exception { - throw new Exception("I'm not coming out"); - } - - public static void main(String[] args) { - try { - Reluctant b = new Reluctant(); - System.out.println("Surprise!"); - } catch (Exception ex) { - System.out.println("I told you so"); - } - } -} diff --git a/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.kt b/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.kt deleted file mode 100644 index b72123c19ca..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_39_The_Reluctant_Constructor/Reluctant.kt +++ /dev/null @@ -1,20 +0,0 @@ -namespace the.reluctant.constructor - -import kotlin.io.* - -public class Reluctant() { - val internalInstance = Reluctant() // Recursion is obvious - { - throw Exception("I'm not coming out") - } -} - -fun main(args : Array) { - try { - val b = Reluctant() - println("Surprise!") - } - catch (ex : Exception) { - println("I told you so") - } -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/BUG b/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/BUG deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.java b/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.java deleted file mode 100644 index dc43d661ba9..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.java +++ /dev/null @@ -1,24 +0,0 @@ -package _05_exceptional._42_Thrown_for_a_Loop; - -public class Loop { - public static void main(String[] args) { - int[][] tests = { { 6, 5, 4, 3, 2, 1 }, { 1, 2 }, - { 1, 2, 3 }, { 1, 2, 3, 4 }, { 1 } }; - int n = 0; - - try { - int i = 0; - while (true) { - if (thirdElementIsThree(tests[i++])) - n++; - } - } catch(ArrayIndexOutOfBoundsException e) { - // No more tests to process - } - System.out.println(n); - } - - private static boolean thirdElementIsThree(int[] a) { - return a.length >= 3 & a[2] == 3; - } -} diff --git a/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.kt b/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.kt deleted file mode 100644 index cd3234cbf65..00000000000 --- a/docs/exPuzzlers/src/_05_exceptional/_42_Thrown_for_a_Loop/Loop.kt +++ /dev/null @@ -1,32 +0,0 @@ -namespace thrown.`for`.a.looop // BUG - -import kotlin.io.* -import kotlin.* - -fun iarr(vararg a : Int) = a // due to a BUG - -fun main(args : Array) { - val tests = array( - iarr(6, 5, 4, 3, 2, 1), iarr(1, 2), - iarr(1, 2, 3), iarr(1, 2, 3, 4), iarr(1) - ) - - var n = 0 - - try { - var i = 0 - while (true) { - if (thirdElementIsThree(tests[i++])) - n++ - } - } - catch (e : ArrayIndexOutOfBoundsException) { - // No more tests to process - } - println(n) -} - -fun thirdElementIsThree(a : IntArray) = -// Problematic code does not compile -// a.size >= 3 & a[2] == 3 - a.size >= 3 && a[2] == 3 \ No newline at end of file diff --git a/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.java b/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.java deleted file mode 100644 index 8245e55d4b7..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.java +++ /dev/null @@ -1,34 +0,0 @@ -package _06_classy._47_Well_Dog_My_Cats; - -class Counter { - private static int count = 0; - public static final synchronized void increment() { - count++; - } - public static final synchronized int getCount() { - return count; - } -} - -class Dog extends Counter { - public Dog() { } - public void woof() { increment(); } -} - -class Cat extends Counter { - public Cat() { } - public void meow() { increment(); } -} - -public class Ruckus { - public static void main(String[] args) { - Dog dogs[] = { new Dog(), new Dog() }; - for (int i = 0; i < dogs.length; i++) - dogs[i].woof(); - Cat cats[] = { new Cat(), new Cat(), new Cat() }; - for (int i = 0; i < cats.length; i++) - cats[i].meow(); - System.out.print(Dog.getCount() + " woofs and "); - System.out.println(Cat.getCount() + " meows"); - } -} diff --git a/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.kt b/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.kt deleted file mode 100644 index 5a9f6b8678c..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_47_Well_Dog_My_Cats/Ruckus.kt +++ /dev/null @@ -1,38 +0,0 @@ -namespace well.dog.my.cats - -import kotlin.io.* -import kotlin.* - -open class Counter { - class object { - private var count = 0 - fun increment() { count++ } - fun getCount() = count - } -} - -class Dog() : Counter { -// Class objects are not inherited: -// fun woof() { increment() } - fun woof() { Counter.increment() } -} - -class Cat() : Counter { -// Class objects are not inherited: -// fun meow() { increment() } - fun meow() { Counter.increment() } -} - -fun main(args : Array) { - val dogs = array(Dog(), Dog()) - for (dog in dogs) - dog.woof() - val cats = array(Cat(), Cat()) - for (cat in cats) - cat.meow() -// Problematic code does not compile: -// println("${Dog.getCount()} woofs") - println("${Counter.getCount()} woofs") -// println("${Cat.getCount()} meows") - println("${Counter.getCount()} meows") -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.java b/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.java deleted file mode 100644 index 9bd44a53a9a..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.java +++ /dev/null @@ -1,20 +0,0 @@ -package _06_classy._48_All_I_Get_Is_Static; - -class Dog { - public static void bark() { - System.out.print("woof "); - } -} - -class Basenji extends Dog { - public static void bark() { } -} - -public class Bark { - public static void main(String args[]) { - Dog woofer = new Dog(); - Dog nipper = new Basenji(); - woofer.bark(); - nipper.bark(); - } -} diff --git a/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.kt b/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.kt deleted file mode 100644 index 78effebff8c..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_48_All_I_Get_Is_Static/Bark.kt +++ /dev/null @@ -1,28 +0,0 @@ -namespace all.i.get.`is`.static - -import kotlin.io.* -import kotlin.* - -open class Dog() { - class object { - fun bark() { - print("woof") - } - } -} - -class Basenji() : Dog() { - class object { - fun bark() { } - } -} - -fun main(args : Array) { - val woofer : Dog = Dog() - val nipper : Dog = Basenji() -// Problematic code does not compile: -// woofer.bark() -// nipper.bark() - Dog.bark() - Basenji.bark() -} diff --git a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.java b/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.java deleted file mode 100644 index 89a6cf15dab..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.java +++ /dev/null @@ -1,24 +0,0 @@ -package _06_classy._53_Do_Your_Thing; - -public class MyThing extends Thing { - private final int arg; - - /* - * This constructor is illegal. Rewrite it so that it has the same - * effect but is legal. - */ - public MyThing() { - this((int)System.currentTimeMillis()); - } - - /* - * This constructor is illegal. Rewrite it so that it has the same - * effect but is legal. - */ - public MyThing(int arg) { - super(arg); - this.arg = arg; - } - - -} diff --git a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.kt b/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.kt deleted file mode 100644 index cf63e66e746..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/MyThing.kt +++ /dev/null @@ -1,14 +0,0 @@ -namespace `do`.your.thing - -import kotlin.io.* -import kotlin.* -import _06_classy._53_Do_Your_Thing.Thing - -class MyThing(val arg : Int) : Thing(arg) { - -} - - -fun main(args : Array) { - println(MyThing(10).arg) -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/Thing.java b/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/Thing.java deleted file mode 100644 index 85111834f2e..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_53_Do_Your_Thing/Thing.java +++ /dev/null @@ -1,7 +0,0 @@ -package _06_classy._53_Do_Your_Thing; - -// This is meant to represent a library class. You must not modify it. -public class Thing { - public Thing(int i) { - } -} diff --git a/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.java b/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.java deleted file mode 100644 index 409aa3392c6..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.java +++ /dev/null @@ -1,11 +0,0 @@ -package _06_classy._54_Null_and_Void; - -public class Null { - public static void greet() { - System.out.println("Hello world!"); - } - - public static void main(String[] args) { - ((Null) null).greet(); - } -} diff --git a/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.kt b/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.kt deleted file mode 100644 index e23e6f3db13..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_54_Null_and_Void/Null.kt +++ /dev/null @@ -1,19 +0,0 @@ -namespace `null`.and.void - -import kotlin.io.* -import kotlin.* - -class Null() { - class object { - fun greet() { - println("Hello world!") - } - } -} - - -fun main(args : Array) { -// The problemati code does not compile: -// (null as Null).greet() - Null.greet() -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_06_classy/_55_Creationism/BUG b/docs/exPuzzlers/src/_06_classy/_55_Creationism/BUG deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.java b/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.java deleted file mode 100644 index 1c6d57869bd..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.java +++ /dev/null @@ -1,21 +0,0 @@ -package _06_classy._55_Creationism; - -public class Creator { - public static void main(String[] args) { -// for (int i = 0; i < 100; i++) -// Creature creature = new Creature(); - System.out.println(Creature.numCreated()); - } -} - -class Creature { - private static long numCreated = 0; - - public Creature() { - numCreated++; - } - - public static long numCreated() { - return numCreated; - } -} diff --git a/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.kt b/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.kt deleted file mode 100644 index 2dd0e94cfb8..00000000000 --- a/docs/exPuzzlers/src/_06_classy/_55_Creationism/Creator.kt +++ /dev/null @@ -1,21 +0,0 @@ -namespace creationism - -import kotlin.io.* -import kotlin.* - -class Creature() { - class object { - var numCreated = 0 - private set - } - - { -// Creature.numCreated++ - } -} - - -fun main(args : Array) { -// for (i in 1..100) -// val creature = Creature() -} \ No newline at end of file diff --git a/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BUG b/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BUG deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.java b/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.java deleted file mode 100644 index 4c49110c285..00000000000 --- a/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.java +++ /dev/null @@ -1,18 +0,0 @@ -package _07_library._56_Big_Problem; - -import java.math.BigInteger; - -public class BigProblem { - public static void main(String[] args) { - BigInteger fiveThousand = new BigInteger("5000"); - BigInteger fiftyThousand = new BigInteger("50000"); - BigInteger fiveHundredThousand - = new BigInteger("500000"); - - BigInteger total = BigInteger.ZERO; - total.add(fiveThousand); - total.add(fiftyThousand); - total.add(fiveHundredThousand); - System.out.println(total); - } -} diff --git a/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.kt b/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.kt deleted file mode 100644 index af212ecd2ee..00000000000 --- a/docs/exPuzzlers/src/_07_library/_56_Big_Problem/BigProblem.kt +++ /dev/null @@ -1,26 +0,0 @@ -namespace big.problem - -import kotlin.io.* -import kotlin.* -import java.math.BigInteger - -fun main(args : Array) { - val fiveThousand = "5000".bi() - val fiftyThousand = "50000".bi() - val fiveHundredThousand = "500000".bi() - - val total : BigInteger = "0".bi()//BigInteger.ZERO - total + fiveThousand - total + fiftyThousand - total + fiveHundredThousand - println(total) // No surprise - - var total1 : BigInteger = "0".bi()//BigInteger.ZERO - total1 += fiveThousand - total1 += fiftyThousand - total1 += fiveHundredThousand - println(total1) // Works -} - -inline fun String.bi() : BigInteger = BigInteger(this) -inline fun BigInteger.plus(other : BigInteger) = this add other \ No newline at end of file diff --git a/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/BUG b/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/BUG deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.java b/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.java deleted file mode 100644 index 3f2bc5cdc8f..00000000000 --- a/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.java +++ /dev/null @@ -1,15 +0,0 @@ -package _07_library._59_Whats_the_Difference; - -import java.util.*; - -public class Differences { - public static void main(String[] args) { - int vals[] = { 789, 678, 567, 456, 345, 234, 123, 012 }; - Set diffs = new HashSet(); - - for (int i = 0; i < vals.length; i++) - for (int j = i; j < vals.length; j++) - diffs.add(vals[i] - vals[j]); - System.out.println(diffs.size()); - } -} diff --git a/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.kt b/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.kt deleted file mode 100644 index 25b92c10076..00000000000 --- a/docs/exPuzzlers/src/_07_library/_59_Whats_the_Difference/Differences.kt +++ /dev/null @@ -1,20 +0,0 @@ -namespace whats.the.difference - -import kotlin.io.* -import kotlin.* -import java.util.* - -fun iarray(vararg a : Int) = a // BUG - -fun main(args : Array) { - // Problematic code does not compile -// val vals = iarray(789, 678, 567, 456, 345, 234, 123, 012) - val vals = iarray(789, 678, 567, 456, 345, 234, 123, 12) - val diffs = HashSet - for (i in vals.indices) - for (j in i..vals.lastIndex()) - diffs.add(vals[i] - vals[j]) - println(diffs.size()) -} - -fun IntArray.lastIndex() = size - 1 \ No newline at end of file