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

Create a solution for a binary number problem #50

Merged
merged 2 commits into from
Oct 21, 2021
Merged
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
67 changes: 67 additions & 0 deletions Java/Algorithm/Threads.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

import java.util.Scanner;

import heavy.threads;
import java.util.Scanner;
public class Threads {

public static void main (String args[]) throws InterruptedException
{
Scanner sc=new Scanner(System.in);
myThread1 t1=new myThread1(); //creating a object of class myThread1
myThread2 t2=new myThread2();
myThread3 t3=new myThread3();
t1.run(); //invoking run method in class muThread1
t1.sleep(4000); //putting for sleep 4 sec
t2.run();
t2.sleep(2000);
t3.run();

}


}
class myThread1 extends Thread
{
public void run()
{

System.out.println("enter any number");
Scanner sc = new Scanner(System.in);
int a=sc.nextInt();
int k=fib(a);
System.out.println(k);

}
public static int fib(int n)
{
if (n <= 1)
{
return n;
}
else
{
return fib(n-1) + fib(n-2);
}
}
}
class myThread2 extends Thread
{
public void run()
{
for(int i=100;i<=150;i++)
{
System.out.println(i);
}
}
}
class myThread3 extends Thread
{
public void run()
{
for(int i=1;i<=10;i++)
{
System.out.println(i);
}
}
}
55 changes: 55 additions & 0 deletions Python/BinaryNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Given a base-10 integer,n, convert it to binary (base-2). Then find and print the base-10 integer denoting the maximum number of consecutive 1's in n's binary representation. When working with different bases, it is common to show the base as a subscript.

Example

n=125

The binary representation of 125 is1111101 . In base 10 , there are 5 and 1 consecutive ones in two groups. Print the maximum, .

Input Format

A single integer,n .

1<=n<=10^6

Output Format

Print a single base-10 integer that denotes the maximum number of consecutive 1's in the binary representation of n.

Sample input
-------
5
Sample output
------
1

Sample input
-------
13
Sample output
------
2


Ans -Python
-----------
#here we need to read a number and find it binary then we need to print the number of maximum ajacent 1 is there
#i converted it into binary using bin fuction and made it into string and then made an list with spilt via '0', Now we just need print the length of maximum valued binary number


import math
import os
import random
import re
import sys
def fun(n):
s="".join(bin(n))
s=s.split('b')
p="".join(s[1])
p=p.split('0')
print(len(max(p)))


if __name__ == '__main__':
n = int(input().strip())
fun(n)