Mini Ludum Dare 50, organised by Friedrich Hanisch, has begun; the theme is “demakes”.


That’s It!

16Mar14

Originally posted on Contest Coding:

After one year of running this website, I have decided to finish my competition. I give a huge thank you to all participants but I am also very sorry to all of you who would like to continue solving puzzles. I particularly thank Mark Bishop, Paul Cleary and Richard Zapor for sending in puzzle submissions. Here are the top five participants for both the Leaderboard and the Cup:
Position Contest Coding Cup Leaderboard
1 Paul Cleary E. Choroba
2 Isaiah Howard Paul Cleary
3 Richard Zapor wanderdoc
4 E. Choroba Mark Bishop
5 wanderdoc David Valles

And here are the top ten from a points table combining both the Leaderboard and the Cup:

Position Name Points
1 Paul Cleary 17
2 E. Choroba 15
3 wanderdoc 12
4 David Valles 10
4 Mark Bishop 10
4 Isaiah Howard 10
7 Jeff Vincent 8
8 Richard Zapor 7
9 Siegbert Steinlechner

View original 34 more words


Mini Ludum Dare 49, organised by Olav Larsen, has begun; the theme is “non-Human player”.


Mini Ludum Dare 48, organised by Pekka Kujansuu, has begun; the themes are “facade”, “scheme”, “conspiracy”, and “deceit”, and participants are free to use any number of those themes.


I recently participated in the Advent Programming Contest 2013 organised by the IEEE Student Branch Klagenfurt (with support from Alpen-Adria-Universität Klagenfurt), wherein – as I’d recently received from Udacity a certificate for Introduction to Programming : Problem Solving with Java (CS046) – I challenged myself to program my solutions to the problems posed by the contest using only Java (I’d used C and C++ when I’d participated in the contest in 2012); I solved eighteen of the problems posed by the contest, achieving a rank of 10th (out of 155 participants).

As submissions of solutions to the contest are now closed, I’m posting here the solutions I submitted to the contest.

Problem (X; easiest difficulty):

Merry Christmas!

This is the last problem in the Advent Programming Contest 2013! Now it is time to wish a merry Christmas!

Problem

Implement a program that writes “merry christmas” in the four languages with the largest number of native speakers, beginning with the language with the most native speakers. Output should be all lowercase, no exclamation or punctuation marks, newline after each wish. Only letters from the English alphabet should be used, diacritical marks should be left out. For example the French “Joyeux Noël!” would be written as “joyeux noel”. If there are several phrases for “merry christmas” in one of the languages which are common, use the shorter version.

Hint

A magyar nyelv nincs azon négy nyelvek között, melyek a legtöbb anyanyelvű beszélővel rendelkeznek.

Solution (X.java):

public class X
{
  public static void main( String p[] )
  {
    System.out.println( "shengdan jie kuaile" ); // Mandarin
    System.out.println( "feliz navidad" );       // Spanish
    System.out.println( "merry christmas" );     // English
    System.out.println( "meri krisamasa" );      // Hindi
  }
}

Testing:

shengdan jie kuaile
feliz navidad
merry christmas
meri krisamasa

I recently participated in the Advent Programming Contest 2013 organised by the IEEE Student Branch Klagenfurt (with support from Alpen-Adria-Universität Klagenfurt), wherein – as I’d recently received from Udacity a certificate for Introduction to Programming : Problem Solving with Java (CS046) – I challenged myself to program my solutions to the problems posed by the contest using only Java (I’d used C and C++ when I’d participated in the contest in 2012); I solved eighteen of the problems posed by the contest, achieving a rank of 10th (out of 155 participants).

As submissions of solutions to the contest are now closed, I’m posting here the solutions I submitted to the contest.

Problem (W; medium difficulty):

Global Warming

Remember Santa’s warehouse from problem Q?

At the North Pole, Santa has a big warehouse for storing the produced toys. The warehouse has a rectangular base area of 100 x 50 meter. All contents inside the warehouse are placed within perfect cuboid boxes. The dimensions and positions of the boxes are given.

Inside the warehouse, the elves had built a huge snowman with a solid volume of 6414 cubic meters of snow. The snow melted, probably due to Global Warming and filled the warehouse with water. Fortunately, the boxes are heavy enough not to float and waterproof. How high will the water rise inside the building? You can assume that one cubic meter of snow melts into 100 liter of water. Seepage or evaporation of water shall be neglected.

Advent Programming Contest 2013 - W

Problem

Your task is to implement a program that reads the dimensions and positions for the boxes. If two boxes are placed at overlapping coordinates, the box that was specified first is on the ground while the other one is located on top of the first one. Your programm shall first read a number indicating the number of boxes, followed by lines of 5-tuples (seperated by space) indicating the boxes x-position, y-position inside the warehouse and the width, length and height dimensions of the box. The x and y position are at the center of the box, and the box’s width is aligned to the x-direction within the warehouse. After reading all information about the boxes the water height shall be caculated in meter, rounded to two decimals after the comma. Trailing zeros shall not be printed.

Example

Input

2
40 25 25 25 5
30 30 4 4 2

Output

0.15

Solution (W.java):

import java.util.Scanner;
import java.text.DecimalFormat;

class AABB
{
  public double m_originX, m_originY, m_halfWidth, m_halfHeight, m_bottom, m_top;

  public AABB( double p_originX, double p_originY, double p_halfWidth, double p_halfHeight )
  {
    m_originX = p_originX;
    m_originY = p_originY;
    m_halfWidth = p_halfWidth;
    m_halfHeight = p_halfHeight;
  }

  public void setTopAndBottom( double p_top, double p_bottom )
  {
    m_top = p_top;
    m_bottom = p_bottom;
  }
}

public class W
{
  public static void main( String p[] )
  {
    Scanner s = new Scanner( System.in );
    AABB boxes[] = new AABB[ s.nextInt() ];
    for( int i = 0; i < boxes.length; i ++ )
    {
      boxes[ i ] = new AABB( s.nextInt(), s.nextInt(), s.nextInt() / 2.0, s.nextInt() / 2.0 );
      final int h = s.nextInt();
      final AABB b = collision( boxes[ i ], boxes, i );
      if( b == null )
        boxes[ i ].setTopAndBottom( h, 0 );
      else
        boxes[ i ].setTopAndBottom( b.m_top + h, b.m_top );
      sortByTop( boxes, i );
    }

    double top, bottom = 0, volume = 6414 * 100 / 1000.0;
    while(( top = nextTop( boxes, bottom )) != -1 )
    {
      final AABB section = new AABB( 0, ( top - bottom ) / 2 + bottom, Integer.MAX_VALUE / 2.0, ( top - bottom ) / 2 );
      double area = 100 * 50;
      for( int i = 0; i < boxes.length; i ++ )
      {
        final AABB box = new AABB( boxes[ i ].m_originX, ( boxes[ i ].m_top - boxes[ i ].m_bottom ) / 2 + boxes[ i ].m_bottom, boxes[ i ].m_halfWidth, ( boxes[ i ].m_top - boxes[ i ].m_bottom ) / 2 );
        if( collision( section, box ))
          area -= ( boxes[ i ].m_halfWidth * 2 * boxes[ i ].m_halfHeight * 2 );
      }

      final double old_volume = volume;
      volume -= ( area * ( top - bottom ));
      if( volume <= 0 )
      {
        DecimalFormat dF = new DecimalFormat();
        dF.setDecimalSeparatorAlwaysShown( false );
        dF.setMinimumFractionDigits( 0 );
        dF.setMaximumFractionDigits( 2 );
        System.out.println( dF.format( old_volume / area + bottom ));
        break;
      }

      bottom = top;
    }
  }

  private static boolean collision( double coordinateA, double halfDimensionA, double coordinateB, double halfDimensionB )
  {
    double d = coordinateA - coordinateB;
    if( d < 0 )
      d = -d;
    d -= ( halfDimensionA + halfDimensionB );
    return d < 0;
  }

  private static AABB collision( AABB box, AABB boxes[], int limit )
  {
    for( int i = 0; i < limit; i ++ )
      if( collision( box.m_originX, box.m_halfWidth, boxes[ i ].m_originX, boxes[ i ].m_halfWidth ) && collision( box.m_originY, box.m_halfHeight, boxes[ i ].m_originY, boxes[ i ].m_halfHeight ))
        return boxes[ i ];
    return null;
  }

  private static void sortByTop( AABB boxes[], int limit )
  {
    boolean sort_occurred;
    do
    {
      sort_occurred = false;
      for( int i = 0; i < limit; i ++ )
        if( boxes[ i ].m_top < boxes[ i + 1 ].m_top )
        {
          sort_occurred = true;
          final AABB b = boxes[ i ];
          boxes[ i ] = boxes[ i + 1 ];
          boxes[ i + 1 ] = b;
        }
    }
    while( sort_occurred );
  }

  private static double nextTop( AABB boxes[], double bottom )
  {
    for( int i = boxes.length - 1; i >= 0; i -- )
      if( boxes[ i ].m_top > bottom )
        return boxes[ i ].m_top;
    return -1;
  }

  private static boolean collision( AABB a, AABB b )
  {
    return collision( a.m_originX, a.m_halfWidth, b.m_originX, b.m_halfWidth ) && collision( a.m_originY, a.m_halfHeight, b.m_originY, b.m_halfHeight );
  }
}

Testing:

2
40 25 25 25 5
30 30 4 4 2
0.15

sealfin:

The second problem I’ve suggested for Contest CodingLexicographic Permutations – has been posted!

Originally posted on Contest Coding:

For the purposes of this problem the characters of the string “Contest Coding” are assigned values, the value assigned to a particular character determined by the position in the string of that character - viz:

‘C’ (1), ‘o’ (2), ‘n’ (3), …etc.…, ‘i’ (12), ‘n’ (13), ‘g’ (14)

That sequence of values is considered the 1st lexicographic permutation; given the characters to which those values are assigned, what nth lexicographic permutation will first contain the sequence of characters “tsetnoC”?

- This puzzle was suggested by Mark Bishop

Remember, to solve this puzzle and appear on the leaderboard, email both your solution and your source code (in any language) to lewiscornwall13@gmail.com. Good luck!!

View all puzzles »

View original


I recently participated in the Advent Programming Contest 2013 organised by the IEEE Student Branch Klagenfurt (with support from Alpen-Adria-Universität Klagenfurt), wherein – as I’d recently received from Udacity a certificate for Introduction to Programming : Problem Solving with Java (CS046) – I challenged myself to program my solutions to the problems posed by the contest using only Java (I’d used C and C++ when I’d participated in the contest in 2012); I solved eighteen of the problems posed by the contest, achieving a rank of 10th (out of 155 participants).

As submissions of solutions to the contest are now closed, I’m posting here the solutions I submitted to the contest.

Problem (U; medium difficulty):

Snowball league

When the elves are not busy making toys, they play at the snowball profi league. A match of snowball consists of up to three sets. Each set is won by the team that first reaches 17 points. The team that has first won 2 sets is the match winner.

Problem

Implement a snowball league table calculator. You program should first read an integer, the number of matches to process, followed by the match results, one per line, consisting of

team1 vs. team2 a:b c:d e:f

where a,b,c,d,e,f are the number of points in the respective sets. If there are onyl two sets in a match, only a:b c:d is given. After reading the matches, your program shall print a list of the the teams according to their position in the table. Each team name should be preceded with the rank in the league followed by a dot and space. The ranking rules of the tyble league are as follows:

  1. Teams are primarily sorted according to the number of matches won.
  2. Teams with no distinction via rule number 1 are ranked according to the quotient of won matches to lost matches.
  3. Teams with no distinction via previous rules are further sorted according to the number of sets won.
  4. Teams with no distinction via previous rules are ranked according to the quotient of won sets to lost sets.

Example

Input

3
Isotopes of the North vs. Santas 17:6 13:17 11:17
Satans vs. Isotopes of the North 17:16 17:8
Satans vs. Santas 17:15 11:17 14:17

Output

1. Santas
2. Satans
3. Isotopes of the North

Solution (U.java):

import java.util.ArrayList;
import java.util.Scanner;

class Team
{
  public String m_name;
  public int m_matchesWon = 0, m_matchesLost = 0, m_setsWon = 0, m_setsLost = 0;

  public Team( String p )
  {
    m_name = p;
  }
}

class Teams
{
  private static ArrayList<Team> m_teams = new ArrayList<Team>();

  public static Team add( String p )
  {
    for( Team t : m_teams )
      if( t.m_name.equals( p ))
        return t;
    m_teams.add( new Team( p ));
    return m_teams.get( m_teams.size() - 1 );
  }

  public static void print()
  {
    for( int i = 0; i < m_teams.size(); i ++ )
      System.out.println(( i + 1 ) + ". " + m_teams.get( i ).m_name );
  }

  public static void sort()
  {
    boolean sort_occurred;
    do
    {
      sort_occurred = false;
      for( int i = 0; i < m_teams.size() - 1; i ++ )
      {
        Team a = m_teams.get( i );
        Team b = m_teams.get( i + 1 );
        if( compare( a, b ) < 0 )
        {
          sort_occurred = true;
          m_teams.set( i, b );
          m_teams.set( i + 1, a );
        }
      }
    }
    while( sort_occurred );
  }

  private static int compare( Team a, Team b )
  {
    if( a.m_matchesWon > b.m_matchesWon )
      return 1;
    if( a.m_matchesWon < b.m_matchesWon )
      return -1;
    double q_a = ( double )a.m_matchesWon / a.m_matchesLost;
    double q_b = ( double )b.m_matchesWon / b.m_matchesLost;
    if( q_a > q_b )
      return 1;
    if( q_a < q_b )
      return -1;
    if( a.m_setsWon > b.m_setsWon )
      return 1;
    if( a.m_setsWon < b.m_setsWon )
      return -1;
    q_a = ( double )a.m_setsWon / a.m_setsLost;
    q_b = ( double )b.m_setsWon / b.m_setsLost;
    if( q_a > q_b )
      return 1;
    if( q_a < q_b )
      return -1;
    return 0;
  }
}

class Set
{
  public int m_a_setsWon = 0, m_a_setsLost = 0, m_b_setsWon = 0, m_b_setsLost = 0, m_index;

  public Set( int p )
  {
    m_index = p;
  }
}

public class U
{
  public static void main( String p[] )
  {
    Scanner scanner = new Scanner( System.in );
    final int number_of_matches = Integer.parseInt( scanner.nextLine());
    for( int i = 0; i < number_of_matches; i ++ )
    {
      String l = scanner.nextLine();
      int k = l.indexOf( " vs. " );
      Team a = Teams.add( l.substring( 0, k ));
      int m = l.indexOf( ':' );
      for( m --; ; m -- )
        if( l.charAt( m ) == ' ' )
          break;
      Team b = Teams.add( l.substring( k + 5, m ));

      Set s = new Set( m + 1 );
      parseSet( l, s );
      parseSet( l, s );
      if( s.m_index < l.length())
        parseSet( l, s );
      if( s.m_a_setsWon > s.m_b_setsWon )
      {
        a.m_matchesWon ++;
        b.m_matchesLost ++;
      }
      else
      {
        b.m_matchesWon ++;
        a.m_matchesLost ++;
      }
      a.m_setsWon += s.m_a_setsWon;
      a.m_setsLost += s.m_a_setsLost;
      b.m_setsWon += s.m_b_setsWon;
      b.m_setsLost += s.m_b_setsLost;
    }
    Teams.sort();
    Teams.print();
  }

  private static void parseSet( String l, Set s )
  {
    int i = l.indexOf( ':', s.m_index );
    int a = Integer.parseInt( l.substring( s.m_index, i ));
    s.m_index = i + 1;
    i = l.indexOf( ' ', s.m_index );
    if( i == -1 )
      i = l.length();
    int b = Integer.parseInt( l.substring( s.m_index, i ));
    s.m_index = Math.min( i + 1, l.length());
    if( a > b )
    {
      s.m_a_setsWon ++;
      s.m_b_setsLost ++;
    }
    else
    {
      s.m_b_setsWon ++;
      s.m_a_setsLost ++;
    }
  }
}

Testing:

3
Isotopes of the North vs. Santas 17:6 13:17 11:17
Satans vs. Isotopes of the North 17:16 17:8
Satans vs. Santas 17:15 11:17 14:17
1. Santas
2. Satans
3. Isotopes of the North

I recently participated in the Advent Programming Contest 2013 organised by the IEEE Student Branch Klagenfurt (with support from Alpen-Adria-Universität Klagenfurt), wherein – as I’d recently received from Udacity a certificate for Introduction to Programming : Problem Solving with Java (CS046) – I challenged myself to program my solutions to the problems posed by the contest using only Java (I’d used C and C++ when I’d participated in the contest in 2012); I solved eighteen of the problems posed by the contest, achieving a rank of 10th (out of 155 participants).

As submissions of solutions to the contest are now closed, I’m posting here the solutions I submitted to the contest.

Problem (S; easy difficulty):

Word search

Advent Programming Contest 2013 - S

Help Santa to solve the word search riddle in the Daily North Pole paper. Words can appear horizontally, vertically, diagonal; in all directions forward or backward.

Problem

Your program shall read one line with two integers seperated by space, those are width and height of the raster. Then you program should read the characters of the raster, no spacing, one line for each row. In the last line the program gets a comma-seperated list of word to search for. All text are uppercase characters. You program should output the set of all the words that have been found at least once, in alphabetical order seperated by commas.

Example

Input

6 7
YSQNER
RAAALU
RENNAD
EERYTI
MDEERA
BLIXEN
NORTHP
SANTA,BLIXEN,RUDOLPH,NORTHPOLE

Output

BLIXEN,SANTA

Solution (S.java):

import java.util.Scanner;
import java.util.ArrayList;

public class S
{
  private static char c[][];

  public static void main( String p[] )
  {
    Scanner s = new Scanner( System.in );
    String l = s.nextLine();
    int i = l.indexOf( ' ' );
    final int W = Integer.parseInt( l.substring( 0, i ));
    final int H = Integer.parseInt( l.substring( i + 1, l.length()));
    c = new char[ H ][ W ];
    for( int y = 0; y < H; y ++ )
    {
      l = s.nextLine();
      for( int x = 0; x < W; x ++ )
        c[ y ][ x ] = l.charAt( x );
    }
    l = s.nextLine();
    int k = 0;
    ArrayList<String> words_to_find = new ArrayList<String>();
    do
    {
      i = l.indexOf( ',', k );
      if( i == -1 )
        i = l.length();
      words_to_find.add( l.substring( k, i ));
      k = i + 1;
    }
    while( i < l.length());

    ArrayList<Integer> words_found = new ArrayList<Integer>();
    for( i = 0; i < words_to_find.size(); i ++ )
    {
      boolean found = false;
      final String word = words_to_find.get( i );
      final String word_reversed = reverse( word );

      for( int y = 0; y < H && !found; y ++ )
        for( int x = 0; x < W - ( word.length() - 1 ) && !found; x ++ )
          found = isWordInArray( x, y, 1, 0, word, word_reversed );

      for( int x = 0; x < W && !found; x ++ )
        for( int y = 0; y < H - ( word.length() - 1 ) && !found; y ++ )
          found = isWordInArray( x, y, 0, 1, word, word_reversed );

      for( int y = 0; y < H - ( word.length() - 1 ) && !found; y ++ )
        for( int x = 0; x < W - ( word.length() - 1 ) && !found; x ++ )
          found = isWordInArray( x, y, 1, 1, word, word_reversed );

      for( int y = 0; y < H - ( word.length() - 1 ) && !found; y ++ )
        for( int x = W - 1; x >= ( word.length() - 1 ) && !found; x -- )
          found = isWordInArray( x, y, -1, 1, word, word_reversed );

      if( found && !intIsAlreadyInArrayList( i, words_found ))
        words_found.add( new Integer( i ));
    }
    String words_found_sorted[] = new String[ words_found.size() ];
    for( i = 0; i < words_found.size(); i ++ )
      words_found_sorted[ i ] = words_to_find.get( words_found.get( i ).intValue());
    boolean sort_occurred;
    do
    {
      sort_occurred = false;
      for( i = 0; i < words_found_sorted.length - 1; i ++ )
        if( words_found_sorted[ i ].compareTo( words_found_sorted[ i + 1 ] ) > 0 )
        {
          sort_occurred = true;
          final String w = words_found_sorted[ i ];
          words_found_sorted[ i ] = words_found_sorted[ i + 1 ];
          words_found_sorted[ i + 1 ] = w;
        }
    }
    while( sort_occurred );
    for( i = 0; i < words_found_sorted.length; i ++ )
    {
      System.out.print( words_found_sorted[ i ] );
      if( i + 1 < words_found_sorted.length )
        System.out.print( "," );
    }
    System.out.println();
  }

  private static String reverse( String p )
  {
    String s = "";
    for( int i = p.length() - 1; i >= 0; i -- )
      s += p.charAt( i );
    return s;
  }

  private static boolean isWordInArray( int x, int y, int x_step, int y_step, String word, String word_reversed )
  {
    String s = "";
    for( ; s.length() < word.length(); x += x_step, y += y_step )
      s += c[ y ][ x ];
    return word.equals( s ) || word_reversed.equals( s );
  }

  private static boolean intIsAlreadyInArrayList( int p_int, ArrayList<Integer> p_arrayList )
  {
    for( Integer i : p_arrayList )
      if( p_int == i.intValue())
        return true;
    return false;
  }
}

Testing:

6 7
YSQNER
RAAALU
RENNAD
EERYTI
MDEERA
BLIXEN
NORTHP
SANTA,BLIXEN,RUDOLPH,NORTHPOLE
BLIXEN,SANTA

Q : Warehouse

17Dec13

I recently participated in the Advent Programming Contest 2013 organised by the IEEE Student Branch Klagenfurt (with support from Alpen-Adria-Universität Klagenfurt), wherein – as I’d recently received from Udacity a certificate for Introduction to Programming : Problem Solving with Java (CS046) – I challenged myself to program my solutions to the problems posed by the contest using only Java (I’d used C and C++ when I’d participated in the contest in 2012); I solved eighteen of the problems posed by the contest, achieving a rank of 10th (out of 155 participants).

As submissions of solutions to the contest are now closed, I’m posting here the solutions I submitted to the contest.

Problem (Q; medium difficulty):

Warehouse

At the north pole, Santa has a big warehouse for storing the produced toys. The warehouse has a rectabgular base area of 100 x 50 meter. All contents inside the warehouse are placed within perfect cuboid boxes,. The dimensions and positions of the boxes are given.

Problem

Your task is to implement a program that reads the dimensions and positions for the storage boxes. If two boxes are placed at overlapping coordinates, the box that was specified first is placed first while the other one is located on top of the first one. Situation where one box would tip over are not considered. Your programm shall first read a number indicating the number of boxes, followed by lines of 5-tuples (seperated by space) indicating the boxes x-position, y-position inside the warehouse and the width, length and height dimensions of the box. The x and y position are at the center of the box, and the box’s width is aligned to the x-direction within the warehouse. Based on the placed boxes, your program shall print the height reached by the top of the boxes.

Example

Input

2
10 10 5 5 5 
11 11 4 4 2

Output

7

Solution (Q.java):

import java.util.Scanner;

class AABB
{
  public double m_originX, m_originY, m_halfWidth, m_halfHeight, m_top;

  public AABB( double p_originX, double p_originY, double p_halfWidth, double p_halfHeight )
  {
    m_originX = p_originX;
    m_originY = p_originY;
    m_halfWidth = p_halfWidth;
    m_halfHeight = p_halfHeight;
  }
}

public class Q
{
  public static void main( String p[] )
  {
    Scanner s = new Scanner( System.in );
    AABB boxes[] = new AABB[ s.nextInt() ];
    for( int i = 0; i < boxes.length; i ++ )
    {
      boxes[ i ] = new AABB( s.nextInt(), s.nextInt(), s.nextInt() / 2.0, s.nextInt() / 2.0 );
      final int h = s.nextInt();
      final AABB b = collision( boxes[ i ], boxes, i );
      if( b == null )
        boxes[ i ].m_top = h;
      else
        boxes[ i ].m_top = b.m_top + h;
      sortByTop( boxes, i );
    }
    double top = boxes[ 0 ].m_top;
    for( int i = 1; i < boxes.length; i ++ )
      if( boxes[ i ].m_top > top )
        top = boxes[ i ].m_top;
    System.out.println(( int )top );
  }

  private static boolean collision( double coordinateA, double halfDimensionA, double coordinateB, double halfDimensionB )
  {
    double d = coordinateA - coordinateB;
    if( d < 0 )
      d = -d;
    d -= ( halfDimensionA + halfDimensionB );
    return d < 0;
  }

  private static AABB collision( AABB box, AABB boxes[], int limit )
  {
    for( int i = 0; i < limit; i ++ )
      if( collision( box.m_originX, box.m_halfWidth, boxes[ i ].m_originX, boxes[ i ].m_halfWidth ) && collision( box.m_originY, box.m_halfHeight, boxes[ i ].m_originY, boxes[ i ].m_halfHeight ))
        return boxes[ i ];
    return null;
  }

  private static void sortByTop( AABB boxes[], int limit )
  {
    boolean sort_occurred;
    do
    {
      sort_occurred = false;
      for( int i = 0; i < limit; i ++ )
        if( boxes[ i ].m_top < boxes[ i + 1 ].m_top )
        {
          sort_occurred = true;
          final AABB b = boxes[ i ];
          boxes[ i ] = boxes[ i + 1 ];
          boxes[ i + 1 ] = b;
        }
    }
    while( sort_occurred );
  }
}

Testing:

2
10 10 5 5 5
11 11 4 4 2
7



Follow

Get every new post delivered to your Inbox.