Skip to content

Instantly share code, notes, and snippets.

View sato11's full-sized avatar
🌴
On vacation

Junichi Sato sato11

🌴
On vacation
View GitHub Profile
@sato11
sato11 / prime.scm
Created February 2, 2022 00:15
Probablistic primality test based on SICP 1.2.6
(define (expmod base exp m)
(cond ((= exp 0) 1)
((even? exp)
(remainder (square (expmod base (/ exp 2) m))
m))
(else
(remainder (* base (expmod base (- exp 1) m))
m))))
(define (fermat-test n)
# Solves arithmetic puzzle.
# Input four integers and the expected answer
# and the program searches a possible expression.
#
# e.g.
# in: 1,3,9,0 and 10
# out: 1+(3*0)+9
# in: 3,4,7,8 and 10
# out: (3-7/4)*8
# test cases that i've used for the lesson below:
# https://app.codility.com/programmers/lessons/5-prefix_sums/count_div/
require 'minitest/autorun'
class CountDivTest < Minitest::Test
def test_solution
a, b, k = [6, 11, 2]
assert_equal 3, solution(a, b, k)
@sato11
sato11 / to_rational.cpp
Created July 9, 2020 12:27
notate rational number including cyclical one. e.g. to_rational(1, 7) == "0.(142857)"
std::string to_rational(int numerator, int denominator)
{
std::string result;
int n = numerator / denominator;
result += std::to_string(n);
if (numerator % denominator == 0) return result;
result += ".";
AWSTemplateFormatVersion: 2010-09-09
Description: |
A stack to manage an S3 bucket for redirecting to the apex domain,
a Route 53 DNS record for using a custom domain,
and a CloudFront Distribution for high availability.
Parameters:
AcmCertificateArn:
Type: String
Description: The ARN of ACM certificate.
AWSTemplateFormatVersion: 2010-09-09
Description: |
A stack to manage an S3 bucket for hosting a static website,
a Route 53 DNS record for using a custom domain,
and a CloudFront Distribution for high availability.
Parameters:
AcmCertificateArn:
Type: String
Description: The ARN of ACM certificate.
@sato11
sato11 / digdag.sh
Last active November 15, 2018 08:21
init script to daemonize digdag server.
#!/bin/bash
# digdag daemon
# chkconfig: 345 20 80
# description: digdag daemon
# processname: digdag
# Credit: https://werxltd.com/wp/2012/01/05/simple-init-d-script-template/
source /home/user_name/.bashrc
source /home/user_name/.bash_profile