This file contains hidden or 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
let result = 2 + 3 + 4 // 左から | |
var str1: String? | |
var str2: String? | |
let string = str1 ?? str2 ?? "string" // 右から | |
let int1 = 1 | |
let int2 = 2 | |
let int3 = 3 | |
int1 == int2 == int3 // エラー |
This file contains hidden or 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
// 矛盾 | |
func contradiction(p: Bool, q: Bool) -> Bool { | |
return false | |
} | |
// トートロジー | |
func tautology(p: Bool, q: Bool) -> Bool { | |
return true | |
} |
This file contains hidden or 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 | |
// encode single UInt32 number | |
func vbEncodeNumber(n: UInt32) -> [UInt8] { | |
var n = n | |
var result = [UInt8]() | |
while true { | |
let byte = n % 128 | |
result.insert(UInt8(byte), at: 0) | |
if n < 128 { |
This file contains hidden or 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
// standard | |
[1,2,3,4,5,6,7].contains(3) | |
// alternative | |
protocol A { | |
func `is`(in haystack: [Self]) -> Bool | |
func `is`(in haystack: Self...) -> Bool | |
} | |
extension A where Self: Comparable { |
This file contains hidden or 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
const { combineReducers } = Redux; | |
const todoApp = combineReducers({ | |
todos, | |
visibilityFilter | |
}); | |
let nextTodoId = 0; | |
const addTodo = (text) => { | |
return { | |
type: 'ADD_TODO', |
This file contains hidden or 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
# pow(3, 8) = 6561 | |
options = ['', '+', '-'] | |
for i in options: | |
for j in options: | |
for k in options: | |
for l in options: | |
for m in options: | |
for n in options: | |
for o in options: | |
for p in options: |
This file contains hidden or 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 | |
enum Token: Character { | |
case A = "A" | |
case B = "B" | |
case C = "C" | |
case D = "D" | |
case E = "E" | |
case F = "F" | |
case G = "G" |
This file contains hidden or 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 struct Enigma { | |
private var rotorBox: RotorBox | |
private let plugboard: Cipher | |
public typealias Key = (Token, Token, Token) | |
public init(rotor0: @escaping Cipher, rotor1: @escaping Cipher, rotor2: @escaping Cipher, plugboard: @escaping Cipher, key: Key) { | |
self.rotorBox = RotorBox( | |
rotor0: RotorBox.Rotor(rotor0, position: key.0), | |
rotor1: RotorBox.Rotor(rotor1, position: key.1), |
This file contains hidden or 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 typealias Cipher = (Token) -> (Token) |
This file contains hidden or 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 enum Token: Character { | |
case A = "A", B = "B", C = "C", D = "D", E = "E", F = "F" | |
case G = "G", H = "H", I = "I", J = "J", K = "K", L = "L" | |
case M = "M", N = "N", O = "O", P = "P", Q = "Q", R = "R" | |
case S = "S", T = "T", U = "U", V = "V", W = "W", X = "X" | |
case Y = "Y", Z = "Z" | |
} |
OlderNewer