Skip to content

Instantly share code, notes, and snippets.

@kazua
kazua / jojo1
Created September 11, 2012 14:35
JOJO
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>素数の時だけJOJO!</title>
<script type="text/javascript">
for(var i = 1; i <= 100; i++){
var c = 0;//カウンタを初期化
var p = 1;//素数フラグを立てる
for(var j = 1; j <= i; j++){
@kazua
kazua / jojo2
Created September 11, 2012 14:37
JOJO-Eratosthenes
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>素数の時だけJOJO!(エラトステネスの篩版)</title>
<script type="text/javascript" src="e:\works\prototype.js"></script>
<script type="text/javascript">
function createprimearray(x){
var primearray = new Array();//素数配列
var searcharray = new Array();//検索配列
@kazua
kazua / prime.scala
Created October 4, 2012 16:14
JOJO-Eratosthenes-scala
//素数の時だけjojo(エラトステネスの篩)
//K.A
import scala.math._
object prime {
def prime(acl : List[Int], sl : List[Int], ms : Int) : List[Int] = sl match {
case Nil => acl.reverse ::: sl
case sl => {
if (sl.head != 2 && (sl.isEmpty || pow(ms, 2) > sl.last)) acl.reverse ::: sl
@kazua
kazua / qksort.scala
Created October 12, 2012 16:35
scalaでクイックソート
object qksort {
def qksort(sl: List[Int]): List[Int] = {
sl match {
case List() => sl
case slh::sll => qksort(sll.filter(slh > _)) ::: List(slh) ::: qksort(sll.filter(slh < _))
}
}
def main(args: Array[String]) {
val ls = List(5, 27, 15, 31, 13, 23, 49, 16, 53, 39, 24, 11, 21, 63, 87)
qksort(ls).foreach{println}
@kazua
kazua / filesearch.scala
Created November 9, 2012 15:32
ファイル検索(ファイル名)
import java.io._
object filesearch {
def filesearch(path : String, schwds : String){
try{
new File(path).listFiles.map{
case d if d.isDirectory() => filesearch(d.getPath(), schwds)
case f if f.isFile() && f.getName().contains(schwds) => println(f.getPath())
case e => e
}
@kazua
kazua / fileinsearch.scala
Created November 9, 2012 15:32
ファイル検索(中身)
import java.io._
import scala.io.Source
object fileinsearch {
def fileinsearch(path : String, schwds : String, schext : String){
try{
new File(path).listFiles.map{
case d if d.isDirectory() => fileinsearch(d.getPath(), schwds, schext)
case f if f.isFile() && f.canRead() && f.getName().endsWith(schext) => {
@kazua
kazua / healthparameter.scala
Created November 11, 2012 16:09
健康チェック用
import scala.math._
object healthparameter {
def healthparameter(name : String, years : Int, sex : String, height : Double, weight : Double) : List[String] = {
lazy val heightm = if (height > 3.0) (height / 100.0) else height
val bmi = weight / pow(heightm, 2)
val sbw = pow(heightm, 2) * 22
val rohrerindex = weight / pow(height, 3) * 10000000
lazy val bmr = if (!sex.contains("f")) (13.397 * height) + (4.799 * height) - (5.677 * years) + 88.362
@kazua
kazua / writtenoracle.scala
Created November 13, 2012 12:58
おみくじ
import scala.math._
object writtenOracle {
def intCalcD(d : Double)(r : Double) : Int = floor((d + 1) * r).toInt
val destinyp = intCalcD(_:Double)(random)
def writtenOracle(name : String) : String = {
val destinypoint = destinyp(100)
destinypoint match {
@kazua
kazua / problem20.scala
Created November 13, 2012 16:31
Project Euler Problem 20
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2020
//K.A
object problem20 {
def sum(acl : Int, xs : List[String]) : Int = xs match {
case Nil => acl
case y :: ys => sum(acl + y.toInt, ys)
}
def problem20(is : Int) : Int ={
sum(0,(BigInt(1) to is).reverse.product.toString.split("").filter(_ != "").toList)
@kazua
kazua / problem21.scala
Last active October 12, 2015 18:48
Project Euler Problem 21
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2021
//K.A
object problem21 {
def calcAmicable(acl : Int, xs : List[Int]) : Int = xs match {
case Nil => acl
case y :: ys => {
val divisora = (Range(1,y + 1).toList.filter(y % _ == 0).sum - y)
calcAmicable(acl + (if (Range(1, divisora + 1).toList.filter(divisora % _ == 0).sum - divisora == y && divisora != y) divisora else 0), ys)
}