Skip to content

Instantly share code, notes, and snippets.

@h2rashee
Last active August 29, 2015 14:08
Show Gist options
  • Save h2rashee/d7071252ac239bbbb0fb to your computer and use it in GitHub Desktop.
Save h2rashee/d7071252ac239bbbb0fb to your computer and use it in GitHub Desktop.
Find the coolness of a number; coolness is number of zeros contained in the decimal representation of the number
import java.io.*;
import java.util.*;
class Coolness
{
public static void main(String[] args)
{
long num;
long num1 = Long.parseLong(args[0]);
long num2 = Long.parseLong(args[1]);
System.out.println(findcoolness(num1));
System.out.println(getNaiveNumCoolRange(num1, num2));
}
static int findcoolness(long num)
{
if(num == 0)
{
return 1;
}
int coolness = 0;
while(num != 0)
{
// if its divisible by 10
if(num % 10 == 0)
{
coolness++;
}
num /= 10;
}
return coolness;
}
static int getNaiveNumCoolRange(long start, long end)
{
if(start > end)
{
return 0;
}
return findcoolness(start) + getNaiveNumCoolRange(start+1, end);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment