Skip to content

Instantly share code, notes, and snippets.

@DeepFriedTwinkie
DeepFriedTwinkie / MixedArrayFilter.swift
Created March 19, 2019 20:33
Filter a mixed value array by type
protocol Token {
var isSomething: Bool {get}
}
struct BasicToken : Token {
let isSomething: Bool
}
struct FancyToken : Token {
let isSomething: Bool
@DeepFriedTwinkie
DeepFriedTwinkie / Day7.playground.swift
Last active December 20, 2016 14:31
AdventOfCode.com 2016/Day 7 Solution
import Foundation
//: ## Helpers
func string(fromFile name:String, fileExtension:String) -> String? {
if let filePath = Bundle.main.path(forResource:name, ofType:fileExtension) {
if let inputData = FileManager.default.contents(atPath: filePath) {
return String(data: inputData, encoding: .utf8)
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day6.playground.swift
Created December 18, 2016 18:30
AdventOfCode.com 2016/Day 6 Solution
import Foundation
//: ## Helpers
func string(fromFile name:String, fileExtension:String) -> String? {
if let filePath = Bundle.main.path(forResource:name, ofType:fileExtension) {
if let inputData = FileManager.default.contents(atPath: filePath) {
return String(data: inputData, encoding: .utf8)
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day5_NSViewController.swift
Last active December 18, 2016 16:02
AdventOfCode.com 2016/Day 5 Solution
//
// ViewController.swift
// AdventOfCodeMac
//
// Created by Scott Atkinson on 12/17/16.
// Copyright © 2016 Fathouse Software. All rights reserved.
//
import Cocoa
@DeepFriedTwinkie
DeepFriedTwinkie / Day4.playground.swift
Last active December 17, 2016 15:02
AdventOfCode.com 2016/Day 4 Solution
import Foundation
//: ## Helpers
func string(fromFile name:String, fileExtension:String) -> String? {
if let filePath = Bundle.main.path(forResource:name, ofType:fileExtension) {
if let inputData = FileManager.default.contents(atPath: filePath) {
return String(data: inputData, encoding: .utf8)
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day3.playground.swift
Last active December 15, 2016 18:34
AdventOfCode.com 2016/Day 3, Part 2 Solution
import Foundation
//: ## Helpers
func string(fromFile name:String, fileExtension:String) -> String? {
if let filePath = Bundle.main.path(forResource:name, ofType:fileExtension) {
if let inputData = FileManager.default.contents(atPath: filePath) {
return String(data: inputData, encoding: .utf8)
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day3Part1.playground.swift
Last active December 15, 2016 17:10
AdventOfCode.com 2016/Day 3 Solution (http://adventofcode.com/2016/day/3) (Part 1)
import Foundation
struct Triangle {
let vertices: [Int]
init?(vertices:[Int]) {
guard vertices.count == 3 else { return nil }
guard vertices[0] + vertices[1] > vertices[2],
@DeepFriedTwinkie
DeepFriedTwinkie / Day2Part2.playground.swift
Last active December 14, 2016 22:11
AdventOfCode.com 2016 Day 2 Solution (http://adventofcode.com/2016/day/2) (Part 2)
import Foundation
enum Instruction:String {
case up = "U"
case down = "D"
case left = "L"
case right = "R"
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day2Part1.playground.swift
Last active December 14, 2016 21:37
AdventOfCode.com 2016 Day 2 Solution (http://adventofcode.com/2016/day/2) (Part 1)
import Foundation
enum Instruction:String {
case up = "U"
case down = "D"
case left = "L"
case right = "R"
}
@DeepFriedTwinkie
DeepFriedTwinkie / Day1Part2.playground.swift
Created December 14, 2016 20:31
AdventOfCode.com 2016 Day 1 Solution (http://adventofcode.com/2016/day/1) (Part 2)
import Foundation
enum Axis {
case X
case Y
}
enum Instruction {
case left (distance:Int)