Skip to content

Instantly share code, notes, and snippets.

View MartinMSPedersen's full-sized avatar
🎯
Focusing

Martin Møller Skarbiniks Pedersen MartinMSPedersen

🎯
Focusing
View GitHub Profile
@MartinMSPedersen
MartinMSPedersen / hat3.R
Last active January 8, 2019 22:30
Hat number 3 in R
x <- function(k, t) {
c( -sin(4*pi*k/1000) + sin(t)*sin(t/3)/5,
-0.5*sin(8*pi*k/1000) + cos(t)/2
)
}
y <- function(k, t) {
c( -cos(2*pi*k/1000) + cos(t)*cos(t/3)/2,
-0.5*cos(4*pi*k/1000) + sin(t)/3
@MartinMSPedersen
MartinMSPedersen / pentalath-board.R
Created January 19, 2019 11:33
Program to generate a Pentalath/Ndengrod board using original layout
library(ggplot2)
hexdf <- function (size = 1, mid = c(0, 0), angle = 90) {
width <- size * 1
height <- size * 0.865
xy <- shape:::getellipse(width, height, mid = mid, dr = 2 * pi/6)
tibble::as_tibble(structure(as.data.frame(
shape::rotatexy(xy,angle = angle, mid = mid)), class = "data.frame", names = c("x", "y")), validate = FALSE)
}
@MartinMSPedersen
MartinMSPedersen / yavalath-board.R
Created January 19, 2019 12:18
Program to generate a Yavalath board
# Yavalath board
library(ggplot2)
hexdf <- function (size = 1, mid = c(0, 0), angle = 90) {
width <- size * 1
height <- size * 0.865
xy <- shape:::getellipse(width, height, mid = mid, dr = 2 * pi/6)
tibble::as_tibble(structure(as.data.frame(
shape::rotatexy(xy,angle = angle, mid = mid)), class = "data.frame", names = c("x", "y")), validate = FALSE)
@MartinMSPedersen
MartinMSPedersen / three_circles.R
Last active January 21, 2019 14:08
Three circles
circleFunc <-
function(center = c(0,0), diameter = 1, npoints = 100, start = 0, end = 2*pi) {
tt <- seq(start, end, length.out = npoints)
data.frame(x = center[1] + diameter / 2 * cos(tt),
y = center[2] + diameter / 2 * sin(tt))
}
add.alpha <- function(col, alpha = 1) {
if(missing(col))
stop("Please provide a vector colors.")
@MartinMSPedersen
MartinMSPedersen / noisyCircles.R
Created January 26, 2019 23:48
Lots of circle placed in a larger circle with some noise
library(ggplot2)
circle_alpha <- 0.3
radius1 <- 25
radius2 <- 75
how_many <- 200
reverse_colors <- FALSE
circleFunc <-
function(center = c(0,0), radius = 1, npoints = 100, start = 0, end = 2*pi) {
polygon <- function(n) {
tibble(
x = accumulate(1:(n-1), ~.x+cos(.y*2*pi/n), .init = 0),
y = accumulate(1:(n-1), ~.x+sin(.y*2*pi/n), .init = 0),
xend = accumulate(2:n, ~.x+cos(.y*2*pi/n), .init = cos(2*pi/n)),
yend = accumulate(2:n, ~.x+sin(.y*2*pi/n), .init = sin(2*pi/n)))
}
ggplot(polygon(5) + geom_segment(aes(x=x, y=y, xend=xend, yend=yend)) + theme_void() + coord_equal()
@MartinMSPedersen
MartinMSPedersen / compute-pi.R
Created May 15, 2019 21:34
Compute 1 million of PI using R
library(gmp)
ONE <- as.bigz("1")
TWO <- as.bigz("2")
THREE <- as.bigz("3")
FOUR <- as.bigz("4")
SEVEN <- as.bigz("7")
TEN <- as.bigz("10")
q <- as.bigz("1")
#http://rosettacode.org/wiki/Generate_Chess960_starting_position
pieces <- c("R","B","N","Q","K","N","B","R")
generateFirstRank <- function() {
attempt <- paste0(sample(pieces), collapse = "")
while (!check_position(attempt)) {
attempt <- paste0(sample(pieces), collapse = "")
}
return(attempt)
library(digest)
DEBUG <- FALSE
while(TRUE) {
flag <- paste0(c(sample(c(letters,LETTERS,0:9,":","_","+"), 8, replace = TRUE)), collapse = "")
shasum <- substr(digest(flag,"md5", serialize=FALSE), 27,32)
cat(flag,shasum,"\n")
}