I hereby claim:
- I am proxpero on github.
- I am proxpero (https://keybase.io/proxpero) on keybase.
- I have a public key whose fingerprint is ABAF 07DE 0D7E EA58 7C60 1131 CB36 31B5 E8CA 11C7
To claim this, I am signing this object:
public func ack(_ m: Int, _ n: Int) -> Int { | |
if m == 0 { return n + 1 } | |
if n == 0 { return ack(m - 1, 1) } | |
return ack(m - 1, ack(m, n - 1)) | |
} | |
for i in (0...5) { | |
for j in (0...5) { | |
print("ack(\(i), \(j)) is \(ack(i, j))") | |
} |
// Part 1 | |
extension String { | |
var characterCounts: [Character: Int] { | |
return self.reduce(into: [Character: Int]()) { $0[$1, default: 0] += 1 } | |
} | |
} | |
extension Bool { | |
var intValue: Int { |
// prepare the puzzle input | |
let input = loadFile(named: "day1") // convenience function in resources | |
.split(separator: "\n") | |
.compactMap(Int.init) // extension on Int to init? with String.Subsequence | |
// part 1 | |
let part1 = input.reduce(0, +) | |
// part 2 |
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 | |
enum Iso3166_1a2: String { | |
case af = "AF" | |
case ax = "AX" | |
case al = "AL" | |
case dz = "DZ" | |
case `as` = "AS" | |
case ad = "AD" | |
case ao = "AO" |
// taken 2018-03-19 from wikipedia. https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes | |
public enum Iso639_1: String { | |
case ab = "AB" | |
case aa = "AA" | |
case af = "AF" | |
case ak = "AK" | |
case sq = "SQ" | |
case am = "AM" | |
case ar = "AR" |
/// Creates a sequence of tuple-3s built out of three underlying sequences. | |
/// Based on Zip2Seqence from the Swift Standard Library. | |
/// https://github.com/apple/swift/blob/9361a6b66f6f8351e89c090f604d7e1f42e2a045/stdlib/public/core/Zip.swift | |
/// | |
/// - Parameters: | |
/// - sequence1: The first sequence or collection to zip. | |
/// - sequence2: The second sequence or collection to zip. | |
/// - sequence3: The third sequence or collection to zip. | |
/// - Returns: A sequence of tuple triples, where the elements of each triplet are | |
/// corresponding elements of `sequence1`, `sequence2`, and `sequence3`. |
// Accompanying blog post: http://127.0.0.1:4000/2017/07/11/encoding-and-decoding-custom-enums-with-associated-values-in-swift-4 | |
// Also: https://gist.github.com/proxpero/189a723fb96bb88fac5bf9e11d6cf9e2 | |
enum Barcode { | |
case upc(Int, Int, Int, Int) | |
case qrCode(String) | |
} | |
extension Barcode: Codable { | |
private enum CodingKeys: String, CodingKey { |
// See http://proxpero.com/2017/07/11/encoding-and-decoding-custom-enums-with-associated-values-in-swift-4/ | |
enum Barcode { | |
case upc(Int, Int, Int, Int) | |
case qrCode(String) | |
} | |
extension Barcode: Codable { | |
init(from decoder: Decoder) throws { | |
self = try Barcode.Coding.init(from: decoder).barcode() | |
} |
I hereby claim:
To claim this, I am signing this object:
// As described in: http://proxpero.com/2017/02/14/an-implementation-of-md5/ | |
extension Collection where Iterator.Element == UInt8 { | |
/// Returns the md5 hash of self. | |
public var md5: String { | |
return self.md5Digest.lazy.reduce("") { | |
var s = String($1, radix: 16) | |
if s.characters.count == 1 { | |
s = "0" + s |