shashi kumar
BAN USERpackage com.eb.corealgo;
public class SquareValue {
int finalCount=0;;
public int getNumberSquareCount(int number){
int foundIndexValue=-1;
int repeatIndexValue=-1;
boolean isComplete=false;
int repeatNumber=-1;
for(int i=1;i<=number;i++){
int doubleVal=i*i;
if(number==doubleVal){
foundIndexValue=i;
isComplete=true;
break;
}
if(doubleVal>number){
foundIndexValue=i;
break;
}
if(doubleVal<number){
foundIndexValue=i;
}
}
if(foundIndexValue!=-1){
repeatIndexValue=foundIndexValue-1;
finalCount++;
}
repeatNumber=number-repeatIndexValue*repeatIndexValue;
if(repeatNumber>0 && repeatNumber!=1 && !isComplete){
//call again
foundIndexValue=-1;
getNumberSquareCount(repeatNumber);
}
else if(!isComplete){
finalCount++;
}
return finalCount;
}
//test
public static void main(String args[]){
SquareValue v=new SquareValue();
v.getNumberSquareCount(11);
}
}
test
package com.eb.corealgo;
import java.util.ArrayList;
public class ChemicalStringSymbol {
public String[] replaceBrackets(String []chemical,String []symbol){
int length=-1;
int currentFoundIndex=-1;
ArrayList<String> returnList=new ArrayList<String>();
for(String che:chemical){
//iterate through symbols
for(int i=0;i<symbol.length;i++){
if(che.contains(symbol[i])){
//found so take length
if(length<symbol[i].length()){
length=symbol[i].length();
currentFoundIndex=i;
}
}
}
//replace highest with bracket
returnList.add(getWithBrackets(che,symbol[currentFoundIndex]));
currentFoundIndex=-1;
length=-1;
}
return returnList.toArray(new String[returnList.size()]);
}
private String getWithBrackets(String che, String tempString) {
//get substring
int subStringLength=che.indexOf(tempString);
if(subStringLength==-1){
return null;
}
String subString=che.substring(subStringLength,tempString.length()+subStringLength);
String appender=subString.replace(subString, "["+subString+"]");
//replace with actual string
return che.replace(subString, appender);
}
//test
public static void main(String args[]){
ChemicalStringSymbol c=new ChemicalStringSymbol();
String s[]=c.replaceBrackets(new String[]{ "Amazon", "Microsoft", "Google" }, new String[]{ "I", "Am", "cro", "Na", "le", "abc" });
for(String ss:s){
System.out.println(ss);
}
}
}
package com.eb.corealgo;
public class StringAnagram {
public String anagramGroup(String []input){
String anagramGroup="";
anagramGroup+="{";
for(int i=0;i<input.length;i++){
for(int j=i+1;j<input.length;j++){
//check for anagram if yes return group
boolean isAnagram=isAnagramGruop(input[i],input[j]);
if(isAnagram){
anagramGroup+="("+input[i]+","+input[j]+")";
}
}
}
return anagramGroup+"}";
}
public boolean isAnagramGruop(String input1,String input2){
//from second to one comparing
int j=input2.length()-1;
for(int i=0;i<input1.length();i++){
if(input1.charAt(i)==input2.charAt(j)){
j--;
continue;
}
else
{
return false;
}
}
return true;
}
//app test
public static void main(String args[]){
StringAnagram an=new StringAnagram();
String input[]=new String[]{"star","dog","car","rats","god"};
System.out.println(an.anagramGroup(input));
}
}
/*Algorithm written by shashei kumar*/
package com.carrierCup;
public class gameCollision2 {
public static int numberToReturn(int num)
{
int iterator=1;
int count=0;
int next=1;
while(count!=num)
{
if((iterator%4)==0||(iterator%7)==0)
{
next=iterator+1;
}
else
{
next=iterator;
count++;
}
iterator++;
}
return next;
}
public static void main(String []a)
{
System.out.print(numberToReturn(10));
}
}
- shashi kumar May 29, 2016