Skip to content

Instantly share code, notes, and snippets.

// from http://b.0218.jp/20121227183142.html
// http://javatechnology.net/java/html-sanitizing/
public class Sanitize {
public static String sanitizing(String str){
if( str == null || str.equals("") ){
return str;
}
// javaでメソッドチェインの使用はどうか
@kcha4github
kcha4github / ListSort.java
Created December 15, 2015 07:47
practice java sort of list
import java.util.*;
class SyainClass {
private int syainNo;
private String syainName;
public SyainClass(int syainNo, String syainName){
this.syainNo = syainNo;
this.syainName = syainName;
}
@kcha4github
kcha4github / monty_hall_problem.py
Last active March 5, 2018 15:20
Test of Monty Hall Problem. Original code is Ruby in "Probability and Statistics for Computer Science" 978-4-274-06775-4 Kazuyuki Hiraoka, Gen Hori.
import random
def choice(doors):
return doors[random.randrange(len(doors))]
def trial(change, times):
doors = "A B C".split(' ')
match = 0
# -*- coding: utf-8 -*-
while True:
bins = input().split()
if len(bins) == 0:
break
for b in bins:
print(chr(int(b,2)), end='')
# -*- coding: utf-8 -*-
names = ["alice", "becky", "charlie", "Dave"]
ages = [25, 38, 12]
for name, age in zip(names, ages):
print(name, age)
# alice 25
# becky 38
# -*- coding: utf-8 -*-
class OldRobot():
def __init__(self):
self.speed = 5
def walk(self):
print("old robot walking {} km/h.".format(self.speed))
class NewRobot():
@kcha4github
kcha4github / knapsack_algorithm.py
Created July 14, 2018 02:25
書籍「アルゴリズムとデータ構造」の動的計画法ナップザック問題をpythonで書き換え。分かりにくいインデックス変数を我流に変更
# -*- coding: utf-8 -*-
ITEMS = 5
SIZE = [2, 3, 5, 6, 9]
VALUE = [2, 4, 7, 10, 14]
NAP_SIZE = 16
nap_value = [0] * (NAP_SIZE + 1)
print("ナップザックの大きさ:", end="")
for i in range(1, NAP_SIZE+1):
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
int[] values = new int[5] { 1, 2, 3, 4, 5 };
Console.WriteLine(string.Join(" ", values));
@kcha4github
kcha4github / OutputDividedString.py
Created July 24, 2018 13:37
Way to output list data divided some string.
# -*- coding: utf-8 -*-
values = [1, 2, 3, 4, 5]
strs = map(str, values)
print(" ".join(strs))
import numpy as np
import matplotlib.pyplot as plt
def step_function(x):
return np.array(x > 0, dtype=np.int)
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def relu(x):