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
// 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 | |
} | |
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
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) |
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
### 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: |
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
### 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: |
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 UIKit | |
import PlaygroundSupport | |
class ExtendableView: UIView { | |
private var isExtended: Bool = false | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
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
extension Int { | |
var asDouble: Double { | |
return Double(self) | |
} | |
} | |
extension Double { | |
var halve: Double { | |
return self / 2 | |
} |
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
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, |
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
use std::collections::HashMap; | |
trait StringToF32 { | |
fn to_f32(self) -> f32; | |
} | |
impl StringToF32 for String { | |
fn to_f32(self) -> f32 { | |
self.parse::<f32>().unwrap() | |
} |
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 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 |
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
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 |
NewerOlder