WWDC 2001 2002 2003 2004 2007 2008 2009 2010 2011 2012 2013
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 solution(_ board:[[Int]], _ moves:[Int]) -> Int { | |
var b = board | |
var st: [Int] = [] | |
var result = 0 | |
for m in moves { | |
var index = 0 | |
while index < b.count,b[index][m-1] == 0 { |
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
// | |
// Currying.swift | |
// | |
// Created by Joshua on 2020/01/12. | |
// Copyright © 2020 Joshua. All rights reserved. | |
// | |
import Foundation | |
precedencegroup Currying { // 왼쪽에서 오른쪽 방향으로 적용 | |
associativity: left |
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 | |
final class FileIO { | |
private let buffer:[UInt8] | |
private var index: Int = 0 | |
init(fileHandle: FileHandle = FileHandle.standardInput) { | |
buffer = Array(try! fileHandle.readToEnd()!)+[UInt8(0)] // 인덱스 범위 넘어가는 것 방지 |
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 Array where Element: Comparable { | |
func lowerBound(of element: Element) -> Int { | |
var left = startIndex | |
var right = count | |
while left < right { | |
let mid = (left+right)/2 | |
if self[mid] >= element { | |
right = mid |
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
struct FenwickTree { | |
var tree: [Int] | |
var arr: [Int] | |
init(size n: Int) { | |
tree = Array(repeating: 0, count: n+1) | |
arr = Array(repeating: 0, count: n) | |
} | |
func sum(_ pos: Int) -> Int { | |
var ret = 0 |
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
public struct Heap<T> { | |
var nodes: [T] = [] | |
let comparer: (T,T) -> Bool | |
var isEmpty: Bool { | |
return nodes.isEmpty | |
} | |
init(comparer: @escaping (T,T) -> Bool) { | |
self.comparer = comparer |
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
func getCombination<T>(elements:[T], select: Int, repetition: Bool) -> [[T]] { | |
func getCombination<T>(elements: ArraySlice<T>, select: Int, repetition: Bool, partialResult: inout [T], totalResult: inout [[T]]) { | |
guard select > 0 else { | |
totalResult.append(partialResult) | |
return | |
} | |
guard let firstElement = elements.first else { return } | |
let remains = repetition ? elements : elements.dropFirst() |
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 Publisher { | |
func coolDown<S: Scheduler>(for cooltime: S.SchedulerTimeType.Stride, | |
scheduler: S) -> some Publisher<Self.Output, Self.Failure> { | |
return self.receive(on: scheduler) | |
.scan((S.SchedulerTimeType?.none, Self.Output?.none)) { | |
let eventTime = scheduler.now | |
let minimumTolerance = scheduler.minimumTolerance | |
guard let lastSentTime = $0.0 else { | |
return (eventTime, $1) | |
} |