Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
hyuki0000 / makeopenapp.rb
Created October 4, 2017 03:11
URLをオープンするだけのアプリを作るスクリプト
#!/usr/bin/env ruby
# cf. http://bit.ly/2raKfLZ
# makeopenapp - URLをオープンするだけのスクリプトをMacのアプリケーションにする
if ARGV.length != 2
abort("Usage: makeopenapp URL Example.app")
end
url = ARGV[0]
appname = ARGV[1]

タイトル

見出し

ろーれむいぷさむ

見出し

見出し

@hyuki0000
hyuki0000 / aveprime.rb
Created September 17, 2017 10:07
小さい方からn個選んだ素数の平均が素数になることはn=1以外にあるかな?
require 'prime'
MAX = 10000_00000_00000
n = Rational(0)
s = Rational(0)
Prime.each(MAX) do |p|
n += 1
s += p
if (s/n).denominator == 1
puts "f(#{n}) = #{s/n} : INTEGER"
@hyuki0000
hyuki0000 / curious.rb
Created August 25, 2017 14:56
まちがった約分なのに、なぜか正しくなる分数
(1..9).each do |a|
(1..9).each do |b|
(1..9).each do |c|
x = (10 * a + b).to_r
y = (10 * b + c).to_r
# puts "a = #{a}, b = #{b}, c = #{c}, x = #{x}, y = #{y}"
if a != c and x / y == a.to_r / c.to_r
puts "\\frac{#{x.to_i}}{#{y.to_i}} = \\frac{#{a}}{#{c}}, "
end
end
@hyuki0000
hyuki0000 / a.rb
Created August 23, 2017 07:16
N人のうち1人が100点でN-1人が0点であるとき、100点の人の偏差値
# N人のうち1人が100点でN-1人が0点であるとき、100点の人の偏差値
N = 15802 # 人数
μ = 100.0 / N # 平均
v = ((N-1) * (0-μ) ** 2 + 1 * (100-μ) ** 2) / N # 分散
σ = Math.sqrt(v) # 標準偏差
puts 50 + (100-μ) / σ * 10 # 100点の人の偏差値
# => 1307.0202862324857
@hyuki0000
hyuki0000 / 1.txt
Last active July 25, 2017 07:16
Who am I? - Twitterの hyuki がどんなリストに入れられているかを調べました
43 math
37 IT
34 science
30 tech
29 数学
27 famous
25 My
23 engineer
20 it
17 twizard-magic-list
/*
* FameList.js
*
* When you see
* https://twitter.com/EXAMPLEUSER/...
* Then you jump to
* https://twitter.com/EXAMPLEUSER/memberships
*
* Written by Hiroshi Yuki.
* Licensed under CC0.
#!/usr/bin/perl
#
# This is UpFtp, Version 1.3
# Copyright (C) 2000,2003,2006,2017 by Hiroshi Yuki.
# http://www.hyuki.com/upftp/
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
use strict;
[ 2017-07-02 23:34:03.2697 29259/7f7fb7fff700 age/Cor/CoreMain.cpp:588 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2017-07-02 23:34:03.2804 29259/7f7fca2e4880 age/Cor/CoreMain.cpp:999 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2017-07-02 23:34:03.2860 29269/7fd29ffff700 age/Ust/UstRouterMain.cpp:430 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2017-07-02 23:34:03.2867 29269/7fd2a9f35880 age/Ust/UstRouterMain.cpp:500 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2017-07-02 23:34:03.2877 29269/7fd29f7fe700 Ser/Server.h:862 ]: [UstRouterApiServer] Freed 0 spare client objects
[ 2017-07-02 23:34:03.2880 29269/7fd29f7fe700 Ser/Server.h:490 ]: [UstRouterApiServer] Shutdown finished
[ 2017-07-02 23:34:03.2878 29269/7fd29ffff700 Ser/Server.h:490 ]: [UstRouter] Shutdown finished
[ 2017-07-02 23:34:03.2855 29259/7f7fca2e
@hyuki0000
hyuki0000 / phi.rb
Created July 2, 2017 12:53
オイラーのφ関数を、RubyのPrimeモジュールを使って素朴に実装したものです
require 'prime'
def φ(n)
if n == 1
return 1
end
Prime.each(n-1) do |p|
if n % p == 0
b = n
j = 0