Skip to content

Instantly share code, notes, and snippets.

View PhDP's full-sized avatar
🏠
Working from home

Philippe Desjardins-Proulx PhDP

🏠
Working from home
View GitHub Profile
@PhDP
PhDP / adj.jl
Last active November 26, 2020 19:56
AdjacencySet for Graphs in Julia
# A graph as a vector of sorted vectors. This is very similar to the way sparse matrices
# are represented except each vertex has its own sorted vector (making it much faster to
# add/remove edges). Using BTrees instead of sorted vector would improve performance for
# adding/removing edges.
#WeightedGraph = Vector{Vector{(UInt32, Float64)}}
Graph = Vector{Vector{UInt32}} # Make more generic...
# There has to be a better way (map?):
function make_graph(order)
@PhDP
PhDP / rust.md
Last active September 23, 2021 22:09
Installing Rust

Installing Rust

Most editors/IDEs have good Rust support at this point, but I recommend Visual Code with Rust Analyzer.

Linux or OSX

Simply copy and paste the command from the rustup website (here) in a terminal. Rustup will install the rustc compiler and, just as importantly, the cargo package manager.

/// You need to add these lines to Cargo.toml's [dependencies]:
/// statrs = "0.15.0"
/// nalgebra = "0.29.0"
use statrs::distribution::{Binomial, Discrete};
use nalgebra::base::DVector;
use nalgebra::dvector;
// Builds a vector of evenly spaced floats within a closed interval [a, b].
pub fn linspace(a: f64, b: f64, n: usize) -> DVector<f64> {
@PhDP
PhDP / euler7.rs
Created January 15, 2022 22:34
euler7.rs
fn nth_primes(n: usize) -> usize {
match n {
0 => 1,
1 => 2,
2 => 3,
_ => {
let mut primes = vec![2, 3];
let mut candidate = 5;
loop {
let max = (candidate as f64).sqrt() as usize;
@PhDP
PhDP / leansandbox.lean
Created October 4, 2022 18:54
Random lean code
def hello := "world"
open List
#check Nat.zero
#check Nat.succ
#check Nat.succ 0
#check Nat.add
#check Nat.add 1
#check Nat.add 2 2
@PhDP
PhDP / lean3-sandbox.lean
Last active October 11, 2022 18:30
First few problems in the Lean 3 number game.
import data.real.basic
#check ℝ
open nat
-- Links:
-- * Lean 3's big math library: https://github.com/leanprover-community/mathlib
-- * Number game: https://www.ma.imperial.ac.uk/~buzzard/xena/natural_number_game/
-- * Agda's Unimath library: https://github.com/UniMath/agda-unimath