Skip to content

Instantly share code, notes, and snippets.

{
"data": {
"user": {
"contributionsCollection": {
"contributionCalendar": {
"weeks": [
{
"contributionDays": [
{
"color": "#9be9a8",
Hello World!
Hello World!
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Pos;
import javafx.geometry.Side;
(use srfi-42)
(use util.stream)
; == 準備こここから ==
; 再帰的定義に基づき、第n項を求める
; (somos 4 10) => 314 [k=4のときの第10項]
(define (somos k n)
(if (>= k n)
1
; bを固定したときの(a,c)の組み合わせを数える
; (count-ac-combs 3) => 3 [(a,c) = (1,1)(1,2)(2,1)]
(define (count-ac-combs b)
(let* ((t (quotient (* b b) 4))
(comb-a<c
(let loop ((a 1) (sum 0))
(if (> (* a (+ a 1)) t)
sum
(loop (+ a 1) (+ sum (- (quotient t a) a))))))
(comb-a=c (inexact->exact (floor (sqrt t)))))
# bを固定したときの(a,c)の組み合わせを数える
# cnt_ac_combs(3) => 3 [(a,c) = (1,1)(1,2)(2,1)]
def cnt_ac_combs(b)
t = b ** 2 / 4
cnt = 0 # a < c
(1..t).each{|a| a * (a + 1) > t ? break : cnt += t / a - a}
cnt * 2 + Math.sqrt(t).to_i
end
# 1 <= b <= m を満たす(a,b,c)の組み合わせの総数を数える
(use srfi-14)
(define (string-split string char-set-delimiter)
(let loop((str (string->list string)) (unit '()) (result '()))
(if (null? str)
(reverse (map (lambda (ls) (list->string (reverse ls))) (cons unit result)))
(if (char-set-contains? char-set-delimiter (car str))
(loop (cdr str) '() (cons unit result))
(loop (cdr str) (cons (car str) unit) result)))))
class Integer
# 整数の桁数を返す ex. 123.digit => 3
def digit
self / 10 == 0 ? 1 : (self / 10).digit + 1
end
# 整数を下1桁、下2桁、下3桁...のように分解して配列に格納する
# ex. 12345.partiton => [5, 45, 345, 2345, 12345]
def partition