[QUOTE=proboardslol;45831283]So predetermine where the blocks will be/go, having the marios check for those locations, regardless of proximity?[/QUOTE]
Blocks and destinations, yeah. Not as a permanent solution, of course, but it should help narrow down the problem.
-moved to WAYO-
Back again guys
I'm trying to make a small program where I generate 3 random numbers between 0 and 9 and then concatenate them into a string to make a lottery number between 000 and 999, so afterwards I input my guess and it prints out whether or not I got the first 2 numbers right, the last 2 numbers right, both first 2 and last 2 correct, or none of them correct.
How would I do something like this in Java using a for loop?
So far this is my code I have:
[code]
import java.util.Scanner;
public class Lottery {
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
int number;
int number2;
int number3;
String threeNumbers = "";
number = (int)(Math.random() * 10 + 1);
number2 = (int)(Math.random() * 10 + 1);
number3 = (int)(Math.random() * 10 + 1);
System.out.println("");
threeNumbers = in.next();
for()
{
}
}
}
[/code]
The output I want would go something along the lines of this:
[code]
Please Enter Your Three Numbers (e.g. 123):
Winner: (Winning Number from String)
Congratulations/Sorry (if guessed number correctly/incorrectly)
[/code]
I need help with more on the for loop than anything else because I cannot for the life of me figure it out.
Thanks in advance
EDIT:
I updated my code to this
[code]
import java.util.Scanner;
public class Lottery {
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
String threeNumbers = "";
int number = (int)(Math.random() * 9 + 1);
int number2 = (int)(Math.random() * 9 + 1);
int number3 = (int)(Math.random() * 9 + 1);
String str1 = Integer.toString(number);
String str2 = Integer.toString(number2);
String str3 = Integer.toString(number3);
String lotteryNumber = str1 + str2 + str3;
System.out.println("Please enter your three numbers:");
threeNumbers = in.next();
//for(threeNumbers != lotteryNumber)
//{
//}
System.out.println(lotteryNumber);
}
}
[/code]
EDITED:
[code]
import java.util.Scanner;
public class Lottery {
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
String threeNumbers = "";
String numberOfTimes = "";
int number = (int)(Math.random() * 9 + 1);
int number2 = (int)(Math.random() * 9 + 1);
int number3 = (int)(Math.random() * 9 + 1);
String str1 = Integer.toString(number);
String str2 = Integer.toString(number2);
String str3 = Integer.toString(number3);
String lotteryNumber = str1 + str2 + str3;
System.out.print("Enter the amount of times you want to play: ");
numberOfTimes = in.next();
int lotNum = Integer.parseInt(lotteryNumber);
int playTimes = Integer.parseInt(numberOfTimes);
int loopVal;
//System.out.println(lotteryNumber.substring(0, 2)); <-- first 2 numbers
//System.out.println(lotteryNumber.substring(1, 3)); <-- last 2 numbers
for(loopVal = 0; loopVal <= playTimes; loopVal++)
{
System.out.println("Please enter your three numbers: ");
threeNumbers = in.next();
if(threeNumbers.substring(0, 2) == lotteryNumber.substring(0, 2))
{
System.out.println("Winner: " + lotteryNumber);
System.out.println("Congratulations, the front pair matched.");
break;
}
else if(threeNumbers.substring(1, 3) == lotteryNumber.substring(1, 3))
{
System.out.println("Winner: " + lotteryNumber);
System.out.println("Congratulations, the back pair matched.");
break;
}
else if(threeNumbers.substring(0, 2) == lotteryNumber.substring(0, 2) && threeNumbers.substring(1, 3) == lotteryNumber.substring(1, 3))
{
System.out.println("Winner: " + lotteryNumber);
System.out.println("Congratulations, both pairs matched.");
break;
}
else if(threeNumbers.substring(0, 2) != lotteryNumber.substring(0, 2) && threeNumbers.substring(1, 3) != lotteryNumber.substring(1, 3))
{
System.out.println("Sorry, none of your numbers matched the pairs.");
}
}
System.out.println("End of game.");
}
}
[/code]
Thoughts?
[QUOTE=joshuadim;45846397]Back again guys
I'm trying to make a small program where I generate 3 random numbers between 0 and 9 and then concatenate them into a string to make a lottery number between 000 and 999, so afterwards I input my guess and it prints out whether or not I got the first 2 numbers right, the last 2 numbers right, both first 2 and last 2 correct, or none of them correct.
How would I do something like this in Java using a for loop?
I updated my code to this
[code]
import java.util.Scanner;
public class Lottery {
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
String threeNumbers = "";
int number = (int)(Math.random() * 9 + 1);
int number2 = (int)(Math.random() * 9 + 1);
int number3 = (int)(Math.random() * 9 + 1);
String str1 = Integer.toString(number);
String str2 = Integer.toString(number2);
String str3 = Integer.toString(number3);
String lotteryNumber = str1 + str2 + str3;
System.out.println("Please enter your three numbers:");
threeNumbers = in.next();
//for(threeNumbers != lotteryNumber)
//{
//}
System.out.println(lotteryNumber);
}
}
[/code][/QUOTE]
For loops are really cool. Here's a slide show I found that may help you understand them better. [URL="https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic5_for_loops_nested_loops.pdf"]https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic5_for_loops_nested_loops.pdf[/URL]
In regards to your program, you can save a lot of time declaring your random number by declaring it in the for loop.
[CODE]for (int i = 0; i < 3; i++) { //run for three times. Remember we start at 0 and increment until the statement in the middle is false.
//maybe we should initialize some variables here.
int number = (int) (Math.random() * 9 + 1); // we can define variables in a loop
threeNumbers = threeNumbers + in.next(); //everything before the for loop is stored in some other variable
lotteryNumber = lotteryNumber + number; //ibid
//We'll use an if statement here and compare the values here
if (lotteryNumber.substring(i).equals(threeNumbers.substring(i))) { //when we're using the .substring() we are checking each value at i
System.out.println("We have a match!");
} else {
System.out.println("No match...");
}
}[/CODE]
For extra credit learn:
what += does
Use substrings to remove characters using a for loop.
Rewrite your program using a char array.
Hope this helps!
[QUOTE=blacksam;45847154]For loops are really cool. Here's a slide show I found that may help you understand them better. [URL="https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic5_for_loops_nested_loops.pdf"]https://www.cs.utexas.edu/~scottm/cs312/handouts/slides/topic5_for_loops_nested_loops.pdf[/URL]
In regards to your program, you can save a lot of time declaring your random number by declaring it in the for loop.
[CODE]for (int i = 0; i < 3; i++) { //run for three times. Remember we start at 0 and increment until the statement in the middle is false.
//maybe we should initialize some variables here.
int number = (int) (Math.random() * 9 + 1); // we can define variables in a loop
threeNumbers = threeNumbers + in.next(); //everything before the for loop is stored in some other variable
lotteryNumber = lotteryNumber + number; //ibid
//We'll use an if statement here and compare the values here
if (lotteryNumber.substring(i).equals(threeNumbers.substring(i))) { //when we're using the .substring() we are checking each value at i
System.out.println("We have a match!");
} else {
System.out.println("No match...");
}
}[/CODE]
For extra credit learn:
what += does
Use substrings to remove characters using a for loop.
Rewrite your program using a char array.
Hope this helps![/QUOTE]
thanks man :)
What should I use to program with C?
[QUOTE=Shirky;45853334]What should I use to program with C?[/QUOTE]
Netbeans, CodeLite, Eclipse or Code::Blocks. Just don't use the Microsoft compiler it sucks anus.
[QUOTE=reevezy67;45853731]Netbeans, CodeLite, Eclipse or Code::Blocks. Just don't use the Microsoft compiler it sucks anus.[/QUOTE]
relevant avatar
Heh, kind of. Visual studio is fucking amazing though.
Just use the visual studio C++ compiler to do the C work.
If you actually end up wanting all the C11/C99 functionality, you can always switch.
Just safe yourself the efforts of setting up whole environment for now.
Beyond missing C99 and C11 functionality, there is nothing wrong with the visual studio compiler.
[QUOTE=Shirky;45853334]What should I use to program with C?[/QUOTE]
Windows:
notepad++
Mingw Cygwin
linux:
kate or gedit
GCC
edit: also add -std=c11 to the end of all of your compilations
[QUOTE=proboardslol;45856378]Windows:
notepad++
Mingw Cygwin
linux:
kate or gedit
GCC
edit: also add -std=c11 to the end of all of your compilations[/QUOTE]
What kind of advice is this supposed to be
Cygwin is overkill - and not portable in various ways - and mingw isn't exactly beginner-friendly. On Windows it'd make sense to go with something that actually works.
Considering a beginner also probably won't run into C11 features, that's unnecessary. -Wall -Wextra are better choices as you do want to get all possible warnings.
[editline]1st September 2014[/editline]
Also, if going with the MinGW/GCC toolchain, you really want to learn how to write Makefiles
[QUOTE=esalaka;45856469]What kind of advice is this supposed to be
Cygwin is overkill - and not portable in various ways - and mingw isn't exactly beginner-friendly. On Windows it'd make sense to go with something that actually works.
Considering a beginner also probably won't run into C11 features, that's unnecessary. -Wall -Wextra are better choices as you do want to get all possible warnings.
[editline]1st September 2014[/editline]
Also, if going with the MinGW/GCC toolchain, you really want to learn how to write Makefiles[/QUOTE]
what do you mean mingw isnt beginner friendly? you type "gcc program.c -o program.exe". thats all a beginner needs to know.
[QUOTE=proboardslol;45856614]what do you mean mingw isnt beginner friendly? you type "gcc program.c -o program.exe". thats all a beginner needs to know.[/QUOTE]
That's not mingw, that's gcc.
[editline]31st August 2014[/editline]
Pretty sure a beginner also has to know how to install mingw.
[editline]31st August 2014[/editline]
And gcc in mingw.
[QUOTE=cartman300;45856633]That's not mingw, that's gcc.[/QUOTE]
[IMG]http://i.imgur.com/BFOpFfn.png[/IMG]
Wait i'm confusing this with cygwin again.
[IMG]https://i.imgur.com/75nqaZ3.png[/IMG]
Please tell me there is a better way to get labels to format...
I don't want them so close, but I don't want to have to manually calculate the vertical distance between each one.
I can only get it to format to the form rather than format with other labels and distance themselves; am I missing some sort of designer tool or property?
**SOLVED, found that godlike format menu :)
I mean Im just a beginner myself. I use MinGW gcc cause it's simple. I dont really know what the difference between compilers are so thats just what I suggest
[QUOTE=Proclivitas;45856746][IMG]https://i.imgur.com/75nqaZ3.png[/IMG]
Please tell me there is a better way to get labels to format...
I don't want them so close, but I don't want to have to manually calculate the vertical distance between each one.
I can only get it to format to the form rather than format with other labels and distance themselves; am I missing some sort of designer tool or property?
**SOLVED, found that godlike format menu :)[/QUOTE]
There are also some layout controls like panels and grids (that are called tables, but whatever)
[QUOTE=Arxae;45857586]There are also some layout controls like panels and grids (that are called tables, but whatever)[/QUOTE]
CONTAINERS *** ;)
But yeah, I was messing with them; you can't align within them..? confused.
I'm trying to create a 24 puzzle. If I type "move" followed by a number next to "0". The numbers will swap places in the array. This is what I have so far, but the numbers won't budge.
[CODE]import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
public class Board
{
File file = new File("input.txt");
File out = new File("output.txt");
int[][] the_frame = new int[5][5];
Scanner command = new Scanner(System.in);
public void readInitialBoard() throws Exception
{
PrintWriter output = new PrintWriter(out);
Scanner input = new Scanner(file); //Reads the input from file "input.txt"
for ( int row = 0; row < the_frame.length; row++) //5 rows in total
{
for (int column = 0; column < the_frame[row].length; column++) //5 columns read from each row
{
the_frame[row][column] = input.nextInt(); //each values are put into array
}
}
}
public int makeMove(String move, int num) throws ArrayIndexOutOfBoundsException
{
Scanner command = new Scanner(System.in);
move = command.nextLine();
if (move.equals("move")) //"move" is inputted follow by number. If number not next to 0, then it will be considered an incorrect move.
{
num = command.nextInt(); //input number
for ( int row = 0; row < the_frame.length; row++ )
{
for (int column = 0; column < the_frame[row].length; column++)
{
if (num == the_frame[row][column]) //"searches" the number within the array. If found it goes to next step
{
if (num >= 100 * (the_frame[row+1][column]))
{
the_frame[row+1][column] = num;
the_frame[row][column] = 0;
System.out.println("Success");
}
else if (num >= 100 * (the_frame[row][column+1]))
{
the_frame[row][column+1] = num;
the_frame[row][column] = 0;
System.out.println("Success");
}
else if (num >= 100 * (the_frame[row-1][column]))
{
the_frame[row-1][column] = num;
the_frame[row][column] = 0;
System.out.println("Success");
}
else if (num >= 100 * (the_frame[row][column-1]))
{
the_frame[row][column-1] = num;
the_frame[row][column] = 0;
System.out.println("Success");
}
else
{
System.out.println("Wrong move");
}
System.out.println("please continue");
}
}
}
}
else if (move.equals("help"))
{
System.out.println("help");
}
else
{
System.out.println("Invalid number found");
}
return num;
}
public void showBoard()
{
String leftAlignFormat = "| %-2s |";
System.out.println("Current board");
for (int row = 0; row < the_frame.length; row++)
{
System.out.println("------------------------------");
for (int column = 0; column < the_frame[row].length; column++)
{
System.out.format(leftAlignFormat, the_frame[row][column]);
}
System.out.println();
}
}
public boolean isCorrect()
{
return false;
}
}[/CODE]
So say if I say "move" "12," this is the result I get.
[CODE]Current board
------------------------------
| 1 || 2 || 3 || 4 || 5 |
------------------------------
| 6 || 7 || 8 || 9 || 10 |
------------------------------
| 11 || 12 || 0 || 13 || 14 |
------------------------------
| 15 || 16 || 17 || 18 || 19 |
------------------------------
| 20 || 21 || 22 || 23 || 24 |
move 12
Invalid number found
Current board
------------------------------
| 1 || 2 || 3 || 4 || 5 |
------------------------------
| 6 || 7 || 8 || 9 || 10 |
------------------------------
| 11 || 12 || 0 || 13 || 14 |
------------------------------
| 15 || 16 || 17 || 18 || 19 |
------------------------------
| 20 || 21 || 22 || 23 || 24 |[/CODE]
Here's the main method if anyone wants to try it out.
[CODE]import java.util.Scanner;
public class Driver
{
Scanner input = new Scanner(System.in);
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
String x = "John Smith";
int y = 0;
int z = 0;
Board b = new Board();
try
{
b.readInitialBoard();
}
catch (Exception e)
{
}
while(z < 100)
{
try
{
b.showBoard();
b.makeMove(x, y);
}
catch (ArrayIndexOutOfBoundsException a)
{
}
}
}
}[/CODE]
In your makeMove method you are doing this:
[code]move = command.nextLine();[/code]
This will set move to "move 12". I believe you want to use next() instead of nextLine(). That should set move to "move" and let you get 12 as the number. Also, due to how Scanner works, after getting the number you have to call command.next() so that the Scanner throws away the newline.
Also, since you are getting the string and number from the makeMove method you don't need to pass anything in as arguments. However, it's probably better design to pass them as arguments so makeMove doesn't have to be tied to standard in.
Something like this:
[code]
void makeMove(int num) {
...
}
void showHelp() {
...
}
void handleInputs() {
//Get command
if (command.equals("move")) {
//Get number
makeMove(num);
}
else if (command.equals("help")) {
showHelp()
}
else {
//Invalid command
}
}
[/code]
[IMG]http://i.imgur.com/ciKSXgR.png[/IMG]
I just realized I'm able to generate click events like this at once..
/gquit
So in my android app I am reading a long list (10,000+) of key:pair combos off a .csv file, which is causing the main UI thread to lag up and skip about 1500-2000 frames.
I've never used different threads before, which is what I assume i will be needing. I need to have some method of reading the file, which I then place into a HashMap and returns once it is finished so I know I can use those hashmaps without getting NPE errors. On the main thread it works when there is <1000 combos but anything over that won't work.
If anyone could point me to the right direction that'd be helpful. The point is that I can't let the other parts of the application continue until it is done reading all that data into hashmaps, alternatively I can let other parts continue but I need to know when it is done so that I can do something in my code
[editline]2nd September 2014[/editline]
By calling the function to read the files from inside an AsyncTask doInBackground I was able to make it correctly load the data, however I would obviously like to not make the user wait 15 seconds each time this activity is opened.
Anybody got any idea if there are compiler switches to enable implicit C like casting when compiling as C++ in visual studio? It's pain in the ass when you have to port C code to C++ and the codebase is huge and the only thing that you have to change is add crapload of explicit casts.
[QUOTE=Bloodsh0t;45870409]So in my android app I am reading a long list (10,000+) of key:pair combos off a .csv file, which is causing the main UI thread to lag up and skip about 1500-2000 frames.
I've never used different threads before, which is what I assume i will be needing. I need to have some method of reading the file, which I then place into a HashMap and returns once it is finished so I know I can use those hashmaps without getting NPE errors. On the main thread it works when there is <1000 combos but anything over that won't work.
If anyone could point me to the right direction that'd be helpful. The point is that I can't let the other parts of the application continue until it is done reading all that data into hashmaps, alternatively I can let other parts continue but I need to know when it is done so that I can do something in my code
[editline]2nd September 2014[/editline]
By calling the function to read the files from inside an AsyncTask doInBackground I was able to make it correctly load the data, however I would obviously like to not make the user wait 15 seconds each time this activity is opened.[/QUOTE]
read it once ? like during the app start and keep the data in global scope so you can access it from all activities without loading it again e.g. after screenrotations?
[QUOTE=Bloodsh0t;45870409]So in my android app I am reading a long list (10,000+) of key:pair combos off a .csv file, which is causing the main UI thread to lag up and skip about 1500-2000 frames.
I've never used different threads before, which is what I assume i will be needing. I need to have some method of reading the file, which I then place into a HashMap and returns once it is finished so I know I can use those hashmaps without getting NPE errors. On the main thread it works when there is <1000 combos but anything over that won't work.
If anyone could point me to the right direction that'd be helpful. The point is that I can't let the other parts of the application continue until it is done reading all that data into hashmaps, alternatively I can let other parts continue but I need to know when it is done so that I can do something in my code
[editline]2nd September 2014[/editline]
By calling the function to read the files from inside an AsyncTask doInBackground I was able to make it correctly load the data, however I would obviously like to not make the user wait 15 seconds each time this activity is opened.[/QUOTE]
As has been mentioned above, you can load your data when your application starts, in a background thread/task, while displaying a loading/splash screen, and keep it in memory until you don't need it any more.
But it sounds like what you do also takes up a lot of memory. You'll generally want to avoid that on mobile devices.
If you're able to, consider using a different data format that doesn't require you to read everything from flash memory into RAM at once and it'd kill two birds with one stone - when opening your app, loading is instantaneous, and your memory footprint is low.
While it might be overkill if you only have key-value pairs, SQLite would be easy to set up. And perhaps you can offload a lot of your data processing/searching to SQL.
Even if you can't change the input data format, if you only need an initial import (meaning there won't be any changes to your input data between app launches, done outside of the app), it might still be a good idea to import that CSV file into a database once and use that from then on.
Java question:
Suppose I want to make a program that calculates the probability of a number being landed on a 6 sided die when I input how many times it should be rolled, how would I make it?
Here's what I have so far.
[code]
import java.util.Random;
import java.util.Scanner;
public class DiceProbability
{
public static void main(String[] args)
{
//Declare and initialize variables and objects
//Input: ask user for number of rolls and number of sides on a die
//Print heading for output table
//***************************************************************************************
//Using nested loops, cycle through the possible sums of the dice.
//Roll the dice the given number of times for each sum.
//Count how many times the sum of the dice match the current sum being looked for.
//***************************************************************************************
//Loop to increment through the possible sums of the dice
//Loop to throw dice given number of times
//Randomly generate values for two dice
//Check if the sum of dice is equal to the given sum
//After all throws, calculate percentage of throws that resulted in the given sum
//Print results
System.out.println(" " + sum + "\t\t" + probability );
System.out.print("Please enter the number of sides on a die: ");
System.out.print("Please enter the number of rolls: ");
System.out.print("\n Sum of dice \t Probability \n");
Scanner in = new Scanner(System.in);
Random randNum = new Random();
probability = (double)match / numRolls * 100;
numSides = in.nextInt();
numRolls = in.nextInt();
match++;
match = 0;
int sum = 0;
int numSides = 0;
int numRolls = 0;
int match = 0; //Number of times sum of dice matches the current sum
int die2 = 0;
int die1 = 0;
double probability = 0.0;
die2 = randNum.nextInt( numSides ) +1;
die1 = randNum.nextInt( numSides ) +1;
if ( die1 + die2 == sum )
{
} // end if
for( sum = 2; sum <= (numSides * 2); sum++ )
{
} //end for
for( int roll = 0; roll < numRolls; roll++ )
{
} //end for
} //end main
}//end class DiceProbability
[/code]
I know that using a nested loop would be optimal here but how would I go about putting it in here?
Thanks in advance.
[QUOTE=joshuadim;45876135]Java question:
Suppose I want to make a program that calculates the probability of a number being landed on a 6 sided die when I input how many times it should be rolled, how would I make it?
Here's what I have so far.
[code]
import java.util.Random;
import java.util.Scanner;
public class DiceProbability
{
public static void main(String[] args)
{
//Declare and initialize variables and objects
//Input: ask user for number of rolls and number of sides on a die
//Print heading for output table
//***************************************************************************************
//Using nested loops, cycle through the possible sums of the dice.
//Roll the dice the given number of times for each sum.
//Count how many times the sum of the dice match the current sum being looked for.
//***************************************************************************************
//Loop to increment through the possible sums of the dice
//Loop to throw dice given number of times
//Randomly generate values for two dice
//Check if the sum of dice is equal to the given sum
//After all throws, calculate percentage of throws that resulted in the given sum
//Print results
System.out.println(" " + sum + "\t\t" + probability );
System.out.print("Please enter the number of sides on a die: ");
System.out.print("Please enter the number of rolls: ");
System.out.print("\n Sum of dice \t Probability \n");
Scanner in = new Scanner(System.in);
Random randNum = new Random();
probability = (double)match / numRolls * 100;
numSides = in.nextInt();
numRolls = in.nextInt();
match++;
match = 0;
int sum = 0;
int numSides = 0;
int numRolls = 0;
int match = 0; //Number of times sum of dice matches the current sum
int die2 = 0;
int die1 = 0;
double probability = 0.0;
die2 = randNum.nextInt( numSides ) +1;
die1 = randNum.nextInt( numSides ) +1;
if ( die1 + die2 == sum )
{
} // end if
for( sum = 2; sum <= (numSides * 2); sum++ )
{
} //end for
for( int roll = 0; roll < numRolls; roll++ )
{
} //end for
} //end main
}//end class DiceProbability
[/code]
I know that using a nested loop would be optimal here but how would I go about putting it in here?
Thanks in advance.[/QUOTE]
first of all, you're using all of these variables before you declare them. It's good practice to put global variables at the top of the main method or class hierarchy.
Next, you shouldn't group expressions and methods together like that; a program is a list of instructions that goes line by line. Call methods, write expressions, declare variables in the logical order instead of grouping them together to look pretty. Use comments to help you with organization.
Finally, Not entirely sure I understand that goal of the program. It rolls the dice a certain amount of times, prints the random result, and THEN prints the probability that that would be the result? In all instances, the probability that you would get that result is 1/NumberOfSides.
Unless you mean, what's the probability that you might get roll a 1 the first time, a 2 the second time, and a 7 the 3rd time? in which case, the probability is equally likely for any amount of configuration, whether that be (5,4,9) or (6,6,6). The formula for the probability of a set of outcomes is (1/(NumberOfSides)^NumberOfDice)) which is to be read: 1 divided by the Number of Sides to the power of the Number of dice.
some pseudocode for rolling dice:
[code]
int main(){
int numOfSides; /*declare global variables at the top*/
int numOfDice;
print("How many sides?");
getInput(numOfSides);
print("How many dice?");
getInput(numOfDice);
print("rolling...");
for(int i = 1; i < numOfDice; i++){ /*start at 1, since you can't roll 0 dice*/
/*if all you want is to display the output, you don't need to have declared any global variables. just use your language's print statement.*/
print(i + " " + randomNum(numOfSides));
}
/*if you want to calculate the likelyhood that the printed results would appear, that likelyhood is:*/
print("probability that previous results would appear:");
print("1/"+numOfSides^numOfDice); /*will display probability in form of fraction */
}
[/code]
edit:
also that big block of comments you put should be at the very very top of your program. the comments that have your name, date the program was created, and the description of the entire program should be before everything in the program, including before the library import statements and pre-processing
[QUOTE=DrTaxi;45875285]As has been mentioned above, you can load your data when your application starts, in a background thread/task, while displaying a loading/splash screen, and keep it in memory until you don't need it any more.
But it sounds like what you do also takes up a lot of memory. You'll generally want to avoid that on mobile devices.
If you're able to, consider using a different data format that doesn't require you to read everything from flash memory into RAM at once and it'd kill two birds with one stone - when opening your app, loading is instantaneous, and your memory footprint is low.
While it might be overkill if you only have key-value pairs, SQLite would be easy to set up. And perhaps you can offload a lot of your data processing/searching to SQL.
Even if you can't change the input data format, if you only need an initial import (meaning there won't be any changes to your input data between app launches, done outside of the app), it might still be a good idea to import that CSV file into a database once and use that from then on.[/QUOTE]
Thanks for the explanation. I am already using SQLite for a lot of other things so that was my go-to option. When I wrote the code I didn't think about the fact that it may be tolling on the system.
[editline]3rd September 2014[/editline]
The reason I need to load all the data at once is so that I can make comparisons between data and substrings of data, and I am unable to cut up the data into smaller sets. I need to get a key on user selection from CSV#1 and compare it to part of the keys in CSV#2 to get the values where they match. Anyways I think I got it sorted, thanks again
Sorry, you need to Log In to post a reply to this thread.