Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
int main(){
int value[] = {2,5,4,3,8,7,9,1,10,6};
int index[] = {0,1,2,3,4,5,6,7,8,9};
int cmp(const void * a, const void * b){
return value[*(int*)a] - value[*(int*)b];
}
@CindyLinz
CindyLinz / SisterPillar.c
Created October 8, 2015 16:42
乖乖寫個柱姐..
/*XXXXXXXXXNXNNXXXXXNNNNNNNNNXKxoloodddddx0XXk0XXXXXXXNNNNNNNNNNNNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXXXXXXNNNNNNXKkdlccllccllccloodOdddxk0KKXXXNNNNNNNNNNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXXXXXXXXXKxc,.''',,;;;,,'....,,'''.,',cdxO0KXNNNNNNNNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXXXXXXXx:........''''..''...........''',:coxOKXNNNNNNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXXXX0l...................................'',;:lkXXNNNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXX0,................''.....................'',,,;o0XNNNNNNNNNNNNNNN
XXXXXXXXXXXXXXK;.........................................'.'''''lKNNNNNNNNNNNNNN
XXXXXXXXXXXXX0c..................'................. .. ...'......,kXNNNNNNNNNNNN
XXXXXXXXXXXK:. .............'...........''......'..... ....'......'dXNNNNNNNNNNN
XXXXXXXXXXO. .... ...........................'''.......''.',.......xNNNNNNNNNNN
@CindyLinz
CindyLinz / g.pl
Created May 6, 2014 18:48
Try: perl g.pl and perl g.pl | perl and perl g.pl | perl | perl
eval(join('',qw{$_=q{eval(join('',qw{$_=q{};$s=sub{substr($o,0,1,'')};($p,$P,$_)=/(.{21})(.{428})(.*)/;$l=0+$_;($_,$d)=/(.{$l})(.*)/;$o="$p$P$d$_";($w,$h,$_)=/\d+\D(\d+)\D(\d+)\D(.*)/;@_=split/\D/;$b=$_[-1]||pop@_;$u=scalar($o)x($w*$h);$u=~y/{}#//d;$o="$p$o${P}q#$u";$o=~s/(.*)\x7D/$1.chr(92).'x7D'/e;$f=substr($o,0,$w+2,'').$/;for(1..$h){$f.=&$s;for(1..$w){$f.=$b?&$s:chr(32);--$_[-1]||pop@_||($b=!$b);}$f.=&$s.$/;}$f.=&$s()for(3..$w);$f.="#}))\n";caller(1)?$f:print$f;930,149,46,1074,6,9,6,12,2,2,2,19,3,1,3,3,1,12,5,1,2,60,6,8,8,8,5,2,5,13,6,1,8,8,8,1,4,58,7,8,6,8,5,4,5,10,6,4,7,7,8,3,4,57,7,9,4,8,5,6,5,8,6,7,5,6,8,4,5,56,8,9,2,8,6,6,6,7,5,9,4,6,8,3,7,55,8,9,2,7,7,6,7,5,6,9,4,5,9,3,7,55,9,8,2,7,7,6,7,5,6,10,3,5,9,2,8,55,10,7,2,6,8,6,8,3,8,9,3,5,9,2,8,55,10,7,2,6,8,6,8,3,10,7,3,5,9,2,7,56,11,6,2,6,8,6,8,3,12,6,2,5,9,3,6,57,10,6,2,6,8,6,8,3,15,10,9,4,4,58,11,5,2,5,9,6,9,2,16,9,9,65,1,1,10,5,2,5,9,6,9,3,17,7,9,65,1,2,10,4,2,5,9,6,9,3,18,6,9,65,1,2,11,3,2,5,9,6,9,4,18,5,9,65,2,2,10,3,2,5,9,6,9,5,17,5,9,65,2,2,11,2,2
@CindyLinz
CindyLinz / gist:5779282
Created June 14, 2013 03:35
sample usage for lazy pattern matching
module Main where
fetch :: [Int] -> Int
fetch args =
let
(n : ~(a : ~(b : ~(c : x)))) = args
in
if n == 1
then a
else if n == 2
@CindyLinz
CindyLinz / gist:5076364
Created March 3, 2013 14:44
Another approach, still lazy. But without stack blowup.
{-# LANGUAGE BangPatterns #-}
module T where
import Control.Concurrent.MVar
main = do
countMVar <- newMVar (\ count -> count):: IO (MVar (Int -> Int))
let
process :: IO ()
@CindyLinz
CindyLinz / gist:5076125
Created March 3, 2013 13:40
This program will steadily read lines from STDIN. When meet a line with "out", it will print out the line number. BUT. if there are many many many many lines before the "out", then the "out" will cause the program crash because of the lazy evaluation 'count + 1'. My solution is add a 'seq' to force the evaluation 'count + 1'.
module T where
import Control.Concurrent.MVar
main = do
countMVar <- newMVar 0 :: IO (MVar Int)
let
process :: IO ()
process = do
@CindyLinz
CindyLinz / gist:5071195
Created March 2, 2013 14:19
Transform ByteString and Integral Num back and forth
positiveDecimalBytesToIntegral :: (Integral num, Num num) => L.ByteString -> num
positiveDecimalBytesToIntegral = collect0
where
collect0 :: (Integral num, Num num) => L.ByteString -> num
collect0 bs = case L.uncons bs of
Just (byte, bs') ->
if 0x30 <= byte && byte <= 0x39
then collect1 (fromIntegral $ byte-0x30) bs'
else collect0 bs'
Nothing -> 0
@CindyLinz
CindyLinz / gist:4975534
Created February 18, 2013 06:57
初學 Go 的疑問~
Go 裡面有 struct, 還有指向 Struct 的指標.
就是.. 有這樣的東西:
type T struct {
A int
}
var t T
var p *T
然後, 於這兩種 type 要 access member 的時候語法一樣, 也就是:
t.A