Skip to content

Instantly share code, notes, and snippets.

View ktnyt's full-sized avatar
🐱

ktnyt ktnyt

🐱
View GitHub Profile
@ktnyt
ktnyt / seive1.c
Created March 24, 2014 09:31
Seive1
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#define BLOCK 30
#define CHECK(X, Y) (X & (1 << (Y - 1)))
int main(int argc, char** argv) {
@ktnyt
ktnyt / seive2.c
Created March 24, 2014 09:31
Seive2
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#define BLOCK 64
int main(int argc, char** argv) {
uint64_t *prime, *mask, limit, i, j;
@ktnyt
ktnyt / seive3.c
Created March 24, 2014 17:12
Seive3
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#define BLOCK 64
#define SHIFT(X) (1ULL << (X - 1))
#define CHECK(X,Y) (X & SHIFT(Y))
@ktnyt
ktnyt / weird-seive.c
Created March 25, 2014 14:55
Weird Stuff
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
const uint64_t mask64[] = {
0x0000000000000001,0x0000000000000002,0x0000000000000004,0x0000000000000008,
0x0000000000000010,0x0000000000000020,0x0000000000000040,0x0000000000000080,
0x0000000000000100,0x0000000000000200,0x0000000000000400,0x0000000000000800,
@ktnyt
ktnyt / tsurukame.c
Created April 17, 2014 01:40
つるかめ算 with C
/* とりあえずここの中はテンプレだと思って大丈夫。
** #include <ライブラリ名.h> ってやるとライブラリを使える。
** stdioとstdlibがあれば大抵できるけど他にもほしくなるケースもあるよ。
** int main() っていうのも定型文で、メインの処理をここに書くよ。
** ※だからmainっていう名前なのね。
** int argcとchar** argvはコマンドライン引数って言うよ。
** コンパイルしたあとに実行するときに
** ./hoge 10 20 みたいにするとスペースで区切られた文字列が入ってるよ。
** テンプレここから ***********************************************************
@ktnyt
ktnyt / fibonacci.c
Created April 17, 2014 01:44
フィボナッチ with C
/* とりあえずここの中はテンプレだと思って大丈夫。
** #include <ライブラリ名.h> ってやるとライブラリを使える。
** stdioとstdlibがあれば大抵できるけど他にもほしくなるケースもあるよ。
** int main() っていうのも定型文で、メインの処理をここに書くよ。
** ※だからmainっていう名前なのね。
** int argcとchar** argvはコマンドライン引数って言うよ。
** コンパイルしたあとに実行するときに
** ./hoge 10 20 みたいにするとスペースで区切られた文字列が入ってるよ。
** テンプレここから ***********************************************************
@ktnyt
ktnyt / easy-prime.c
Created April 22, 2014 02:53
かんたんな素数列挙
#include <stdio.h>
int isPrime(int n) {
int i;
for(i = 2; i * i <= n; ++i) {
if(n % i == 0) {
return 0;
}
}
@ktnyt
ktnyt / nyancat.c
Last active August 29, 2015 14:01
Let's nyan
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 256
int main() {
char str1[MAXLINE];
char str2[MAXLINE];
char str3[MAXLINE];
@ktnyt
ktnyt / srl.c
Last active August 29, 2015 14:02
Self referencing list
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// struct listじゃなくてlistで定義できるおまじない
typedef struct _list {
char* name;
struct _list* next;
} list;
@ktnyt
ktnyt / picture.pde
Created July 7, 2014 07:49
Press enter to take a picture
import processing.video.*;
Capture camera;
PImage picture = null;
void setup() {
size(640, 480);
camera = new Capture(this, 640, 480, 30);
camera.start();