test
This file contains hidden or 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 SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
ScrollView { | |
MyView() | |
Text("Hello") | |
} | |
} | |
} |
This file contains hidden or 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
// わざわざ async let を使って代入を挟まなくても | |
// 非同期処理を↓のようにして並行に実行できるようにするのは | |
// | |
// await (foo() + bar()) // 並行 | |
// (await foo()) + (await bar()) // 直列 | |
// | |
// try との整合性の関係で難しそう。 | |
// | |
// try の仕様が、↓の (A) では "foo" と "bar" が、 | |
// (B) では "foo" のみが表示されるようになっていれば |
This file contains hidden or 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 pow<Integer>(_ a: Integer, _ b: Integer, modulus: Integer?) -> Integer where Integer: BinaryInteger { | |
var result: Integer = 1 | |
var a = a | |
var b = b | |
if let modulus = modulus { | |
while true { | |
if b & 0x1 != 0 { | |
result = (result * a) % modulus | |
} | |
b >>= 1 |
This file contains hidden or 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 readInt3(line: Int = #line, file: String = #file) -> (Int, Int, Int) { | |
guard let string = readLine() else { | |
preconditionFailure("No input (at line \(line) in \(file))") | |
} | |
let values: [Int] = string.split(separator: " ").map { part in | |
guard let value = Int(part) else { | |
preconditionFailure("Illegal input value: \(string) (at line \(line) in \(file))") | |
} | |
return value | |
} |
This file contains hidden or 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 SwiftUI | |
struct ContentView: View { | |
@StateObject private var state: ContentViewState = .init() | |
var body: some View { | |
ZStack { | |
VStack { | |
Text(state.count.description) | |
Button("Count Up") { |
This file contains hidden or 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 SwiftUI | |
struct ContentView: View { | |
@StateObject private var state: ContentViewState = .init() | |
var body: some View { | |
VStack { | |
Text(state.count.description) | |
Button("Count Up") { state.countUp() } | |
Button("Reset") { state.reset() } | |
} |
This file contains hidden or 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 binarySearch<Values>(_ value: Values.Element, in values: Values) -> Int? where Values: Collection, Values.Element: Comparable, Values.Index == Int { | |
var values: Values.SubSequence = values[...] | |
while !values.isEmpty { | |
let midIndex = values.startIndex + (values.endIndex - values.startIndex) / 2 | |
let midValue = values[midIndex] | |
if value < midValue { | |
values = values[..<midIndex] | |
} else if value > midValue { | |
values = values[(midIndex + 1)...] | |
} else { |
This file contains hidden or 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
let pp = readLine()!.split(separator: " ") | |
let e = pp[0] | |
let y = Int(pp[1])! | |
let m = Int(pp[2])! | |
let d = Int(pp[3])! | |
let dd = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] | |
struct YMD: Comparable { | |
let y: Int |
This file contains hidden or 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
let aa = (1...100).shuffled().dropFirst(50).sorted() | |
print(aa.count, 100) | |
print(aa.map(\.description).joined(separator: " ")) | |
let aaSet = Set(aa) | |
var count = 0 | |
var ans: [Int] = [] | |
for i in 1 ... 1000 { | |
if aaSet.contains(i) { continue } |