Challenge: 


  Print set intersections.


Specifications: 


  Your program should accept as its first argument a path to a filename.
  Each line in the file is a test case.
  Each test case contain two semicolon delimited sorted lists of numbers in ascending order, whose numbers are separated by a comma.
  
  Print out the ascending order sorted intersection of the lists, one per line.
  Print empty new line in case the lists have no intersection


Solution:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class SetIntersection {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner input = new Scanner(new File(args[0]));
        String[] parts;

        while (input.hasNextLine()) {
            parts = input.nextLine().split(";");

            System.out.println(
                findIntersection(
                    toIntArray(parts[0].split(",")),
                    toIntArray(parts[1].split(","))
                )
            );
        }
    }

    private static String findIntersection(int[] foo, int[] bar) {
        Set&lt;Integer&gt; intersection = new LinkedHashSet&lt;&gt;();

        for (int i = 0, j = 0; i &lt; foo.length; i++) {
            while (foo[i] &gt; bar[j] &amp;&amp; j &lt; bar.length) {
                j++;
            }
            if (foo[i] &lt; bar[j]) {
                continue;
            } else {
                intersection.add(bar[j++]);
            }
        }

        if (intersection.isEmpty()) {
            return ""; // none found
        }

        String result = intersection.toString();
        return result.substring(1, result.length() - 1);
    }

    private static int[] toIntArray(String[] array) {
        int[] nums = new int[array.length];

        for (int i = 0; i &lt; array.length; i++) {
            nums[i] = Integer.parseInt(array[i]);
        }

        return nums;
    }
}


Sample Input: 


  9,10,11;33,34,35
  3,7,8,22;11,22
  11,12,13,14;14,15,16
  20,21,22;45,46,47
  77,78,79;78,79,80,81,82
  33,35;3,18,26,35


Sample Output:


  
  22
  14  
  
  78, 79
  35


I wanted to take advantage of the fact the lists were sorted, but I fear my efforts only served to render my code convoluted and inefficient. What do you think?


Question: ip2nation - don't understand how the ip value is stored
Answer: I believe, it uses INET_ATON() and INET_NTOA() mysql function

update:
Yep. I've just checked.

SELECT INET_NTOA( 687865856 )
&gt;&gt; 41.0.0.0
SELECT INET_NTOA( 689963008 )
&gt;&gt; 41.32.0.0