Hello Swift crew!
This is my first post. I'm on a self-learning journey with Swift. I'm working my way through Stanford's latest iOS course that's available publicly.
As an exercise, I'm going to complete an assignment that creates a game of Solo Set.
I've come up with a way to represent each card (81 in total) using integers from 0...2.
I've even managed to generate all the cards with these combinations using iteration.
let variations = 0...2
var cards:[[Int]] = []
for shape in variations {
for shading in variations {
for colour in variations {
for numItems in variations {
cards.append([shape, shading, colour, numItems])
}
}
}
}
cards.forEach { print("\($0)") }
"""
Outputs:
[0, 0, 0, 0]
[0, 0, 0, 1]
...
[2, 2, 2, 2]
"""
But I don't have a computer science background thus no experience in algorithms or recursion — it's something I want to rectify.
I suspect there is a better way to achieve what I'm achieving through either an algorithm or recursion.
I checked out this WWDC video on the Swift Algorithms and Collections packages. I suspect I could use combinations or permutations, but I haven't been able to crack it.
Those in the know, would you be able to nudge me in the right direction using an algorithm or recursion? I would like to build my understanding and would love any hints or tips to help move me along.
Thanks for considering my post