Skip to content

Commit ca9b201

Browse files
Added Codes for Project Euler Solutions
1 parent 00d07a1 commit ca9b201

33 files changed

+510
-21
lines changed
1.17 KB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import java.math.BigInteger;
2+
import java.io.*;
3+
public class BigIntegerFactorial{
4+
public static void main(String[] args)throws IOException{
5+
final BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
6+
int t=Integer.parseInt(br.readLine());
7+
for(int i=0;i<t;i++){
8+
System.out.println(factorial(Integer.parseInt(br.readLine())));
9+
}
10+
}
11+
private static BigInteger factorial(int n){
12+
BigInteger result = BigInteger.ONE;
13+
for(int i=2;i<=n;i++){
14+
result=result.multiply(BigInteger.valueOf(i));
15+
}
16+
return result;
17+
}
18+
}

Codechef/beg/SmallFact.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
12 KB
Binary file not shown.
-1.09 KB
Binary file not shown.
-847 Bytes
Binary file not shown.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java.util.Scanner;
2+
public class IncreasingDecreasingSequence{
3+
public static void main(String[] args){
4+
Scanner cin=new Scanner(System.in);
5+
int n=cin.nextInt();
6+
if(n==0){
7+
System.out.println(false);
8+
return;
9+
}
10+
int[] array=new int[n];
11+
for(int i=0;i<n;i++){
12+
array[i]=cin.nextInt();
13+
}
14+
if(checkSortedInc(array)==true || (checkSortedDec(array)==true || checkSortedDecInc(array))){
15+
System.out.println("true");
16+
}else{
17+
System.out.println("false");
18+
}
19+
}
20+
public static boolean checkSortedInc(int[] array){
21+
for(int i=1;i<array.length;i++){
22+
if(array[i-1]>array[i]){
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
public static boolean checkSortedDec(int[] array){
29+
for(int i=0;i<array.length-1;i++){
30+
if(array[i]<array[i+1]){
31+
return false;
32+
}
33+
}
34+
return true;
35+
}
36+
//3 2 1 2 3
37+
public static boolean checkSortedDecInc(int[] array){
38+
int j=0;
39+
boolean check=false;
40+
for(int i=0;i<array.length-1;i++){
41+
if(array[i]<array[i+1]){
42+
check=true;
43+
}
44+
else{
45+
j=i;
46+
check=false;
47+
break;
48+
49+
}
50+
}
51+
//System.out.println(j);
52+
for(;j<array.length-1;j++){
53+
if(array[j+1]>array[j]){
54+
check=true;
55+
}else{
56+
check=false;
57+
}
58+
}
59+
if(check==true){
60+
return true;
61+
}else{
62+
return false;
63+
}
64+
}
65+
66+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// sum=sum*(nrow-cst)/cst
2+
import java.util.Scanner;
3+
public class PascalTriangle{
4+
public static void main(String[] args){
5+
Scanner cin=new Scanner(System.in);
6+
int n=cin.nextInt();
7+
int nrow=1;
8+
int nst=1;
9+
int nsp=n-1;
10+
while(nrow<=n){
11+
int sum=1;
12+
int cst=1;
13+
while(cst<=nst){
14+
System.out.print(sum+"\t");
15+
sum=sum*(nrow-cst)/cst;
16+
cst++;
17+
}
18+
//prep
19+
System.out.println();
20+
nst++;
21+
++nrow;
22+
}
23+
}
24+
}
-1.11 KB
Binary file not shown.

cdblocks/challenge1/PatternMountain.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public static void main(String[] args){
2525
System.out.print("\t");
2626
++csp;
2727
}
28-
if(nrow==n){--val;}
2928
int csd=1;
29+
if(nrow==n){
30+
csd=2;
31+
--val;
32+
}
3033
while(csd<=nst){
3134
System.out.print(val+"\t");
3235
++csd;

0 commit comments

Comments
 (0)