Skip to content

Instantly share code, notes, and snippets.

View siman-man's full-sized avatar
🌴
On vacation

Shuichi Tamayose siman-man

🌴
On vacation
  • Japan
View GitHub Profile
@siman-man
siman-man / calc_perf.rb
Created November 3, 2023 20:46
AHC rating calculation
S = 724.4744301
R = 0.8271973364
perfs = DATA.map(&:to_i)
Q = []
perfs.each do |perf|
1.upto(100) do |j|
Q << perf - S * Math.log(j)
end
@siman-man
siman-man / HappyGrid.cpp
Created June 22, 2023 22:12
MM146 last submit
// C++17
#include <cassert>
#include <cmath>
#include <chrono>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <unordered_map>
#include <queue>
@siman-man
siman-man / parse_ranking_json.rb
Created March 5, 2022 10:51
parse mm ranking json file.
require 'json'
require 'time'
user_name = 'simanman'
body = JSON.parse(File.read('ranking.json'))
submissions = body.select { |b| b['createdBy'] == user_name }
submissions.sort_by! { |sub| Time.parse(sub['submittedDate']) }
last_sub = submissions.last
class RedBlackTree
RED = :red
BLACK = :balck
Node = Struct.new(:value, :parent, :left, :right, :color, keyword_init: true)
NUL = Node.new(value: nil, parent: nil, left: nil, right: nil, color: BLACK)
def initialize
@tree = []
@root = NUL
end
class BinarySearchTree
Node = Struct.new(:value, :parent, :left, :right, keyword_init: true)
NUL = Node.new(value: nil, parent: nil, left: nil, right: nil)
attr_reader :root
def initialize
@root = NUL
end
# 'Hello World' を出力するようにプログラムを修正してください。
# Q1
n = 314
if n > 4782968
puts 'Hello World'
else
puts 'Hello Ruby'
end
@siman-man
siman-man / trace_plus_ope.rb
Last active April 17, 2019 22:11
最適化されて TracePoint で取得できなくなっている `+` 演算子を最適化 OFF にして取得する
RubyVM::InstructionSequence.compile_option = false
class RubyVM::InstructionSequence
def self.load_iseq(fpath)
RubyVM::InstructionSequence.compile_file(fpath)
end
end
require_relative 'add'
def extract_source(parent)
$source ||= File.readlines(__FILE__)
if parent.first_lineno == parent.last_lineno
src = $source[parent.first_lineno][parent.first_column..parent.last_column]
else
src = ' ' * parent.first_column + $source[parent.first_lineno][parent.first_column..]
((parent.first_lineno + 1)...(parent.last_lineno)).each do |lineno|
src << $source[lineno]
end
src << $source[parent.last_lineno][0..parent.last_column]
require 'pathname'
class PathFinder
SUFFIXES = ['',
'.rb',
*%w(DLEXT DLEXT2).map { |key|
val = RbConfig::CONFIG[key]
next unless val and not val.empty?
".#{val}"
}
@siman-man
siman-man / sinatra_routes.rb
Last active September 2, 2018 01:29
get sinatra routes.
require 'parser/current'
class SinatraRoutes
attr_reader :filepath
def initialize(filepath)
@filepath = filepath
end
def routes