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
/** | |
Swift はメモリー管理にARC(Automatic Reference Counting) という仕組みを利用しています。 | |
ARCは、インスタンスが作成されるたびに、値を保存するためのメモリを確保します。 | |
このメモリは、以下の情報を保持します。 | |
- インスタンスの型に関する情報 | |
- プロパティの値 | |
インスタンスが不要になると、ARCは使用されているメモリを自動的に解放します。 | |
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 SwiftSyntax | |
import SwiftParser | |
let sourceFile = Parser.parse(source: "let number = 100") | |
print(sourceFile.debugDescription) | |
func getLetMethod() { | |
let statements = Array(sourceFile.statements) | |
let item = statements[0].item |
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 | |
@propertyWrapper | |
struct UserDefault<T> { | |
let key: String | |
let defaultValue: T | |
init(key: String, defaultValue: T) { | |
self.key = key | |
self.defaultValue = defaultValue |
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
private func readStringArray(_ count: Int) -> [[Character]] { | |
return (1...count).map { _ in | |
let value = Array(readLine()!) | |
return Array<Character>(value) | |
} | |
} | |
//example: | |
// | |
//count = 3 |
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
private func isSimilar(str1: String, str2: String) -> String { | |
var ok: String = "Yes" | |
// 条件1のチェック | |
if (str1.count != str2.count) { | |
ok = "No" | |
return ok | |
} | |
// 条件2のチェック | |
var diffCount = 0 |
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
// 点(x, y)が第何象限にあるか(1, 2, 3, 4)を返す関数 | |
// ただし、それでもなければ0を返すようにした | |
private func quadrant(x: Int, y: Int) -> Int { | |
if (0 < x && 0 < y) { | |
return 1 | |
} else if (0 > x && 0 < y) { | |
return 2 | |
} else if (0 > x && 0 > y) { | |
return 3 | |
} else if (0 < x && 0 > y) { |
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
// 偏差値 (Z score) を計算する | |
def float: calc_zscore(int: N, float[]: scores, float score) | |
float: average = 0.0 | |
for (初期値: index = 0, 条件: index < N, 更新: index += 1) | |
average += scores[index] | |
endfor | |
average = average ÷ N の値 | |
float: sd = 0.0 | |
for (初期値: index = 0, 条件: index < N, 更新: index += 1) | |
sd += (scores[index] - average) * (scores[index] - average) |