Skip to content

Instantly share code, notes, and snippets.

@masakih
masakih / CodePiece.swift
Last active June 10, 2022 11:20
発展させてみた #CodePiece
struct GeneratedError<T>: Error {
let host: T
let id: Int
let message: String
let file: String
let line: Int
@masakih
masakih / hoge.swift
Last active June 3, 2022 00:20
teratailのやつ
func setBit(_ x: Int, _ n: Int) -> Int { ... }
func unsetBit(_ x: Int, _ n: Int) -> Int { ... }
func reverseBit(_ x: Int, _ n: Int) -> Int { ... }
func print8Bit(_ x: Int) { ... }
// 標準入力から整数を読み込む
// 整数以外であれば例外
func readInt() throws -> Int { ... }
@masakih
masakih / CodePiece.swift
Created May 3, 2022 10:53
骨が出来た #CodePiece
struct JoinedCollection<C1: Collection, C2: Collection, Element>: Collection
where C1.Element == Element, C2.Element == Element, C1.Index == Int, C2.Index == Int {
var left: C1
var right: C2
init(_ left: C1, _ right: C2) {
self.left = left
self.right = right
}
@masakih
masakih / 41.swift
Created August 25, 2021 17:11
algo41
let aa: [[Int]] = [
[768, 527, 845],
[978, 444, 266],
[777, 746, 419],
[109, 58, 54],
[544, 391, 391],
[937, 308, 901],
[105, 310, 594],
[830, 795, 221],
[792, 547, 688],
@masakih
masakih / 325.swift
Created August 25, 2021 03:58
algo325
let aa = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3 ]
func getInt() -> Int { aa.count }
func getIntArray() -> [Int] { aa }
///
let n = getInt()
var dp = Array<Array<Int?>>(repeating: Array<Int?>(repeating: nil, count: n), count: n)
dp[0] = getIntArray()
@masakih
masakih / 324.swift
Created August 24, 2021 22:45
algo324
let aa = [0, 2, 7, 8]
func getIntArray() -> [Int] { aa }
///
var dp = Array<Array<Int?>>(repeating: Array<Int?>(repeating: nil, count: 4), count: 4)
dp[0] = getIntArray()
func solve(_ n: Int, _ m: Int) -> Int {
@masakih
masakih / 323.swift
Created August 23, 2021 23:38
algo323
let aa = [696, 300, 458, 384, 75, 431, 353, 626, 219, 941, 46, 816, 724, 361]
func getInt2() -> (Int, Int) { (899, 14) }
func getIntArray() -> [Int] { aa }
///
let (n, m) = getInt2()
let a = getIntArray()
var dp = Array<Bool?>(repeating: nil, count: n + 1)
dp[0] = true
@masakih
masakih / 306.swift
Created August 22, 2021 10:37
algo306
let aa = [3, 1, 4, 1, 5, 9, 2, 6]
func getInt2() -> (Int, Int) { (aa.count, 4) }
func getIntArray() -> [Int] { aa }
///
let (n, m) = getInt2()
let a = getIntArray()
var dp = Array<Int?>(repeating: nil, count: n)
dp[0] = 0
@masakih
masakih / CodePiece.swift
Created March 16, 2021 14:46
lazy付けて配列生成のオーバーヘッド減らしたらちょっとだけ速くなった #CodePiece
struct Reader: Sequence {
struct Iterator: IteratorProtocol {
func next() -> String? {
readLine()
}
}
func makeIterator() -> Iterator {
.init()
}
@masakih
masakih / CodePiece.swift
Created March 16, 2021 14:30
これ #CodePiece
struct Reader: Sequence {
struct Iterator: IteratorProtocol {
func next() -> String? {
readLine()
}
}
func makeIterator() -> Iterator {
.init()
}