Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visualization with Julia #84

Merged
merged 6 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions misc/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# shellcheck shell=bash
source $HOME/.config/direnv/envrc
use flake
61 changes: 61 additions & 0 deletions misc/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions misc/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
description = "A basic flake with a shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.default = pkgs.mkShell {
packages = [
pkgs.bashInteractive
pkgs.graphviz
pkgs.julia-bin
];
};
});
}
37 changes: 37 additions & 0 deletions misc/grid18.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env julia
import Pkg
# Pkg.add("JSON"),
# Pkg.add("Plots"),
# Pkg.add("GridVisualize"),
# Pkg.add("Colors"),
using JSON, Plots, Colors

grid_data = JSON.parse(read("2024/day18.json", String))["line"]

# Extract dimensions of the grid
rows = 1 + maximum([g[1] for g in grid_data])
cols = 1 + maximum([g[2] for g in grid_data])
len = length(grid_data)

# Create an empty matrix for plotting purposes
grid_matrix = fill(RGB(1.0, 1.0, 1.0), rows, cols)
for (i, g) in enumerate(grid_data)
c = (len - i) / len
grid_matrix[g[1]+1, g[2]+1] = RGB(c, c, c)
end
grid_matrix[1, 1] = RGB(1.0, 0.0, 0.0)

# color_map = Dict(
# :red => RGB(1.0, 0.0, 0.0),
# :white => RGB(1.0, 1.0, 1.0),
# :black => RGB(0.0, 0.0, 0.0),
# )
# color_matrix = [color_map[element] for element in grid_matrix]

heatmap(
# color_matrix,
grid_matrix,
title="Y2024 day18",
aspect_ratio=:equal
)
savefig("day18-grid.png")
34 changes: 34 additions & 0 deletions misc/hist2024.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env julia
# import Pkg
# Pkg.add("JSON")
# Pkg.add("Plots")
# Pkg.add("KernelDensity")
using JSON, Plots, KernelDensity

data2024 = read("2024/execution_time.json", String)
data = JSON.parse(data2024)
times = [item["time"] for item in data if haskey(item, "time")]
tl = log2.(times)
ktd = kde(tl)

histogram(
tl,
xlims=(-5, 20),
ylims=(0, 0.4),
bins=20,
normalize=true,
title="AoC2024 execution time distribution in Rust",
xlabel="log2(time[ms])",
# xlabel="時間",
ylabel="Freq",
legend=false,
# fontfamily="Noto Sans CJK JP"
)
plot!(
ktd.x,
ktd.density,
ylims=(0, 0.4),
color=:red,
linewidth=2)

savefig("hist2024.png")