Last active
May 17, 2019 10:19
-
-
Save hmhmsh/fa9efdea29fcc854aaaf33ca8b9166d0 to your computer and use it in GitHub Desktop.
Saizeriya Menu List (2019.05.17時点) // jsonのsaltの桁数あとで修正予定
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
enum SaizeriyaMenuCategory: String, Codable { | |
case saladSoup = "サラダ・スープ" | |
case appetizer = "前菜・おつまみ" | |
case fromItalyWine = "イタリアの味・ワイン" | |
case pizza = "ピザ" | |
case pasta = "パスタ" | |
case doriaRice = "ドリア・米料理" | |
case hamburgSteak = "肉料理" | |
case dessert = "デザート" | |
var list: [SaizeriyaMenuCategory] { | |
return [.saladSoup, .appetizer, .fromItalyWine, .pizza, .pasta, .doriaRice, .hamburgSteak, .dessert] | |
} | |
} |
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
struct SaizeriyaOrder { | |
let money: Int | |
private let database = SaizeriyaMenuDatabase() | |
func order() -> [SaizeriyaMenu] { | |
var remain = money | |
var order = [SaizeriyaMenu]() | |
while remain > 0 { | |
guard let menu = randomMenu(remain: remain) else { | |
break | |
} | |
remain = remain - menu.price | |
order.append(menu) | |
} | |
return order | |
} | |
private func randomMenu(remain: Int) -> SaizeriyaMenu? { | |
let list = database.all.filter({ $0.price < remain }) | |
guard list.count > 0, | |
let menu = list.randomElement() else { | |
return nil | |
} | |
return menu | |
} | |
} | |
let order = SaizeriyaOrder(money: 1000).order() | |
let name = order.map({ $0.name }) | |
let price = order.reduce(0, { $0 + $1.price }) | |
let cal = order.reduce(0, { $0 + $1.kcal }) | |
let salt = order.reduce(0, { $0 + $1.salt }) | |
print(name) | |
print(String(price) + "円") | |
print(String(cal) + "kcal") | |
print(String(salt) + "g") | |
/* 出力例 | |
["アーリオ・オーリオ(Wサイズ)", "ポップコーンシュリンプ", "スモールライス"] | |
992円 | |
1486kcal | |
7.8g | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment