Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
import re
s = '''
01001001 01101110
01110100 01100101
01101100 00100000
01001000 01100101
01100001 01110010
01110100 01110011
00100000 01011001
@st98
st98 / fizzbuzz.rb
Last active December 28, 2015 02:49
Rubyの練習。FizzBuzzです。
1.upto(100) do |i|
s = "#{[:Fizz][i % 3]}#{[:Buzz][i % 5]}"
puts s.empty? ? i : s
end
@st98
st98 / fizzbuzz2.rb
Last active December 28, 2015 02:59
Rubyの練習。FizzBuzzです。今度は素直に実装しました。
1.upto(100) do |i|
puts i % 15 != 0 ? i % 3 != 0 ? i % 5 != 0 ? i : 'Buzz' : 'Fizz' : 'FizzBuzz'
end
@st98
st98 / fizzbuzz3
Created November 12, 2013 14:11
Rubyの練習。FizzBuzzです。怠惰バージョン。
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
@st98
st98 / fizzbuzz4.rb
Created November 12, 2013 14:21
もうRuby関係ない。FizzBuzzです。
system 'curl https://gist.github.com/st98/7431455/raw/552a45a51a2d26c6bf56e7cba2f33eb763ed3297/fizzbuzz3'
@st98
st98 / 99-bottles-of-beer.rb
Last active December 28, 2015 04:39
Rubyの練習。99 Bottles of Beerです。
def bottles_of_beer(n)
def bottle(n)
bottles = case n
when 0
"No more bottles"
when 1
"#{n} bottle"
else
"#{n} bottles"
end
@st98
st98 / partition.coffee
Last active December 28, 2015 08:19
文字列をn文字ずつ分割する関数。
String::partition = (n) -> @match new RegExp('(.{' + n + '})|(.+)', 'g')
@st98
st98 / gen-variable-name.py
Last active December 28, 2015 18:39
変数名を生成する関数。英小文字オンリーです。
from random import randint
def gen_variable_name(a):
while True:
yield ''.join([
chr(0x61 + randint(0, 25))
for _ in range(a)
])
if __name__ == '__main__':
@st98
st98 / factorial.py
Created December 3, 2013 12:03
階乗を求める関数。
from functools import reduce
from operator import mul
def fact(n):
return reduce(mul, range(1, n + 1))
@st98
st98 / ascii.js
Last active December 30, 2015 08:09
ascii.encode('hoge') === '686f6765';
(function () {
'use strict';
var root = this;
var ascii = {};
var prevAscii = root.ascii;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {