Skip to content

Instantly share code, notes, and snippets.

View JCSooHwanCho's full-sized avatar

SooHwanCho JCSooHwanCho

View GitHub Profile
@JCSooHwanCho
JCSooHwanCho / Question1.swift
Last active May 1, 2020 12:06
카카오 2020겨울인턴 코딩테스트 해답 코드
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 {
@JCSooHwanCho
JCSooHwanCho / Currying.swift
Last active January 14, 2020 15:50
Currying Implementation with swift
//
// Currying.swift
//
// Created by Joshua on 2020/01/12.
// Copyright © 2020 Joshua. All rights reserved.
//
import Foundation
precedencegroup Currying { // 왼쪽에서 오른쪽 방향으로 적용
associativity: left
@JCSooHwanCho
JCSooHwanCho / FileIO.swift
Last active August 2, 2024 06:27
ps할 때 입력을 한꺼번에 받기 위한 유틸리티 클래스. fread의 swift 버전.
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)] // 인덱스 범위 넘어가는 것 방지
@JCSooHwanCho
JCSooHwanCho / upper&lowerBound.swift
Last active December 27, 2022 10:27
비내림차순 배열에서의 upperBound&lowerBound 구현
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
@JCSooHwanCho
JCSooHwanCho / FenwickTree.swift
Last active April 8, 2021 13:51
FenwickTree의 Swift 구현체
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
@JCSooHwanCho
JCSooHwanCho / Heap.swift
Created September 12, 2020 14:20
swift로 간단하게 구현한 힙
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
@JCSooHwanCho
JCSooHwanCho / Combination.swift
Last active April 16, 2021 14:15
Swift로 구현한 모든 조합을 구하는 코드
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()
@JCSooHwanCho
JCSooHwanCho / README.md
Created August 7, 2023 07:50 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
@JCSooHwanCho
JCSooHwanCho / Combine+Cooldown.swift
Created September 2, 2023 13:48
Combine operator that mimics RxSwift's throttle when latest: false
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)
}