uniform function call syntax
This commit is contained in:
@@ -2,7 +2,7 @@ func part1[l1: Array, l2: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..l1->size
|
||||
out += math.abs(array.nth(l1, i) - array.nth(l2, i))
|
||||
out += (l1->nth(i) as i64 - l2->nth(i) as i64)->abs()
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -10,7 +10,7 @@ func part2[l1: Array, l2: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..l1->size
|
||||
out += array.nth(l1, i) * alg.count(l2, array.nth(l1, i))
|
||||
out += l1->nth(i) * l2->count(l1->nth(i))
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -19,21 +19,21 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
|
||||
l1 := []
|
||||
l2 := []
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
|
||||
parts := str.split(line, " ")
|
||||
parts := line->split(" ")
|
||||
|
||||
array.push(l1, str.parse_i64(array.nth(parts, 0)))
|
||||
array.push(l2, str.parse_i64(array.nth(parts, 1)))
|
||||
l1->push((parts->nth(0) as str)->parse_i64())
|
||||
l2->push((parts->nth(1) as str)->parse_i64())
|
||||
|
||||
alg.quicksort(l1)
|
||||
alg.quicksort(l2)
|
||||
l1->quicksort()
|
||||
l2->quicksort()
|
||||
|
||||
part1(l1, l2)
|
||||
part2(l1, l2)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
func check[report: Array] : bool
|
||||
increasing := array.nth(report, 0) < array.nth(report, 1)
|
||||
increasing := report->nth(0) < report->nth(1)
|
||||
|
||||
for i in 0..report->size-1
|
||||
if array.nth(report, i) > array.nth(report, i + 1) && increasing
|
||||
if report->nth(i) > report->nth(i + 1) && increasing
|
||||
return false
|
||||
if array.nth(report, i) < array.nth(report, i + 1) && !increasing
|
||||
if report->nth(i) < report->nth(i + 1) && !increasing
|
||||
return false
|
||||
|
||||
diff := math.abs(array.nth(report, i) - array.nth(report, i + 1))
|
||||
diff := (report->nth(i) as i64 - report->nth(i + 1) as i64)->abs()
|
||||
if diff < 1 || diff > 3
|
||||
return false
|
||||
|
||||
@@ -17,7 +17,7 @@ func part1[data: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..data->size
|
||||
if check(array.nth(data, i))
|
||||
if check(data->nth(i))
|
||||
out += 1
|
||||
|
||||
io.println_i64(out)
|
||||
@@ -26,12 +26,12 @@ func part2[data: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..data->size
|
||||
if check(array.nth(data, i))
|
||||
if check(data->nth(i))
|
||||
out += 1
|
||||
else
|
||||
arr : Array = array.nth(data, i)
|
||||
arr : Array = data->nth(i)
|
||||
for j in 0..arr->size
|
||||
sliced := array.concat(array.slice(arr, 0, j), array.slice(arr, j + 1, arr->size - (j + 1)))
|
||||
sliced := arr->slice(0, j)->concat(arr->slice(j + 1, arr->size - (j + 1)))
|
||||
|
||||
if check(sliced)
|
||||
out += 1
|
||||
@@ -44,16 +44,16 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
|
||||
data := []
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
|
||||
report := str.split(line, " ")
|
||||
report := line->split(" ")
|
||||
for i in 0..report->size
|
||||
array.set(report, i, str.parse_i64(array.nth(report, i)))
|
||||
array.push(data, report)
|
||||
report->set(i, (report->nth(i) as str)->parse_i64())
|
||||
data->push(report)
|
||||
|
||||
part1(data)
|
||||
part2(data)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
func check[lines: Array, x: i64, y: i64, dx: i64, dy: i64] : bool
|
||||
if x + dx * 3 < 0 || x + dx * 3 >= lines->size || y + dy * 3 < 0 || y + dy * 3 >= str.len(array.nth(lines, 0))
|
||||
if x + dx * 3 < 0 || x + dx * 3 >= lines->size || y + dy * 3 < 0 || y + dy * 3 >= (lines->nth(0) as str)->len()
|
||||
return false
|
||||
|
||||
if array.nth(lines, x)[y] != 'X'
|
||||
if lines->nth(x)[y] != 'X'
|
||||
return false
|
||||
if array.nth(lines, x + dx)[y + dy] != 'M'
|
||||
if lines->nth(x + dx)[y + dy] != 'M'
|
||||
return false
|
||||
if array.nth(lines, x + dx * 2)[y + dy * 2] != 'A'
|
||||
if lines->nth(x + dx * 2)[y + dy * 2] != 'A'
|
||||
return false
|
||||
if array.nth(lines, x + dx * 3)[y + dy * 3] != 'S'
|
||||
if lines->nth(x + dx * 3)[y + dy * 3] != 'S'
|
||||
return false
|
||||
|
||||
return true
|
||||
@@ -17,7 +17,7 @@ func part1[lines: Array] : void
|
||||
out := 0
|
||||
|
||||
for x in 0..lines->size
|
||||
for y in 0..str.len(array.nth(lines, x))
|
||||
for y in 0..(lines->nth(x) as str)->len()
|
||||
if check(lines, x, y, 0, 1)
|
||||
out += 1
|
||||
if check(lines, x, y, 0, -1)
|
||||
@@ -42,15 +42,16 @@ func part2[lines: Array] : void
|
||||
s := _stackalloc(5) as str
|
||||
|
||||
for x in 1..lines->size-1
|
||||
for y in 1..str.len(array.nth(lines, x))-1
|
||||
if array.nth(lines, x)[y] == 'A'
|
||||
s[0] = array.nth(lines, x - 1)[y - 1]
|
||||
s[1] = array.nth(lines, x + 1)[y - 1]
|
||||
s[2] = array.nth(lines, x + 1)[y + 1]
|
||||
s[3] = array.nth(lines, x - 1)[y + 1]
|
||||
line_len := (lines->nth(x) as str)->len()
|
||||
for y in 1..line_len-1
|
||||
if lines->nth(x)[y] == 'A'
|
||||
s[0] = lines->nth(x - 1)[y - 1]
|
||||
s[1] = lines->nth(x + 1)[y - 1]
|
||||
s[2] = lines->nth(x + 1)[y + 1]
|
||||
s[3] = lines->nth(x - 1)[y + 1]
|
||||
s[4] = 0
|
||||
|
||||
if str.equal(s, "MSSM") || str.equal(s, "SMMS") || str.equal(s, "MMSS") || str.equal(s, "SSMM")
|
||||
if s->equal("MSSM") || s->equal("SMMS") || s->equal("MMSS") || s->equal("SSMM")
|
||||
out += 1
|
||||
|
||||
io.println_i64(out)
|
||||
@@ -60,7 +61,7 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
|
||||
part1(lines)
|
||||
part2(lines)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
func rule_exists[rules_left: Array, rules_right: Array, a: i64, b: i64] : bool
|
||||
for k in 0..rules_left->size
|
||||
if array.nth(rules_left, k) == a && array.nth(rules_right, k) == b
|
||||
if rules_left->nth(k) == a && rules_right->nth(k) == b
|
||||
return true
|
||||
return false
|
||||
|
||||
func check[update: Array, rules_left: Array, rules_right: Array] : bool
|
||||
for i in 0..update->size
|
||||
for j in 0..i
|
||||
if rule_exists(rules_left, rules_right, array.nth(update, i), array.nth(update, j))
|
||||
if rule_exists(rules_left, rules_right, update->nth(i), update->nth(j))
|
||||
return false
|
||||
return true
|
||||
|
||||
@@ -17,21 +17,21 @@ func sort_by_rules[update: Array, rules_left: Array, rules_right: Array] : void
|
||||
while swapped
|
||||
swapped = false
|
||||
for i in 0..update->size-1
|
||||
a : i64 = array.nth(update, i)
|
||||
b : i64 = array.nth(update, i+1)
|
||||
a : i64 = update->nth(i)
|
||||
b : i64 = update->nth(i+1)
|
||||
if rule_exists(rules_left, rules_right, b, a)
|
||||
tmp := a
|
||||
array.set(update, i, b)
|
||||
array.set(update, i+1, tmp)
|
||||
update->set(i, b)
|
||||
update->set(i+1, tmp)
|
||||
swapped = true
|
||||
|
||||
func part1[updates: Array, rules_left: Array, rules_right: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..updates->size
|
||||
update : Array = array.nth(updates, i)
|
||||
update : Array = updates->nth(i)
|
||||
if check(update, rules_left, rules_right)
|
||||
out += array.nth(update, update->size / 2)
|
||||
out += update->nth(update->size / 2)
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -39,10 +39,10 @@ func part2[updates: Array, rules_left: Array, rules_right: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..updates->size
|
||||
update : Array = array.nth(updates, i)
|
||||
update : Array = updates->nth(i)
|
||||
if !check(update, rules_left, rules_right)
|
||||
sort_by_rules(update, rules_left, rules_right)
|
||||
out += array.nth(update, update->size / 2)
|
||||
out += update->nth(update->size / 2)
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -51,27 +51,27 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
data := str.split(input, "\n\n")
|
||||
data := input->split("\n\n")
|
||||
|
||||
rules_left := []
|
||||
rules_right := []
|
||||
rules_lines := str.split(array.nth(data, 0), "\n")
|
||||
rules_lines := (data->nth(0) as str)->split("\n")
|
||||
for i in 0..rules_lines->size
|
||||
line : str = array.nth(rules_lines, i)
|
||||
parts := str.split(line, "|")
|
||||
line : str = rules_lines->nth(i)
|
||||
parts := line->split("|")
|
||||
|
||||
array.push(rules_left, str.parse_i64(array.nth(parts, 0)))
|
||||
array.push(rules_right, str.parse_i64(array.nth(parts, 1)))
|
||||
rules_left->push((parts->nth(0) as str)->parse_i64())
|
||||
rules_right->push((parts->nth(1) as str)->parse_i64())
|
||||
|
||||
updates := []
|
||||
updates_lines := str.split(array.nth(data, 1), "\n")
|
||||
updates_lines := (data->nth(1) as str)->split("\n")
|
||||
for i in 0..updates_lines->size
|
||||
line : str = array.nth(updates_lines, i)
|
||||
xs := str.split(line, ",")
|
||||
line : str = updates_lines->nth(i)
|
||||
xs := line->split(",")
|
||||
|
||||
for i in 0..xs->size
|
||||
array.set(xs, i, str.parse_i64(array.nth(xs, i)))
|
||||
array.push(updates, xs)
|
||||
xs->set(i, (xs->nth(i) as str)->parse_i64())
|
||||
updates->push(xs)
|
||||
|
||||
part1(updates, rules_left, rules_right)
|
||||
part2(updates, rules_left, rules_right)
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
func concat[a: i64, b: i64] : i64
|
||||
ab_str := _stackalloc(50) as str
|
||||
io.snprintf(ab_str, 50, "%d%d", a, b)
|
||||
return str.parse_i64(ab_str)
|
||||
ab_str->format_into(50, "%d%d", a, b)
|
||||
return ab_str->parse_i64()
|
||||
|
||||
func solve[ops: Array, e: Array] : i64
|
||||
e_1 : Array = array.nth(e, 1)
|
||||
e_1 : Array = e->nth(1)
|
||||
n := e_1->size - 1
|
||||
indices := []
|
||||
for i in 0..n
|
||||
array.push(indices, 0)
|
||||
indices->push(0)
|
||||
|
||||
while true
|
||||
res : i64 = array.nth(e_1, 0)
|
||||
res : i64 = e_1->nth(0)
|
||||
for i in 0..n
|
||||
op : str = array.nth(ops, array.nth(indices, i))
|
||||
op : str = ops->nth(indices->nth(i))
|
||||
|
||||
if str.equal(op, "add")
|
||||
res += array.nth(e_1, i + 1)
|
||||
else if str.equal(op, "mul")
|
||||
res = res * array.nth(e_1, i + 1)
|
||||
else if str.equal(op, "concat")
|
||||
res = concat(res, array.nth(e_1, i + 1))
|
||||
if res == array.nth(e, 0)
|
||||
if op->equal("add")
|
||||
res += e_1->nth(i + 1)
|
||||
else if op->equal("mul")
|
||||
res = res * e_1->nth(i + 1)
|
||||
else if op->equal("concat")
|
||||
res = concat(res, e_1->nth(i + 1))
|
||||
if res == e->nth(0)
|
||||
return res
|
||||
|
||||
done := true
|
||||
i := n - 1
|
||||
|
||||
while i >= 0
|
||||
array.set(indices, i, array.nth(indices, i) + 1)
|
||||
if array.nth(indices, i) < ops->size
|
||||
indices->set(i, indices->nth(i) + 1)
|
||||
if indices->nth(i) < ops->size
|
||||
done = false
|
||||
break
|
||||
array.set(indices, i, 0)
|
||||
indices->set(i, 0)
|
||||
i -= 1
|
||||
|
||||
if done
|
||||
@@ -42,7 +42,7 @@ func part1[equations: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..equations->size
|
||||
out += solve(["add", "mul"], array.nth(equations, i))
|
||||
out += solve(["add", "mul"], equations->nth(i))
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -50,7 +50,7 @@ func part2[equations: Array] : void
|
||||
out := 0
|
||||
|
||||
for i in 0..equations->size
|
||||
out += solve(["add", "mul", "concat"], array.nth(equations, i))
|
||||
out += solve(["add", "mul", "concat"], equations->nth(i))
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -59,18 +59,18 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
equations := []
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
parts := str.split(line, ": ")
|
||||
line : str = lines->nth(i)
|
||||
parts := line->split(": ")
|
||||
|
||||
xs := str.split(array.nth(parts, 1), " ")
|
||||
xs := (parts->nth(1) as str)->split(" ")
|
||||
for j in 0..xs->size
|
||||
array.set(xs, j, str.parse_i64(array.nth(xs, j)))
|
||||
xs->set(j, (xs->nth(j) as str)->parse_i64())
|
||||
|
||||
array.push(equations, [str.parse_i64(array.nth(parts, 0)), xs])
|
||||
equations->push([(parts->nth(0) as str)->parse_i64(), xs])
|
||||
|
||||
part1(equations)
|
||||
part2(equations)
|
||||
|
||||
@@ -3,9 +3,9 @@ func part1[lines: Array] : void
|
||||
dial := 50
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
dir := line[0]
|
||||
n := str.parse_i64(str.substr(line, 1, str.len(line) - 1))
|
||||
n := line->substr(1, line->len() - 1)->parse_i64()
|
||||
|
||||
if dir == 'L'
|
||||
dial -= n
|
||||
@@ -26,9 +26,9 @@ func part2[lines: Array] : void
|
||||
dial := 50
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
dir := line[0]
|
||||
n := str.parse_i64(str.substr(line, 1, str.len(line) - 1))
|
||||
n := line->substr(1, line->len() - 1)->parse_i64()
|
||||
|
||||
if dir == 'L'
|
||||
for i in 0..n
|
||||
@@ -51,7 +51,7 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
|
||||
part1(lines)
|
||||
part2(lines)
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
func part1_is_invalid_id[s: str] : bool
|
||||
len := str.len(s)
|
||||
len := s->len()
|
||||
if len % 2 != 0
|
||||
return false
|
||||
|
||||
first := str.substr(s, 0, len / 2)
|
||||
second := str.substr(s, len / 2, len / 2)
|
||||
first := s->substr(0, len / 2)
|
||||
second := s->substr(len / 2, len / 2)
|
||||
|
||||
return str.equal(first, second)
|
||||
return first->equal(second)
|
||||
|
||||
func part1[ranges: Array] : void
|
||||
sum := 0
|
||||
|
||||
for i in 0..ranges->size
|
||||
parts := str.split(array.nth(ranges, i), "-")
|
||||
start := str.parse_i64(array.nth(parts, 0))
|
||||
end := str.parse_i64(array.nth(parts, 1))
|
||||
parts := (ranges->nth(i) as str)->split("-")
|
||||
start := (parts->nth(0) as str)->parse_i64()
|
||||
end := (parts->nth(1) as str)->parse_i64()
|
||||
|
||||
for n in (start)..end+1
|
||||
if part1_is_invalid_id(str.from_i64(n))
|
||||
if part1_is_invalid_id(n->to_str())
|
||||
sum += n
|
||||
|
||||
io.println_i64(sum)
|
||||
|
||||
// had to cheat this one
|
||||
func part2_is_invalid_id[s: str] : bool
|
||||
len := str.len(s)
|
||||
len := s->len()
|
||||
if len < 2
|
||||
return false
|
||||
for div in 1..(len / 2 + 1)
|
||||
if len % div == 0
|
||||
u := str.substr(s, 0, div)
|
||||
u := s->substr(0, div)
|
||||
is_repeat := true
|
||||
for k in 1..(len / div)
|
||||
segment := str.substr(s, k * div, div)
|
||||
if !str.equal(segment, u)
|
||||
segment := s->substr(k * div, div)
|
||||
if !segment->equal(u)
|
||||
is_repeat = false
|
||||
if is_repeat
|
||||
return true
|
||||
@@ -43,12 +43,12 @@ func part2[ranges: Array] : void
|
||||
sum := 0
|
||||
|
||||
for i in 0..ranges->size
|
||||
parts := str.split(array.nth(ranges, i), "-")
|
||||
start := str.parse_i64(array.nth(parts, 0))
|
||||
end := str.parse_i64(array.nth(parts, 1))
|
||||
parts := (ranges->nth(i) as str)->split("-")
|
||||
start := (parts->nth(0) as str)->parse_i64()
|
||||
end := (parts->nth(1) as str)->parse_i64()
|
||||
|
||||
for n in (start)..end+1
|
||||
if part2_is_invalid_id(str.from_i64(n))
|
||||
if part2_is_invalid_id(n->to_str())
|
||||
sum += n
|
||||
|
||||
io.println_i64(sum)
|
||||
@@ -58,7 +58,7 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
ranges := str.split(input, ",")
|
||||
ranges := input->split(",")
|
||||
|
||||
part1(ranges)
|
||||
part2(ranges)
|
||||
|
||||
@@ -3,15 +3,15 @@ func part1[lines: Array] : void
|
||||
s := _stackalloc(3) as str
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
|
||||
largest := 0
|
||||
for j in 0..str.len(line)
|
||||
for k in (j+1)..str.len(line)
|
||||
for j in 0..line->len()
|
||||
for k in (j+1)..line->len()
|
||||
s[0] = line[j]
|
||||
s[1] = line[k]
|
||||
s[2] = 0
|
||||
n := str.parse_i64(s)
|
||||
n := s->parse_i64()
|
||||
if n > largest
|
||||
largest = n
|
||||
|
||||
@@ -22,7 +22,7 @@ func part1[lines: Array] : void
|
||||
func part2_rec[bank: str, start: i64, remaining: i64] : i64
|
||||
largest := 0
|
||||
largest_idx := start
|
||||
len := str.len(bank)
|
||||
len := bank->len()
|
||||
|
||||
for i in (start)..(len-remaining+1)
|
||||
v := (bank[i] - '0') as i64
|
||||
@@ -39,7 +39,7 @@ func part2[lines: Array] : void
|
||||
sum := 0
|
||||
|
||||
for i in 0..lines->size
|
||||
line : str = array.nth(lines, i)
|
||||
line : str = lines->nth(i)
|
||||
|
||||
sum += part2_rec(line, 0, 12)
|
||||
io.println_i64(sum)
|
||||
@@ -49,7 +49,7 @@ func main[] : i64
|
||||
if !ok
|
||||
panic("failed to open input.txt")
|
||||
|
||||
lines := str.split(input, "\n")
|
||||
lines := input->split("\n")
|
||||
|
||||
part1(lines)
|
||||
part2(lines)
|
||||
|
||||
@@ -4,9 +4,9 @@ func main[] : i64
|
||||
for a in 500..1000
|
||||
for b in 500..1000
|
||||
if a * b > out
|
||||
s := str.from_i64(a * b)
|
||||
s_rev := str.reverse(s)
|
||||
if str.equal(s, s_rev)
|
||||
s := (a * b)->to_str()
|
||||
s_rev := s->reverse()
|
||||
if s->equal(s_rev)
|
||||
out = a * b
|
||||
mem.free(s)
|
||||
mem.free(s_rev)
|
||||
|
||||
@@ -3,7 +3,7 @@ func main[] : i64
|
||||
|
||||
i := 1
|
||||
while true
|
||||
if math.is_prime(i)
|
||||
if i->is_prime()
|
||||
found += 1
|
||||
if found == 10001
|
||||
io.println_i64(i)
|
||||
|
||||
@@ -2,7 +2,7 @@ func main[] : i64
|
||||
n := "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
|
||||
|
||||
out := 0
|
||||
max := str.len(n) - 13
|
||||
max := n->len() - 13
|
||||
for i in 0..max
|
||||
s := 1
|
||||
j := 0
|
||||
|
||||
@@ -2,6 +2,6 @@ func main[] : i64
|
||||
sum := 0
|
||||
|
||||
for i in 0..2000000
|
||||
if math.is_prime(i)
|
||||
if i->is_prime()
|
||||
sum += i
|
||||
io.println_i64(sum)
|
||||
|
||||
@@ -2,35 +2,35 @@ func main[] : i64
|
||||
N := 20
|
||||
|
||||
grid := []
|
||||
array.push(grid, [8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8])
|
||||
array.push(grid, [49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0])
|
||||
array.push(grid, [81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65])
|
||||
array.push(grid, [52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91])
|
||||
array.push(grid, [22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80])
|
||||
array.push(grid, [24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50])
|
||||
array.push(grid, [32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70])
|
||||
array.push(grid, [67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21])
|
||||
array.push(grid, [24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72])
|
||||
array.push(grid, [21, 36, 23, 9, 75, 0, 76, 44, 20, 45, 35, 14, 0, 61, 33, 97, 34, 31, 33, 95])
|
||||
array.push(grid, [78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 3, 80, 4, 62, 16, 14, 9, 53, 56, 92])
|
||||
array.push(grid, [16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 0, 17, 54, 24, 36, 29, 85, 57])
|
||||
array.push(grid, [86, 56, 0, 48, 35, 71, 89, 7, 5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58])
|
||||
array.push(grid, [19, 80, 81, 68, 5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 4, 89, 55, 40])
|
||||
array.push(grid, [4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66])
|
||||
array.push(grid, [88, 36, 68, 87, 57, 62, 20, 72, 3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69])
|
||||
array.push(grid, [4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36])
|
||||
array.push(grid, [20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16])
|
||||
array.push(grid, [20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54])
|
||||
array.push(grid, [1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48])
|
||||
grid->push([8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8])
|
||||
grid->push([49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0])
|
||||
grid->push([81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 3, 49, 13, 36, 65])
|
||||
grid->push([52, 70, 95, 23, 4, 60, 11, 42, 69, 24, 68, 56, 1, 32, 56, 71, 37, 2, 36, 91])
|
||||
grid->push([22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80])
|
||||
grid->push([24, 47, 32, 60, 99, 3, 45, 2, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50])
|
||||
grid->push([32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70])
|
||||
grid->push([67, 26, 20, 68, 2, 62, 12, 20, 95, 63, 94, 39, 63, 8, 40, 91, 66, 49, 94, 21])
|
||||
grid->push([24, 55, 58, 5, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72])
|
||||
grid->push([21, 36, 23, 9, 75, 0, 76, 44, 20, 45, 35, 14, 0, 61, 33, 97, 34, 31, 33, 95])
|
||||
grid->push([78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 3, 80, 4, 62, 16, 14, 9, 53, 56, 92])
|
||||
grid->push([16, 39, 5, 42, 96, 35, 31, 47, 55, 58, 88, 24, 0, 17, 54, 24, 36, 29, 85, 57])
|
||||
grid->push([86, 56, 0, 48, 35, 71, 89, 7, 5, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58])
|
||||
grid->push([19, 80, 81, 68, 5, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 4, 89, 55, 40])
|
||||
grid->push([4, 52, 8, 83, 97, 35, 99, 16, 7, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66])
|
||||
grid->push([88, 36, 68, 87, 57, 62, 20, 72, 3, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69])
|
||||
grid->push([4, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 8, 46, 29, 32, 40, 62, 76, 36])
|
||||
grid->push([20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 4, 36, 16])
|
||||
grid->push([20, 73, 35, 29, 78, 31, 90, 1, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 5, 54])
|
||||
grid->push([1, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 1, 89, 19, 67, 48])
|
||||
|
||||
out := 0
|
||||
|
||||
for i in 0..N-3
|
||||
for j in 0..N-3
|
||||
h : i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i), j+1) * array.nth(array.nth(grid, i), j+2) * array.nth(array.nth(grid, i), j+3)
|
||||
v : i64 = array.nth(array.nth(grid, j), i) * array.nth(array.nth(grid, j+1), i) * array.nth(array.nth(grid, j+2), i) * array.nth(array.nth(grid, j+3), i)
|
||||
d1 : i64 = array.nth(array.nth(grid, i), j) * array.nth(array.nth(grid, i+1), j+1) * array.nth(array.nth(grid, i+2), j+2) * array.nth(array.nth(grid, i+3), j+3)
|
||||
d2 : i64 = array.nth(array.nth(grid, i), N-j-1) * array.nth(array.nth(grid, i+1), N-j-2) * array.nth(array.nth(grid, i+2), N-j-3) * array.nth(array.nth(grid, i+3), N-j-4)
|
||||
h : i64 = (grid->nth(i) as Array)->nth(j) * (grid->nth(i) as Array)->nth(j+1) * (grid->nth(i) as Array)->nth(j+2) * (grid->nth(i) as Array)->nth(j+3)
|
||||
v : i64 = (grid->nth(j) as Array)->nth(i) * (grid->nth(j+1) as Array)->nth(i) * (grid->nth(j+2) as Array)->nth(i) * (grid->nth(j+3) as Array)->nth(i)
|
||||
d1 : i64 = (grid->nth(i) as Array)->nth(j) * (grid->nth(i+1) as Array)->nth(j+1) * (grid->nth(i+2) as Array)->nth(j+2) * (grid->nth(i+3) as Array)->nth(j+3)
|
||||
d2 : i64 = (grid->nth(i) as Array)->nth(N-j-1) * (grid->nth(i+1) as Array)->nth(N-j-2) * (grid->nth(i+2) as Array)->nth(N-j-3) * (grid->nth(i+3) as Array)->nth(N-j-4)
|
||||
out = math.max(out, math.max(h, math.max(v, math.max(d1, d2))))
|
||||
|
||||
io.println_i64(out)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
func num_divisors[n: i64] : i64
|
||||
end := math.isqrt(n)
|
||||
end := n->isqrt()
|
||||
|
||||
out := 0
|
||||
for i in 1..end+1
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
func main[] : i64
|
||||
n := 37107287533 + 46376937677 + 74324986199 + 91942213363 + 23067588207 + 89261670696 + 28112879812 + 44274228917 + 47451445736 + 70386486105 + 62176457141 + 64906352462 + 92575867718 + 58203565325 + 80181199384 + 35398664372 + 86515506006 + 71693888707 + 54370070576 + 53282654108 + 36123272525 + 45876576172 + 17423706905 + 81142660418 + 51934325451 + 62467221648 + 15732444386 + 55037687525 + 18336384825 + 80386287592 + 78182833757 + 16726320100 + 48403098129 + 87086987551 + 59959406895 + 69793950679 + 41052684708 + 65378607361 + 35829035317 + 94953759765 + 88902802571 + 25267680276 + 36270218540 + 24074486908 + 91430288197 + 34413065578 + 23053081172 + 11487696932 + 63783299490 + 67720186971 + 95548255300 + 76085327132 + 37774242535 + 23701913275 + 29798860272 + 18495701454 + 38298203783 + 34829543829 + 40957953066 + 29746152185 + 41698116222 + 62467957194 + 23189706772 + 86188088225 + 11306739708 + 82959174767 + 97623331044 + 42846280183 + 55121603546 + 32238195734 + 75506164965 + 62177842752 + 32924185707 + 99518671430 + 73267460800 + 76841822524 + 97142617910 + 87783646182 + 10848802521 + 71329612474 + 62184073572 + 66627891981 + 60661826293 + 85786944089 + 66024396409 + 64913982680 + 16730939319 + 94809377245 + 78639167021 + 15368713711 + 40789923115 + 44889911501 + 41503128880 + 81234880673 + 82616570773 + 22918802058 + 77158542502 + 72107838435 + 20849603980 + 53503534226
|
||||
n_str := str.from_i64(n)
|
||||
io.println(str.substr(n_str, 0, 10))
|
||||
io.println(n->to_str()->substr(0, 10))
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
func main[] : i64
|
||||
n := []
|
||||
array.push(n, 1)
|
||||
n := [1]
|
||||
|
||||
for j in 0..1000
|
||||
carry := 0
|
||||
for i in 0..n->size
|
||||
tmp : i64 = array.nth(n, i) * 2 + carry
|
||||
array.set(n, i, tmp % 10)
|
||||
tmp : i64 = n->nth(i) * 2 + carry
|
||||
n->set(i, tmp % 10)
|
||||
carry = tmp / 10
|
||||
while carry > 0
|
||||
array.push(n, carry % 10)
|
||||
n->push(carry % 10)
|
||||
carry = carry / 10
|
||||
|
||||
sum := 0
|
||||
for i in 0..n->size
|
||||
sum += array.nth(n, i)
|
||||
sum += n->nth(i)
|
||||
|
||||
io.println_i64(sum)
|
||||
|
||||
@@ -6,21 +6,21 @@ func main[] : i64
|
||||
sum := 0
|
||||
|
||||
for i in 1..10
|
||||
sum += array.nth(s1, i)
|
||||
sum += s1->nth(i)
|
||||
for i in 0..10
|
||||
sum += array.nth(s2, i)
|
||||
sum += s2->nth(i)
|
||||
for i in 20..100
|
||||
sum += array.nth(s3, i / 10) + array.nth(s1, i % 10)
|
||||
sum += s3->nth(i / 10) + s1->nth(i % 10)
|
||||
|
||||
for i in 1..10
|
||||
sum += array.nth(s1, i) + 7
|
||||
sum += s1->nth(i) + 7
|
||||
for j in 1..10
|
||||
sum += array.nth(s1, i) + 7 + 3 + array.nth(s1, j)
|
||||
sum += s1->nth(i) + 7 + 3 + s1->nth(j)
|
||||
for j in 0..10
|
||||
sum += array.nth(s1, i) + 7 + 3 + array.nth(s2, j)
|
||||
sum += s1->nth(i) + 7 + 3 + s2->nth(j)
|
||||
for j in 20..100
|
||||
sum += array.nth(s1, i) + 7 + 3 + array.nth(s3, j / 10) + array.nth(s1, j % 10)
|
||||
sum += s1->nth(i) + 7 + 3 + s3->nth(j / 10) + s1->nth(j % 10)
|
||||
|
||||
sum += array.nth(s1, 1) + 8
|
||||
sum += s1->nth(1) + 8
|
||||
|
||||
io.println_i64(sum)
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
func findmax[triangle: Array, row: i64, col: i64] : i64
|
||||
if row == 14
|
||||
return array.nth(array.nth(triangle, row), col)
|
||||
return (triangle->nth(row) as Array)->nth(col)
|
||||
|
||||
left := findmax(triangle, row + 1, col)
|
||||
right := findmax(triangle, row + 1, col + 1)
|
||||
|
||||
return array.nth(array.nth(triangle, row), col) + math.max(left, right)
|
||||
return (triangle->nth(row) as Array)->nth(col) + math.max(left, right)
|
||||
|
||||
func main[] : i64
|
||||
triangle := []
|
||||
array.push(triangle, [75])
|
||||
array.push(triangle, [95, 64])
|
||||
array.push(triangle, [17, 47, 82])
|
||||
array.push(triangle, [18, 35, 87, 10])
|
||||
array.push(triangle, [20, 4, 82, 47, 65])
|
||||
array.push(triangle, [19, 1, 23, 75, 3, 34])
|
||||
array.push(triangle, [88, 2, 77, 73, 7, 63, 67])
|
||||
array.push(triangle, [99, 65, 4, 28, 6, 16, 70, 92])
|
||||
array.push(triangle, [41, 41, 26, 56, 83, 40, 80, 70, 33])
|
||||
array.push(triangle, [41, 48, 72, 33, 47, 32, 37, 16, 94, 29])
|
||||
array.push(triangle, [53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14])
|
||||
array.push(triangle, [70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57])
|
||||
array.push(triangle, [91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48])
|
||||
array.push(triangle, [63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31])
|
||||
array.push(triangle, [4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23])
|
||||
triangle->push([75])
|
||||
triangle->push([95, 64])
|
||||
triangle->push([17, 47, 82])
|
||||
triangle->push([18, 35, 87, 10])
|
||||
triangle->push([20, 4, 82, 47, 65])
|
||||
triangle->push([19, 1, 23, 75, 3, 34])
|
||||
triangle->push([88, 2, 77, 73, 7, 63, 67])
|
||||
triangle->push([99, 65, 4, 28, 6, 16, 70, 92])
|
||||
triangle->push([41, 41, 26, 56, 83, 40, 80, 70, 33])
|
||||
triangle->push([41, 48, 72, 33, 47, 32, 37, 16, 94, 29])
|
||||
triangle->push([53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14])
|
||||
triangle->push([70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57])
|
||||
triangle->push([91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48])
|
||||
triangle->push([63, 66, 4, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31])
|
||||
triangle->push([4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23])
|
||||
|
||||
io.println_i64(findmax(triangle, 0, 0))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
func multiply[n: Array, x: i64] : void
|
||||
carry := 0
|
||||
for i in 0..n->size
|
||||
prod : i64 = array.nth(n, i) * x + carry
|
||||
array.set(n, i, prod % 10)
|
||||
prod : i64 = n->nth(i) * x + carry
|
||||
n->set(i, prod % 10)
|
||||
carry = prod / 10
|
||||
while carry > 0
|
||||
array.push(n, carry % 10)
|
||||
n->push(carry % 10)
|
||||
carry = carry / 10
|
||||
|
||||
func main[] : i64
|
||||
@@ -16,6 +16,6 @@ func main[] : i64
|
||||
|
||||
sum := 0
|
||||
for i in 0..n->size
|
||||
sum += array.nth(n, i)
|
||||
sum += n->nth(i)
|
||||
|
||||
io.println_i64(sum)
|
||||
|
||||
Reference in New Issue
Block a user