Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evil no #799

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JavaScript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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)
Expand Down
20 changes: 20 additions & 0 deletions JavaScript/prefix_sum_Array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*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<n;i++){
new_arr[i]=new_arr[i-1]+arr[i]
}
return new_arr
}
const test_array=[5,2,4,5,1]
console.log(prefix_sum(test_array))

//Sample Output:5,7,11,16,17
66 changes: 22 additions & 44 deletions Python/Evil_Number.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
# 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")

# 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.")

"""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