type inference for variables
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
func check[report: Array] : bool
|
||||
let increasing: bool = array.nth(report, 0) < array.nth(report, 1)
|
||||
let increasing = array.nth(report, 0) < array.nth(report, 1)
|
||||
|
||||
for i in 0..report->size-1
|
||||
if array.nth(report, i) > array.nth(report, i + 1) && increasing
|
||||
@@ -7,7 +7,7 @@ func check[report: Array] : bool
|
||||
if array.nth(report, i) < array.nth(report, i + 1) && !increasing
|
||||
return false
|
||||
|
||||
let diff: i64 = math.abs(array.nth(report, i) - array.nth(report, i + 1))
|
||||
let diff = math.abs(array.nth(report, i) - array.nth(report, i + 1))
|
||||
if diff < 1 || diff > 3
|
||||
return false
|
||||
|
||||
@@ -31,7 +31,7 @@ func part2[data: Array] : void
|
||||
else
|
||||
let arr: Array = array.nth(data, i)
|
||||
for j in 0..arr->size
|
||||
let sliced: Array = array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
|
||||
let sliced = array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
|
||||
|
||||
if check(sliced)
|
||||
out = out + 1
|
||||
@@ -40,13 +40,13 @@ func part2[data: Array] : void
|
||||
io.println_i64(out)
|
||||
|
||||
func main[] : i64
|
||||
let lines: Array = must(io.read_text_file?("input.txt")) |> str.split("\n")
|
||||
let lines = must(io.read_text_file?("input.txt")) |> str.split("\n")
|
||||
|
||||
let data: Array = []
|
||||
let data = []
|
||||
for i in 0..lines->size
|
||||
let line: str = array.nth(lines, i)
|
||||
|
||||
let report: Array = str.split(line, " ")
|
||||
let report = str.split(line, " ")
|
||||
for i in 0..report->size
|
||||
array.set(report, i, str.parse_i64(array.nth(report, i)))
|
||||
array.push(data, report)
|
||||
|
||||
Reference in New Issue
Block a user