Skip to content

Instantly share code, notes, and snippets.

@XerxesZorgon
XerxesZorgon / curveString.m
Created October 20, 2020 18:16
Generates string for Bezier curves in GeoGebra
% Generates Bezier polynomials in x and y for use in Geogebra
%
%
% Input(s)
% n: Degree of Bezier curve
%
% Output(s)
% cStr: String used to define Bezier curve in Geogebra
%
% Example:
@XerxesZorgon
XerxesZorgon / Turtles Circling Sun and Moon.nlogo
Created November 18, 2020 19:32
NetLogo demonstration of circling turtles
@XerxesZorgon
XerxesZorgon / kFilt.gp
Created December 30, 2020 22:12
Filtering function for KenKen in PARI/GP
/*
Filters vectors for KenKen game
Inputs
v: vector
c: Number of elements in the sum (size of the KenKen cell)
n: Maximum value in the sum (length of a side in the game)
u: T/F flag for uniqueness. Set if the cell is contained in a single row or column
e: Exclusion set vector. Numbers appearing in the same row or column as the cell
@XerxesZorgon
XerxesZorgon / unique.gp
Created December 30, 2020 22:16
PARI/GP function returns unique elements of a vector, tests vectors for uniqueness
/*
Returns a vector of the unique elements of v
Input
v: vector
Output
u: Vector of unique elements of v
Example:
@XerxesZorgon
XerxesZorgon / mnumbpart.gp
Created December 30, 2020 22:19
Returns the cardinality of the multiplicative partition set for an integer (in PARI/GP)
/*
Returns the number of multiplicative partitions of integer n
Ref: https://oeis.org/A001055
https://oeis.org/A162247
https://oeis.org/A162247/a162247.txt
Inputs:
n: Non-negative integer
m: Maximum factor (optional)
@XerxesZorgon
XerxesZorgon / mpartitions.gp
Created December 30, 2020 22:21
PARI/GP function to generate the set of multiplicative partitions of a non-negative integer
/*
Returns the multiplicative partition of integer n
Ref: https://oeis.org/A001055
https://oeis.org/A162247
https://oeis.org/A162247/a162247.txt
Inputs:
n: Non-negative integer
Output:
@XerxesZorgon
XerxesZorgon / montyhall.r
Created January 9, 2021 16:47
Simulates the Monty Hall problem in R
# Monty Hall problem simulation
#
# Parameters
# ----------
# n: Number of samples
#
# Returns
# -------
# p: Probability of winning
#
@XerxesZorgon
XerxesZorgon / meshFunctions.m
Created March 9, 2021 22:36
Octave code to estimate volume from point meshes
% Opens a .ply mesh file, creates mesh structure with faces, vertices
% Requires plyread function:
% https://www.mathworks.com/matlabcentral/fileexchange/47484-plyread-m?s_tid=srchtitle
% https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/47484/versions/1/previews/plyread.m/index.html
%
%
% Input(s)
% plyFile: Name of .ply file to read (inc. path)
%
% Output(s)
@XerxesZorgon
XerxesZorgon / chakravala.gp
Last active March 27, 2021 23:58
Solves the Brahmagupta (Pell) equation using the chakravala method
/*
Finds the minimal solution to a Pell's equation, a^2 - nb^2 = 1 for given n
Inputs:
n: Non-negative integer
Output:
a,b: Minimal solution to Pell's equation
Example:
@XerxesZorgon
XerxesZorgon / MLB_brier.r
Created April 23, 2021 21:36
Calculates the Brier Score for the 2020 MLB season using Skiena and Bayes predictors
# Skiena probability in 1-on-1 match
# Based on Skiena "Calculated Bets"
#
# Parameters
# ----------
# a,b: Probability of win against all competitors for Teams A, B
#
#
# Returns
# -------