Skip to content

Instantly share code, notes, and snippets.

[ plaster@cymbal:~ ]
% sudo apt-get build-dep dash
[sudo] plaster のパスワード:
パッケージリストを読み込んでいます... 完了
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 0 個。
[ plaster@cymbal:~ ]
% fakeroot
@plaster
plaster / factorize.hs
Created December 19, 2015 15:43
素直な素因数分解
factorize :: Integer -> [ Integer ]
factorize n = factorize' n $ takeWhile (\x -> x * x <= n) [ 2 .. n ] where
factorize' n [] = case n of
1 -> []
_ -> [n]
factorize' n ds@(d:ds') = case n `mod` d of
0 -> d : factorize' (n `div` d) ds
_ -> factorize' n ds'
main = interact $ show . factorize . read
-- 4回readしたいけどこれで正しいか?もしくはもっとシンプルな書き方があるか?
parse :: String -> (Int, Int, Int, Int)
parse s = (c1, p1, c2, p2) where
[(c1, s')] = readsPrec 10 s
[(p1, s'')] = readsPrec 10 s'
[(c2, s''')] = readsPrec 10 s''
[(p2, s'''')] = readsPrec 10 s'''
@plaster
plaster / abc.hs
Last active August 29, 2015 14:19
a :: Int
b :: Int
c :: Int
c = a + b
a = 5
b = 7
main = print c
use utf8;
use strict;
use IO::File;
use IPC::Open2;
my $ifh0 = IO::Handle->new;
my $ifh1 = IO::File->new_tmpfile;
my $ofh0 = IO::Handle->new;
my $pid0 = open2($ifh0, $ofh0, qw(cat -n));
use utf8;
use strict;
use IO::File;
use IPC::Open2;
my $ofh = IO::File->new_tmpfile;
for (my $i = 1; $i < 20; ++$i) {
print $ofh ('x' x $i), "\n";
}
@plaster
plaster / hello-world.scm
Last active December 22, 2015 09:29
Hello, world! without {number,character,string}-literals
#!/usr/bin/env gosh
(for-each (.$ display ucs->char length)
'#0=(#1=(#0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0# .
#2=(#0##0##0##0##0##0##0##0##0##0##0# .
#3=(#0# . #4=(#0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0# . #0#))))
#5=(#0# . #6=(#0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0##0# . #1#))
#7=(#0##0##0##0##0##0##0# . #5#)
#7##8=(#0##0##0# . #7#)
#2##4##9=(#0##0##0##0##0# . #10=(#0##0##0# . #8#)) #8##10##7##6##3#))
@plaster
plaster / fizzbuzz.hs
Created June 15, 2013 17:58
Eitherの練習。リスト脳。
type FizzBuzz = Either Int String
hit :: String -> FizzBuzz -> FizzBuzz
hit s (Left _) = Right s
hit s (Right s') = Right $ s ++ s'
fizz :: [ FizzBuzz -> FizzBuzz ]
fizz = cycle [ id, id, hit "fizz" ]
buzz :: [ FizzBuzz -> FizzBuzz ]
buzz = cycle [ id, id, id, id, hit "buzz" ]
fizzbuzz :: [ FizzBuzz -> FizzBuzz ]
@plaster
plaster / command
Last active December 17, 2015 23:29
precompでparentの入るinternal defineの例
% gosh -V
Gauche scheme shell, version 0.9.3 [utf-8,pthreads], x86_64-unknown-linux-gnu
% gosh precomp -e -P -o even--odd even-odd.scm
--- a/src/mzscheme/src/bool.c Sat Jun 01 00:04:45 2013 +0900
+++ b/src/mzscheme/src/bool.c Sat Jun 01 00:12:44 2013 +0900
@@ -124,6 +124,9 @@
return SAME_OBJ(obj1, obj2);
}
+#ifdef MZ_XFORM
+START_XFORM_SKIP;
+#endif
XFORM_NONGCING static MZ_INLINE int double_eqv(double a, double b)