Skip to content

Instantly share code, notes, and snippets.

View leontabak's full-sized avatar
💭
I am currently learning React with Udacity.

Leon Tabak leontabak

💭
I am currently learning React with Udacity.
View GitHub Profile
@leontabak
leontabak / Main.kt
Created October 13, 2021 13:10
Kotlin: What is familiar? What is new?
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 = "")
@leontabak
leontabak / Main.kt
Created October 11, 2021 18:58
Create clusters of points with Kotlin
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
@leontabak
leontabak / Repeats.scala
Created October 8, 2021 14:19
Solve one part of Playfair Cipher problem in Scala.
// 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.
@leontabak
leontabak / AlphabetTable.scala
Created October 6, 2021 20:50
Suggestions that might help with the Playfair Cipher project
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
@leontabak
leontabak / HelloGoodbye.scala
Created October 6, 2021 18:40
Another example of the use of a closure in Scala.
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").
@leontabak
leontabak / Higher.scala
Created October 5, 2021 18:45
examples of currying and a closure
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
@leontabak
leontabak / Main.kt
Created September 30, 2021 13:52
Make list of simulated processes
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
@leontabak
leontabak / Main.kt
Created September 29, 2021 15:12
how to fill a list with objects whose properties have random values
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())}
@leontabak
leontabak / Main.kt
Created September 29, 2021 15:02
fill a list with numbers drawn from an exponential distribution
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())
@leontabak
leontabak / Main.kt
Created September 24, 2021 18:08
introducing lambda in Kotlin
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 )