101 や 12321 のように左右反転しても同じである数を回文数という.
base 進数における N 桁の回文数の個数を考える. base 進数における N 桁の回文数は以下の制約を満たす必要がある.
| #!/usr/bin/env bash | |
| set -eu -o posix -o pipefail | |
| shopt -s extglob | |
| declare -gr EXIT_STATUS_SUCCESS=0 | |
| declare -gr EXIT_STATUS_NO_ARGUMENTS=1 | |
| declare -gr EXIT_STATUS_INVALID_FORMAT=2 | |
| declare -gr STANDARD_BREAK_TIME_IN_MINUTES=60 |
| """ | |
| High and Low における戦略別の的中率を求める. | |
| 背景 | |
| ---- | |
| あるゲーム内のミニゲームに High and Low があった. | |
| * 連続的中回数に応じてアイテムを獲得できる. | |
| * アイテムの獲得は 1 日 1 回までであり, 毎日リセットされる. | |
| * 1 回目にコインを支払えば, 2 回目以降は無料でプレイできる. |
| """ | |
| HTML を生成するためのテンプレートを提供する. | |
| テンプレートには変数で値を置き換えるために, | |
| 以下のようにプレースホルダを含めることができる. | |
| <p>こんにちは <%= name %> さん</p> | |
| 変数の値はデフォルトで HTML エスケープされるため, | |
| 意図しない XSS (Cross Site Scripting) 脆弱性を防ぐことができる. |
| // | |
| // Amazon の商品ページなどの URL を正規化する bookmarklet です. | |
| // | |
| // 具体例: | |
| // | |
| // https://www.amazon.co.jp/XXXXX/dp/B07FQ4DJ7X?tag=xxx&ref=xxx | |
| // -> https://www.amazon.co.jp/dp/B07FQ4DJ7X | |
| // | |
| // https://www.amazon.co.jp/gp/product/B07FQ4DJ7X?tag=xxx&ref=xxx | |
| // -> https://www.amazon.co.jp/dp/B07FQ4DJ7X |
| /** | |
| * 指定された日付が休業日であるか判定する. | |
| * | |
| * @param {Date} date | |
| * 判定対象の日付. | |
| * | |
| * @return {Object} | |
| * 休業日の場合は Truthy な値. | |
| * 休業日ではない場合は Falsy な値. | |
| */ |
| #!/bin/ruby | |
| # | |
| # Amazon の URL から冗長な要素を削除する. | |
| # | |
| # Example: | |
| # cat amazon-urls.txt | ruby reduce-amazon-url.rb | |
| # | |
| while line = gets do | |
| url = line.chomp |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <base target="_top"> | |
| <style> | |
| fieldset { | |
| margin-top: 1em; | |
| margin-bottom: 1em; | |
| } | |
| #generate { |
| function memo { | |
| local memo_dir=~/.memo | |
| mkdir -p "$memo_dir" | |
| local current_memo_file=$memo_dir/memo.`date '+%Y-%m-%d'`.txt | |
| local previous_memo_file=$memo_dir/`ls -1 "$memo_dir" | tail -1` | |
| if [ ! -f "$current_memo_file" -a -f "$previous_memo_file" ]; then | |
| cp -pi "$previous_memo_file" "$current_memo_file" | |
| fi |
| require 'openssl' | |
| class Cipher | |
| # 初期化ベクトル. | |
| attr_reader :iv | |
| # 暗号鍵. | |
| attr_reader :key |