Skip to content

Instantly share code, notes, and snippets.

@kazua
kazua / MailC.java
Created September 5, 2013 16:06
Javaでメール送信-commons-emailバージョン
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.activation.FileDataSource;
import org.apache.commons.mail.MultiPartEmail;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.codec.binary.Base64;
public class MailC {
private String mailP = "[\\w\\.\\-]+@(?:[\\w\\-]+\\.)+[\\w\\-]+";
@kazua
kazua / Mail.java
Created September 4, 2013 10:45
Javaでメール
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
@kazua
kazua / problem72.scala
Created August 23, 2013 15:15
Project Euler Problem 72
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2072
//http://projecteuler.net/index.php?section=problems&id=72
//write kazua
import scala.math._
import scala.collection.mutable._
object problem72 {
val lmt = 1000000
@kazua
kazua / jsonandwebstorage.html
Last active December 21, 2015 08:58
JSON読み込みとwebstorageの読み書きのお試し
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
//write kazua
var json = '{"record": ['
+ '{"name": "Yusuke Sasaki", "score": {"japanese" : 74, "english" : 65}},'
+ '{"name": "Kazuki Tajima", "score": {"japanese" : 61, "english" : 87}},'
+ '{"name": "Minako Ogawa", "score": {"japanese" : 45, "english" : 91}},'
@kazua
kazua / ArrayCustom3.js
Last active December 21, 2015 04:49
JavaScriptのArrayの拡張3
//write kazua
if (!Array.prototype.contains) {
Array.prototype.contains = function(value) {
for ( var i = 0; i < this.length; i++)
if (this[i] === value)
return true;
return false;
};
}
@kazua
kazua / ArrayCustom2.js
Last active December 20, 2015 21:58
JavaScriptのArrayの拡張2
//write kazua
if (!Array.prototype.contains) {
Array.prototype.contains = function(value) {
for ( var i = 0; i < this.length; i++)
if (this[i] === value)
return true;
return false;
};
}
@kazua
kazua / problem57.scala
Last active December 20, 2015 16:59
Project Euler Problem 57
//http://projecteuler.net/index.php?section=problems&id=57(英語)
//http://x2357.github.io/projecteuler_jatrans/problem/57.html(日本語)
//2の平方根は無限に続く連分数で表すことができる.
//√ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213...
//最初の4回の繰り返しを展開すると以下が得られる.
//1 + 1/2 = 3/2 = 1.5
//1 + 1/(2 + 1/2) = 7/5 = 1.4
//1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666...
//1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379...
//次の3つの項は99/70, 239/169, 577/408である. 第8項は1393/985である. これは分子の桁数が分母の桁数を超える最初の例である.
@kazua
kazua / problem45.scala
Created August 3, 2013 05:56
Project Euler Problem 45
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2045
//http://projecteuler.net/index.php?section=problems&id=45
//write kazua
import scala.math._
object problem45 {
def isPenNum(d : Double) = (sqrt(1.0 + 24.0 * d) + 1.0) / 6.0 == ((sqrt(1.0 + 24.0 * d) + 1.0) / 6.0).toInt
def problem45(n : Int = 143 + 1, a : Long = 0) : Long = a match {
@kazua
kazua / problem100.scala
Created July 31, 2013 12:56
Project Euler Problem 100
//Project Euler Problem 100
//箱の中に15個の青い円盤と6個の赤い円盤からなる21個の色のついた円盤が入っていて、無作為に2つ取り出すとき、青い円盤2つを取り出す確率P(BB)は
//P(BB) = (15/21) × (14/20) = 1/2であることがわかる。
//無作為に2つ取り出すとき、青い円盤2つを取り出す確率がちょうど1/2となるような次の組み合わせは、箱が85個の青い円盤と35個の赤い円盤からなるときである。
//箱の中の円盤の合計が1,000,000,000,000を超えるような最初の組み合わせを考える。箱の中の青い円盤の数を求めよ。
//write kazua
object problem100 {
def problem100(limit : Long, ac : Long = 21, bc : Long = 15) : Long = ac match {
@kazua
kazua / problem99.scala
Created July 20, 2013 01:58
Project Euler Problem 99
//http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2099
//指数の形で表される2つの数, 例えば 2^11 と 3^7, の大小を調べることは難しくはない. 電卓を使えば, 2^11 = 2048 < 3^7 = 2187 であることが確かめられる.
//しかし, 632382^518061 > 519432^525806 を確認することは非常に難しい (両者ともに300万桁以上になる).
//各行に1組が書かれている1000個の組を含んだ22Kのテキストファイルbase_exp.txtから, 最大の数が書かれている行の番号を求めよ.
//write kazua
import scala.io.Source
import scala.math._