From e71079523f4f9afcf31356a3db939e99bcf63457 Mon Sep 17 00:00:00 2001 From: Rishabrp99 Date: Mon, 19 Oct 2020 20:52:44 +0530 Subject: [PATCH 1/6] Added Floyd warshall Algorithm in C#. Added Flyod Warshall Algorithm in c#.Also updates README .  --- C#/README.md | 2 ++ C#/floydwarshallalgo.cs | 57 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 C#/floydwarshallalgo.cs diff --git a/C#/README.md b/C#/README.md index d062891c..df01417d 100644 --- a/C#/README.md +++ b/C#/README.md @@ -11,6 +11,8 @@ Format: -[Program name](name of the file) -[FizzBuzz](FizzBuzz.cs) +-[floyd Warshall Algorithm](flyodwarshallalgo.cs) + -[Mean and Median](MeanAndMedian.cs) -[Power Set](Power_Set.cs) diff --git a/C#/floydwarshallalgo.cs b/C#/floydwarshallalgo.cs new file mode 100644 index 00000000..1b5dcd34 --- /dev/null +++ b/C#/floydwarshallalgo.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +class floyd_warshall{ + static void Main(string[] args){ + int n=0; + n=Console.ReadLine(); + int[][] adjmat=new int[n][n]; + for(int i=0;i Date: Tue, 20 Oct 2020 13:09:46 +0530 Subject: [PATCH 2/6] Added Evil Number Code in Python. --- Python/Evil_Number.py | 48 +++++++++++++++++++++++++++++++++++++++++++ Python/README.md | 2 ++ 2 files changed, 50 insertions(+) create mode 100644 Python/Evil_Number.py diff --git a/Python/Evil_Number.py b/Python/Evil_Number.py new file mode 100644 index 00000000..40621c6c --- /dev/null +++ b/Python/Evil_Number.py @@ -0,0 +1,48 @@ +# Python program to check if a number is +# Evil number or Odious number + +# returns number of 1s from the binary number +def count_one(n): + c_one = 0 + while n != 0: + rem = n % 10 + + # Counting 1s + if rem == 1: + c_one = c_one + 1 + n = n / 10 + + return c_one + +# Check if nnumber is evil or not +def checkEvil(n): + i = 0 + binary = 0 + + # Converting n to binary form + while n != 0: + r = n % 2 + # Calculating Remainder + # Storing the remainders in binary + # form as a number + binary = binary + r*(int(10**i)) + n = n / 2 + + # Calling the count_one function to count + # and return number of 1s in bin + n_one = count_one(binary) + if n_one % 2 == 0: + return True + return False + +# Driver Code +num = 32 +check = checkEvil(num) +if check: + print (num, "is Evil Nummber") +else: + print (num, "is Not a evil Number") + + + + diff --git a/Python/README.md b/Python/README.md index c85d13df..f60ea5a4 100644 --- a/Python/README.md +++ b/Python/README.md @@ -8,6 +8,8 @@ Format: -[Program name](name of the file) -[Arithmetic Progression](arithmetic.py) +-[Evil Number](Evil_Number.py) + -[AVL Tree](avl-tree.py) -[Automorphic Number](automorphic.py) From 40802ea90c6f020c9c6060dcee182bd6396ac18a Mon Sep 17 00:00:00 2001 From: Rishabrp99 Date: Thu, 22 Oct 2020 14:56:25 +0530 Subject: [PATCH 3/6] Added Program to find prefix sum array . --- JavaScript/prefix_sum_Array.js | 16 ++++++++++++++++ Python/Evil_Number.py | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 JavaScript/prefix_sum_Array.js diff --git a/JavaScript/prefix_sum_Array.js b/JavaScript/prefix_sum_Array.js new file mode 100644 index 00000000..f78e74c4 --- /dev/null +++ b/JavaScript/prefix_sum_Array.js @@ -0,0 +1,16 @@ +const arr = [10, 5, 6, 12, 7, 1]; +const sumRecursively = (arr, start = 0, res = 0) => { + if(start < arr.length){ + return sumRecursively(arr, start+1, res+arr[start]); + }; + return res; +}; +const partSumRecursively = (arr, partSum = [], start = 0, end = +arr.length-1) => { + if(start <= end){ + return partSumRecursively(arr, partSum.concat(sumRecursively(arr, + start)), ++start, end); + }; + return partSum; +}; +console.log(partSumRecursively(arr)); \ No newline at end of file diff --git a/Python/Evil_Number.py b/Python/Evil_Number.py index 40621c6c..63850a8e 100644 --- a/Python/Evil_Number.py +++ b/Python/Evil_Number.py @@ -36,13 +36,21 @@ def checkEvil(n): return False # Driver Code -num = 32 +num = 23 check = checkEvil(num) if check: - print (num, "is Evil Nummber") + print (num, "is Evil Number") else: print (num, "is Not a evil Number") +"""An evil number is a non-negative number that has an even number of 1s in its binary expansion. +(Binary Expansion – is representation of a number in the binary numeral system or base-2 numeral system which represents numeric values using two different symbols: typically 0 (zero) and 1 (one)). +sample input: +23 + +Output: +23 is Evil Number +""" From 05445d1f5116a7e45b30285f0a9cdd9e00f18f85 Mon Sep 17 00:00:00 2001 From: Rishabrp99 Date: Thu, 22 Oct 2020 20:21:06 +0530 Subject: [PATCH 4/6] Added Program to find Prefix sum array of an array. --- JavaScript/README.md | 2 ++ JavaScript/prefix_sum_Array.js | 36 +++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/JavaScript/README.md b/JavaScript/README.md index 9a7c3a3a..dc55952a 100644 --- a/JavaScript/README.md +++ b/JavaScript/README.md @@ -45,6 +45,8 @@ Format: -[Program name](name of the file) -[Powerset of a set](Powerset.js) +-[Prefix sum Array](prefix_Sum_Array.js) + -[QuickSort](QuickSort.js) -[Selection Sort](SelectionSort.js) diff --git a/JavaScript/prefix_sum_Array.js b/JavaScript/prefix_sum_Array.js index f78e74c4..826476c3 100644 --- a/JavaScript/prefix_sum_Array.js +++ b/JavaScript/prefix_sum_Array.js @@ -1,16 +1,20 @@ -const arr = [10, 5, 6, 12, 7, 1]; -const sumRecursively = (arr, start = 0, res = 0) => { - if(start < arr.length){ - return sumRecursively(arr, start+1, res+arr[start]); - }; - return res; -}; -const partSumRecursively = (arr, partSum = [], start = 0, end = -arr.length-1) => { - if(start <= end){ - return partSumRecursively(arr, partSum.concat(sumRecursively(arr, - start)), ++start, end); - }; - return partSum; -}; -console.log(partSumRecursively(arr)); \ No newline at end of file + /*Program to find the Prix Sum Array of the given Array. + Prefix Sum Array: + Prefix sum array is another array made by sequence sum of the elements of the given array. + */ +//function to +const prefix_sum=(arr)=>{ + //To calculate length of given array + const n=arr.length + //Creating new array of same size as inputs. + const new_arr=new Array(n) + new_arr[0]=arr[0] + for(var i=1;i Date: Thu, 22 Oct 2020 20:38:32 +0530 Subject: [PATCH 5/6] Added Program to find evil number in python. --- Python/Evil_Number.py | 73 +++++++++++++------------------------------ 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/Python/Evil_Number.py b/Python/Evil_Number.py index 63850a8e..d077d4af 100644 --- a/Python/Evil_Number.py +++ b/Python/Evil_Number.py @@ -1,56 +1,27 @@ -# Python program to check if a number is -# Evil number or Odious number +# Program to find the Evil Number . +#Taking input from the user +n=int(input()) +i=0 +binry=0 +while(n!=0): + remainder=n%2 + binry=binry+remainder*(int(10**i)) + n=n//2 +#Counting number of 1's +while(binry!=0): + rem=binry%2 + if rem==1: + count=count+1 + binry=binry//10 +if count%2==0: + print("Evil Number.") +else: + print("Not an evil number.") -# returns number of 1s from the binary number -def count_one(n): - c_one = 0 - while n != 0: - rem = n % 10 - - # Counting 1s - if rem == 1: - c_one = c_one + 1 - n = n / 10 - - return c_one +"""An evil number is the number which has even number of 1's in its binary equivalent. +Sample input:256 +Sample output:Not a evil number -# Check if nnumber is evil or not -def checkEvil(n): - i = 0 - binary = 0 - - # Converting n to binary form - while n != 0: - r = n % 2 - # Calculating Remainder - # Storing the remainders in binary - # form as a number - binary = binary + r*(int(10**i)) - n = n / 2 - - # Calling the count_one function to count - # and return number of 1s in bin - n_one = count_one(binary) - if n_one % 2 == 0: - return True - return False - -# Driver Code -num = 23 -check = checkEvil(num) -if check: - print (num, "is Evil Number") -else: - print (num, "is Not a evil Number") - -"""An evil number is a non-negative number that has an even number of 1s in its binary expansion. -(Binary Expansion – is representation of a number in the binary numeral system or base-2 numeral system which represents numeric values using two different symbols: typically 0 (zero) and 1 (one)). - -sample input: -23 -Output: -23 is Evil Number """ - From 74c8e53dab2751c7564ee9516748ab2a68c430d3 Mon Sep 17 00:00:00 2001 From: Rishabrp99 Date: Thu, 22 Oct 2020 21:21:28 +0530 Subject: [PATCH 6/6] Added python program to find wheter number is evil number. --- Python/Evil_Number.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Python/Evil_Number.py b/Python/Evil_Number.py index d077d4af..6f5067e1 100644 --- a/Python/Evil_Number.py +++ b/Python/Evil_Number.py @@ -21,7 +21,5 @@ """An evil number is the number which has even number of 1's in its binary equivalent. Sample input:256 Sample output:Not a evil number - - """