[QUOTE=Shadaez;39816257]oh god that quadtree stuff looks complicated
[editline]5th March 2013[/editline]
So I assume you set a limit for the depth to the quad tree, right?[/QUOTE]
Could. Plus odds are your shapes aren't going to be less than 1 pixel, so it doesn't make sense to have the quadtree get that small (smaller than your shapes). Again I haven't looked into it that much but subdivisions happen when there's x amount of collidable things in a grid. So when it subdivides there should hopefully be less than x things per box.
[QUOTE=Ducluck7;39812376]so I've created some functions to find prime factors
[cpp]#include <iostream>
#include <vector>
#include <math.h>
std::vector<long> prime_sieve(long n) {
std::vector<bool> boolvector (n, true);
for(long i=2; i<sqrt(n); i++) {
if(boolvector[i]) {
for(long j=i*i; j<n; j+=i) {
boolvector[i] = false;
}
}
}
boolvector[0] = boolvector[1] = false;
std::vector<long> primevector;
for(long i=0; i<n; i++) {
if(boolvector[i]) primevector.push_back(i);
}
return primevector;
}
int trial_division(long long n) {
std::vector<long> primes = prime_sieve(sqrt(n));
int primefactor = 0;
std::vector<long>::iterator it;
for(it = primes.begin(); it < primes.end(); it++) {
if((*it)*(*it) > n) break;
else if(n % (*it) == 0) {
std::cout << *it << "\n";
primefactor = *it;
n /= *it;
}
}
return primefactor;
}
int main() {
return trial_division(600851475143);
}[/cpp]
but it takes 10 seconds to execute. I've tried it with lower values, and it works faster. VS2012 says most of the program is spent on the line
[cpp]boolvector[i] = false;[/cpp]
how would I fix this?[/QUOTE]
I'll give you a little tip: You don't need to worry about factors being prime. If you just work your way upwards through the integers, starting at 2, all the factors you find will be prime.
[cpp]#include <iostream>
void trialDivision(long long n)
{
int primeFactor = 2;
while (n > 1) {
if ((n % primeFactor) == 0) {
n /= primeFactor;
std::cout << primeFactor << std::endl;
} else {
primeFactor++;
}
}
}
int main()
{
trialDivision(600851475143);
return 0;
}[/cpp]
Does anyone know if it's possible to allow the user to create custom layouts in android? If so, do you know of any methods/resources?
I don't think it's possible by default, but you could write your own code to load the layout from a file on their storage device. So it's possible if you really want to, but it'll crash if they have something setup wrong in their layout.
[editline]7th March 2013[/editline]
You'll have to write your own parser, though.
program to find fibonacci numbers and primes etc
I don't know what I'm screwing up. problem one: my calculated sizes of arrays are stupidly wrong but i'll deal with that later. problem two: when either case 1 or 2 (the only cases that have a function prepared) hits it cout, the program just dies. problem 3. my prime function is giving stupidly wrong answers.
[img]http://puu.sh/2dKbQ[/img]
the stupidly long number in the second debug line is supposed to be a five.
[cpp]switch (choice)
{
case 1:
cout << "Enter lower and upper limits (lower first, separated by a space): ";
cin >> lowLim >> upLim;
while (lowLim >= limit|| lowLim <= 0 || upLim >= limit|| upLim <= 0 || lowLim >= upLim)
{
cout << "Invalid limits. Please re-enter limits: ";
cin >> lowLim >> upLim;
}
cout << display (primes, primeSize, lowLim, upLim) << " numbers were printed.\n";
break;
case 2:
cout << "Enter lower and upper limits (lower first, separated by a space): ";
cin >> lowLim >> upLim;
while (lowLim >= limit|| lowLim < 0 || upLim >= limit|| upLim <= 0 || lowLim >= upLim)
{
cout << "Invalid limits. Please re-enter limits: ";
cin >> lowLim >> upLim;
}
cout << "test" << display (fibos, fibosSize, lowLim, upLim) << " numbers were printed.\n";
break;
default:
cout << "invalid choice\n";
break;
}
}
return 0;
}
int display (int disArray [], int arraySize, int lowLim, int upLim)
{
int numDisplay = 0;
int lowI;
int highI;
for (int i = 0; i <= arraySize; i++)
if (disArray [i] >= lowLim)
lowI = i;
for (int i = 0; i <= arraySize; i++)
if (disArray [i] > upLim)
highI = i--;
for (int i = lowI; i <= highI; i++)
{
cout << disArray [i] << " ";
numDisplay ++;
}
cout << endl;
return numDisplay;
}
int getprimes (int pArray [], int size, int limit)
{
int filledSize = 0;
int testNum = 1;
for (int i = 0; i < size; i++)
{
testNum++;
if (isprime (testNum))
{
pArray [i] = testNum;
filledSize++;
}
}
return filledSize;
}
bool isprime (int checkNum)
{
for (int i = 1; i < (checkNum / 2) - 1; i++)
{
if (checkNum % i == 0)
return true;
}
return false;
}
int getfibos (int fibosArray [], int size, int limit)
{
int filledSize = 0;
int dummyFibos;
fibosArray [0] = 0;
fibosArray [1] = 1;
for (int i = 2; i < size; i++)
{
dummyFibos = fibosArray [i-1] + fibosArray[i-2];
if (dummyFibos < limit)
{
filledSize++;
fibosArray [i] = dummyFibos;
}
}
return filledSize;
}[/cpp]
When I try to run this, it gives me
[code]NameError: global name 'false'is not defined[/code]
(in python)
I'm running this from a shell, with the code imported:
[code]from math import ceil
def FermatFactor(n):
a = ceil(n**0.5)
b2 = a*a - n
while(isinstance(n**0.5, int) == False):
a+=1
b2 = a*a - n
return a - b2**0.5[/code]
Hi again, i'm back, with c this time. We got an assignment to cript ints into chars with base28 manner. I'm stuck at the part where i must do Euclidean algorithm and get out the five remainders. Everything compiles, but when i try to run it, the program returns 0. What am i doing wrong?
int first-the value that is filled by the user("how many numbers will you use", it must be multiples of three)
int Result[]- result of the numbers inputed by user(by three), where the formula goes like this. Result[i]=firstnum*256^2 +secondnum*256+thirdnum
[code]
int Remainder[first/3][5];
for(int i = 0; i < first/3; i++){
for(int j = 5; j > 0; j--){
Remainder[i][j] = Result[i]-(floor(Result[i]/28))*28;
Result[i] = floor(Result[i]/28);
}
}
[/code]
P.s Remainders must be backwards that's why j--
[QUOTE=Ducluck7;39835929]When I try to run this, it gives me
[code]NameError: global name 'false'is not defined[/code]
(in python)
I'm running this from a shell, with the code imported:
[code]from math import ceil
def FermatFactor(n):
a = ceil(n**0.5)
b2 = a*a - n
while(isinstance(n**0.5, int) == False):
a+=1
b2 = a*a - n
return a - b2**0.5[/code][/QUOTE]
There are several problems here. First of all, I don't get that NameError. Are you sure this is the code you're running? Secondly n**0.5 always returns a float, even if n is a perfect square. Third, that loop will never terminate anyway, since the condition checks n and n is never modified.
Recommendations: use math.sqrt, since that's what you're doing. Use the is_integer function instead of isinstance.
[editline]7th March 2013[/editline]
[QUOTE=RandomDexter;39836044]Hi again, i'm back, with c this time. We got an assignment to cript ints into chars with base28 manner. I'm stuck at the part where i must do Euclidean algorithm and get out the five remainders. Everything compiles, but when i try to run it, the program returns 0. What am i doing wrong?
int first-the value that is filled by the user("how many numbers will you use", it must be multiples of three)
int Result[]- result of the numbers inputed by user(by three), where the formula goes like this. Result[i]=firstnum*256^2 +secondnum*256+thirdnum
[code]
int Remainder[first/3][5];
for(int i = 0; i < first/3; i++){
for(int j = 5; j > 0; j--){
Remainder[i][j] = Result[i]-(floor(Result[i]/28))*28;
Result[i] = floor(Result[i]/28);
}
}
[/code]
P.s Remainders must be backwards that's why j--[/QUOTE]
I can't comment on your math since I don't understand your explanation, but your j index is wrong. Since you start j at 5, you need to subtract one [I]before[/I] the loop starts (but after you check the loop condition). You can do this with the awesome "[URL="http://stackoverflow.com/questions/1642028/what-is-the-name-of-this-operator"]goes to[/URL]" operator:
[cpp]
for (int j = 5; j --> 0;)
...
[/cpp]
How would I write 2 bytes to memory in C++?
[cpp]BYTE bAmmo[2] = { 0xFF, 0x06 };[/cpp]
Obviously I need WriteProcessMemory, but is there a special way to do it? or is it just &bAmmo as the buffer to write with?
[QUOTE=raccoon12;39839443]How would I write 2 bytes to memory in C++?
[cpp]BYTE bAmmo[2] = { 0xFF, 0x06 };[/cpp]
Obviously I need WriteProcessMemory, but is there a special way to do it? or is it just &bAmmo as the buffer to write with?[/QUOTE]
For just dumping some data into the target process on Windows, WriteProcessMemory works well.
If bAmmo is an array like in your example, the buffer argument to WriteProcessMemory is not &bAmmo, it's just bAmmo. If it's an integer, say:
[cpp]uint16_t bAmmo = 0x06ff;[/cpp]
then it's &bAmmo (also note the reversed byte order for ints compared to byte arrays)
Keep in mind that WriteProcessMemory is not atomic. If the other program is using the data while you're writing it, it may be in an inconsistent state.
Trying to make my own scripting language in C# for running some engine stuff - I'm getting somewhere but I'm not sure I am doing it correctly. Here is a current working script example:
[quote]
function "functions/testfunc.txt" "TestFunc";
var text;
text=TestFunc();
MsgBox(test);
[/quote]
The way I currently handle things like functions is just a mess of workarounds. There are so many problems due to my method such as bugs and no adding/subtracting. You also cannot put functions within function arguments etc. The current way that I do it is like so:
[B] - Parse script character by character[/B]
[B] - Read through sections and try and create tokens[/B]
[B] - Check for 'expressions' and parse them[/B]
[B] - Pass to engine[/B]
[B] - Engine goes through each token and interprets[/B]
There is no array, variable scope support either, is their a tutorial I can follow or some code I can look at to try and make the whole process as simple as possible?
[QUOTE=ThePuska;39839812]For just dumping some data into the target process on Windows, WriteProcessMemory works well.
If bAmmo is an array like in your example, the buffer argument to WriteProcessMemory is not &bAmmo, it's just bAmmo. If it's an integer, say:
uint16_t bAmmo = 0x06ff;
then it's &bAmmo (also note the reversed byte order for ints compared to byte arrays)
Keep in mind that WriteProcessMemory is not atomic. If the other program is using the data while you're writing it, it may be in an inconsistent state.[/QUOTE]
bAmmo is the same as &bAmmo if it's an array: [URL]http://codepad.org/QJwx5h8E[/URL]
C, but also applies to C++.
[editline]8th March 2013[/editline]
[QUOTE=KillerLUA;39845065]Trying to make my own scripting language in C# for running some engine stuff - I'm getting somewhere but I'm not sure I am doing it correctly. Here is a current working script example:
The way I currently handle things like functions is just a mess of workarounds. There are so many problems due to my method such as bugs and no adding/subtracting. You also cannot put functions within function arguments etc. The current way that I do it is like so:
[B] - Parse script character by character[/B]
[B] - Read through sections and try and create tokens[/B]
[B] - Check for 'expressions' and parse them[/B]
[B] - Pass to engine[/B]
[B] - Engine goes through each token and interprets[/B]
There is no array, variable scope support either, is their a tutorial I can follow or some code I can look at to try and make the whole process as simple as possible?[/QUOTE]
You should read the dragon book, LLVM's kaleidoscope tutorial would also be a good source of example code for lexing and parsing.
I created a lexer a while ago, and was told it was good, so maybe it will help you: [URL]https://gist.github.com/dajoh/5119002[/URL]
[QUOTE=KillerLUA;39845065]Trying to make my own scripting language in C# for running some engine stuff - I'm getting somewhere but I'm not sure I am doing it correctly. Here is a current working script example:
The way I currently handle things like functions is just a mess of workarounds. There are so many problems due to my method such as bugs and no adding/subtracting. You also cannot put functions within function arguments etc. The current way that I do it is like so:
[B] - Parse script character by character[/B]
[B] - Read through sections and try and create tokens[/B]
[B] - Check for 'expressions' and parse them[/B]
[B] - Pass to engine[/B]
[B] - Engine goes through each token and interprets[/B]
There is no array, variable scope support either, is their a tutorial I can follow or some code I can look at to try and make the whole process as simple as possible?[/QUOTE]
You're gonna want to learn about recursive descent parsing as well as calling conventions. The prior will let you parse most languages in a powerful, easily-handwritten manner, and the latter will help you know what to do when you call functions and return from them.
[QUOTE=dajoh;39845260]bAmmo is the same as &bAmmo if it's an array: [URL]http://codepad.org/QJwx5h8E[/URL]
C, but also applies to C++.[/QUOTE]
Not as a function argument, as arrays are converted to pointers when passed to functions. Which is why I'd always treat arrays the same as pointers of the equivalent type. If you choose to lop off a piece of your code and put it in a function, you would have to change every "&bAmmo" to "bAmmo".
[cpp]int do_stuff(int buffer [2])
{
// &buffer is not the same as buffer in this function
}[/cpp]
Anyone know what I'm doing wrong? This is my first time using JSON.
[cpp]
Request req = Request.to("/me/followers");
HttpResponse resp = wrapper.get(req);
json = Http.getString(resp);
System.out.println(json);
followers = new JSONObject(json);
System.out.println(json);
String[] names = JSONObject.getNames(followers);
for(int i = 0; i < names.length; i++)
{
System.out.println(names[i]);
}
[/cpp]
json is
[CODE]
[{"id":726789,"kind":"user","permalink":"jaooe","username":"Jaooe","uri":"https://api.soundcloud.com/users/726789","permalink_url":"http://soundcloud.com/jaooe","avatar_url":"https://i1.sndcdn.com/avatars-000024466800-uc4d5k-large.jpg?c6caf18","country":"Britain (UK)","full_name":"","description":"jaooe.tumblr.com","city":"Lancaster","discogs_name":null,"myspace_name":null,"website":null,"website_title":null,"online":false,"track_count":4,"playlist_count":0,"plan":"Free","public_favorites_count":33,"followers_count":26,"followings_count":44,"subscriptions":[]}]
[/CODE]
[editline]8th March 2013[/editline]
Oh yeah, also, the exception is:
[CODE]
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
[/CODE]
ALL JSON files must begin with an '{' and end with an '}'. You'll also have to give your array a name, and do followers.getJSONArray("your_array_name"), not JSONObject.getNames().
To check if your JSON is valid, without having to run it through your app (and to get a better error than Android gives you) use [URL="http://jsonlint.com/"]JSONLint[/URL]
I was hoping somebody could, in detail, describe to me what the "inline" type specifier in C++ does? Thank.
[QUOTE=cody8295;39846429]I was hoping somebody could, in detail, describe to me what the "inline" type specifier in C++ does? Thank.[/QUOTE]
say you have a method:
[cpp]inline int add(int a, int b){
return a + b;
}
...
int i = add(5,6);[/cpp]
if the compiler thinks that you could gain some performance by replacing the method call by the method code directly, then it does it, meaning the previous code would get compiled as:
[cpp]int i = 5 + 6;[/cpp]
[QUOTE=cody8295;39846429]I was hoping somebody could, in detail, describe to me what the "inline" type specifier in C++ does? Thank.[/QUOTE]
It hints the compiler that a function should be inlined.
That's essentially all it is. It doesn't force inlining. I believe a compiler is technically free to ignore any instance of inline.
If you don't know what function inlining is, it's basically the compiler pasting the function body with parameters substituted where-ever it's called instead of adding a normal function call.
^the "inline" type qualifier just explicitly tells the compiler to do this if it can.
[editline]8th March 2013[/editline]
Ninja'd
Im trying to make a sort of "global lua game maker thing" with LuaInterface in C#, but the documentation for LuaInterface is either outdate or 404'ring. Does anyone know where i could find proper documentation or a tutorial of sorts to get started?
[QUOTE=Gulen;39845935]ALL JSON files must begin with an '{' and end with an '}'. You'll also have to give your array a name, and do followers.getJSONArray("your_array_name"), not JSONObject.getNames().
To check if your JSON is valid, without having to run it through your app (and to get a better error than Android gives you) use [URL="http://jsonlint.com/"]JSONLint[/URL][/QUOTE]
Incorrect, a JSON-text can be either an array or object.
[quote=RFC4627]
A JSON text is a sequence of tokens. The set of tokens includes six
structural characters, strings, numbers, and three literal names.
A JSON text is a serialized object or array.
JSON-text = object / array
[/quote]
Ohh, alright, thanks for the help guys:)
[QUOTE=dajoh;39846588]Incorrect, a JSON-text can be either an array or object.[/QUOTE]
Oh, well he needs to change the new JSONObject(json) to new JSONArray(json), then it should work.
Does anybody know why this code is crashing?
[code]
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int addRow(string strs[]);
string printRow(int rowID);
string printRows();
string printRows(int fromRow1, int toRow2);
int main()
{
printRows(3, 6);
//ofstream file("logFile.csv");
//file << "Hello File World!";
//file.close();
//cout<<"Done!";
cin.get();
return 0;
}
int addRow(string strs[]){
return 0;
}
string printRow(int rowID){
return "nothing";
}
string printRows(){
cout<<"Printing all rows!";
return "balls"
}
string printRows(int fromRow1, int toRow2){
cout<<"Printing rows in RANGE!";
return "balls"
}
[/code]
EDIT:
Nvm, I changed those string functions to void, removed the return statements and it works now.
It won't even compile.
[QUOTE=dajoh;39849401]It won't even compile.[/QUOTE]
It compiled for me, got past the cout part and then crashed...
Anyways, I solved it.
But I have another problem, I have a string array, like this:
[code]
string arr[100];
[/code]
And I'm filling it up with less than 100 strings. How can I check if there's a string at item n?
You could initialize every string to the empty string and check whether item n is the empty string
I'm trying to optimise a relatively small program for a competition, I'm using the visual studio 2012 profiler to help me, but I'm having trouble getting it to show any useful information. It says 53% of the runtime was used by "mscorlib.ni.dll" and nothing else, so that's 53% I can't analyze. 28% is "Unknown" which I can't analyze either, 19% is used by "System.Core.ni.dll" which.. I neither can analyze! And finally my program's main which takes up 0.01%, and if I click it there's only one "hotline" which is almost definitely out of place.
How do I get this to show any useful information at all?
[QUOTE=cody8295;39849923]It compiled for me, got past the cout part and then crashed...
Anyways, I solved it.
But I have another problem, I have a string array, like this:
[code]
string arr[100];
[/code]
And I'm filling it up with less than 100 strings. How can I check if there's a string at item n?[/QUOTE]
Use an arrayList if you don't know how many objects you want to put in it.
Sorry, you need to Log In to post a reply to this thread.