This file contains 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 musicURL = try! FileManager.default.url(for: .musicDirectory, in: .userDomainMask, appropriateFor: nil, create: false) | |
let source = musicURL.appendingPathComponent("錄音/原始.wav") | |
let input = try! AVAudioFile(forReading: source) | |
let format = input.fileFormat | |
let destination = musicURL.appendingPathComponent("錄音/複製.wav") | |
let output = try! AVAudioFile(forWriting: destination, settings: format.settings, commonFormat: format.commonFormat, interleaved: format.isInterleaved) | |
while input.framePosition < input.length { |
This file contains 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
:- set_prolog_flag(verbose, silent). | |
:- initialization(main). | |
可整除(X, Y):- | |
0 is X mod Y. | |
有因數(X, Y):- | |
可整除(X, Y). | |
有因數(X, Y):- | |
X > Y+1, |
This file contains 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
protocol Init { | |
init() | |
} | |
extension KeyedDecodingContainer { | |
func decode<T: Codable & Init>(_ type: T.Type, | |
forKey key: Key) throws -> T { | |
try decodeIfPresent(type, forKey: key) ?? .init() | |
} | |
} |
This file contains 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
:- set_prolog_flag(verbose, silent). | |
:- initialization(main). | |
非質數([X | _], Value):- | |
Mod is Value mod X, | |
Mod = 0. | |
非質數([_ | Other], Value):- | |
非質數(Other, Value). |
This file contains 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
:- set_prolog_flag(verbose, silent). | |
:- initialization(main). | |
帳號(學號). 密碼("IMD12345"). | |
登入(Account, Password):- | |
帳號(Account), 密碼(Password), | |
write("帳號與密碼正確可進行提款"), nl. | |
登入:- |
This file contains 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
extension String { | |
subscript(_ i: Int) -> String { | |
let idx1 = index(startIndex, offsetBy: i) | |
let idx2 = index(idx1, offsetBy: 1) | |
return String(self[idx1..<idx2]) | |
} | |
subscript (r: Range<Int>) -> String { | |
let start = index(startIndex, offsetBy: r.lowerBound) | |
let end = index(startIndex, offsetBy: r.upperBound) |
This file contains 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 Combine | |
import Foundation | |
struct Version: Codable { | |
var stringValue: String | |
init(rawValue: String) { | |
stringValue = rawValue | |
} | |
init(from decoder: Decoder) throws { |
This file contains 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 combine<Sequence1, Sequence2>(_ sequence1: Sequence1, _ sequence2: Sequence2) -> CombineSequence<Sequence1, Sequence2> { | |
return CombineSequence(sequence1, sequence2) | |
} | |
struct CombineSequence<Sequence1: Sequence, Sequence2: Sequence> { | |
let _sequence1: Sequence1 | |
let _sequence2: Sequence2 | |
init(_ sequence1: Sequence1, _ sequence2: Sequence2) { | |
(_sequence1, _sequence2) = (sequence1, sequence2) | |
} |
This file contains 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 Cocoa | |
import Foundation | |
extension String { | |
static func ~= (lhs: String, rhs: String) -> Bool { | |
if lhs == rhs { | |
return true | |
} | |
if let range = rhs.range(of: lhs, options: .regularExpression) { | |
return rhs[range] == rhs |
This file contains 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 Foundation | |
import PlaygroundSupport | |
import Combine | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
enum RequestError: Error { | |
case sessionError(error: Error) | |
} |
NewerOlder