Skip to content

Instantly share code, notes, and snippets.

@yattom
yattom / fraction.md
Last active July 25, 2017 22:54
TDDのお題 計算機

いろいろな計算ができる計算機を作ってください。以下のインターフェースはあくまで一例(イメージ)です。

  1. 整数の足し算ができるようにしてください

calc("+", 3, 4) => 7

  1. 整数の引き算ができるようにしてください

calc("-", 10, 4) => 6

スーパーの支払金額計算

スーパーで買い物したときの支払金額を計算する

以下の商品リストがあるとする。先頭の数字は商品番号。

  1. りんご 100円
  2. みかん 40円
  3. ぶどう 150円
  4. のり弁 350円
@yattom
yattom / __main__.py
Created December 28, 2017 07:01
du.py
import sys
from du import main
if __name__=='__main__':
if len(sys.argv) > 1:
main.main(sys.argv[1])
else:
main.main()
@yattom
yattom / gist:6ffc5cee8a6cddb9134bae6f3561901b
Last active October 28, 2019 00:25
small greasemonkey script to make facebook more productive (i.e. less counterproductive)
// ==UserScript==
// @name Facebook cleaner
// @namespace http://yattom.jp
// @include https://www.facebook.com/
// @version 2
// @grant GM_addStyle
// ==/UserScript==
// 右側の、上から3番目のエリアに、People You May Knowや、広告が表示される。それを非表示にする。
var ego_section = document.getElementsByClassName("ego_section");
@yattom
yattom / FizzBuzz.php
Created June 1, 2018 04:03
An example of PHP unit test for FizzBuzz and implementations (a very buggy one and correct one)
<?php
declare(strict_types=1);
final class FizzBuzz
{
public function translate($num) {
if ( $num % 15 == 14 ) {
return "FizzBuzz";
}
if ( $num % 3 == 0 && $num != 72) {
[ec2-user@ip-172-30-0-209 ~]$ mkdir foo
[ec2-user@ip-172-30-0-209 ~]$ cd foo
[ec2-user@ip-172-30-0-209 foo]$ python3 -m venv .
[ec2-user@ip-172-30-0-209 foo]$ . bin/activate
(foo) [ec2-user@ip-172-30-0-209 foo]$ pip install pytest-testmon
Collecting pytest-testmon
Downloading https://files.pythonhosted.org/packages/04/71/0f7ff7772cfd96b5ac1627d1218e2568ce2a2cb6d40b8c7dede4f25d262a/pytest-testmon-0.9.11.tar.gz
Collecting pytest<4,>=2.8.0 (from pytest-testmon)
Downloading https://files.pythonhosted.org/packages/d3/75/e79b66c9fe6166a90004bb8fb02bab06213c3348e93f3be41d7eaf625554/pytest-3.6.1-py2.py3-none-any.whl (194kB)
100% |████████████████████████████████| 194kB 4.0MB/s
@yattom
yattom / dist_dice.py
Last active August 7, 2018 04:31
show distribution of roll of dices
def dice_dist(n):
d = [0]
for i in range(n):
d = [b + r for b in d for r in range(1, 7)]
for r, c in {n: d.count(n) for n in d}.items():
print(f"{r:>3} {c/6**n:>5.1%} {'*'*c}")
@yattom
yattom / DFG.md
Last active June 20, 2023 23:45
プログラミングお題: 大富豪の手判定

プログラミングお題: 大富豪の手判定

トランプゲームである大富豪のプログラムを書きましょう。

1. トランプのカード

トランプのカードは、4種類のスート(スペード、ハート、ダイヤ、クラブ)と13のランク(A, 2, 3, 4, 5, 6, 7, 8, 9, J, Q, K) の組み合わせです。またジョーカーもカードです。ひと組のトランプは、全53枚(4スート13ランク+ジョーカー1枚)のカードです。

1-1. 1枚のカードを表現する

@yattom
yattom / vending_machine.md
Last active July 15, 2023 19:14
プログラミングのお題: 自動販売機 (設計進化重視バージョン)

自動販売機のプログラムをTDDで書いてみよう!

飲み物の自動販売機の動きを、プログラムで表現してください。

最終的な自動販売機の全機能は、不確定です。 テスト駆動開発のアプローチを有効活用して、 進化的に設計をどんどん変えていきましょう。

命名のヒント

@yattom
yattom / fizzbuzzA.py
Last active September 25, 2018 05:49
[print(("Fizz" if i%3==0 else "") + ("Buzz" if i%5 == 0 else "") or str(i)) for i in range(1,101)]