read data
This commit is contained in:
@@ -1,7 +1,37 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strconv"
|
||||
import "core:strings"
|
||||
|
||||
DATA_FILE :: "res/knapPI_12_500_1000_82.csv"
|
||||
NUMBER_OF_ITEMS :: 500
|
||||
CAPACITY :: 280785
|
||||
|
||||
Item :: struct {
|
||||
profit, weight: int,
|
||||
}
|
||||
|
||||
items: [NUMBER_OF_ITEMS]Item
|
||||
|
||||
read_data :: proc(file: string) -> (res: [NUMBER_OF_ITEMS]Item, ok := true) {
|
||||
data := string(os.read_entire_file(file) or_return)
|
||||
data = strings.trim_space(data)
|
||||
defer delete(data)
|
||||
|
||||
for line, idx in strings.split_lines(string(data))[1:] {
|
||||
s := strings.split(line, ",")
|
||||
res[idx] = {strconv.parse_int(s[1]) or_return, strconv.parse_int(s[2]) or_return}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
fmt.println("hello world")
|
||||
items, ok := read_data(DATA_FILE)
|
||||
if !ok {
|
||||
fmt.eprintln("failed to read data from", DATA_FILE)
|
||||
return
|
||||
}
|
||||
fmt.println(items)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user