Related
I have a vector that looks like this:
y =
Columns 1 through 19:
1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2
Columns 20 through 38:
2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4
Columns 39 through 57:
4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6
Columns 58 through 67:
6 6 6 6 6 6 6 6 6 6
The vector y is always start at 1 and be counted up. You see that there are lots of same numbers. It's the classes for the samples.
Here we have 1 1 1 1 1 1 1 1 1 1 1 1 = 12 samples for class number 1.
We have 2 2 2 2 2 2 2 2 2 2 2 = 11 samples for class number 2.
My problem here is that I want to find start and stop for every class. For example: Class 1 begins always at index 0 and ends, in this case, at index 11.
Class 2 begins directly after class 1 ends.
Question:
I'm using EJML (Effient Java Matrix Library) and I'm planning to use this function:
C = A.extractMatrix(1,4,2,8)
Which is equal to this MATLAB code:
C = A(2:4,3:8)
But I need to find the start and stop indexes from this y vector. In what index does e.g class 3 stops and starts? Do you have any smart ideas how to do that?
Sure, I could use a for-loop, to do this, but for-loops in Java is quite slow because I'm going to have a very very large y vector.
Suggestions?
Edit:
Here is an suggestion. Is that good, or could it be done better?
private void startStopIndex(SimpleMatrix y, int c, Integer[] startStop) {
int column = y.numCols();
startStop[0] = startStop[1] + 1; // Begin at the next class
for(int i = startStop[0]; i < column; i++) {
if(y.get(i) != c) {
break;
}else {
startStop[1] = i;
}
}
}
Assuming that we are calling the method from:
Integer[] startStop = new Integer[2];
for(int i = 0; i < c; i++) {
startStopIndex(y, c, startStop);
}
If you want to do it faster then binary search is your friend. Threw this together really quick and it does things in O(log n) time, where as a linear search does it in O(n). It's pretty basic and assumes your data looks pretty much like you describe it. Feed it weird data and it will break.:
int[] breakPoints(int[] arr, int low, int high){
int[] rtrn = new int[high];
for(int i=low;i<high;i++){
rtrn[i]=binarySearch(arr, i, 0, arr.length-1);
}
return rtrn;
}
int binarySearch(int[] arr, int k, int start, int end){
int mid = (start+end)/2;
if(mid==arr.length){
return -1;
}
if(arr[mid]==k && arr[mid+1]==k+1){
return mid+1; //or just mid if you want before breakpoint
}
if(arr[mid]<=k){
return binarySearch(arr, k, mid+1, end);
}
return binarySearch(arr, k, start, mid-1);
}
You'd call it like this:
int[] data = {1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,5,5,6,6,6,6};
int[] bp = breakPoints(data,1,6);
//return 0, 3, 8, 13, 16, 18
I think there is a name for this, but I can't remember what it might be, but you start looking for the next boundary with an accelerating search, and use a binary search after that.
You know the numbers are in ascending order, and there are potentially a lot of the same number, so you start by checking the next element. But instead of keep going 1 step at a time, you accelerate and step 2, 4, 8, 16, ... until you find a higher number.
Once you've found a higher number, you've gone too far, but the last step had the initial number, so you know the boundary is somewhere between the last two steps, and you then apply a binary search for the boundary.
Once you've fund the boundary, you start over stepping 1, 2, 4, ... for the next boundary.
If you expect most numbers to have about the same number of occurrences, you could keep a running average count, and make the first step with that average, to get a running start.
I'll leave it to you to actually code this.
The below is in MATLAB. the for loop will go through each unique value stored in x1 and then find the first and last occurrence of that value.
x = [ 1 1 1 2 2 3 3 3 3 3 4 4 4 4 5 5 5 ]
x1 = unique(x)'
for k1 = 1:length(x1)
x1(k1,2:3) = [find(x == x1(k1,1),1,"first"), find(x == x1(k1,1),1,"last")];
end
the above code yields x1 to be a 3 column matrix
1 1 3
2 4 5
3 6 10
4 11 14
5 15 17
If we have a loop like this
for(int i=0; i<n; i+=2)
{
total+=1;
}
I assume there is one instruction in the header, and it executes one instruction in the body so the total number of instruction is (n-0)/2*1+1 (last condition). Is it the right way to do it? How would you count it?
Also, how about this?
for(int i=1; i<n; i*=2)
{
total+=1;
}
If n = 20, i goes like 1,2,4,8,16, and I'm not sure how to calculate it
Just write them out on paper and look for a pattern. For your first example:
for(int i=0; i<n; i+=2)
n i's total
0 [] 0
1 [0] 1
2 [0] 1
3 [0,2] 2
4 [0,2] 2
5 [0,2,4] 3
6 [0,2,4] 3
and so on..
That is floor((n+1)/2) (or integer division).
The second one; we can see it's going to be related to log2 just by examination, so let's compare the counts with log2(n) to see if we can find a pattern:
for(int i=1; i<n; i*=2)
n i's total log2(n)
1 [] 0 ---
2 [1] 1 1
3 [1,2] 2 1.58
4 [1,2] 2 2
5 [1,2,4] 3 2.32
6 [1,2,4] 3 2.58
7 [1,2,4] 3 2.81
8 [1,2,4] 3 3
9 [1,2,4,8] 4 3.17
10 [1,2,4,8] 4 3.32
11 [1,2,4,8] 4 3.46
12 [1,2,4,8] 4 3.58
13 [1,2,4,8] 4 3.70
14 [1,2,4,8] 4 3.81
15 [1,2,4,8] 4 3.91
16 [1,2,4,8] 4 4
17 [1,2,4,8,16] 5 4.09
Looking at this and thinking about it for a moment we can see it is floor(1+log2(n-1)), with special cases for n=0 (total=0) and n=1 (total=0).
The thought process in that last one is: we have to "shift" the log2 column down one to make it line up with the total column (hence log2(n-1)), and we have to add 1 to it to make the values match.
I apologize if this is a simple question but I'm having trouble grasping the concept of modulus division when the first number is smaller than the second number. For example when 1 % 4 my book says the remainder is 1. I don't understand how 1 is the remainder of 1 % 4. 1 / 4 is 0.25. Am I thinking about modulus division incorrectly?
First, in Java, % is the remainder (not modulo) operator, which has slightly different semantics.
That said, you need to think in terms of integer-only division, as if there were no fractional values. Think of it as storing items that cannot be divided: you can store zero items of size 4 in a storage of overall capacity one. Your remaining capacity after storing the maximum number of items is one. Similarly, 13%5 is 3, as you can fit 2 complete items of size 5 in a storage of size 13, and the remaining capacity is 13 - 2*5 = 3.
If you divide 1 by 4, you get 0 with a remainder of 1. That's all the modulus is, the remainder after division.
I am going to add a more practical example to what "Jean-Bernard Pellerin" already said.
It is correct that if you divide 1 by 4 you get 0 but, Why when you do 1 % 4 you have 1 as result?
Basically it is because this:
n = a / b (integer), and
m = a % b = a - ( b * n )
So,
a b n = a/b b * n m = a%b
1 4 0 0 1
2 4 0 0 2
3 4 0 0 3
4 4 1 0 0
5 4 1 4 1
Conclusion: While a < b, the result of a % b will be "a"
Another way to think of it as a representation of your number in multiples of another number. I.e, a = n*b + r, where b>r>=0. In this sense your case gives 1 = 0*4 + 1. (edit: talking about positive numbers only)
I think you are confused between %(Remainder) and /(Division) operators.
When you say %, you need to keep dividing the dividend until you get the remainder 0 or possible end. And what you get in the end is called Remainder.
When you say /, you divide the dividend until the divisor becomes 1. And the end product you get is called Quotient
Another nice method to clear things up,
In modulus, if the first number is > the second number, subtract the second number from the first until the first number is less than the second.
17 % 5 = ?
17 - 5 = 12
12 % 5 = ?
12 - 5 = 7
7 % 5 = ?
7 - 5 = 2
2 % 5 = 2
Therefore 17 % 5, 12 % 5, 7 % 5 all give the answer of 2.
This is because 2 / 5 = 0 (when working with integers) with 2 as a remainder.
OK here is what I have to do
As an employee of MCI (Mammoth Cakes Incorporated), it is your job to create extremely large
layered birthday cakes. A layered birthday cake is made by taking small circular cakes layers and
stacking them on top of each other.
To perform your job, you stand in front of a big conveyor belt
while layers of varying sizes pass in front of you. When you see one you like, you may take it off the
conveyor belt and add it to your cake.
You may add as many layers to your cake as you would like,
as long as you follow these rules:
Once a layer is added to your cake it cannot be moved. (It messes up the icing.) Thus, layers
can only be added to the top of your cake.
Each layer passes in front of you only once. You may take it or leave it. If you take it, you
must add it to the top of your cake. If you leave it, it will move on down the conveyor belt,
never to return.
Each layer in your cake must be at least as small as the layer below. You cannot place a
larger layer on top of a smaller one.
You will be told in advance the diameters (in inches) of the layers coming down the conveyor belt.
Your job is to create the tallest cake possible using those layers.
For example, suppose the following list represents the diameters of the layers coming down the
conveyor belt: 8 16 12 6 6 10 5
Suppose you take the first layer (with a diameter of 8”) for your cake. That means you may not take the second layer (since you already have a layer of size 8”, and 16” > 8”). Similarly, you could not
take the third layer, but you could take the fourth layer (since 6” < 8”).
Following that, you could
also take the fifth layer (the rule is simply that the layer on top cannot be larger; it can be the same
size). Proceeding in this fashion we can create a cake with a height of 4 layers: 8 6 6 5
However, if we had let the first layer go on by and started with the second layer, we could create a
cake with a height of 5: 16 12 6 6 5
Your program will process multiple input sets, one per line. Each line will begin with an integer N,
followed by N positive integers representing the sizes of the cake layers in the order that they will be
arriving on the conveyor belt. N will always be a non-negative integer, 0 N 100,000. Each layer
will have a diameter between 1 and 100,000, inclusive. A line where N = 0 marks the end of the
input
Sample Input
7 8 16 12 6 6 10 5
10 45 25 40 38 20 10 32 25 18 30
10 10 9 8 7 6 5 4 3 2 1
0
Sample Output
5
6
10
Question: Find the tallest layer of Cakes
Here is what I have written so far:
import java.io.*;
import java.util.*;
public class cake
{
private static String line;
private static ArrayList storage = new ArrayList();
private static Integer highestStack = 0;
public static void main(String [] args)throws IOException
{
FileReader fin = new FileReader("cake.in");
BufferedReader infile = new BufferedReader(fin);
FileWriter fout = new FileWriter("cake.out");
BufferedWriter outfile = new BufferedWriter(fout);
line = infile.readLine();
do
{
String[] temp = line.split(" ");
String number;
for(int j = temp.length-1; j!=0; j--)
{
if(Integer.parseInt(temp[j]) <= Integer.parseInt(temp[j-1]))
{
highestStack++;
}
}
storage.add(highestStack);
// Collections.sort(storage);
line = infile.readLine();
}while(!line.equals("0"));
infile.close();
outfile.close();
}
}
As I commented on several answers totally missing the point, this is a Dynamic Programming problem.
Now that you added the constraints, it is clear that a Dynamic Programming solution running in O(n^2) is the way to go, and the fact that N won't go above 100 000 makes it easy to solve using DP (and probably very hard to solve using non-DP algos).
At every moment, you have to ask yourself "What is the best I can do up to 'x'".
Here's how it looks like for you first example :
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 (Best we can do using pieces: 5 )
0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 2 (Best we can do using pieces: 5 10 )
0 0 0 0 0 1 2 2 2 2 2 2 2 2 2 2 2 (Best we can do using pieces: 5 10 6 )
0 0 0 0 0 1 3 3 3 3 3 3 3 3 3 3 3 (Best we can do using pieces: 5 10 6 6 )
0 0 0 0 0 1 3 3 3 3 3 3 4 4 4 4 4 (Best we can do using pieces: 5 10 6 6 12 )
0 0 0 0 0 1 3 3 3 3 3 3 4 4 4 4 5 (Best we can do using pieces: 5 10 6 6 12 16 )
0 0 0 0 0 1 3 3 4 4 4 4 4 4 4 4[5] (Best we can do using pieces: 5 10 6 6 12 16 8 )
Tallest cake as a height of: 5
The way to read a line above is easy. Let's take the first line for example:
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
It means that the tallest cake we can make that has a base of anywhere from 5 to 16 is made of one element (our first piece, the '5').
Then we get the piece '10', and we get the line:
0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 2 2
It means that the tallest cake we can make from 5 to 9 will have one element (our '5') and that from 10 to 16 we can stuff two pieces (5 and 10).
And you repeat like that, with up to 100 000 elements if you want.
On my computer a full 100 000 solution takes less than 20 seconds to be solved using Dynamic Programming.
Here's the code solving your problems and outputting the above. I added output statements on purpose so that you can see what is going on (it will only look pretty with relatively small numbers that said, it is really just to get what is going on with the algorithm).
public static void main( String[] args ) {
doIt( new int[] {8,16,12,6,6,10,5} );
doIt( new int[] {0, 45, 25, 40, 38, 20, 10, 32, 25, 18, 30} );
doIt( new int[] {10, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1} );
}
public static void doIt( int[] r ) {
final int[] a= new int[r.length];
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
max = Math.max( max, a[i] );
a[(a.length-1)-i] = r[i];
}
final int[] s = new int[max+1];
for (int i = 0; i < a.length; i++) {
final int size = a[i];
s[size]++;
for (int j = size+1; j < s.length; j++) {
s[j] = Math.max( s[j-1], s[j] );
}
for (int j = 0; j < s.length; j++) {
System.out.print( " " + ((s[j]) > 9 ? "" : " ") + s[j] );
}
System.out.print( " (Best we can do using pieces: " );
for (int k = 0; k <= i; k++) {
System.out.print( a[k] + " " );
}
System.out.println( ")" );
}
System.out.println( "Tallest cake as a height of: " + s[s.length-1] );
}
I'm not certain what you're asking, exactly.. So, I'll give you some general hints.
Look into the Stack data structure, instead of an ArrayList. Push a layer onto the stack, and then use peek to check the diameter of the topmost layer of your cakestack against the current item in the conveyor.
If the goal is to find the tallest possible cake, a naive approach would be to simply apply the above algorithm by starting with the first layer in the conveyor, continuing to the end, and recording the ultimate height (stack.size()). Then repeat with the second item in the conveyor as your base, and then the third, and so on, comparing the resulting height against the recorded max at the conclusion of each loop.
Let's walk through the process. Each time we encounter a layer on the assembly line, we make a decision: use this layer or not? The best result overall is the better of the following two outcomes:
We use this layer, and build on top of it the tallest cake using the remaining layers not larger than this layer.
We don't use this layer, and build the tallest cake using any of the remaining layers.
We can model this simply with recursion - pseudocode:
tallest(remaining_layers, base_size) = # set base_size = infinity the first time
max(
first_layer + tallest(other_layers, size(first_layer)),
tallest(other_layers, base_size)
)
where first_layer = first(remaining_layers),
other_layers = rest(remaining_layers)
However, that won't cut it by itself, since we're supposed to use dynamic programming.
The idea is that we're recursively calling tallest with other_layers both times. Wouldn't it be nice if we could call it once, and have all the information we need?
What information do we need? Well, if we had the tallest cake using the remaining layers for any base size, we'd be set: we just pick the tallest cake that can fit on the current layer, and see if that makes an improvement versus the tallest cake overall. But here's the trick: even if it doesn't make an improvement, we may still gain information. The idea is to have a list of the most "efficient" (smallest base) cakes for each size.
Our process will therefore be as follows:
Set up a list of cakes, with one cake in it that has zero layers.
# There will be, at all times, one cake in the list of any given height.
# Starting at zero instead of one makes the iteration neater.
For each layer on the conveyor belt, working **backwards** from the last:
Find the tallest cake in the list that fits on this layer.
Construct the cake 'c' consisting of that cake on top of this layer.
If there is already a cake in the list of the same height as 'c':
If the other cake has a smaller base, throw 'c' away. # It didn't help.
Otherwise, remove the other cake from the list. # 'c' is better.
If we still have 'c', add it to the list.
The tallest possible cake for the input is now the tallest one in the list.
This input sequence is tricky:
10 45 25 40 38 20 10 32 25 18 30
A simplistic approach that only skips lead-in layers would find these [cakes]:
[10] 45 25 40 38 20 10 32 25 18 30
10 [45 25] 40 38 20 10 32 25 18 30
10 45 [25] 40 38 20 10 32 25 18 30
10 45 25 [40 38 20 10] 32 25 18 30 <-- naive tallest, 4
10 45 25 40 [38 20 10] 32 25 18 30
10 45 25 40 38 [20 10] 32 25 18 30
10 45 25 40 38 20 [10] 32 25 18 30
10 45 25 40 38 20 10 [32 25 18] 30
10 45 25 40 38 20 10 32 [25 18] 30
10 45 25 40 38 20 10 32 25 [18] 30
10 45 25 40 38 20 10 32 25 18 [30]
The rules of the game allow you to skip any layer, though, not just the lead ones, and so the correct tallest cake in this case would be:
10 [45] 25 [40] [38] 20 10 [32] [25] [18] 30
Or written out with only the selected layers:
45 40 38 32 25 18
The problem you're trying to solve is a dynamic programming question (albeit a simple one).
Algorithm
public static int findMaxHeight(int[] layers) {
int[] max = new int[layers.length];
for(int i=layers.length - 1; i >= 0; i--) {
int localMax = 0;
for(int j=0; j < layers.length; j++) {
if(layers[j] < layers[i]) {
if(max[j] > localMax) {
localMax = max[j];
}
}
}
max[i] = localMax + 1;
}
int height = 0;
for(int i=0; i < max.length; i++) {
if(max[i] > height) {
height = max[i];
}
}
return height;
}
Step By Step
As a step through of how this works, consider:
8 16 12 6 6 10 5
Since we are going in reverse order,
5 10 6 6 12 16 8
Starting with 5, there are smaller than 5 values from []:
5 10 6 6 12 16 8
1
From [5], max[5] = 1 so 1+1
5 10 6 6 12 16 8
1 2
And so on...
5 10 6 6 12 16 8
1 2 2 3 4 5 4
Then we find out max of the list [1, 2, 2, 3, 4, 5, 4], which is 5.
And, as explained above, this is the correct answer to the provided example that he stepped through in the problem description.
How It Works
The algorithm works by taking saving the maximum value for each layer. The question explains that, for any given layer, it can stack only cakes less than or equal to its diameter. Therefore, the maximum of any given layer will always be the maximum of a layer of equal or less size which follows it on the belt plus 1 (counting the layer itself). If there are no layers that can be stacked onto it, we know that the max for this layer is 1.
Actually is very simple, it goes like this:
int[] layers = new int[] {x1,x2,x3...xn};
int[] count = new int[layers.length];
for(int i = 1; i < layers.length; i++)
{
for(int j = i+1 ; j < layers.length; j++)
{
if ( layers[j] >= layers[i]) count[i]++;
}
}
answer = Collections.max(Arrays.asList(count));
I have to create a program that displays the 9 rows of a sudoku as 9 9-digit numbers and then prompt the user to do one of 6 operations on the sudoku. Then we have to output the sudoku each time the user performs an operation. This is sort of a sample run of how it should go:
Welcome to Sudoku Permuter.
C C C C C C C C C
1 2 3 4 5 6 7 8 9
R1 0 8 0 4 0 2 0 6 0
R2 0 3 4 0 0 0 9 1 0
R3 9 6 0 0 0 0 0 8 4
R4 0 0 0 2 1 6 0 0 0
R5 2 0 0 0 0 9 6 0 0
R6 0 1 0 3 5 7 0 0 8
R7 8 4 0 0 0 0 0 7 5
R8 0 2 6 0 0 0 1 3 0
R9 0 9 0 7 0 1 0 4 0
(0 denotes a blank)
Enter 1 to swap two rows in a panel
Enter 2 to swap two columns in a panel
Enter 3 to swap two row panels
Enter 4 to swap two column panels
Enter 5 to swap two numbers
Enter 0 to end:
Let's say the user enters 3 (to swap two row panels). This would come up:
Enter row panels (1-3) to swap: 3 1
It would swap row panels 1 and 3, and this would be the output:
C C C C C C C C C
1 2 3 4 5 6 7 8 9
R1 8 4 0 0 0 0 0 7 5
R2 0 2 6 0 0 0 1 3 0
R3 0 9 0 7 0 1 0 4 0
R4 0 0 0 2 1 6 0 0 0
R5 2 0 0 0 0 9 6 0 0
R6 0 1 0 3 5 7 0 0 8
R7 0 8 0 4 0 2 0 6 0
R8 0 3 4 0 0 0 9 1 0
R9 9 6 0 0 0 0 0 8 4
Rows 1-3 have been switched with rows 7-9.
Let's say the user inputs 5. This comes up:
Enter two numbers: 2 8
The original sudoku is outputted again, except 2's and 8's are switched throughout.
C C C C C C C C C
1 2 3 4 5 6 7 8 9
R1 0 2 0 4 0 8 0 6 0
R2 0 3 4 0 0 0 9 1 0
R3 9 6 0 0 0 0 0 2 4
R4 0 0 0 8 1 6 0 0 0
R5 8 0 0 0 0 9 6 0 0
R6 0 1 0 3 5 7 0 0 2
R7 2 4 0 0 0 0 0 7 5
R8 0 8 6 0 0 0 1 3 0
R9 0 9 0 7 0 1 0 4 0
If the user entered 1, something would come up saying
Enter two rows (1-9) to switch:
And whichever rows the user enters, those two individual rows would be swapped and the sudoku would once again be outputted. It'd be similar if the user entered 2, except 2 columns would be switched. Similarly, if the user entered 4, two column panels would be switched.
We're supposed to use a two dimensional array like this:
int [] [] sudoku = new int[10] [10]
I have no idea how to do this. I've been struggling all semester, this is my first programming class. I just don't understand arrays at all, and I don't understand how we're even supposed to display the sudoku in the first place. This problem isn't in our book, so I have nothing to look back on, either. I really need to pass this class. If anyone could help me, I really appreciate it. Try to make it easy to understand, there's a lot of stuff I haven't learned how to do yet (ex: for the record, idk what parseInt is). I've tried reading the book (several times). It helps some, but this program is going to be impossible. Thank you SO much for the help.
Do you know how to read input?
Do you know how to work with 1-dimensional arrays (lists), like {1, 2, 3, 4, 5}?
Do you understand for loops?
What part of the concept of arrays seems difficult to you?
For instance, here's a block of code that just prints out the raw contents of the array. Does this code make sense?
int [] [] sudoku = new int[10] [10];
// loop through all of the rows
for (int row = 0; row < 10; row++) {
// loop through all columns for each row
for (int column = 0; column < 10; column++) {
// print out the sudoku value at that row and column
System.out.print(sudoku[row] [column] + " ");
}
// at the end of the row, print a blank line to start the next row
System.out.println();
}
Here's how you can hard-code your sample board to work with it:
int [] [] sudoku = new int [] [] {
{ 0, 8, 0, 4, 0, 2, 0, 6, 0 },
{ 0, 3, 4, 0, 0, 0, 9, 1, 0 },
etc.
}
Here's some pseudo-code for swapping two rows.
Get first row # from user
Get second row # from user
Loop through each column in the board
Swap(cell at first row #, current column, cell at second row #, current column)
End Loop
Swapping basically requires a temporary variable to hold one of the values while swapping:
Swap(a, b)
Store a into Temp
Store b into a
Store Temp into b
As mellamokb's comment says, breaking things down into parts is the trick. At first glance I would probably do something like this:
Hardcode in a sudoku board, and make a routine to print the board out
Once that works right, then you'd need a menu. So extend your program to make a little menu that prints back the user's selection, and does nothing more
Once that's going, you can start filling in the menu choices. So when the user selects option one, make the routine for swapping two rows. The other menu items can still just print out their number.
Once you've got that working, you're actually nearly done. You can take your routine from #3 and make copies of it with small changes to make other 4 modifications possible.
You don't mention where the sudoku board comes from. If it's hardcoded, you're done. If not, then all you have to is make that method. At this point, you already know that you can print the board right, show the menu, and change the board.
You mention problems with arrays, and they can be a bit of a leap. Is there a specific question you have about arrays that we might be able to help with? They are like anything else in programming. You start not knowing a ton about them, and just sort of following what guidance and code you find elsewhere. As you gain more experience (as you will on this project and future projects), they'll be less mysterious and make more sense until one day they're as easy as 3 + 7.