Skip to content

Instantly share code, notes, and snippets.

View luki's full-sized avatar

Lou Süsslin luki

View GitHub Profile
@luki
luki / caesar.swift
Last active April 6, 2019 11:15
Caesar Encryption (Functional/Recursive Solution in Swift)
// For uppercase letters
func encrypt(key: Int) -> ((String) -> String) {
// 25 is the highest number for a possible shift
let actualKey = key % 25
// If the new index is bigger than 90 (which is an X), calculate the remainder and add 64 (which is A)
var actualNewIndex: (Int) -> Int = { i in
if i > 90 { return i % 90 + 64 }
return i
}
@luki
luki / jpg-automaton.hs
Created December 15, 2018 22:25
code snippet from the video
type State = Int
checkInput :: State -> String -> State
checkInput s [] = s
checkInput 0 (x:xs)
| x == 'j' = checkInput 1 xs
| x == 'p' = checkInput 0 xs
| x == 'g' = checkInput 0 xs
| otherwise = checkInput 0 xs
checkInput 1 (x:xs)
### Keybase proof
I hereby claim:
* I am luki on github.
* I am luki (https://keybase.io/luki) on keybase.
* I have a public key whose fingerprint is D922 52AC EF2E 75C0 E2C4 979B 0886 FE80 BDB8 B602
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am luki on github.
* I am luki (https://keybase.io/luki) on keybase.
* I have a public key whose fingerprint is D922 52AC EF2E 75C0 E2C4 979B 0886 FE80 BDB8 B602
To claim this, I am signing this object:
@luki
luki / Contents.swift
Created December 30, 2017 15:53
Playground contents
import UIKit
import PlaygroundSupport
class ExtendableView: UIView {
private var isExtended: Bool = false
override init(frame: CGRect) {
super.init(frame: frame)
}
@luki
luki / binary_search.swift
Created November 11, 2017 15:30
Binary Search Algorithm (Must be sorted!)
extension Int {
var asDouble: Double {
return Double(self)
}
}
extension Double {
var halve: Double {
return self / 2
}
@luki
luki / bidirectional-map.rs
Created November 2, 2017 14:23
A bidirectional map in Rust
use std::collections::HashMap;
use std::hash::Hash;
pub struct BidirectionalMap<K, V> {
right_to_left: HashMap<K, V>,
left_to_right: HashMap<V, K>
}
impl<K,V> BidirectionalMap<K, V>
where K: Hash + Eq + Clone,
use std::collections::HashMap;
trait StringToF32 {
fn to_f32(self) -> f32;
}
impl StringToF32 for String {
fn to_f32(self) -> f32 {
self.parse::<f32>().unwrap()
}
import Foundation
func executeOperation<A: Numeric>(_ op: @escaping (_ a: A, _ b: A) -> A) -> (_ n1: A, _ n2: A) -> A {
return { n1, n2 in
op(n1, n2)
}
}
func subtract(_ n1: Int, _ n2: Int) -> Int {
return n1 - n2
@luki
luki / search.rs
Created August 8, 2017 11:28
Studying search algorithms, implementing them in Rust
fn linear_search<T: Ord>(vec: &Vec<T>, key: &T) -> Option<usize> {
let mut result: Option<usize> = None;
for (i, n) in vec.into_iter().enumerate() {
if n == key {
result = Some(i)
}
};
result