-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
int("")==0
; adding trim()
, trim_left()
and trim_right()
; new …
…`-no-register` option to disable register optimizations (#272) * Allow leanier string to int conversion * Don't break the hex/octal/binary * Adding trim, trim_left, trim_right * linter fix * Added -no-register flag/option - makes advent 11 faster yet ... still too slow * Adding advent day 11 code
- Loading branch information
Showing
9 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// https://adventofcode.com/2024/day/11 | ||
|
||
func applyRules(v, depth) { | ||
if depth == 0 { | ||
1 | ||
} else if v == 0 { | ||
applyRules(1, depth-1) | ||
} else { | ||
s := str(v) | ||
l := len(s) | ||
depth = depth - 1 | ||
if l%2 == 1 { | ||
applyRules(2024*v, depth) | ||
} else { | ||
left := int(s[0:l/2]) | ||
right := int(trim_left(s[l/2:l], "0")) | ||
applyRules(left, depth) + applyRules(right, depth) | ||
} | ||
} | ||
} | ||
|
||
n :=25 | ||
println(applyRules(125,n)+applyRules(17,n)) | ||
|
||
// Despite auto memoization, this is still too slow even with the new -no-register | ||
|
||
// n = 75 | ||
// println(applyRules(125,n)+applyRules(17,n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters