Skip to content

Instantly share code, notes, and snippets.

@pcyu16
pcyu16 / prime.cpp
Created March 24, 2010 16:24
building prime table
/*
* building isprime table and prime_seq table
* build 10^6 isprime + prime_seq table cost <0.1 sec
* seq_top means the total numer in prime_seq ( 1~10^6 : 78498 prime )
* isprime: false false true true false TRUE ...
* 0 1 2 3 4 5
* prime_seq: 2 3 5 7 11 13 ...
*
* example:
* 1. check if 234567 is a prime => Yes
@pcyu16
pcyu16 / coin_change.c
Created March 24, 2010 16:39
DP problem - Coin Change
/*
* dp problem - coin change
* change[n]: number of ways to make change of n with coin_set given
*
* example
* with coin set {1,5,10,25,50}
* There are 2050869227 ways to make change of 7400
*/
#include <stdio.h>
#include <string.h>
@pcyu16
pcyu16 / bigmod.c
Created March 24, 2010 16:40
Bigmod
/*
* bigmod: caculate ( base ^ power ) mod modular
* usage: bigmod ( base, power, modular);
*
* input: base, power, modular
* output: return value
*
* example: print value of ( 2374859 ^ 3029382 ) % 36123
* output 13195
*/
@pcyu16
pcyu16 / code.java
Created April 4, 2010 23:02
all permutation example, using bit mask checking
public class code
{
public static int pow2(int power)
{
int ret = 1;
for(int t=0;t<power;t++)
ret <<= 1;
return ret;
}
@pcyu16
pcyu16 / test.lex
Created April 18, 2010 21:49
basic lex file
%{
int yywarp(void);
%}
%%
%%
int main()
{
yylex();
return 0;
}
@pcyu16
pcyu16 / SPFA.cpp
Created May 16, 2010 17:42 — forked from CrBoy/SPFA.cpp
SPFA
/*
* SPFA - Shortest Path Faster Algorithm
*/
#include <cstdio> // printf
#include <cstdlib> // NULL
#include <algorithm> // fill
#include <vector>
#include <queue>
using namespace std;
@pcyu16
pcyu16 / sample.output
Created May 24, 2010 13:36
output for compiler hw
Read: x
If
Op: <
Const: 0
Id: x
Assign to: fact
Const: 1
Repeat
Assign to: fact
Op: *
@pcyu16
pcyu16 / getch.c
Created May 30, 2010 18:08
getch for unix-like system
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
@pcyu16
pcyu16 / LayoutTest.java
Created June 5, 2010 08:05
java GUI layout test
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
public class LayoutTest extends JFrame{
public static final int x_start = 150, y_start = 100;
public static final int WIDTH = 500, HEIGHT = 150;
* Standard prelude:
0: LD 6,0(0) load maxaddress form location 0
1: ST 0,0(0) clear location 0
* End of standard prelude
2: LDA 0,1(7) save return address in ac
4: HALT 0,0,0 program end
5: ST 0,-1(6) start function code section(save return address)
6: LDC 0,1(0) ac = 1
* One instruction's place is reserved here