shnarazk / advent-of-code Goto Github PK
View Code? Open in Web Editor NEWThe annual event for computer science enthusiasts!
Home Page: https://adventofcode.com
License: Creative Commons Zero v1.0 Universal
The annual event for computer science enthusiasts!
Home Page: https://adventofcode.com
License: Creative Commons Zero v1.0 Universal
×4;⍥(|2.2 +1⊙(+÷∶2×+2.+1×4).)/× 50_1000_1000 0 0 # 28.03
×4;⍥(|2.2 +1∶+⊙∶÷∶2×+2.+1×4.)/× 50_1000_1000 0 0 # 30.71
Copy the idea used in the BQN program, which uses the upper bounds of robots.
introduces the upper bounds of robots as the BQN version
commit | time |
---|---|
ff7a60e | 75.24 |
44c0d12 | 3.98 |
The following change is a degression.
diff --git a/bqn/2022/day19.bqn b/bqn/2022/day19.bqn
index 033c888..cfd2262 100755
--- a/bqn/2022/day19.bqn
+++ b/bqn/2022/day19.bqn
@@ -15,13 +15,12 @@ Solve ⇐ { part 𝕊 line:
𝕊 ⟨⟩: best;
𝕊 to_visit:
𝕊 ⟨⟩ { time‿resources‿robots 𝕊 next:
- { 𝕊 i:
+ next { i 𝕊 next:
upto< t ← time- w ← 1+⌈⌈´(i⊏masks)/robots÷˜(n ← i⊏bp)(0⊸⌈-)resources ?
- { ¬∨´(∧´𝕩⊸≤)¨next ? next ⟨𝕩⟩⊸∾ ↩ ;@ } t∾(n-˜resources+w×robots)∾((1⊸+)⌾(i⊸⊑)robots)
+ { ¬∨´(∧´𝕩⊸≤)¨next ? ⟨𝕩⟩∾next ; next } t∾(n-˜resources+w×robots)∾((1⊸+)⌾(i⊸⊑)robots)
;
- best ((¯1⊑resources)+(time-upto)ׯ1⊑robots)⊸⌈ ↩
- }¨{robots<○(𝕩⊸⊑)limits }¨⊸/↕4
- next
+ best ((¯1⊑resources)+(time-upto)ׯ1⊑robots)⊸⌈ ↩, next
+ }´{robots<○(𝕩⊸⊑)limits }¨⊸/↕4
}´{⟨⊑𝕩,4↑1↓𝕩,5↓𝕩⟩}¨to_visit
}
(•Fmt n) lib.Debug Expand ⟨⟨0⟩∾⟨0,0,0,0⟩∾⟨1,0,0,0⟩⟩ # ⟨time,resources,robots⟩
Is this a path-finding problem?
Over
advent-of-code/bqn/2022/day21.bqn
Line 4 in 6656829
But all operators are evaluated once. So hardly expect speedup.
see #21
But in Pharo.
Add --serialize
option.
flowchart LR
rust/serde -- serialize --> Id1[(JSON)]
Id1[(JSON)] --> Pharo/Roassal
[Metacello new
baseline: 'Roassal';
repository: 'github://pharo-graphics/Roassal';
load: 'Full' ] on: MCMergeOrLoadWarning do: [:warning | warning load ]
| data nodes canvas lb elements |
data :='/Users/nash/Repositories/advent-of-code/day25.json' asFileReference readStreamDo: [ :stream | STON fromStream: stream ].
nodes := data inject: (Dictionary new) into: [ :dic :element | dic at: (element at:1) update: [ :set | set add: (element at: 2);yourself] initial: [Set new add: (element at: 2); yourself ]; yourself].
data do: [ :each | | to | to := each at: 2. (nodes keys includes: to) not ifTrue: [ nodes at: to put: { } ] ].
canvas := RSCanvas new.
elements := nodes keys collect: [ :c | RSEllipse new size: 5; model: c] as: RSGroup.
elements @ RSDraggable .
canvas addAll: elements .
lb := RSLineBuilder line.
lb canvas: canvas.
lb color: Color red.
lb connectFromAll: [:each | nodes at: each ].
RSForceBasedLayout new on: elements.
canvas @ RSCanvasController.
lb canvas.
under development
advent-of-code/bqn/2022/day19.bqn
Lines 12 to 24 in 2851da7
does not finish and
is a cheat so far.
$ cargo run -- 2022 23 0 0 > 2022-12-23.json
func _ready():
var file = FileAccess.open("res://2022-12-23.json", FileAccess.READ)
var content = file.get_as_text()
var j = JSON.parse_string(content)
for elf in j:
var c = cube.instantiate()
c.position.x = float(elf["x"])
c.position.y = float(elf["y"])
add_child(c)
Cuis requires Json package to handle it.
s := 'Repositories/GD4.1/2022-12-23.json' fileContents.
j := Json readFrom: (ReadStream on: s from: 0 to: s size).
(j at: 1 ) at: 'x'
The updating expression might contain self-reference, that disabled the early release of memory.
advent-of-code/bqn/2018/day14.bqn
Line 2 in eccb2fc
Not make sense to define type Answer
.
cargo clippy
cargo update
see #21
But in Pharo.
Add --serialize
option.
flowchart LR
rust/serde -- serialize --> Id1[(JSON)]
Id1[(JSON)] --> Pharo/Roassal
[Metacello new
baseline: 'Roassal';
repository: 'github://pharo-graphics/Roassal';
load: 'Full' ] on: MCMergeOrLoadWarning do: [:warning | warning load ]
Where should I put them?
Added https://github.com/shnarazk/learn-bqn
!/usr/bin/env bqn
# Advent of Code 2022 Day 01
input ← ⟨199, 200, 208, 210, 200, 207, 240, 269, 260, 263⟩
•Show +´{(0⊸⊏𝕩)<(1⊸⊏𝕩)}˘(2⊸↕)input
•Show +´{(0⊸⊏𝕩)<(1⊸⊏𝕩)}˘(2⊸↕)+´˘3↕ input
It's a cheat
under construction
progress!("{x}");
is expanded to
dbg!("\[33m??{x}\[33m");
Dim2<usize>
, Vec2<usize>
Vec2<isize>
, Dim2<isize>
Dim3<usize>
, Vec3<usize>
Vec3<isize>
, Dim3<isize>
y2021 day5
commit | time |
---|---|
3df882b2c3b5a8cdf38f406d71e7a4613a395c68 | 64.77 |
f86ba2ad14043c5d4589c9f9ba9c25fd38cf6673 | 0.26 |
The next drop traces the same path as the previous one!
So it'll help to speed up the BQN version.
old: ./aoc.bqn 2022 14 2 95.91s user 0.07s system 99% cpu 1:36.12 total
new: ./aoc.bqn 2022 14 2 95.73s user 0.19s system 99% cpu 1:36.12 total
On the flip side:
cargo run --release -- 2022 14 2 0.17s user 0.02s system 65% cpu 0.297 total
Again!
Stop checking all points in the solution space.
It should be on the edge of one of the sensing spaces.
So the complexity should be
Make an iterator traversing the edge of a sensor.
scheme | time1 | time2 | time3 |
---|---|---|---|
new | 10.11 | 10.32 | 10.28 |
--release | 0.55 | 0.55 | 0.55 |
brute-force | 10.63 | 10.56 | 10.56 |
--release | 0.90 | 0.88 | 0.91 |
This was a good idea. The checking cost seems high.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.