Skip to content

Instantly share code, notes, and snippets.

View Koitaro's full-sized avatar

Yasusi Koibuti Koitaro

View GitHub Profile
@Koitaro
Koitaro / problem71.R
Created August 21, 2012 17:46
R: Project Euler 70-79
2 + (1000000-5) %/% 7 * 3
@Koitaro
Koitaro / problem62.R
Created August 18, 2012 10:03
R: Project Euler 60-69
library(gmp)
library(hash)
h <- hash()
n <- 1
maxDigits <- Inf
repeat {
v <- as.character(pow.bigz(n, 3))
s <- strsplit(v, "")[[1]]
@Koitaro
Koitaro / problem50.R
Created August 17, 2012 19:09
R: Project Euler 50-59
library(pracma)
library(gmp)
p <- primes(1e6%/%21)
answer <- 0
maxLength <- 0
while (length(p) > 0) {
x <- rev((x <- cumsum(p))[x < 1e6])
while (length(x) > 0) {
@Koitaro
Koitaro / problem41.R
Last active October 8, 2015 15:18
R: Project Euler 40-49
library(pracma)
xs <- colSums(t(perms(1:7)) * (10^(6:0)))
for (x in xs) if(isprime(x)) {answer <- x; break} else next
answer
@Koitaro
Koitaro / problem30.R
Last active October 8, 2015 13:18
R: Project Euler 30-39
limit <- 1
while (9^5*limit >= 10^limit) limit <- limit+1
n <- 2:(9^5*limit)
f <- function(x, y) (x %/% 10^y %% 10)^5
sum(n[n == rowSums(outer(n, limit:0, f))])
@Koitaro
Koitaro / problem20.R
Last active October 8, 2015 11:18
R: Project Euler 20-29
library(gmp)
n <- factorialZ(100)
sum(n %/% pow.bigz(10, (floor(log10(n)):0)) %% 10)
@Koitaro
Koitaro / problem10.R
Last active October 8, 2015 10:48
R: Project Euler 10-19
library(pracma)
sum(primes(2e6))
@Koitaro
Koitaro / problem1.R
Last active October 8, 2015 10:27
R: Project Euler 1-9
f <- function(n) {
x <- 999%/%n
x * (x + 1) / 2 * n
}
f(3) + f(5) - f(15)
@Koitaro
Koitaro / heap.go
Created June 27, 2012 15:09
Go: package Pairing heap
package heap
type Node struct {
Order
tails
}
type Order interface {
Ord(*Node) bool
}
@Koitaro
Koitaro / problem90.go
Created June 23, 2012 04:44
Go: Project Euler 90-99
package main
import (
"fmt"
"time"
)
type digits []int
func (xs digits) nexts() (answer []digits) {