Skip to content

Instantly share code, notes, and snippets.

View tanishiking's full-sized avatar
🤖

Rikito Taniguchi tanishiking

🤖
View GitHub Profile
object FibGen {
def main(args: Array[String]): Unit = {
fibGen.take(10).print
}
private[this] lazy val fibGen: Stream[Int] = 0 #:: 1 #:: fibGen.zip(fibGen.tail).map(n => n._1 + n._2)
}
scala> (1 to 10000000).filter(_ % 2 == 0).take(5)
// Range(1, 2, ...., 10000000) というコレクションを展開した上で
// 全てに対して filter などの処理がが行われるためメモリに大きな負担を与え
// 最終的に必要なのは前方5つだけなのに全体をなめるので処理にかなり時間がかかる.
scala> (1 to 10000000).view.filter(_ % 2 == 0).take(5).force
res0: scala.collection.immutable.IndexedSeq[Int] = Vector(5, 10, 15, 20, 25)
// filter や take は遅延評価される
// force メソッドで正格なコレクションに戻すことができる.
scala> 1 :: 2 :: 3 :: Nil
res22: List[Int] = List(1, 2, 3)
scala Stream.cons(1, Stream.cons(2, Stream.cons (3, Stream.empty)))
res23: Stream.Cons[Int] = Stream(1, ?)
scala> 1 #:: 2 #:: 3 #:: Stream.empty
res24: scala.collection.immutable.Stream[Int] = Stream(1, ?)
# -*- coding: utf-8 -*-
from time import sleep
import json
import pickle
import lxml.html
TARGET_URL = 'http://www.kyochari-navi.jp/churin/index.html'
BASE_URL = 'http://www.kyochari-navi.jp/churin/'
from sys import maxsize
class Alignmenter(object):
def __init__(self, array1, array2):
self.array1 = array1
self.array2 = array2
self.rows = len(self.array1) + 1
self.cols = len(self.array2) + 1
self.table = []
object LevenshteinDistance {
private def editDistance(str1: String, str2: String): Int = {
val cols: Int = str1.length
val rows: Int = str2.length
val chars1: Array[Char] = str1.toCharArray
val chars2: Array[Char] = str2.toCharArray
val dp = new Array[Array[Int]](rows + 1).map(ys => new Array[Int](cols + 1))
for (row <- 0 to rows) {
dp(row)(0) = row
object problem50 {
def getMaxSumOfPrimes(limit: Int): Option[Int] = {
// 1000000以下の素数の遅延リスト
lazy val primes: Stream[Int] = Stream.cons(2, Stream.from(3).filter(i => primes.takeWhile(j => j * j <= i).forall(i % _ > 0))).takeWhile(_ <= limit)
def isPrime(num: Int): Boolean = primes.contains(num)
// 素数を小さい順に足していって1000000以下で最大となるまでの素数の遅延リスト
val primeSumLimit: List[Int] = primes.takeWhile(i=> primes.takeWhile(_ <= i).map(_.toLong).sum <= limit).toList
for (span <- primeSumLimit.length to 1 by -1) {
if (primeSumLimit.sliding(span).map(_.sum).exists(isPrime)) {
class hoge:
def __init__(self):
self.a = 1
def __get_a(self):
return self.a
def geta(self):
# 普通に __get_a()にアクセスできる
a = self.__get_a()
return a
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
RUN add-apt-repository "deb http://dl.hhvm.com/ubuntu $(lsb_release -sc) main"
RUN apt-get update
RUN apt-get install -y hhvm
RUN hhvm --version
import numpy as np
import matplotlib
from math import sqrt
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
def binomial_to_normal(samples, trials, probability, bins=50):
data = []
for i in range(samples):