|
Groovy example source code file (magicsquares.java)
The Groovy magicsquares.java source code
/* The Computer Language Shootout
http://shootout.alioth.debian.org/
benchmark implementation (not optimized)
JRE 1.5 only
contributed by Josh Goldfoot */
import java.io.*;
import java.lang.*;
import java.util.*;
public class magicsquares {
static int n;
static int mn;
public static class FfmResult {
public int x;
public int y;
public int[] moves;
public FfmResult(int ix, int iy, int[] imoves) {
x = ix;
y = iy;
moves = (int[]) imoves.clone();
}
}
public static class PQNode implements Comparable {
public int [] grid;
boolean priorityCalculated;
private int priority;
private FfmResult ffm;
public PQNode() {
grid = new int [n * n];
int i;
for (i = 0; i < n * n; i++)
grid[i] = 0;
priorityCalculated = false;
ffm = null;
}
public PQNode(PQNode other) {
grid = (int[]) other.grid.clone();
priorityCalculated = false;
}
public int[] gridRow(int y) {
int[] r = new int[n];
int x;
for (x = 0; x < n; x++)
r[x] = grid[x + y * n];
return r;
}
public int[] gridCol(int x) {
int[] r = new int[n];
int y;
for (y = 0; y < n; y++)
r[y] = grid[x + y * n];
return r;
}
public int[] diagonal(int q) {
int[] r = new int[n];
int i;
for (i = 0; i < n; i++) {
if (q == 1)
r[i] = grid[i + i * n];
else if (q == 2) {
r[i] = grid[i + (n - 1 - i) * n];
}
}
return r;
}
public int[] possibleMoves(int x, int y) {
int zerocount, sum, highest, j, i;
if (grid[x + y * n] != 0)
return ( new int [] { });
ArrayList<int[]> cellGroups = new ArrayList
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy magicsquares.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.