This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *を使って次の図を書くプログラムを作成せよ。ただし、必ずfor文を使用すること | |
// | |
// * | |
// ** | |
// *** | |
// **** | |
// *** | |
// ** | |
// * | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(load (expand-file-name (concat (getenv "HOME") "/.emacs.d/common.el"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int gcd(int m, int n) { | |
int r = m % n; | |
if (r == 0) { | |
return n; | |
} | |
return gcd(n, r); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import math | |
def eratosthenes(x): | |
sieve = [] | |
prime = [] | |
for num in range(2, x): | |
sieve.append(num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
require 'hiredis' | |
$redis = Redis.new( | |
host: "127.0.0.1", | |
port: 6379, | |
timeout: 30.0, | |
driver: :hiredis | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f1 = 1 | |
f2 = 2 | |
sum = 0 | |
loop { | |
break if f2 > 4000000 | |
sum += f2 if f2 % 2 == 0 | |
f2 = f1 + f2 | |
f1 = f2 - f1 | |
} |
OlderNewer