Skip to content

Instantly share code, notes, and snippets.

View BrandonShega's full-sized avatar

Brandon Shega BrandonShega

View GitHub Profile
@BrandonShega
BrandonShega / snakes-and-ladders.swift
Last active July 15, 2020 15:04
Snakes and Ladders
class Solution {
var moves = 0
var rows = 0
var cols = 0
func snakesAndLadders(_ board: [[Int]]) -> Int {
let newBoard = convertTo1D(board)
print(newBoard)
let n = board.count
var queue: [Int] = []
var visited: [Bool] = Array(repeating: false, count: n * n)
@BrandonShega
BrandonShega / errors.txt
Created January 7, 2019 14:13
Error when using Alexa commands
Microsoft Windows [Version 10.0.16299.785]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\jcourtri>c d/
'c' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\jcourtri>cd /
C:\>D:
@BrandonShega
BrandonShega / Playground.swift
Created May 22, 2018 14:55
Passing info to popup controller
//: A UIKit based Playground for presenting user interface
import UIKit
import Foundation
import PlaygroundSupport
struct Recipe {
let name: String
}
@BrandonShega
BrandonShega / AsynchronousOperation.swift
Last active March 19, 2018 20:23 — forked from calebd/AsynchronousOperation.swift
Concurrent NSOperation in Swift
import Foundation
/// An abstract class that makes building simple asynchronous operations easy.
/// Subclasses must implement `execute()` to perform any work and call
/// `finish()` when they are done. All `NSOperation` work will be handled
/// automatically.
open class AsynchronousOperation: Operation {
// MARK: - Properties
040e6d66d623e5acc8096514bcba63fe401d945635372ab4c0fdacf7d5634c014012a28826946ada435da2df3b71a0e740369caa378cc08a1838f7b3c9bd271067;aaronpearce
@BrandonShega
BrandonShega / Playground.swift
Created October 18, 2017 13:31
StackViews with Buttons
//: Playground - noun: a place where people can play
import Foundation
import UIKit
import PlaygroundSupport
let buttonTitles = [["shortTitle", "longerTitle", "short"], ["reallyLongTitle", "short", "short"],["short", "short", "short"]]
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 300.0, height: 300.0))
import Foundation
import Result
public extension Result {
/// Constructs a success wrapping `value`, iff `value` is not nil and `error` is nil.
///
/// Constructs a failure wrapping `error`, iff `error` is not nil and `value` is nil.
///
/// Otherwise, returns nil.
@BrandonShega
BrandonShega / Fibonacci.swift
Last active June 30, 2017 19:13
Fibonacci Sequence
import UIKit
import XCPlayground
import PlaygroundSupport
struct FibonacciIterator: IteratorProtocol {
var (first, second) = (0,1)
mutating func next() -> Int? {
(first, second) = (second, first + second)
return first
@BrandonShega
BrandonShega / PrimeNumber.swift
Created June 30, 2017 13:47
Prime Number Sequence
struct PrimeIterator: IteratorProtocol {
var newValue = 2
var foundPrimes: [Int] = []
mutating func next() -> Int? {
var nextPrime = newValue
while foundPrimes.contains(where: { nextPrime % $0 == 0 }) {
nextPrime += 1
}
@BrandonShega
BrandonShega / SortedArray.swift
Created June 30, 2017 13:43
Swift Sorted Array
import UIKit
import XCPlayground
import PlaygroundSupport
struct SortedArray<Element: Comparable> {
var elements: [Element]
init<S: Sequence>(unsorted: S) where S.Iterator.Element == Element {
elements = unsorted.sorted()
}