Skip to content

Instantly share code, notes, and snippets.

View neetsdkasu's full-sized avatar
🔰
take it easy

Leonardone @ NEETSDKASU neetsdkasu

🔰
take it easy
View GitHub Profile
@neetsdkasu
neetsdkasu / convert.R
Last active September 7, 2015 15:50
R言語 文字列と数値の変換
# 数値から文字列へ
n <- 100
s <- as.character(n)
# 文字列から数値へ
s <- "1234"
n <- as.integer(s)
@neetsdkasu
neetsdkasu / strreverse.R
Last active October 7, 2015 16:21
Reverse a String in R ( strReverse function ) [ R言語での文字列の反転 ]
strReverse <- function(x) {
return(paste(rev(strsplit(x, NULL)[[1]]), collapse=""))
}
# example 1
s <- strReverse("abcdefghij")
cat(s) # output is "jihgfedcba"
# example 2
@neetsdkasu
neetsdkasu / PrimitiveArrayUtil.java
Last active November 22, 2015 13:10
プリミティブ配列ユーティリティ(PrimitiveArrayUtil)
// package myapp.util;
/*
* wrap ... e.g. int[] -> Integer[]
* unwrap ... e.g. Integer[] -> int[]
* toInt ... e.g. double[] -> int[]
* toDouble ... e.g. int[] -> double[]
*
*/
@neetsdkasu
neetsdkasu / Permutation.java
Last active December 2, 2015 13:04
並べ替え全パターン生成(置換Permutationと言うらしい)
// package myapp.util;
import java.util.Arrays;
public class Permutation
{
protected final int[] unuses, stack;
protected int stack_end = 0;
protected boolean hasnext = true;
@neetsdkasu
neetsdkasu / bigint.cpp
Last active December 26, 2015 00:39
class managing Big Integer ( test on ideone: http://ideone.com/EGANYD )
#include <iostream>
#include <cstdio>
using namespace std;
class Carrier;
class BigInt;
class Decimal;
class Carrier {
friend class Decimal;
@neetsdkasu
neetsdkasu / Main.clj
Last active January 17, 2016 02:00
Clojureのmap/for遅延評価ポポポーン!
(defn main []
(let [a (fn [k] (println k) (for [i (range 5)] i))
b (map (fn [x] (println "unko") (* x 2)) (a "unko2"))
c (map (fn [x] (println "hage") (* x 3)) (a "hage3"))
d (for [i (a "beef4")] (let [j (* i 4)] (println "beef") j))
e (for [i (a "wolf5")] (let [j (* i 5)] (println "wolf") j))
]
(loop [i 5 d d e e b b c c]
(if (= i 0) 0
(let []
@neetsdkasu
neetsdkasu / Main.java
Created January 18, 2016 20:54
引数と戻り値のnull不可について考えた結果
public class Main {
static class UnkoException extends RuntimeException {}
static ResultG<Integer> testResultG(Integer value) {
return ResultG.wrap(value);
}
static ResultW<Integer> testResultW(Integer value) {
@neetsdkasu
neetsdkasu / gen_intercal.rb
Last active February 14, 2016 15:49
INTERCAL CODE GENERATOR (固定テキスト表示のみ) - ruby
# INTERCAL CODE GENERATOR (固定テキスト表示のみ)
# Author: Leonardone @ NEETSDKASU
# License: MIT License
# Target: Intercal c-intercal 28.0-r1
def test_genIC()
f = 'TextFile.txt'
ARGV << f if ARGV.empty? && ARGF.eof? && FileTest.exist?(f)
puts genIC(ARGF.read, false) if !ARGF.eof?
end
@neetsdkasu
neetsdkasu / genBF.rb
Last active February 14, 2016 15:57
Brainf*ck Code Generator (固定文字列表示のみ) - ruby
# Brainf*ck Code Generator (固定文字列表示のみ)
# Author: Leonardone @ NEETSDKASU
# License: MIT License
def test_genBF()
f = 'TextFile.txt'
ARGV << f if ARGV.empty? && ARGF.eof? && FileTest.exist?(f)
puts genBF(ARGF.read, 60, 10) if !ARGF.eof?
end
@neetsdkasu
neetsdkasu / gen_unlambda.rb
Last active February 14, 2016 15:57
Unlambda Code Generator (半角文字の固定テキスト表示のみ) - ruby
# Unlambda Code Generator (半角文字の固定テキスト表示のみ)
# Autohr: Leonardone @ NEETSDKASU
# License: MIT License
# Target: unlambda-2.0.0
def test_genUL()
f = 'TextFile.txt'
ARGV << f if ARGV.empty? && ARGF.eof? && FileTest.exist?(f)
puts genUL(ARGF.read, 0, 60) if !ARGF.eof?
end