Skip to content

Instantly share code, notes, and snippets.

Toshihiko Arai araemon

View GitHub Profile
View radar.py
# -*- coding: utf-8 -*-
# このプログラムはpython2で実行すること
import RPi.GPIO as GPIO
import time
import os
import signal
GPIO.setmode(GPIO.BCM) # 役割ピン番号で命名
TRIG = 20
View hc-sr04.py
# -*- coding: utf-8 -*-
# python2で実行すること
import RPi.GPIO as GPIO
import time
import os
import signal
GPIO.setmode(GPIO.BCM)
TRIG = 20
View servo.py
# -*- coding: utf-8 -*-
# python2で実行すること
import RPi.GPIO as GPIO
import time
import os
import signal
GPIO.setmode(GPIO.BCM)
SIG = 26
View factorial.py
n = 5
r = 3
result = factorial(n) / (factorial(n - r) * factorial(r))
print(result)
View factorial.py
def factorial(n):
res = 1
for i in range(1, n + 1):
res *= i
return res
View combination.py
n = 35
total = 0
for r in range(1, n+1):
res = combination(n, r)
print("{n}C{r} = {res}".format(
n=n,
r=r,
res=res))
total += res
View combination.py
def combination(n, r):
return factorial(n) / (factorial(n - r) * factorial(r))
View combination.py
def nCr(s1, r): # ただしmは、1 <= m <= len(s1) の範囲とする
a = s1[0] # 配列の最初の値を対象する
# a と組み合わせられる値は aを以外の配列を対象とすれば良い
s2 = s1[1:] # => [2, 3, 4, 5]
res = []
if r == 1: # 例外ケースとして処理
for a in s1:
res.append(a)
View combination.py
cache = {}
def join(a):
s = ""
for b in a:
s += str(b) + "_"
return s
View MainActivity.kt
class MainActivity : AppCompatActivity() {
var mWorker: Thread? = null
var running = AtomicBoolean(false)
var counter:Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
You can’t perform that action at this time.