prmd89
BAN USERimport java.util.Scanner;
public class Bleak {
/**
In Mathematics each number has one special number, which it supports, chosen as follows.
It counts the number of ones in its own binary representation, and adds this count to itself
to obtain the value of the number it supports. That is, if j(m) means the number of ones in
the binary representation of m, then m supports m+j(m). For example, the number eight (1000 in binary)
supports nine, whereas nine supports eleven.
However, in this way not all the numbers get supported; some are left without support, and we call
these numbers bleak. For example since one supports two, two supports three and three supports five,
there is no number less than four, which would support four, so four is bleak.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
while(true){
System.out.println("Enter Num");
Scanner scanner = new Scanner(System.in);
int val=scanner.nextInt();
System.out.println(isBleak(val,0,val));
System.out.println("-------------------------------");
}
}
static int supppoertedValue(int inputVal){
System.out.println(Integer.toBinaryString(148).replace("0", "").length()+148);
return Integer.toBinaryString(inputVal).replace("0", "").length()+inputVal;
}
static boolean isBleak(int high,int low,final int value){
int med=(high+low)/2;
boolean bool=false;
while (med <= high-1 && low<high-1) {
med=(high+low)/2;
int val=supppoertedValue(med);
System.out.println(" high:"+high+" low:"+low+" med:"+med+" val:"+val+"=="+value);
if (val==value) {
bool= true;
break;
}
if(val<value){
low= med;
}else if(val>value){
high=med;
}
}
return bool;
}
}
public static void main(String[] args) {
int[] num1={1,2,3,4,5};
int[] num2={1,2,4,6};
System.out.println(multiply(breakNumbers(num1), breakNumbers(num2)));
int sum=0;
Map<Integer,Integer> multiplyMap = multiply(breakNumbers(num1), breakNumbers(num2));
for (Map.Entry<Integer,Integer> entry : multiplyMap.entrySet()) {
sum +=(entry.getKey()*(Math.pow(10,entry.getValue())));
}
System.out.println(sum);
}
static Map<Integer,Integer> multiply(Map<Integer,Integer> num1,Map<Integer,Integer> num2){
Map<Integer,Integer> multiplyMap=new LinkedHashMap<Integer,Integer>();
for (Map.Entry<Integer,Integer> entry1 : num1.entrySet()) {
for (Map.Entry<Integer,Integer> entry2 : num2.entrySet()) {
multiplyMap.put(entry1.getKey()*entry2.getKey(), entry1.getValue()+entry2.getValue());
}
}
return multiplyMap;
}
static Map<Integer,Integer> breakNumbers(int[] num1){
Map<Integer,Integer> numMap=new LinkedHashMap<Integer,Integer>();
String s="";
int count=0;
for(int i=0;i<num1.length;i++){
count++;
if(count==3 || i==num1.length-1){
s+=num1[i];
numMap.put(Integer.valueOf(s), num1.length-(i+1));
s="";
count=0;
}else{
s+=num1[i];
}
}
return numMap;
}
String [][] pDirArr = {{"abc", "123"},{"Abc", "1234"}, {"ABC", "789"},{"xy", "123"},{"XY", "456"}};
Map<String,String> inputDirectoryMap = new HashMap<String,String>();
for(int i=0;i<pDirArr.length;i++){
String name=(pDirArr[i][0]).toLowerCase();
if(inputDirectoryMap.containsKey(name)){
String previousNum= inputDirectoryMap.get(name);
inputDirectoryMap.put(name,previousNum+" , "+pDirArr[i][1]);
}else{
inputDirectoryMap.put(name,pDirArr[i][1]);
}
}
for (Map.Entry<String,String> entry : inputDirectoryMap.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
public static void main(String[] args) {
String[] arr={"abc","cab","fdg","sbc","bac","bsc"};
String inputKey="cba";
System.out.println(getAllPaatern(arr,inputKey));
}
static List<String> getAllPaatern(String[] inputArray, String searchKey){
List<String> wordList= new ArrayList<String>();
for(int i=0;i <inputArray.length;i++){
if(getSortedString(inputArray[i].toLowerCase()).equals(getSortedString(searchKey.toLowerCase()))){
wordList.add(inputArray[i]);
}
}
return wordList;
}
static String getSortedString(String str){
char [] c = str.toCharArray();
Arrays.sort(c);
return new String(c);
}
import java.util.Scanner;
- prmd89 November 23, 2015public class Bleak {
/**
In Mathematics each number has one special number, which it supports, chosen as follows.
It counts the number of ones in its own binary representation, and adds this count to itself
to obtain the value of the number it supports. That is, if j(m) means the number of ones in
the binary representation of m, then m supports m+j(m). For example, the number eight (1000 in binary)
supports nine, whereas nine supports eleven.
However, in this way not all the numbers get supported; some are left without support, and we call
these numbers bleak. For example since one supports two, two supports three and three supports five,
there is no number less than four, which would support four, so four is bleak.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
while(true){
System.out.println("Enter Num");
Scanner scanner = new Scanner(System.in);
int val=scanner.nextInt();
System.out.println(isBleak(val,0,val));
System.out.println("-------------------------------");
}
}
static int supppoertedValue(int inputVal){
System.out.println(Integer.toBinaryString(148).replace("0", "").length()+148);
return Integer.toBinaryString(inputVal).replace("0", "").length()+inputVal;
}
static boolean isBleak(int high,int low,final int value){
int med=(high+low)/2;
boolean bool=false;
while (med <= high-1 && low<high-1) {
med=(high+low)/2;
int val=supppoertedValue(med);
System.out.println(" high:"+high+" low:"+low+" med:"+med+" val:"+val+"=="+value);
if (val==value) {
bool= true;
break;
}
if(val<value){
low= med;
}else if(val>value){
high=med;
}
}
return bool;
}
}