Tuesday, July 19, 2011

resolved handler for very large integers. Here is the code.

package EZ;
import java.util.ArrayList;
public class large {
 ArrayList<Integer> value;
public large(String s1){
value = changer(s1);
}
public  ArrayList<Integer> getVal(){
return value;
}
public static ArrayList<Integer> changer(String s1){
ArrayList<Integer> temp = new ArrayList<Integer>();
for(int i=0;i<s1.length();i++){
int tempp = Integer.valueOf(s1.substring(i,i+1));
temp.add(tempp);
}
return temp;
}
public static ArrayList<Integer> addTwo(large l1,large l2){
int larger =0;
int checkto = 0;
int diff = 0;
ArrayList<Integer> sum = new ArrayList<Integer>();
System.out.println(l1.getVal().size() + " " + l2.getVal().size());
if(l1.getVal().size() > l2.getVal().size()){
System.out.println("l1 is bigger");
larger = 1;
checkto = l2.getVal().size();
diff = l1.getVal().size() - l2.getVal().size();
}
if(l1.getVal().size() < l2.getVal().size()){
System.out.println("l2 is bigger");
larger = 2;
checkto = l1.getVal().size();
diff = l2.getVal().size() - l1.getVal().size();
}
System.out.println(larger + " " + checkto + "  " + diff);
switch (larger){
case 0: break;
case 1: for(int j=0;j<diff;j++){
sum.add(l1.getVal().get(0));
l1.getVal().remove(0);
} printer(l1.getVal());
case 2: for(int k=0;k<diff;k++){
sum.add(l2.getVal().get(0));
System.out.println(l2.getVal().get(0) + "Deleted");
l2.getVal().remove(0);
} printer(l2.getVal());
System.out.println(sum);
}
for(int i=0;i<checkto;i++){
sum.add(l1.getVal().get(i) + l2.getVal().get(i));
}
for(int l=sum.size()-1;l>=0;l--){
System.out.println(sum.get(l));
if(sum.get(l) >9 && l!=0){
sum.set(l,sum.get(l)%10);
sum.set(l-1,sum.get(l-1)+1);
}
else if(sum.get(l) >9 && l==0){
sum.set(l,sum.get(l%10));
sum = addTen(sum);
}
}
return sum;
}
public static ArrayList<Integer> addTen(ArrayList<Integer> A1){
ArrayList<Integer> temp = new ArrayList<Integer>();
temp.add(1);
for(int i=0;i<A1.size();i++){
temp.add(A1.get(i));
}
return temp;
}
public static void printer(ArrayList<Integer> A1){
for(int i=0;i<A1.size();i++){
System.out.print(A1.get(i));
}
System.out.println("\n");
}
public static void main(String[]args){
large one = new large("23562134");
large two = new large("3245623945112341");
printer(addTwo(one,two));
//22455390246824682468
//    3357539024682468
}
}

I really need to go over constructors and shit like that. apparently it changes EVERYTHING. I'm having a deja vu with this...
Working on a large number handler for Java. to handle number that exceed 2^63-1, the limit for long. Project Euler evidently is obsessed with handing these problems out.

Wednesday, June 29, 2011

project euler.

Have solved first 8 problems. no problem, all in a day's work.
stuck on number 9.

Saturday, June 25, 2011

Random number generator resulted in that I should learn sql. I changed the default workspace in the eclipse.
New set of files to work with, will upload code, and will look back on to optimize the code for returning the getName function.

package decisionrandom;
import java.util.Random;
import java.util.ArrayList;
public class Randomm {
static int weight;
static String name;
static int totval = 0;
static ArrayList<Randomm> total = new ArrayList<Randomm>();
static Randomm alg = new Randomm(30,"algorithms");
static Randomm PHP = new Randomm(5,"PHP");
static Randomm Javascript = new Randomm(5,"Javascript");
static Randomm sql = new Randomm(5,"SQL");
Random rand = new Random();
public static void loop(){
for(int i=0;i<total.size();i++){
totval += getWeight(total.get(i));
}
}
public Randomm(int i1,String s1){
weight = i1;
name = s1;
}
public static int getWeight(Randomm r1){
return weight;
}
public static String getName(Randomm r1){
return name;
}
public static String checker(){
if(totval <= 30)
return(getName(alg));
else if(totval<=35)
return(getName(PHP));
else if(totval<=40)
return(getName(Javascript));
else if(totval<=45)
return(getName(sql));
else
return("noresult");

}
public static void main(String[] args){
total.add(alg);
total.add(PHP);
total.add(Javascript);
total.add(sql);
loop();
System.out.println(checker());
}
}

Do realize that I should go to sleep, when I confuse String.out.println and System.out.println. I should push on at this point to train myself for the programming marathons that I will have to be engaged in for the future.
have created a java program to generate a random result for which to further learn.
have come up on a roadblock, the program won't run for some reason. Redownloading the JDR and JRE.
<p> algorithms for programming or internet access/database work, php, sql, more extensive HTML and javascript. not sure </p>
planning on programming a temporary random number generator, assigning weights to all of the values, and determining my next course of action. of course, this is with the knowledge that the PRNG in the JAVA library is predetermined, but it should be sufficient for my purpose.
Watching social network.
Recently completed learning HTML/Javascript and some PHP.
All in a day's work.
Currently trying to figure out how to work out this EMAC script for perl and this GNU WGET.