# Weird Numbers-Square-Thingy

#### Accname

##### 2D-Graphics enthusiast
Here is the code for TWV's weird number square thingy: (Java)
Code:
public class WeirdNumberSquareThingy {

public static void main(String[] args) {
System.out.println(new WeirdNumberSquareThingy(5));
/* Prints:
[  1 |  2 |  6 |  7 | 15]
[  3 |  5 |  8 | 14 | 16]
[  4 |  9 | 13 | 17 | 22]
[ 10 | 12 | 18 | 21 | 23]
[ 11 | 19 | 20 | 24 | 25]
*/
}

private final int[] table;
private final int size;

public WeirdNumberSquareThingy(int size) {
this.size = size;
table = new int[size * size];

int num = 1;
int steps = 1;
int x = 0;
int y = 0;
boolean growing = true;

while (num <= table.length) {
for (int i = 1; i < steps; i++) {
set(x, y, num++);
if (steps % 2 == 1) {
x += 1;
y -= 1;
} else {
x -= 1;
y += 1;
}
}
if (steps == size) {
growing = false;
}
set(x, y, num++);
if (growing == (steps % 2 == 1)) {
x += 1;
} else {
y += 1;
}

if (growing) {
steps++;
} else {
steps--;
}
}
}

private void set(int x, int y, int number) {
table[x + y * size] = number;
}

public int get(int x, int y) {
return table[x + y * size];
}

public String toString() {
StringBuilder sb = new StringBuilder();

for (int y = 0; y < size; y++) {
sb.append("[ ");
for (int x = 0; x < size; x++) {
int num = get(x, y);
if (num < 10) {
sb.append(" ");
}
sb.append(num);
if (x != size -1) {
sb.append(" | ");
}
}
sb.append("]\n");
}

return sb.toString();
}

}

Last edited:

#### tom_mai78101

##### The Helper Connoisseur / Ex-MineCraft Host
Staff member
I feel @thewrongvine wanted the exact order from bottom left, counting to the top right, row major.

And where exactly is the origin located for the main platform? Usually, it's top left for origin.

#### Accname

##### 2D-Graphics enthusiast
There is no "top-left" or "bottom-left" or any other corner within the code. arrays do not have a left or right, a top or bottom. Its all what you make of it.
Now the toString() method I wrote may put the top-left as the origin. But you can just as easily use any other point as the origin by simply printing it out in a different order.

#### tom_mai78101

##### The Helper Connoisseur / Ex-MineCraft Host
Staff member
Oh, my mistake. I also didn't notice the numbers are increasing while zigzagging across the grid.

#### jonas

##### Ultra Cool Member
http://www.HostMath.com/Show.aspx?C...w(x,y) & \text{o.w.} \end{cases} \end{align*}

x,y start from 0 and go up to size-1.

Code:
Lemma 1: row(r) has the number of fields before row r.
Proof by induction on r.
r = 0: row(0) = lowrow(0) = 0
r -> r+1: if r<=size: row r adds r new fields, gaussian sum works
if r = size+1: both branches of the definition agree for r, proof below works
if r > size+1: row r adds 2*size-r new fields, gaussian sum gives that this is exactly the difference

Theorem: val(x,y) gives the right value
by induction on x.
x = 0, x+y odd: starts with total number of fields until (including) row x+y
x = 0, x+y even: first field of row x+y
x -> x+1: old diagonal: we decrease y by one: decreases by one in odd fields, increases by one in even fieds, x+y stays stable, fine.
new diagonal: then x+y >= size, and y = size -1, so you get the first field, proof like x=0.

General chit-chat
Help Users
• No one is chatting at the moment.
• jonas:
Cool, I went 14+7 and 7+3 before, but the first time the 7 just meant not entering crowded places, the second time I had to stay in the quarantine hotel because I'm 外国人 and don't have a home where I could self-isolate
• jonas:
Do you have family in taiwan?
• The Helper:
man at this point better for Tom to not say on the public internet just saying
• The Helper:
I am sure we have posted news here that has pissed china off though I have not heard anything
• jonas:
Your website isn't blocked by GFW so much is for sure
• tom_mai78101:
Do you have family in taiwan? <-- Yes.
• jonas:
• The Helper:
Have a great vacation Tom!
• The Helper:
Happy Friday Night!
+1
• V-SNES:
Happy Friday Night!
+1
• The Helper:
Going out of a town for the weekend will be back sunday night! Hope everyone has a great weekend!
+2
• The Helper:
Happy Monday!
• Ghan:
Monday? Speak for yourself.
+2
• The Helper:
Happy Taco Tuesday!
+1
• The Helper:
Tacos!
• The Helper:
Check out the discord for taco pictures You cannot put pictures in this chat
+1
• The Helper:
Damn here come the bots again - 193 online but they are totally invisible to any stats - bunch of bots!'
• C cubanismo:
Re: Taco Tuesday, if there were some way to share edible tacos over the internet, technology would be complete.
+2
• The Helper:
One can only wish!
• tom_mai78101:
I'm back from Taiwan
+1
• The Helper:
I am reorganizing the site I know nobody will notice but I am not done quite yet but the main forums order has been changed and there is a new news category in Other News which is all the remaining headline news stuff not categorized - Headline News is just the stuff that shows on the main page now and the news archive is off the main forums page
• The Helper:
and the real archive lives off of headline news