diff --git a/misc/.envrc b/misc/.envrc new file mode 100644 index 00000000..2ddd3a9c --- /dev/null +++ b/misc/.envrc @@ -0,0 +1,3 @@ +# shellcheck shell=bash +source $HOME/.config/direnv/envrc +use flake diff --git a/misc/flake.lock b/misc/flake.lock new file mode 100644 index 00000000..477036c5 --- /dev/null +++ b/misc/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1736241350, + "narHash": "sha256-CHd7yhaDigUuJyDeX0SADbTM9FXfiWaeNyY34FL1wQU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8c9fd3e564728e90829ee7dbac6edc972971cd0f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/misc/flake.nix b/misc/flake.nix new file mode 100644 index 00000000..f7f86888 --- /dev/null +++ b/misc/flake.nix @@ -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 + ]; + }; + }); +} diff --git a/misc/grid18.jl b/misc/grid18.jl new file mode 100755 index 00000000..a45cfecb --- /dev/null +++ b/misc/grid18.jl @@ -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") diff --git a/misc/hist2024.jl b/misc/hist2024.jl new file mode 100755 index 00000000..fd78a36a --- /dev/null +++ b/misc/hist2024.jl @@ -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")