Skip to content

Instantly share code, notes, and snippets.

Martin Møller Skarbiniks Pedersen MartinMSPedersen

View GitHub Profile
@MartinMSPedersen
MartinMSPedersen / hat3.R
Last active Jan 8, 2019
Hat number 3 in R
View hat3.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 Jan 19, 2019
Program to generate a Pentalath/Ndengrod board using original layout
View pentalath-board.R
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 Jan 19, 2019
Program to generate a Yavalath board
View yavalath-board.R
# 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)
View three_circles.R
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 Jan 26, 2019
Lots of circle placed in a larger circle with some noise
View noisyCircles.R
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) {
View polygon.R
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
Compute 1 million of PI using R
View compute-pi.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")
View Generate_Chess960_starting_position.R
#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)
View permutation_game.md5.R
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")
}
You can’t perform that action at this time.