Skip to content

Instantly share code, notes, and snippets.

お題: 数値データを処理する

  • CSVファイルを読む
    • SKU ID, 商品名, アクセス数
  • 壊れてる行を取り除く
  • アクセス数(3カラム目)の平均を出力する
    • 外れ値を取り除く(最大値と最小値)
  • アクセス数(3カラム目) が平均を超える行をすべて出力する
@yattom
yattom / excel.ps1
Created June 28, 2021 02:41
Excelのカラムの表記をインデックスを元に求める(0->A, 25->Z, 26->AAなど。インデックスは0始まり(Excelでは1始まり))
function ColumnKey($idx)
{
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $true
$book = $excel.Workbooks.Add()
$sheet = $book.Sheets(1)
$cell = $sheet.Cells(1, 1)
$col = $idx + 1
$cell.Formula = "=ADDRESS(1,$($col),4)"
$text = $cell.Text
@yattom
yattom / なりきり登場人物.md
Last active October 1, 2018 04:42
心理的安全性ゲームの拡張ルール: なりきり登場人物

概要

ゲームをやるグループで、1人ひとりが登場人物の設定を受け持ち、その設定に従って演技します。一番上手に演技できた人が勝利します。

進め方

  1. ゲームを始める前に、1人ひとり「なりきり登場人物」(後述)の設定を選びます。自由に選んでもいいし、サイコロなどで選ぶのも面白いでしょう。
  2. 選んだら、その人物になりきって、ゲームへの意気込みを一言で話してください。
  • 例) 設定が「きびしい」「先生」「眠れない」だったら、「(眠そうな目で)おまえらしっかりやれよ!」と言う
  • 例) 設定が「遊び好きな」「マネージャー」「出会いがあった」だったら、「楽しくやろう!いいことあるかもよ!」と言う
@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)]
@yattom
yattom / vending_machine.md
Last active July 15, 2023 19:14
プログラミングのお題: 自動販売機 (設計進化重視バージョン)

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

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

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

命名のヒント

@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 / 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}")
[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 / 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) {