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 / main.cc
Last active October 10, 2023 03:46
A simple tutorial on C++11's random number generators.
// Compile with:
// $ clang++ -O3 -std=C++11 main.cc -o main
#include <iostream>
#include <random> // The header for the generators.
#include <ctime> // To seed the generator.
using namespace std;
int main() {
@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
@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 / 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;
/// 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 / fol.pegjs
Created October 1, 2016 03:04
PEGJs Logic + Math parser
{
function getTerms(t, ts) {
if (t) {
var arr = [];
for (var i = 0; i < ts.length; ++i) {
arr.push(ts[i][2]);
}
return [t].concat(arr);
}
return [];
@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.

@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 / formula.cpp
Created May 1, 2015 02:21
Playing with propositional logic / first-order logic in C++ with boost::variant.
#include <iostream>
#include <string>
#include <memory>
#include <set>
#include <boost/variant.hpp>
#include <format.h>
// Selection of symbols
/** A set of symbols for printing / parsing formula. */
@PhDP
PhDP / ge.h
Created March 22, 2020 21:36
Draft of grammatical evolution.
/**
* @file grammatical_evolution.h
* @brief Functions to use grammatical evolution to evolve programs, mathematical
* functions, sentences, whatever you want, just use your imagination!
*/
#ifndef RAW_GRAMMATICAL_EVOLUTION_H_
#define RAW_GRAMMATICAL_EVOLUTION_H_
#include "raw/common.h"
#include "raw/grammar.h"