Skip to content

Instantly share code, notes, and snippets.

View st98's full-sized avatar

st98 st98

View GitHub Profile
@st98
st98 / svmmohmm.py
Created February 27, 2014 08:48
Python 3では動きません。
# coding: rot13
qrs svmm_ohmm(a):
sbe k va enatr(1, a + 1):
vs k % 15 == 0:
cevag "FizzBuzz"
ryvs k % 3 == 0:
cevag "Fizz"
ryvs k % 5 == 0:
cevag "Buzz"
ryfr:
@st98
st98 / rule-18
Last active August 29, 2015 13:56
#
# #
# #
@st98
st98 / elementary-cellular-automaton.rb
Created March 1, 2014 18:39
Rubyの練習。一次元セルオートマトン。
class String
def zfill(width)
self.rjust(width, '0')
end
end
class ElementaryCellularAutomaton
attr_reader :rule, :width, :cells
def initialize(rule = rand(256), width = 75)
@st98
st98 / to-whitespace.js
Created March 3, 2014 05:54
54 => " \t\t \t\t \n", -54 => "\t\t\t \t\t \n"
var toWhitespace = function (n) {
var result = '';
var table = {
0: ' ',
1: '\t'
};
result += (n < 0) ? table[1] : table[0];
result += Math.abs(n).toString(2).replace(/[01]/g, function (m) {
@st98
st98 / format.js
Last active August 29, 2015 13:57
Pythonのstr#formatもどき。
(function () {
var slice = [].slice;
String.prototype.format = function (/* ...args */) {
var args = slice.call(arguments);
var count = 0;
return this.replace(/{(\d+)?}/g, function (m, n) {
if (typeof n === 'undefined') {
return args[count++];
@st98
st98 / main.html
Last active August 29, 2015 13:57
ワイヤワールドというセルオートマトンを実装してみました。
<!doctype html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Wireworld</title>
<style>
body {
font-family: Helvetica, Arial, sans-serif;
}
@st98
st98 / KEMURI.js
Last active August 29, 2015 13:57
JavaScriptでKEMURI処理系。 参考: http://www.nishiohirokazu.org/blog/2006/09/kemuri.html
var Kemuri = (function () {
function Kemuri(source) {
if (!(this instanceof Kemuri)) {
return new Kemuri(source);
}
this.source = source || '';
this.stack = [];
this.at = 0
};
@st98
st98 / tr.js
Created March 23, 2014 10:05
'ABC'.tr('ABC', 'DEF'); // => 'DEF'
String.prototype.tr = function (search, replace) {
var pattern = new RegExp('[' + search + ']', 'g');
return this.replace(pattern, function (m) {
return replace[search.indexOf(m)] || '';
});
};
@st98
st98 / suicide.py
Last active August 29, 2015 13:57
import os; os.kill(os.getpid(), 9)
@st98
st98 / bogosort.js
Last active August 29, 2015 13:57
JavaScriptでボゴソート。
var randint = function (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
var swap = function (obj, i, j) {
var tmp;
tmp = obj[i];
obj[i] = obj[j];
obj[j] = tmp;