散歩

動画の切り出し

ffmpeg を使う。開始5分の時点から1分間切り出す。ついでに mkv から mp4 へ変換。時間指定は「hh:mm:ss」という形式でも OK。 $ ffmpeg -ss 300 -i a.mkv -t 60 a1.mp4「-ss」が前に来るようにする。動画の連結はこちら。 ※参考 FFmpegで素早く正確に動画を…

CPSCO2019 Session4

CPSCO2019 Session4 - AtCoder A - Swimming l, x = gets.split.map(&:to_i) n = x / l puts n.even? ? x % l : (n + 1) * l - x B - Meeting n, d = gets.split.map(&:to_i) table = d.times.map do gets.chomp.chars.map.with_index {|st, i| i if st == "…

Ruby 2.6 で Gem 'chipmunk' を使う(Ubuntu)

Ubuntu 19.04 の Ruby 2.6 で Gem 'chipmunk' がインストールできない。解決策:GitHub で修正されているものを使う。 $ git clone https://github.com/chipmunk-rb/chipmunk.git $ cd chipmunk $ rake clean compile $ gem build chipmunk.gemspec Successf…

AOJ(問題集)20

AIZU ONLINE JUDGE: Programming Challenge 0190 Eleven Puzzle 素直に幅優先探索を実行して死んだので、ここを参考に解いた。「両側探索」というらしい。 start = "fff0fff" "ff123ff" "f45678f" "ff9abff" "fff0fff" result1 = {} result1[start] = 0 stac…

AtCoder(AtCoder Beginners Selection)

AtCoder Beginners Selection - AtCoder PracticeA - はじめてのあっとこーだー(Welcome to AtCoder) a = gets.to_i b, c = gets.split.map(&:to_i) s = gets print "#{a + b + c} #{s}" ABC086A - Product a, b = gets.split.map(&:to_i) puts (a * b).od…

AOJ(問題集)19

AIZU ONLINE JUDGE: Programming Challenge 0180 Demolition of Bridges until (given = $<.gets.split.map(&:to_i)) == [0, 0] n, m = given bridges = m.times.map {$<.gets.split.map(&:to_i)}.sort_by(&:last) city = Array.new(n, false) city[0] = tru…

ffmpeg で mp3 ファイルの編集

$ ffmpeg -i 09.mp3 -t 124 -af "afade=t=out:st=120:d=3" 僕の中の少年.mp3全部で 124秒、先頭から 120 秒でフェイドアウト、フェイドアウトの時間は 3秒。

AOJ(ALDS)その2

AIZU ONLINE JUDGE: Programming Challenge ALDS1_9_A Complete Binary Tree #完全二分木 $<.gets given = [nil] + $<.gets.split.map(&:to_i) a = nil given.drop(1).each_with_index do |key, i| j = i + 1 str = "node #{j}: key = #{key}, " str += "par…

Ruby/Opal サンプル

require 'native' d = Native(`document`) area = d.getElementById("text") button = d.getElementById("start") interval = Native(`window.setInterval`) z, d = zd = ["ズン", "ドコ"] st = "" line = [] f = false zundoko = ->{ return if f line {int…

AOJ(問題集)18

AIZU ONLINE JUDGE: Programming Challenge 0170 Lunch until (n = $<.gets.to_i).zero? data = n.times.map {$<.gets.split}.map {|a, *b| [a] + b.map(&:to_i)} selected = [] all = [*0...n] solve = ->(left, order) { return if data[order.last][2] < …

AOJ(問題集)17

AIZU ONLINE JUDGE: Programming Challenge 0160 Delivery Fee table = [[60, 2, 600], [80, 5, 800], [100, 10, 1000], [120, 15, 1200], [140, 20, 1400], [160, 25, 1600]] until (n = $<.gets.to_i).zero? result = n.times.map {$<.gets.split.map(&:to…

AOJ(問題集)16

AIZU ONLINE JUDGE: Programming Challenge 0150 Twin Prime N = 10007 sieve = [*0..N] 2.upto(Math.sqrt(N).to_i) do |i| next if sieve[i].zero? 2.upto(N / i) {|j| sieve[i * j] = 0} end sieve = sieve[2..-1].reject {|x| x.zero?} until (n = $<.get…

AOJ(問題集)15

AIZU ONLINE JUDGE: Programming Challenge 0140 Bus Line line = [*0..9] + [5, 4, 3, 2, 1] line += line $<.gets.to_i.times do start, goal = $<.gets.split.map(&:to_i) str = if 1 <= start and start <= 5 and start > goal [*goal..start].reverse.j…

AOJ(問題集)14

AIZU ONLINE JUDGE: Programming Challenge 0130 Train $<.gets.to_i.times do given = $<.gets.chomp.split(/(->|<-)/) train = [given.shift] while (dir = given.shift) car = given.shift next if train.include?(car) (dir == "->") ? train.push(car) …

AOJ(問題集)13

AIZU ONLINE JUDGE: Programming Challenge 0120 Patisserie @memo = {} def length(circles) return @memo[circles] if @memo[circles] l = case (s = circles.size) when 0 then 0 when 1 then 0 when 2 r1, r2 = circles.first, circles.last Math.sqrt((…

AOJ(問題集)12

AIZU ONLINE JUDGE: Programming Challenge 0110 Alphametic $<.readlines.map(&:chomp).map {|l| l.split(/\+|=/)}.each do |given| catch(:jump) do 10.times do |i| d = given.map {|a| a.gsub("X", i.to_s)} next unless d.select {|s| s.length >= 2 an…

SSD の寿命を Linux で判断する

SSD(Intel X25-M)で寿命を確認するには at nkjmkzk.net $ sudo smartctl -i /dev/sdc -d sat -a smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.18.0-13-generic] (local build) Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.…

AOJ(問題集)11

AIZU ONLINE JUDGE: Programming Challenge 0100 Sale Result 問題が曖昧。同じ社員が二度出てくるかどうかはっきりしない。 Border = 1_000_000 until (n = $<.gets.to_i).zero? data = Hash.new(0) entry = [] n.times do e, p, q = $<.gets.split.map(&:t…

Nexus 7 に Ubuntu 13.04 を入れるの記

Nexus 7 2012 android 4.4.4 Kernel 3.1.10

AOJ(問題集)10

AIZU ONLINE JUDGE: Programming Challenge 0091 Blur L = 10 table = [[[0, 0], [0, 1], [-1, 1], [1, 1], [0, 2], [-1, 2], [-2, 2], [1, 2], [2, 2], [0, 3], [-1, 3], [1, 3], [0, 4]], [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2…

Ruby のバージョンアップ

まずは rbenv install --list の更新(参照)。 $ cd ~/.rbenv/plugins/ruby-build $ git pull origin master インストール。 $ rbenv install 2.x.x $ rbenv global 2.x.x #例 ローカルな Gem の更新。該当ディレクトリで $ rbenv exec gem install bundler…

AOJ(問題集)9

AIZU ONLINE JUDGE: Programming Challenge 0081 A Symmetric Point require 'matrix' $<.readlines.map {|l| l.split(",").map(&:to_f)}.each do |x1, y1, x2, y2, xq, yq| p1 = Vector[x1, y1] n = Vector[y2 - y1, x1 - x2].normalize q = Vector[xq, yq]…

AOJ(問題集)8

AIZU ONLINE JUDGE: Programming Challenge 0071 Bombs Chain $<.gets.to_i.times do |co| $<.gets field = Array.new(8) {$<.gets.chomp.chars.map(&:to_i)} xi, yi = $<.gets.to_i, $<.gets.to_i blast = ->(x, y) { field[y][x] = 2 3.times do |i| [[1, …

古い Linux Kernel のインストール

askubuntu.comここが参考になる。 例えばここ、ここ、ここから linux-image-4.4.0-98-generic_4.4.0-98.121_amd64.deb linux-headers-4.4.0-98_4.4.0-98.121_14.04.1_all.deb linux-headers-4.4.0-98-generic_4.4.0-98.121_14.04.1_amd64.deb を拾ってきてひ…

Ubuntu 16.04 LTS のインストール後の設定 + VMware Player 12.1.0 の導入

AOJ(問題集)7

AIZU ONLINE JUDGE: Programming Challenge 0061 Rank Checker data = [] until (st = $<.gets.chomp) == "0,0" data << st.split(",").map(&:to_i) end data.sort! {|a, b| b[1] <=> a[1]} x = data.first.last h = {} l = 1 data.each do |d| l += 1 unles…

AOJ(問題集)6

AIZU ONLINE JUDGE: Programming Challenge 0051 Differential II $<.readlines.drop(1).map {|a| a.chomp.chars.map(&:to_i).sort}.each do |ary| puts ary.reverse.join.to_i - ary.join.to_i end 0052 Factorial II until (n = $<.gets.to_i).zero? five …

Ruby で遅延評価メモ

AOJ(問題集)5

AIZU ONLINE JUDGE: Programming Challenge 0041 Expression def solve(ary) if ary.size <= 1 return ary[0] if eval(ary[0]) == 10 else idxs = [*0...ary.size] idxs.combination(2) do |i, j| a, b = ary[i], ary[j] nxt = (idxs - [i, j]).map{|x| ary[…