Sort by

recency

|

2818 Discussions

|

  • + 0 comments

    python 3

    def base2(n):

    mybin = bin(n)[2::]
    
    return max(map(len, mybin.split('0')))
    
  • + 0 comments

    Pyhton

    n = int(input())

    binary_representation = bin(n)[2:]

    consecutive_ones = binary_representation.split('0')

    max_consecutive_ones = max(len(group) for group in consecutive_ones)

    print(max_consecutive_ones)

  • + 0 comments

    My C# solution

    public static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine().Trim());

        string binary = Convert.ToString(n ,2);
    
        char[] c = binary.ToCharArray();
    
        int iCount = 1;   
        int left = 0;
        int right = 1;
        // This list will be used to store each count.
        // After each iteration, we add the count to the list.
        // After the loop has finished, we sort the elements in the 
        //list,
        // and finally, we print the last element of the list.
       List<int> lstCounts = new List<int>();
    
        for(int i = 0 ; i < c.Length ; i++)
        {
             if(right <= c.Length -1 )
            {
                 if(c[left] == c[right] && c[right] == '1')
                { 
                    iCount++;
                    lstCounts.Add(iCount);
                }
                 else 
                 { 
                    lstCounts.Add(iCount);
                    iCount = 1;
                 }
            }
    
            left++;
            right++;          
        }
    
    // sort elements from the list  
     lstCounts.Sort();
     //print the highest count from the list
     Console.Write(lstCounts.LastOrDefault()); 
    
    
    }
    
  • + 0 comments

    import math import os import random import re import sys

    def intoBinary(number): binarynumber="" if (number!=0): while (number>=1): if (number %2==0): binarynumber=binarynumber+"0" number=number/2 else: binarynumber=binarynumber+"1" number=(number-1)/2 else: binarynumber="0" return "".join(reversed(binarynumber))

    def count_consecutive(bin_num): count=0 flag=0 max_count=-1 for i in range(len(bin_num)): if bin_num[i]=='1': flag=1 else: flag=0 if flag==1: count+=1
    if (flag==0) or (i==len(bin_num)-1): if max_count

    if name == 'main': n = int(input().strip()) #print(intoBinary(n)) #print(intoBinary(125)) count_consecutive(intoBinary(n))

  • + 0 comments

    Python 3 code

    import math import os import random import re import sys

    if name == 'main': n = int(input().strip()) binary = bin(n)[2:] print(len(max(binary.split("0"))))