Thursday, February 16, 2012

ECLIPSE AND DEPENDENT PDE BUILDS


ECLIPSE AND DEPENDENT PDE BUILDS

The primary reason for blogging on this topic is that i found a lot of blogs that explain how PDE build can be used but not a lot of blogs explain how can we use dependent builds using the above system.

And to keep things short I will not get into much details of the whole build system. The whole build system is awesome and takes a lot of headache from the developers point of view by auto generating build files for all feature plugins. In short
“The goal of PDE Build is to facilitate the automation of plug-in build processes. Essentially, PDE Build produces Ant scripts based on development-time information provided by, for example, the plugin.xml and build.properties files. The generated Ant scripts, can fetch the relevant projects from a CVS repository, build jars, Javadoc, source zips, put everything together in a format ready to ship and send it out to a remote location (e.g., a local network or a downloads server).”
Well the major 2 advantages that you achieve by shifting RCP products to such builds are:
  • No need to maintain separate build files for every plugin
  • No need to keep track of plugin dependencies in such build files (rather dependencies are resolved by the build system)
Although the above two points are very evident they can become a real pain if the number of plugins are large ( 80-100 dependant plugins sound fun for a starter like me :P) .
Different Approaches for Dependant PDE builds:
Some basic assumptions:
  • Product P depends on 3 fragment plugin say  A, B and C.
  • A, C can be built independently and do not depend on each other.
  • B depends on both A and C and can not be build before A and C.
Approach 1 :
  • Do not build A and C.
  • Dump every thing along with C including srcs of all the three A,B,C in one location
  • Build P3 against a fresh eclipse and include dependencies on C ,A in the feature plugin of B
Approach 2 :
  • Build A and C independently.
  • Dump this builds in the folder structure of B sources with their feature plugins in the feature folder of B
  • Build B against a fresh eclipse.
Approach 3 :
  • Build A and C independently.
  • Take a fresh eclipse and provision it with A and C builds.
  • Build B against the eclipse obtained after the above step
Approach 3 and Approach 2 extract out the real use of dependent PDE build system.
Approach 1 is more holistic and shows the power of PDE builds.
Approach 2 or 3 could be used to live up to expectations of large products which have large dependent components in which some of them can be built independently.

Download All the 3 plugins here

Sunday, February 5, 2012

Problem 24

Problem Statement :Problem24

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012   021   102   120   201   210
What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
Approach:
  • Well if the actual number  is a0,a1,a2,a3,a4,a5,a6,a7,a8,a9:
    a0*9! + a1*8! + a2*7! + ..... + a9*0! = 10^6 
  • To do this start filling the number from the right 
  • In every iteration decide the digit at that position and subtract the remaining from count.
  • In each iteration we are removing multiples of k! 
  • Quit when count reaches 0.  

Solution:
    import java.util.ArrayList;
    import java.util.List;
    
    public class problem24 {
     public static List list = new ArrayList();
     
     public static long getFactorial(int limit) {
      long factorial = 1;
      for (int i = 1; i <= limit; i++)
       factorial = factorial * i;
      return factorial;
     }
    
     public static void main(String chars[]) {
      long count = 1000000;
      int num = 9;
      list.add(0);
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      list.add(8);
      list.add(9);
      
      String s = "";
      while (count != 0) {
       long fact = getFactorial(num--);
       int p1 = (int) (count / fact);
       s=s+""+list.get(p1);
       list.remove(p1);
       count = count - fact * p1;
      }
     System.out.println(s+list.get(0));
     }
    }
    

Wednesday, February 1, 2012

Problem 23


Problem Statement :Problem23
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.
As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.
Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.


Approach:
  • Find all abundant numbers and fill them in a list
  • Iterate over the list in 2 for loops and generate all possible abundant numbers
  • Use an array to mark the index (ie generated abundant numbers).
  • All indexes that are not marked will not be abundant.  

Solution:
    import java.util.ArrayList;
    import java.util.List;
    
    public class problem24 {
     public static List<Integer> list = new ArrayList<Integer>();
     
     public static long getFactorial(int limit) {
      long factorial = 1;
      for (int i = 1; i <= limit; i++)
       factorial = factorial * i;
      return factorial;
     }
    
     public static void main(String chars[]) {
      long count = 1000000;
      int num = 9;
      list.add(0);
      list.add(1);
      list.add(2);
      list.add(3);
      list.add(4);
      list.add(5);
      list.add(6);
      list.add(7);
      list.add(8);
      list.add(9);
      
      String s = "";
      while (count != 0) {
       long fact = getFactorial(num--);
       int p1 = (int) (count / fact);
       s=s+""+list.get(p1);
       list.remove(p1);
       count = count - fact * p1;
      }
     System.out.println(s+list.get(0));
     }
    }
    

Problem 22


Problem Statement :Problem22

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
For example, when the list is sorted into alphabetical order, COLIN, which is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN would obtain a score of 938 × 53 = 49714.
What is the total of all the name scores in the file?


Approach:
  • Just follow what is written in the problem
Solution:
    import java.util.Arrays;
    public class problem22 {
    	public static void main(String args[])
    	{
    		String x;//read from file
    		long t1=System.currentTimeMillis();
    		String arr[]=x.split(",");
    		Arrays.sort(arr);
    		long total=0;
    		for(int i=0;i

Problem 21

Problem Statement :Problem21
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers.
For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.
Evaluate the sum of all the amicable numbers under 10000.


Approach:
  • Function getvalue will return the value of all divisors of a number 
  • Call it twice and and just check whether they are equal or not.
Solution:
    public class problem21 {
     public static int isPrime(int n1) {
      int num = n1;
      for (int i = 2; i <= Math.sqrt(num); i++) {
       if (num % i == 0)
        return i;
      }
      return 0;
     }
    
    
     static int getvalue(int num) {
      if (isPrime(num) == 0)
       return 1;
      int value = 0;
      for (int i = 1; i <= num / 2; i++) {
       if (num % i == 0)
        value = value + i;
      }
      return value;
     }
    
     public static void main(String args[]) {
      int n = 10000, sum = 0;
      for (int i = 2; i < n; i++) {
       int val = getvalue(i);
       int revval = getvalue(val);
       if (i == revval && val != i)
        sum = sum + revval;
      }
      System.out.println(sum);
     }
    }
    

Problem 20


Problem Statement :Problem21



n! means n × (n − 1) × ... × 3 × 2 × 1
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!


Approach:
  • For solving this we use the same multiplication of strings method as used earlier
  • Then add the sum of digits 

Solution:
    import java.util.ArrayList;
    
    public class problem20 {
     // to add two numbers using strings a,b are two numbers
     public static String stringAddition(String a, String b) {
      String sum = "";
      int carry = 0;
      if (a.length() > b.length()) {
       String temp = a;
       a = b;
       b = temp;
      }
      for (int i = 0; i < a.length(); i++) {
       int s = a.charAt(a.length() - 1 - i) + b.charAt(b.length() - 1 - i)
         - 96 + carry;
       if (s > 9) {
        carry = (s - s % 10) / 10;
        s = s % 10;
       } else {
        carry = 0;
       }
       sum = s + sum;
      }
    
      for (int i = 0; i < b.length() - a.length(); i++) {
       int s = b.charAt(b.length() - a.length() - 1 - i) + carry - 48;
    
       if (s > 9) {
        carry = (s - s % 10) / 10;
        s = s % 10;
       } else {
        carry = 0;
       }
       sum = s + sum;
    
      }
      if (carry != 0)
       return carry + sum;
      else
       return sum;
     }
    
     public static String stringMultiplication(String s1, String s2) {
      String zero = "", num = "";
      ArrayList<String> list = new ArrayList<String>();
      for (int i = s1.length() - 1; i >= 0; i--) {
       int carry = 0;
       int c1 = s1.charAt(i) - '0';
       num = "";
       for (int j = s2.length() - 1; j >= 0; j--) {
        int c2 = s2.charAt(j) - '0';
        int prod = c1 * c2 + carry;
        int add = prod % 10;
        carry = prod / 10;
        num = add + num;
       }
       if (carry != 0)
        num = carry + num;
       list.add(num + zero);
       zero = zero + "0";
      }
      num = "0";
      for (int i = 0; i < list.size(); i++)
       num = stringAddition(num, list.get(i));
      return num;
     }
    
     public static void main(String args[]) {
      String sum = "1";
      for (int i = 2; i <= 100; i++) {
       sum = stringMultiplication(sum, i + "");
      }
      int num = 0;
      for (int i = 0; i < sum.length(); i++)
       num += (sum.charAt(i) - '0');
      System.out.println(num);
     }
    }
    


Monday, January 30, 2012

Problem 18

Problem Statement :Problem18


By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.

3
7 4
2 4 6
8 5 9 3
That is, 3 + 7 + 4 + 9 = 23.
Find the maximum total from top to bottom of the triangle below:

75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

Approach:
  • For solving this we generate all possible paths from the top to the bottom.
  • At every point we have 2 directions to search and we explore every possible path through recursion.
  • when the path terminates we put the result in  a global list.
  • Next after generation of all possible paths we find the maximum from the global list.
Solution:
    import java.util.ArrayList;
    import java.util.List;
    
    public class problem18 {
     static List<Integer> l = new ArrayList<Integer>();
     static int M[][] = { { 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 95, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 17, 47, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 18, 35, 87, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 20, 04, 82, 47, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 19, 01, 23, 75, 03, 34, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 88, 02, 77, 73, 07, 63, 67, 0, 0, 0, 0, 0, 0, 0, 0 },
       { 99, 65, 04, 28, 06, 16, 70, 92, 0, 0, 0, 0, 0, 0, 0 },
       { 41, 41, 26, 56, 83, 40, 80, 70, 33, 0, 0, 0, 0, 0, 0 },
       { 41, 48, 72, 33, 47, 32, 37, 16, 94, 29, 0, 0, 0, 0, 0 },
       { 53, 71, 44, 65, 25, 43, 91, 52, 97, 51, 14, 0, 0, 0, 0 },
       { 70, 11, 33, 28, 77, 73, 17, 78, 39, 68, 17, 57, 0, 0, 0 },
       { 91, 71, 52, 38, 17, 14, 91, 43, 58, 50, 27, 29, 48, 0, 0 },
       { 63, 66, 04, 68, 89, 53, 67, 30, 73, 16, 69, 87, 40, 31, 0 },
       { 4, 62, 98, 27, 23, 9, 70, 98, 73, 93, 38, 53, 60, 4, 23 } },
       n = 15;
    
     public static void getSum(int csum, int x, int y) {
      if (x == n - 1) {
       csum = csum + M[x][y];
       l.add(csum);
       return;
      }
      csum = csum + M[x][y];
      int bsum, rsum, lsum;
      getSum(csum, x + 1, y);
      getSum(csum, x + 1, y + 1);
     }
    
     public static void main(String args[]) {
      long t1 = System.currentTimeMillis();
      getSum(0, 0, 0);
      int max = l.get(0);
      for (int i = 1; i < l.size(); i++) {
       if (l.get(i) >= max) {
        max = l.get(i);
       }
      }
      System.out.println(max);
      long t2 = System.currentTimeMillis();
      System.out.println("TIME: " + (t2 - t1) + " millisec");
     }
    }