This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WordScrambler { | |
// 4+ letters, 2+ distinct inners | |
// \p{IsLatin} equals [a-zA-ZÀ-ÿ] | |
// Range [À-ÿ]: accented letters | |
private static final Pattern WORD_REGEX = | |
Pattern.compile("\\p{IsLatin}(\\p{IsLatin})\\1*(?!\\1)\\p{IsLatin}\\p{IsLatin}+"); | |
// Scramble words within text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wscrambler | |
import java.io.File | |
// 4+ Latin letters, 2+ distinct inners | |
private val WORD_REGEX = | |
"""\p{IsLatin}(\p{IsLatin})\1*(?!\1)\p{IsLatin}\p{IsLatin}+""" | |
.toRegex() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val reader: java.io.InputStreamReader = | |
/*new*/ java.io.File(filename).reader() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final var reader = | |
new InputStreamReader( | |
new FileInputStream( | |
new File(filename))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect readers from args/stdin | |
val readers = | |
if (args.isNotEmpty()) | |
args.map { File(it).reader() } | |
else | |
listOf(System.`in`.reader()) | |
// Swallow all readers into one string | |
val content = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect readers from args/stdin | |
final Stream<BufferedReader> readers; | |
if (args.length > 0) { | |
readers = Arrays.stream(args) | |
.map(filename -> { | |
try { | |
return new BufferedReader( | |
new FileReader(filename)); | |
} catch (Exception e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// File: Echo.kt | |
package example | |
fun main(args: Array<String>) { | |
println(args.joinToString(" ")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ kotlin example.EchoKt Testing 1 2 3... | |
Testing 1 2 3... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val words = arrayOf( | |
"out", "of", "mind", | |
"back", "in", "five") | |
println(words[2]) // prints "mind" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() = println("Greetings Earth!") |
OlderNewer