標準入力で1以上の整数が一つ与えられます。このとき、1から与えられた整数までの合計を計算して出力するプログラムを、Swiftで書いて下さい。
次のようなSwiftプログラムを書くことで、1から与えられた整数までの合計を計算して出力できます。
import Foundation
// 入力
import SwiftUI | |
import Foundation | |
import FoundationModels | |
import AudioToolbox | |
enum Role: Hashable { | |
case user | |
case assistant | |
} |
// https://twitter.com/koher/status/1627284858493075463 | |
for n in 2 ... 1000000 { | |
var a = n * n - 1 | |
while a.isMultiple(of: 2) { | |
a /= 2 | |
} | |
while a.isMultiple(of: 5) { | |
a /= 5 | |
} | |
guard a == 1 else { continue } |
import Foundation | |
actor UUIDSerialNumberGenerator { | |
static let shared: UUIDSerialNumberGenerator = .init() | |
private var nextSerialNumber: Int = 0 | |
private var uuidToSerialNumber: [UUID: Int] = [:] | |
private init() {} | |
標準入力で1以上の整数が一つ与えられます。このとき、1から与えられた整数までの合計を計算して出力するプログラムを、Swiftで書いて下さい。
次のようなSwiftプログラムを書くことで、1から与えられた整数までの合計を計算して出力できます。
import Foundation
// 入力
import CoreGraphics | |
let vectors: [CGVector] = [CGVector(dx: 2, dy: 1), CGVector(dx: -3, dy: 0)] | |
// ∞ノルムの平均の計算 | |
// extension なし | |
vectors.lazy | |
.map { max($0.dx.magnitude, $0.dy.magnitude) } | |
.reduce(0, +) / CGFloat(vectors.count) |
enum JSON { | |
case number(Double) | |
case boolean(Bool) | |
case string(String) | |
case array([JSON]) | |
case object([String: JSON]) | |
case null | |
} | |
extension JSON: Codable { |
// https://algo-method.com/tasks/302 | |
func readInt3(line: Int = #line, file: String = #file) -> (Int, Int, Int) { | |
let values = readLine()!.split(separator: " ").map { Int(String($0))! } | |
precondition(values.count == 3) | |
return (values[0], values[1], values[2]) | |
} | |
var (n, x, y) = readInt3() | |
for _ in 2 ..< n { |
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 } |
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 |