Skip to content

Instantly share code, notes, and snippets.

Martin Møller Skarbiniks Pedersen MartinMSPedersen

Block or report user

Report or block MartinMSPedersen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View RSA_simple.R
# work-in-progress
# based on https://www.di-mgt.com.au/rsa_alg.html
library(gmp)
# returns a random odd value. The first bit and last bit is 1.
random_value <- function(how_many_bits = 512) {
hex_values <- ceiling(how_many_bits/4)-4
if (hex_values < 1) stop("more bits please.")
result <- c(
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")
}
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)
@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 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 / 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 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 / 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)
@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)
}
You can’t perform that action at this time.