Skip to content

Commit 1b00ed0

Browse files
authored
Add files via upload
1 parent 2fe1d5b commit 1b00ed0

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Project : Yacht Sea
2+
// Written by: Mason Z
3+
// Date: Sept 16, 2024
4+
// Description: Yacht Sea - Missing "4 of a kind, Big Straight, and Choice" Detection. Original approach.
5+
// note, full house will be recoded to use a set or dictionary instead of current approach as per goal - however, fully functional at said moment.
6+
7+
import Foundation
8+
9+
for _ in 1...20 {
10+
// variables
11+
var highestScore: Int = 0 // highest score, default zero
12+
var category: String = "default" // category default temp placeholder
13+
var dice = [Int]()
14+
15+
// create random array
16+
for _ in 1...5 {
17+
let number = Int.random(in: 1...6)
18+
dice.append(number)
19+
}
20+
21+
// Yacht Sea - if all values is the same
22+
if (dice.allSatisfy({ $0 == dice.first }) == true) {
23+
highestScore = 50 // highest possible score
24+
category = "Yacht Sea"
25+
}
26+
27+
// small straight
28+
let setArray: Set = Set(dice)
29+
let c1: Set = [1, 2, 3, 4]
30+
let c2: Set = [2, 3, 4, 5]
31+
let c3: Set = [3, 4, 5 ,6]
32+
let comparison = [c1, c2, c3]
33+
34+
for c in comparison {
35+
if (setArray == c && highestScore < 30) {
36+
highestScore = 30
37+
category = "Small Straight"
38+
}
39+
}
40+
41+
// create an array that checks in the original "array" length of 5, for the values 1 through 6
42+
// 1 2 3 4 5 6
43+
var value = [0, 0, 0, 0, 0, 0]
44+
45+
for i in 1...6 { // index 0
46+
for number in dice {
47+
if (number == i) {
48+
value[i-1] += 1
49+
}
50+
}
51+
}
52+
53+
if (value.contains(2) && value.contains(3) && highestScore < 25) {
54+
highestScore = 25
55+
category = "Full House"
56+
}
57+
58+
for i in 1...6 { // get all the occurances worth their value, say 2 threes in an array? it'll now be 6.
59+
value[i-1] *= i
60+
}
61+
62+
let max: Int = value.max() ?? 0 // find the max value in the value array
63+
let index: Int = value.firstIndex(of: max) ?? 0 // plus what index it was detected in.
64+
65+
let numerals = ["Ones", "Twos", "Threes", "Fours", "Fives", "Sixes"]
66+
if (max > highestScore) {
67+
highestScore = max
68+
category = numerals[index]
69+
}
70+
print("input: \(dice) | output: \(highestScore) | explanation: \(category)")
71+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<playground version='5.0' target-platform='ios' buildActiveScheme='true' importAppTypes='true'>
3+
<timeline fileName='timeline.xctimeline'/>
4+
</playground>

Swift Practice + Warmups/Yacht Sea P2.playground/playground.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)