Skip to content

Instantly share code, notes, and snippets.

@yutaono
yutaono / fizzbuzz.sh
Created February 11, 2014 06:53
Fizz-Buzz Problem Solver by Shell Script
#!/bin/bash
#
# Fizz-Buzz Problem Solver by Shell Script
#
for i in `seq 1 30`
do
if [ `expr $i % 3` -eq 0 ] && [ `expr $i % 5` -eq 0 ]; then
echo "fizzbuzz"
// *を使って次の図を書くプログラムを作成せよ。ただし、必ずfor文を使用すること
//
// *
// **
// ***
// ****
// ***
// **
// *
//
@yutaono
yutaono / gist:10612219
Last active August 29, 2015 13:59
.emacs
(load (expand-file-name (concat (getenv "HOME") "/.emacs.d/common.el")))
@yutaono
yutaono / gcd.java
Created May 2, 2014 08:32
最大公約数をユークリッドの互除法で求める
private int gcd(int m, int n) {
int r = m % n;
if (r == 0) {
return n;
}
return gcd(n, r);
}
@yutaono
yutaono / eratosthenes.py
Last active August 29, 2015 14:01
Sieve of Eratosthenes by python.
# coding: utf-8
import math
def eratosthenes(x):
sieve = []
prime = []
for num in range(2, x):
sieve.append(num)
import scala.io.Source
val source = Source.fromFile("triangle.txt")
val triangle = collection.mutable.Map[Int, List[Int]]()
source.getLines foreach { line =>
triangle += triangle.size -> line.split(" ").map(_.toInt).toList
}
def neighborsMaxList(list: List[Int]): List[Int] = list match {
case l if l.length == 1 => Nil
// project euler 28
//
// The sum of the vertices can be expressed as follows. The w is width of the square.
//
// sum = (w - 2)^2 + (w - 1)
// + (w - 2)^2 + 2(w - 1)
// + (w - 2)^2 + 3(w - 1)
// + (w - 2)^2 + 4(w - 1)
// = 4w^2 - 6w + 6
//
require 'redis'
require 'hiredis'
$redis = Redis.new(
host: "127.0.0.1",
port: 6379,
timeout: 30.0,
driver: :hiredis
)
require 'date'
t1 = DateTime.parse(ARGV[0])
t2 = DateTime.parse(ARGV[1])
seconds = ((t2 - t1) * 24 * 60 * 60).to_i
r = seconds.divmod(60)
puts "#{r[0]}min#{r[1]}sec"
f1 = 1
f2 = 2
sum = 0
loop {
break if f2 > 4000000
sum += f2 if f2 % 2 == 0
f2 = f1 + f2
f1 = f2 - f1
}