This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Square | |
{ | |
public static void drawSquare(int N, double x, double y, double r) | |
{ | |
if(N == 0) | |
return; | |
StdDraw.square(x, y, r); | |
StdDraw.show(100); | |
drawSquare(N-1, x - r , y + r, r/2.2); | |
drawSquare(N-1, x + r , y + r, r/2.2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Combination | |
{ | |
public static void combinate(String prefix, String s) | |
{ | |
StdOut.println(prefix); | |
int N = s.length(); | |
if (N == 0) return; | |
for (int i = 0; i < N; i++) | |
combinate(prefix + s.charAt(i), s.substring(i+1, N)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Permutation | |
{ | |
public static void perm1(String s) { perm1("", s); } | |
public static void perm1(String prefix, String s) | |
{ | |
int N = s.length(); | |
if (N == 0) System.out.println(prefix); | |
else | |
{ | |
for(int i = 0; i < N; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BP | |
{ | |
public static String binary(int N) | |
{ | |
if(N / 2 == 0) return "" + N; | |
return binary(N/2) + "" + N % 2; | |
} | |
public static void main(String[] args) | |
{ | |
int N = Integer.parseInt(args[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Ruler | |
{ | |
public static String ruler(int N) | |
{ | |
if (N <= 0) return ""; | |
if (N == 1) return "1"; | |
return ruler(N-1) + N + ruler(N-1); | |
} | |
public static void drawRuler(String a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Post | |
{ | |
public static void halfHeight(double i) | |
{ | |
StdDraw.setPenRadius(.01); | |
StdDraw.line(i, 0, i, 1); | |
} | |
public static void fullHeight(double i) | |
{ | |
StdDraw.setPenRadius(0.01); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Mine | |
{ | |
public static void main(String[] args) | |
{ | |
int M = Integer.parseInt(args[0]); | |
int N = Integer.parseInt(args[1]); | |
double p = Double.parseDouble(args[2]); | |
boolean[][] mine = new boolean[M+2][M+2]; | |
for(int i = 1; i <= M; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Calendar | |
{ | |
public static boolean isLeapYear(int year) | |
{ | |
if((year % 4 ==0 && year % 100 != 0) || (year % 400 == 0)) | |
return true; | |
return false; | |
} | |
public static String getMonth(int month) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Hadamard | |
{ | |
public static void main(String[] args) | |
{ | |
int N = Integer.parseInt(args[0]); | |
boolean[][] H = new boolean[N][N]; | |
H[0][0] = true; | |
for(int n = 1; n < N; n += n) | |
{ | |
for(int i = 0; i < n; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Kary | |
{ | |
public static void main(String[] args) | |
{ | |
int i = Integer.parseInt(args[0]); | |
int k = Integer.parseInt(args[1]); | |
int v = 1; | |
while (v <= i/k) | |
v *= k; | |
int n = i; |