commit 3da69bccc66cd24fcb8492055d5df281dcd69e79 Author: benjamyn Date: Tue Sep 28 19:51:07 2021 +1000 initial diff --git a/deck/deck.go b/deck/deck.go new file mode 100644 index 0000000..e431a04 --- /dev/null +++ b/deck/deck.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "io/ioutil" + "strings" +) + +// Create a new type of 'deck +// which is a slice of string + +type deck []string + +func newDeck() deck { + cards := deck{} + cardSuits := []string{"Spades", "Hearts", "Diamonds", "Clubs"} + cardValues := []string{"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"} + + for _, suit := range cardSuits { + for _, value := range cardValues { + cards = append(cards, value+" of "+suit) + } + } + return cards +} + +func (d deck) print() { + for _, card := range d { + fmt.Println(card) + + } +} + +func deal(d deck, handsize int) (deck, deck) { + return d[:handsize], d[handsize:] + +} + +func (d deck) toString() string { + return strings.Join([]string(d), ",") +} + +func (d deck) saveToFile(fileName string) error { + error := ioutil.WriteFile(fileName, []byte(d.toString()), 0644) + return error +} diff --git a/deck/main.go b/deck/main.go new file mode 100644 index 0000000..8a17fa7 --- /dev/null +++ b/deck/main.go @@ -0,0 +1,6 @@ +package main + +func main() { + cards := newDeck() + cards.saveToFile("mydeck.txt") +} diff --git a/hello_world/.vscode/launch.json b/hello_world/.vscode/launch.json new file mode 100644 index 0000000..608d3c6 --- /dev/null +++ b/hello_world/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileDirname}" + } + ] +} \ No newline at end of file diff --git a/hello_world/main b/hello_world/main new file mode 100755 index 0000000..7ae47e8 Binary files /dev/null and b/hello_world/main differ diff --git a/hello_world/main.go b/hello_world/main.go new file mode 100644 index 0000000..91e7378 --- /dev/null +++ b/hello_world/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello World") +}