Skip to content

Instantly share code, notes, and snippets.

View sh0hei's full-sized avatar
λ=

Shohei Shimomura sh0hei

λ=
  • Tokyo, Japan
View GitHub Profile
@sh0hei
sh0hei / NumericUtility.scala
Last active April 7, 2016 10:29
Scala Numeric Utility
val isPrime(v: Int) = {
v match {
case v if (v <= 1) => false
case v if (v == 2) => true
case v => !(2 to (v - 1)).exists(x => v % x == 0)
}
}
val isPerfect(v: Int) = {
v == (1 until v).foldLeft(0) { (acc, i) =>
@sh0hei
sh0hei / .xmodmap
Created July 27, 2015 11:57
Swap Ctrl and Caps_Lock in *NIX Console
! Swap Ctrl and Caps_Lock
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
@sh0hei
sh0hei / In Java
Last active August 29, 2015 14:16
Scala_vs_Java
public List<String> filterNames(List<String> names, int len) {
List<String> res = new ArrayList<>();
for (String n : names) {
if (n.length() >= len) {
res.add(n.toUpperCase());
}
}
return res;
}
module Main where
take' _ [] = []
take' 0 _ = []
take' n (x:xs) = x : take' (n - 1) xs
drop' _ [] = []
drop' 0 xs = xs
drop' n (x:xs) = drop' (n - 1) xs
@sh0hei
sh0hei / gist:541be159c206d5e37d9f
Created September 7, 2014 11:04
AtCoder Regular Contest #009-A
object Arc009A {
def main(args: Array[String]) = {
val n = io.Source.stdin.getLines.next().toInt
var sum = 0
for (i <- 0 until n) {
val tmp = io.Source.stdin.getLines().next().split(" ").map(_.toInt)
sum += tmp(0) * tmp(1)
}
println((sum * 1.05).toInt)
}
@sh0hei
sh0hei / gist:34f28a5bfc3cc46f203a
Last active August 29, 2015 14:05
AtCoder Regular Contest #008-B
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Arc008B {
@SuppressWarnings({ "unused", "resource" })
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int shopNameLength = sc.nextInt();
@sh0hei
sh0hei / gist:85d788b42ebacee6a354
Last active August 29, 2015 14:05
AtCoder Regular Contest #008-A
import java.util.Scanner;
public class Arc008A {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int needs = sc.nextInt();
int sets = needs / 10;
int bits = needs % 10;