Skip to content

Instantly share code, notes, and snippets.

@naohaq
naohaq / quicksort.txt
Last active December 12, 2015 03:09
procedure quicksort(A,M,N); value M,N;
array A; integer M,N;
begin integer I,J;
if M < N then begin partition(A,M,N,I,J);
quicksort(A,M,J);
quicksort(A,I,N);
end
end quicksort
@naohaq
naohaq / sudoku.ps
Created March 14, 2013 14:14
Solving sudoku by postscript.
/# {load def} bind def
/! {exch def} bind def
/M/moveto #/L/lineto #/RM/rmoveto #/RL/rlineto #
/s/stroke #/f/fill #/S/show #/CP/closepath #
/sudokuDict 256 dict def
sudokuDict begin
@naohaq
naohaq / furui.hs
Created April 10, 2013 09:58
Sieve of Eratosthenes.
import System.Environment (getArgs)
data PFilter a = PFilter a (a -> Bool)
instance Show a => Show (PFilter a) where
show (PFilter s _) = "PF " ++ show s
mfilter :: Integral a => a -> a -> Bool
mfilter p x = (x `mod` p) /= 0
@naohaq
naohaq / HeapTree.hs
Created July 1, 2013 14:22
IFPH Section 6.3 / Heap Tree
module HeapTree where
data HTree a = HNull | HFork a (HTree a) (HTree a) deriving Show
hflatten :: (Ord a) => HTree a -> [a]
hflatten HNull = []
hflatten (HFork x xt yt) = x : merge (hflatten xt) (hflatten yt)
merge :: (Ord a) => [a] -> [a] -> [a]
merge [] ys = ys
module Sumlen where
sumList :: (Num a) => [a] -> a
sumList = foldr (+) 0
lenList :: (Num b) => [a] -> b
lenList = foldr (\_ y->y+1) 0
sumlenList :: (Num a, Num b) => [a] -> (a,b)
sumlenList = foldr (\x (y,z)->(x+y,z+1)) (0,0)
#!/usr/bin/make -f
CFLAGS = -O3
.PHONY: all clean
all: main
main: main.c hoge.o
cc $(CFLAGS) -o $@ $^
@naohaq
naohaq / ps-mode.el
Created April 3, 2015 05:26
Emacs lisp for semi-automatic update of "CreationDate" comment on a postscript file
(defun format-time-string-with-locale-c (fmt)
(let ((system-time-locale "C")) (format-time-string fmt)))
(require 'ps-mode)
(defun ps-mode-update-creationdate ()
(interactive nil)
(save-excursion
(goto-char (point-min))
(and
(re-search-forward "^%%CreationDate: " nil t)
#!/usr/bin/tail -1
55
#!/bin/sh
echo -n 'aababcabcdabcdeabcdefabcdefgabcdefghabcdefghiabcdefghij' | wc -c
@naohaq
naohaq / summation_next.sh
Created May 14, 2015 03:44
Sum of 1 to 10
#!/bin/sh
fn=`mktemp`
echo -n 'a' >> $fn
echo -n 'aa' >> $fn
echo -n 'aaa' >> $fn
echo -n 'aaaa' >> $fn
echo -n 'aaaaa' >> $fn
echo -n 'aaaaaa' >> $fn