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
import kotlin.text.Regex | |
fun makeScrambler(order: List<Int>): (String) -> String { | |
fun scrambler(plainText: String): String { | |
val word = plainText.toList() | |
val code = order.indices.map { word[order[it] - 1] } | |
return code.joinToString( | |
prefix = "", | |
separator = "", | |
postfix = "") |
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
import java.awt.Color | |
import java.awt.Graphics | |
import java.awt.Graphics2D | |
import java.awt.geom.AffineTransform | |
import java.awt.geom.Ellipse2D | |
import javax.swing.JFrame | |
import javax.swing.JPanel | |
import kotlin.math.cos | |
import kotlin.math.sin |
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
// This is an effort to solve a problem that | |
// arose in the course of an effort to write | |
// a program that encrypts a message using | |
// the Playfair Cipher. | |
// It divides the plain text into groups of | |
// 2 letters (digrams), ensuring that no | |
// diagram contains 2 identical letters. |
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 com.eonsahead | |
import com.sun.tools.javac.util.Pair | |
import scala.collection.mutable.Map | |
object AlphabetTable extends App { | |
// This program contains some functions that | |
// you might find useful in your effort to | |
// create a program that encrypts messages |
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 com.eonsahead | |
object HelloGoodbye extends App { | |
def greetingMaker (): () => String = { | |
// This is a function that returns a function | |
// to its caller. | |
// This function ("greetingMaker") has one local | |
// variable (named "arriving"). |
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
import java.io.PrintWriter | |
import scala.io.Source | |
object Higher extends App { | |
println("Sputnik!") | |
// Here's an example of a closure. | |
// f is a function that returns a | |
// function to its caller | |
// the function g that it returns |
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
import kotlin.random.Random | |
// Create a list of processes. | |
// Each process has 2 properties: | |
// * it knows how much time has elapsed | |
// between the time that the previous | |
// process entered the waiting line | |
// and the time it took its place | |
// at the end of the line | |
// * it knows the time at which it |
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
data class Process( val x0:Double, val x1:Double ) | |
fun main() { | |
// create random number generator | |
val rng = kotlin.random.Random(System.nanoTime()) | |
val elementInitializer: (Int) -> Process = | |
{_:Int -> Process(rng.nextDouble(), rng.nextDouble())} |
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
import kotlin.math.ln | |
fun main() { | |
// a specified mean for an exponential | |
// distribution of random numbers | |
val specifiedMean = 3.0 | |
// create a random number generator | |
val rng = kotlin.random.Random(System.nanoTime()) |
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("Experiment with lambda functions.") | |
val doublePlusOne: (Int) -> Int = {x:Int-> 2 * x + 1} | |
println( doublePlusOne(3) ) | |
val data = (0..3).map( doublePlusOne ) | |
println( data::class.simpleName ) | |
println( data ) |
NewerOlder