標準入力で1以上の整数が一つ与えられます。このとき、1から与えられた整数までの合計を計算して出力するプログラムを、Swiftで書いて下さい。
次のようなSwiftプログラムを書くことで、1から与えられた整数までの合計を計算して出力できます。
import Foundation
// 入力| // 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 { |
| enum JSON { | |
| case number(Double) | |
| case boolean(Bool) | |
| case string(String) | |
| case array([JSON]) | |
| case object([String: JSON]) | |
| case null | |
| } | |
| extension JSON: Codable { |
| 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) |
標準入力で1以上の整数が一つ与えられます。このとき、1から与えられた整数までの合計を計算して出力するプログラムを、Swiftで書いて下さい。
次のようなSwiftプログラムを書くことで、1から与えられた整数までの合計を計算して出力できます。
import Foundation
// 入力| import Foundation | |
| actor UUIDSerialNumberGenerator { | |
| static let shared: UUIDSerialNumberGenerator = .init() | |
| private var nextSerialNumber: Int = 0 | |
| private var uuidToSerialNumber: [UUID: Int] = [:] | |
| private init() {} |
| // 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 SwiftUI | |
| import Foundation | |
| import FoundationModels | |
| import AudioToolbox | |
| enum Role: Hashable { | |
| case user | |
| case assistant | |
| } |
At WWDC 25 Apple opened up the on-device large-language model that powers Apple Intelligence to every iOS, iPadOS, macOS and visionOS app via a new “Foundation Models” framework. The model is a compact ~3 billion-parameter LLM that has been quantized to just 2 bits per weight, so it runs fast, offline and entirely on the user’s device, keeping data private while still handling tasks such as summarization, extraction, short-form generation and structured reasoning. ([developer.apple.com][1], [machinelearning.apple.com][2]) Below is a developer-focused English-language overview—based mainly on Apple’s own announcements, docs and WWDC sessions—followed by ready-to-paste Swift code samples.
Apple ships two sibling LLMs: a device-scale model (~3 B params) embedded in Apple silicon and a server-scale mixture-of-experts model that runs inside Private Cloud Compute when more heft is required. ([machinelearning.apple.com][2]) The
Claude Opus 4.7 は、Anthropic の公式発表では「難しいソフトウェア工学タスクでの改善」「長時間タスクの厳密さと一貫性」「指示追従の精度向上」「報告前の自己検証」が主な売りです。あわせて視覚性能も強化され、UI・スライド・文書生成の品質も上がっています。Claude Code 側でも、この“長く走れる・自分で確かめる・より自律的”という性格に合わせた機能が増えています。 ([Anthropic][1])
default モデルは、Max / Team Premium は Opus 4.7、Pro / Team Standard / Enterprise / Anthropic API は Sonnet 4.6 です。さらに、Opus の使用量しきい値に達すると Sonnet にフォールバックすることがあります。Opus 4.7 を確実に使いたいなら、/model opus か /model claude-opus-4-7 で明示的に切り替えるのが安全です。なお、Enterprise pay-as-you-go と Anthropic API の既定モデルは 2026年4月23日に Opus 4.7 へ変更予定です。 ([Claude][2])opus[1m] や claude-opus-4-7[1m] を選べます。Max / Team / Enterprise では Opus の 1M context がサブスク内、Pro は extra usage です。 ([Claude][2])opusplan も有力です。これは Plan Mode では Opus、実行時は Sonnet に切り替えるハイブリッド設定です。長い設計検討だけ Opus に任せたいときに向いています。 ([Claude][2])