Skip to content

Commit

Permalink
Merge pull request #84 from shnarazk/julia-visualization-20250105
Browse files Browse the repository at this point in the history
Visualization with Julia
  • Loading branch information
shnarazk authored Jan 11, 2025
2 parents 397e9e7 + fccb84f commit 0fa992e
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 0 deletions.
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")

0 comments on commit 0fa992e

Please sign in to comment.