Skip to content

Commit

Permalink
Merge pull request #2 from ambujraj/master
Browse files Browse the repository at this point in the history
Merging
  • Loading branch information
jvalbhani authored Oct 23, 2018
2 parents ff06439 + 7680407 commit 378e6db
Show file tree
Hide file tree
Showing 310 changed files with 13,664 additions and 249 deletions.
2 changes: 2 additions & 0 deletions # HacktoberFest2018_chimdolin_come
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# HacktoberFest2018_chimdolin_come
# HacktoberFest2018_chimdolin_come
Binary file removed .DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
Expand Down
181 changes: 181 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions 1-0_knapsack_problem/0-1_knapsack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//0-1 Knapsack problem using dynamic programming
#include<iostream.h>

int max(int a, int b) { return (a > b)? a : b; }

int knapSack(int W, int wt[], int val[], int n)
{
int i, w;
int K[n+1][W+1];

for (i = 0; i <= n; i++)
{
for (w = 0; w <= W; w++)
{
if (i==0 || w==0)
K[i][w] = 0;
else if (wt[i-1] <= w)
K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]);
else
K[i][w] = K[i-1][w];
}
}

return K[n][W];
}

void main()
{
int val[] = {50, 110, 115};
int wt[] = {10, 20, 30};
int W = 50;
int n = 1;
int c=knapSack(W, wt, val, n);
cout<<c;
}
28 changes: 28 additions & 0 deletions 1-0_knapsack_problem/1-0_knapsak_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
""" Knapsack problem by dynamic programming """
weight = [1,3,4,5]
value = [1,4,5,7]
n = len(weight)+1
max_wt = 7
v = [[0 for j in range(max_wt+1)] for i in range(n)]

def print_items(i, j):
if i>0 and j>0 :
if v[i][j] != v[i-1][j] :
print(str(weight[i-1])+"\t\t\t"+str(value[i-1]))
print_items(i-1, v[i-1].index(v[i][j]-value[i-1]))
else :
print_items(i-1, j)


def knapsack():
for i in range(1, n):
for j in range(1, max_wt+1):
if j-weight[i-1] >= 0 :
v[i][j] = max([v[i-1][j], v[i-1][j-weight[i-1]]+value[i-1]])
else :
v[i][j] = v[i-1][j]
print("Selected Weight\t\tValue")
print_items(n-1, max_wt)
print("\nMaximum Value : "+str(v[n-1][max_wt]))

knapsack()
34 changes: 34 additions & 0 deletions 1-0_knapsack_problem/matrix_chain_mul.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

//chain matrix multiplication using recursion
#include<iostream.h>

int Order(int m[], int i, int j)
{
if(i == j)
return 0;
int k;
int min=0;
int count;

for (k = i; k <j; k++)
{
count = Order(m, i, k) +
Order(m, k+1, j) +
m[i-1]*m[k]*m[j];

if (count < min)
min = count;
}

return min;
}


void main()
{
int arr[] = {1, 2, 3, 4, 5};
int n = 5;

int c=Order(arr, 1, n-1));
cout<< "min no. of multiplications is: "<< c;
}
32 changes: 32 additions & 0 deletions 8 queen/queen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<stdio.h>

int main(){
int st1[8]={2,4,7,4,8,5,5,2},st2[8]={3,2,7,5,2,4,1,1},st3[8]={2,4,4,1,5,1,2,4},st4[8]={3,2,5,4,3,2,1,3};
int i,st1f,st2f,st3f,st4f;
/* printf("Enter st1: ");
for(i=0;i<8;i++)
scanf("%d",&st3[i]);
*/
printf("ST1 : ");
for(i=0;i<8;i++){
printf("%d ",st1[i]);
}
printf("\nST2 : ");
for(i=0;i<8;i++){
printf("%d ",st1[i]);
}
printf("\nST3 : ");
for(i=0;i<8;i++){
printf("%d ",st1[i]);
}
printf("\nST4 : ");
for(i=0;i<8;i++){
printf("%d ",st1[i]);
}
printf("\nEnter fitness functions of st1, st2, st3 and st4 : ");
scanf("%d%d%d%d",&st1f,&st2f,&st3f,&st4f);
printf("Fitness function :\n st1=%d\t st2=%d\t st3=%d\t st4=%d ",st1f,st2f,st3f,st4f);

return 0;

}
4 changes: 1 addition & 3 deletions ArrayToArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static void main(String args[])
ArrayList<Integer> ar=new ArrayList<>(Arrays.asList(i));
ar.add(54889);
System.out.println(ar);




}

}
10 changes: 10 additions & 0 deletions BigInteger_InJava/Demo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public static void main(String[] args) {
BigInteger bigNum = new BigInteger("100000000000000000000000");
long temp = 1235678900;

/*Some constants also be defined in BigInteger such as*/

BigInteger bI = BigInteger.TEN; // some other constants are BigInteger.ONE and BigInteger.ZERO

//------------------------------------------------------

System.out.println("Added value : " + bigNum.add(BigInteger.valueOf(temp)));

System.out.println("Multiplied value : " + bigNum.multiply(BigInteger.valueOf(temp)));
Expand All @@ -28,6 +34,10 @@ public static void main(String[] args) {

System.out.println("GCD value : " + bigNum.gcd(BigInteger.valueOf(temp)));

System.out.println("ABS value : " + bigNum.abs(BigInteger.valueOf(temp)));

System.out.println("Divided and Remainder value : " + bigNum.divideAndRemainder(BigInteger.valueOf(temp)));


}
}
Loading

0 comments on commit 378e6db

Please sign in to comment.