Skip to content

Instantly share code, notes, and snippets.

@Akiyah
Akiyah / graph_animation.r
Last active January 8, 2022 13:07
graph_animation
#install.packages("ggplot2")
library(ggplot2)
path <- '~/Dropbox/tech/graph_animation'
fun <- function(x) 2^x
for (j in seq(66, 98, by=1)) {
p <- ggplot(data=data.frame(X=c(-1, 10 + 1)), aes(x=X))
p <- p + stat_function(fun=fun)
draw <- function(l, filename) {
png(filename, width=500, height=500)
barplot(dpois(0:10, l), names.arg=0:10, ylim=c(0,1), col="#993435")
text(5, 0.8, paste0("λ=", sprintf("%1.1f", l)), cex=5)
dev.off()
}
l <- (1:50) / 10
for (i in 1:length(l)) {
draw(l[i], sprintf("plot_%04d.png", i))
@Akiyah
Akiyah / function_dsl.r
Last active October 26, 2019 16:36
slime_equation_edit
# plus
"%+%" <- function(f, g) {
return(paste0("(", f, ") * (", g,")"))
}
# minus
m <- function(f) {
paste0( "-(", f, ")" )
}
@Akiyah
Akiyah / result.txt
Last active May 4, 2019 14:38
Solver of RubyKaigi 2019 Cookpad Daily Ruby Puzzles
Example
2019-05-04 02:31:22 +0900
...........................
-----
def foo
"Hello world" if%
false
end
puts foo
require 'benchmark'
M = 1000
Benchmark.bm 30 do |r|
[1, 10, 100, 1000].each do |n|
a = (0...(n*100)).to_a
b0 = ((0*n)...(1*n)).to_a
b1 = ((1*n)...(2*n)).to_a
b2 = ((2*n)...(3*n)).to_a
outer_product <- function (a, b) {
c(a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1])
}
d <- function(t) {
s <- t/sqrt(3)
h <- sqrt(1 - ((1 + sqrt(3)/2)^2 + (1/2)^2)*s^2)
A <- c(s, 0, 0)
B <- c(-1/2*s, sqrt(3)/2*s, 0)
outer_product <- function (a, b) {
c(a[2]*b[3] - a[3]*b[2], a[3]*b[1] - a[1]*b[3], a[1]*b[2] - a[2]*b[1])
}
d <- function(t) {
s <- t/sqrt(3)
h <- sqrt(1 - ((1 + sqrt(3)/2)^2 + (1/2)^2)*s^2)
A <- c(s, 0, 0)
B <- c(-1/2*s, sqrt(3)/2*s, 0)
library(gmp)
library(gtools)
MARIO <- paste0(
" ...",
" ***** ...",
" *********..",
" @@@..@. @@@",
" @.@...@...@@",
" @.@@...@...@",
@Akiyah
Akiyah / README
Last active November 19, 2016 02:41
Oimo.jsとThree.jsでマウスドラッグ
WebGL必要です
@Akiyah
Akiyah / README
Last active March 6, 2016 16:52
Raphaelで手描き風の線
参考
https://bramp.github.io/js-sequence-diagrams/