Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Add Go runner #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions go/gilded-rose.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package main

import "fmt"

type Item struct {
name string
sellIn, quality int
Expand All @@ -16,12 +14,6 @@ var items = []Item{
Item{"Conjured Mana Cake", 3, 6},
}

func main() {
fmt.Println("OMGHAI!")
// fmt.Print(items)
GildedRose()
}

func GildedRose() {
for i := 0; i < len(items); i++ {

Expand Down
41 changes: 41 additions & 0 deletions go/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
)

func main() {
inFile := os.Args[1]
outFile := os.Args[2]
dnephin marked this conversation as resolved.
Show resolved Hide resolved
fmt.Printf("Reading from: %v. Writing to: %v\n", inFile, outFile)
dat, err := ioutil.ReadFile(inFile)
if err != nil {
panic(err)
dnephin marked this conversation as resolved.
Show resolved Hide resolved
}
lines := strings.Split(string(dat), "\n")
items = nil
for i := 0; i < len(lines); i++ {
if !strings.HasPrefix(lines[i], ";") && (lines[i] != "") {
pieces := strings.Split(lines[i], "__")
name := pieces[0]
sellIn, _ := strconv.Atoi(pieces[1])
quality, _ := strconv.Atoi(pieces[2])
items = append(items, Item{name, sellIn, quality})
}
}

GildedRose()
dnephin marked this conversation as resolved.
Show resolved Hide resolved

var outStrings []string
for i := 0; i < len(items); i++ {
dnephin marked this conversation as resolved.
Show resolved Hide resolved
outStrings = append(outStrings, fmt.Sprintf("%v__%v__%v", items[i].name, items[i].sellIn, items[i].quality))
}
err = ioutil.WriteFile(outFile, []byte(strings.Join(outStrings, "\n")), 06444)
if err != nil {
panic(err)
}
}