Giter VIP home page Giter VIP logo

advent-of-code's People

Contributors

dependabot[bot] avatar shnarazk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

timminn

advent-of-code's Issues

(uiua) which one is better?

×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

y2022 day19 part2 needs something to prune branches

Rust side

Copy the idea used in the BQN program, which uses the upper bounds of robots.

records

introduces the upper bounds of robots as the BQN version

commit time
ff7a60e 75.24
44c0d12 3.98

BQN side

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⟩

y2023 day25

  • 2023 day18: 可視化するまで初期化に問題があるとは気づかなかった。
  • 2023 day20: 可視化するまで問題の構造に合わせた戦略を取れなかった。
  • 2023 day21: 可視化するまで処理過程のイメージが持てなかった。

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.
スクリーンショット 2023-12-29 10 48 51

Use _while_ instead of recursion

Expand ← {
𝕊 ⟨⟩ : best ;
𝕊 cands :
𝕊∧⟨⟩{time‿resources‿robots 𝕊 next :
{𝕊 i :
upto< t ← time-w ← 1+⌈⌈´(i⊏masks)/robots÷˜(n ← i⊏bp)(0⊸⌈-)resources ?
{¬∨´(∧´𝕩⊸≤)¨next ? next ⟨𝕩⟩⊸∾ ↩ ⋄ best ((4⊑𝕩)+(t-upto)ׯ1⊑𝕩)⊸⌈ ↩ ; @
}t∾(n-˜resources+w×robots)∾((1⊸+)⌾(i⊸⊑)robots)
; @
}¨{robots<○(𝕩⊸⊑)limits}¨⊸/↕4
next
}´{⟨⊑𝕩,4↑1↓𝕩,5↓𝕩⟩}¨cands
}

Visualization with Godot or Bevy

flow

$ 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'

better array update in uiua

Preparation for 2021

  • rename to advent-of-code
  • add a new branch or directory and set it as default
  • cargo clippy
  • cargo update
  • documentation on my framework

Embed an automatic visualization framework

  • 2023 day18: 可視化するまで初期化に問題があるとは気づかなかった。
  • 2023 day20: 可視化するまで問題の構造に合わせた戦略を取れなかった。
  • 2023 day21: 可視化するまで処理過程のイメージが持てなかった。

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 ]

BQN version

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⊸↕)inputShow +´{(0⊸⊏𝕩)<(1⊸⊏𝕩)}˘(2⊸↕)+´˘3input

y2022 day15

xで順序付け

2本の直線と二つの線分の全交点を求める問題:線分と直線の交差はするかしないかだけ

geogebra-export-3

Optimize the code for y2022 day14

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

y2022 day15 part2 better cands by iterating points on the (extended) edges

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 $O(4\times\mbox{sensor-range})$ instead of $O(400000^2)$.
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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.