[QUOTE=Dr. Evilcop;44316414]I do all the superficial stuff like that already. I mean more the structure of the code itself.[/QUOTE]
[url=http://en.wikipedia.org/wiki/Design_Patterns]This might be very useful to you.[/url] There's lots of other literature about this topic, too.
[QUOTE=blacksam;44313353][QUOTE]call a method that [B]returns[/B] the
country with the largest area (this method should use the
largerArea method inside the class; it should not compare the
area of countries directly).[/QUOTE][/QUOTE]
This looks like you're supposed to return the country to main and print there.
Just call the [I]largerArea[/I] method (not quite well named imo) in the [code]if (countryList.get(i).getArea() > tMax) {[/code] bit instead of retrieving the area there, then you also only need to store the current larget country.
It's not that good to store list indices if you want to return only the country anyway, since it forces you to retrieve it all the time again and again.
Also get rid of the [I]tMax[/I] variable, you can (actually have to in this assignment) use just the largest found country instead.
[U]Don't initialize stuff to nonsensical values![/U] In this case you're creating 0 values out of thin air.
If you aggregate information like here, plug in the first item in your list and then iterate over the rest only, [U]if there is no sensible default[/U].
(If you were adding the sizes you'd have 0 as neutral element of addition, but there is no neutral element of "largest"... unless you want to return [I]null[/I] instead of throwing an exception which is a [B]bad[/B] idea.)
Trying to initialize to the first element also ensures the method fails immediately if there is none, which is something you want to always happen if there's no default.
[editline]22nd March 2014[/editline]
[QUOTE=WitheredGryphon;44317549][...]
Then I would check each variable using bitwise operators
[code]
int highVal(list<int> sampleList)
{
int highest = 0;
for(list<int>::iterator it = sampleList.begin(); it != sampleList.end(); ++it)
{
if(
((!(0x8000000 & *it) && 0x8000000 & *(it + 1)) || -- *it >= 0 and *(it+1) < 0
(!(0x80000000 & *it) && *(it + 1) == 0) || -- or *it >= 0 and *(it+1) == 0
(0x80000000 & *it && 0x80000000 & *(it + 1)) || -- or *it < 0 and *(it+1) < 0
(!(0x80000000 & *it) && !(0x80000000 & *(it + 1)))) > 0 -- or *it >= 0 and *(it+1) >=0 -- return > 1 if true
)
{
highest = *it;
}
else { continue; }
}
return highest;
}
[/code]
This won't work because C++ lists aren't random access so you can't get the next value in the list, but the comparison idea is still the same and works. I'm also not sure why it's putting " ="keyword operator"> " or whatever everywhere but ignore that.
[...][/QUOTE]
This also won't work in Java since that language doesn't support pointers at all.
Read the question again, the solution is far simpler than this.
In my defense, my professor told us to name the method as such, and I couldn't agree more with you about the naming. The assignment is from the book Big Java Late Objects. It's a fantastic book! She added those methods to implement in one of the questions.
Funny story, I got a quarter of a point taken off in an assignment because I didn't write her name at the top of the comments.
snip
[QUOTE=Alternative Account;44319299][url=http://en.wikipedia.org/wiki/Design_Patterns]This might be very useful to you.[/url] There's lots of other literature about this topic, too.[/QUOTE]
Be careful with design patterns: [url]http://blog.codinghorror.com/rethinking-design-patterns/[/url]
In my experience, asking "How is this [I]supposed[/I] to be organized?" or "What design pattern should I use here?" is the wrong way to go about it. Instead, ask "How can I change this in order to make my life easier?" Often the answer it to apply some design patterns, but not always. The goal should always be to simplify and streamline; forcing your code to fit a certain design pattern can often achieve the opposite.
[QUOTE=Tamschi;44319587]
This also won't work in Java since that language doesn't support pointers at all.
Read the question again, the solution is far simpler than this.[/QUOTE]
Why does that make my solution dumb? It doesn't directly compare using boolean operators and you don't have to use pointers for it to work, you can just as easily use indexing and it work just as well. It should have been clarified that all he needed was an extra method that could use boolean comparisons but whatever.
[QUOTE=blacksam;44320349]In my defense, my professor told us to name the method as such, and I couldn't agree more with you about the naming. The assignment is from the book Big Java Late Objects. It's a fantastic book! She added those methods to implement in one of the questions.
Funny story, I got a quarter of a point taken off in an assignment because I didn't write her name at the top of the comments.[/QUOTE]
Our professor requires us to do that except with our names and he docks multiple points if we don't put it there (even though we have to use BlackBoard to submit our assignments through our account anyway). It's weird but whatever.
[QUOTE=WitheredGryphon;44323906]Why does that make my solution dumb? It doesn't directly compare using boolean operators and you don't have to use pointers for it to work, you can just as easily use indexing and it work just as well. It should have been clarified that all he needed was an extra method that could use boolean comparisons but whatever.[/QUOTE]
Unfortunately we don't have the bad reading rating any more.
The original post states very clearly what is meant by not comparing directly, it's even in the same sentence.
I have no idea how you could miss that.
[QUOTE=Tamschi;44325814]Unfortunately we don't have the bad reading rating any more.
The original post states very clearly what is meant by not comparing directly, it's even in the same sentence.
I have no idea how you could miss that.[/QUOTE]
Saying "it should not compare the areas of the countries directly" implies to me that it should not compare them directly I.E. area1 < area2. I didn't know sticking it in a method would alleviate that issue, but that the method was also required by the problem. I've had multiple programming problems where it says "write a method to do x" and "x" still had to happen in the method.
[QUOTE=WitheredGryphon;44326658]Saying "it should not compare the areas of the countries directly" implies to me that it should not compare them directly I.E. area1 < area2. I didn't know sticking it in a method would alleviate that issue, but that the method was also required by the problem. I've had multiple programming problems where it says "write a method to do x" and "x" still had to happen in the method.[/QUOTE]
That's why I wrote "bad reading", all of this is clearly stated in the assignment (or at least something that looks like one):
[QUOTE=blacksam;44313353][quote][...] (this method should use the
largerArea method inside the class[B];[/B] it should not compare the
area of countries directly).[/quote][...][/QUOTE]
[QUOTE=Dr. Evilcop;44316414]I do all the superficial stuff like that already. I mean more the structure of the code itself.[/QUOTE]
I read this some time ago, and found it explaining different ways to do structuring of code quite nicely.
[URL="http://gameprogrammingpatterns.com/"]Webbook: Game Programming Patterns[/URL]
Though you should be careful after a while when your code is starting to get large, my code is starting to get quite off the pattern I started out with due to needing other methods than I first thought of.
Has anyone ever used WordNet? I have no experience in programming, and here is what I want to do. I want to take WordNet and render a 3D object with it which will show every connection between every word and each word will only show up once in the structure. I am thinking of sort of onion shape, where the deepest layer of the onion will contain the words with most alternative words or connections, and the outside layer will contain words with least alternative words. What I want to end up with is sort of sphere, where each node is a word, and each branch leaving each node represents a meaning or a concept connecting 2 nodes together. I want each branch to stick close to any other close branch to an extent. Kinda like this but instead of a circle I want to make a sphere with multiple layers:
[IMG]http://designinginterfaces.com/wp-content/images/radial-table-car-models.png[/IMG]
The idea is to show the English language in a single 3D structure which would allow you to see connections between different ideas. For example words like love would extend their network to one direction while words like hate would take another route.
It really is hard to explain, I came up with the idea high after all but I think it's feasible. I just don't have the required skills to do this yet. Would anyone be interested in helping? I know I probably need to analyse the raw data first somehow to determine how the pattern will go together but I just have no idea how.
[QUOTE=bootv2;44329734]I'm using this piece of code to determine if a certain object in a vector is used, and if it is not used, delete it from the vector
[code]for (int i = 0; i < valuemap.size(); i++)
{
if (!valuemap.at(i).used)
{
valuemap.erase(valuemap.begin() + i);
}
}[/code]
Now when I count the amount of used variables, I get about 4000 variables, yet when I do this, I end up with about 133.000 variables(which are about triple the variables I start out with)
now why the fuck does this happen and how do I fix this?
[editline]23rd March 2014[/editline]
I fixed the issue by not calling the code snippet at all, and just writing a new file containing only the sorted used variables. I would still like to know why vector::erase() behaves like this though.[/QUOTE]
I don't understand the specific issue you seem to have (the vector's size is 4000 elements before and 133000 after the loop?) but your loop behaves incorrectly. When element 0 gets thrown out, you continue with element 1, which was element 2 before the erase, so you skip one inbetween.
This should be used to erase on the fly:
[cpp]for (auto it = std::begin(valuemap); it != std::end(valuemap);)
{
if (!it->used)
it = valuemap.erase(it);
else
++it;
}[/cpp]
or just something like
[cpp]
std::remove_if(std::begin(valuemap), std::end(valuemap), [](const decltype(valuemap)::value_type& o){return !o.used;});
[/cpp]
[QUOTE=bootv2;44329901]The issue was that I started out with about 30.000 variables and ended with the amount of 133.000 variables. I can see the issue that I'm skipping the deletion of some variables in my loop now but I still don't understand why it causes the vector to grow instead of to shrink[/QUOTE]
Me neither, when I test your loop the vector shrinks as expected. It must be some other side effect in your code.
[QUOTE=bootv2;44329997]maybe vector::shrink_to_fit() did something weird, I called it after deleting all those variables and then I checked the size of the vector. I thought this function had to be called after deleting variables in a vector because it would leave empty spots in the vector if I didn't.
So, judging from your code I don't need to call shrink_to_fit after deleting variables right?[/QUOTE]
It's an optional operation to reduce the reserved memory space. It does not change the content in any way, just the memory layout behind it. It also invalidates all iterators, but unless you use those to determine the size, this should not affect your result.
[IMG]http://3devs.bplaced.net/wp-content/uploads/2014/03/path.png[/IMG]
Trying to find paths in polygons...
The image above uses a heuristic approach.. it places random circles into the polygon and trys to maximize their radius. The biggest circles should create a more or less perfect path in the polygon. So... the problem is reducing the circles and avoid picking the small ones...
I would appreciate any fresh ideas :)
(Building the final path is already solved... only reducing the circles by their amount is the problem here...)
Does anyone know any good tutorials or resources for working with simple networking in C#? I just want to practice with a simple client and server console application.
How to pass a security token/account verification in WebRequest in C#?
I want to load a page in a thread from Facepunch but it returns me "Sup guy! This thread is hidden from the public gaze!"
[code]
WebRequest request = WebRequest.Create("http://facepunch.com/showthread.php?t=1321763");
request.Credentials = CredentialCache.DefaultCredentials;
[/code]
There's a credentials interface but I don't know how to use it correctly.
EDIT:
Or do I put security token in header
I have to write a small program in C++ for my graphics programming course, it has to draw a simple smooth shaded triangle using 3 points.
I have the algorithm to draw the scan lines to fill it done and the rest of the framework is there (I just need to do a clipping function), The part I'm stuck with is sorting the points counter clockwise.
If I have a triangle with 3 points the top point should be P1, the other 2 points are P2 and P3. So the next point should be P3 and the next one P2, I know that I should be able to do something using the angles of the points but I can't figure out how to do it, please help.
[editline]24th March 2014[/editline]
for example
[img]http://i.imgur.com/AtXvkW4.png[/img]
The first triangle is already sorted, but on the second triangle the green point should be C and the blue point should be B.
Here's what I have which I think should sort them, however this only applies to 3 point polygons so it would not work if there were more points. I haven't tested this yet so if there is anything wrong with it C++ wise, this is the first time I've been using C++ seriously and I would like help with that.
[code]// Sort the vertices of triangle into the anticlockwise sense.
// a should be the topmost & leftmost point.
void Core::sortTriVertices(Point &a, Point &b, Point &c)
{
// If point A has a higher Y value than point C, swap point A with point C
if(a.y > c.y) {
Point temp_a = a;
a = c;
c = temp_a;
}
// If point B has a higher Y value than point C, swap point B with point C
if (b.y > c.y) {
Point temp_b = b;
b = c;
c = temp_b;
}
// If point A has a higher Y value than point B, swap point A with point B
if(a.y > b.y) {
Point temp_a = a;
a = b;
b = temp_a;
}
// If point A has equal Y value with point B, find the lowest X value point
// and put B in that point, C in the other
if (a.y == b.y && a.x > b.x) {
Point temp_b = b;
b = a;
a = temp_b;
}
// If point B has equal Y value with point C, find the lowest X value point
// and put B in that point, C in the other
if (c.y == b.y && b.x > c.x) {
Point temp_b = b;
b = c;
c = temp_b;
}
// Sort Point B and C anti-clockwise
if (b.x < c.x) {
Point temp b = b;
b = c;
c = temp_b;
}
}[/code]
[QUOTE=aurum481;44332636]How to pass a security token/account verification in WebRequest in C#?
I want to load a page in a thread from Facepunch but it returns me "Sup guy! This thread is hidden from the public gaze!"
[code]
WebRequest request = WebRequest.Create("http://facepunch.com/showthread.php?t=1321763");
request.Credentials = CredentialCache.DefaultCredentials;
[/code]
There's a credentials interface but I don't know how to use it correctly.
EDIT:
Or do I put security token in header[/QUOTE]
I think the credentials are only for HTTP auth, what you need is a cookie.
You can get one by POSTing the login to Facepunch or ripping it out of the local browser data (which is definitely possible, you can open Firefox's SQLite database for example).
The proper way to do things like this would probably be to display an OAuth web UI, but Facepunch doesn't support that currently.
However, the [URL="http://lab.facepunch.com"]labpunch[/URL] API is far better suited to what you want to do, you even don't have to deal with cookies or scraping.
[editline]24th March 2014[/editline]
[QUOTE=Pat.Lithium;44334368][...]
I have the algorithm to draw the scan lines to fill it done and the rest of the framework is there (I just need to do a clipping function), The part I'm stuck with is sorting the points counter clockwise.
[...][/QUOTE]
You only have to check whether the third point is "left" or "right" to the line connecting the first ones.
To do that,
1. get the vector from A to B,
2. rotate it 90° (switch the values and flip the sign on one of them),
3. multiply with the vector from A (or B, any point on that first line works) to C.
The sign of the result tells you the ordering.
[editline]24th March 2014[/editline]
Winding order I mean :v:
Apparently ° too breaks editing.
[editline]24th March 2014[/editline]
[QUOTE=Pat.Lithium;44334368]I have to write a small program in C++ for my graphics programming course, it has to draw a simple smooth shaded triangle using 3 points.
I have the algorithm to draw the scan lines to fill it done and the rest of the framework is there (I just need to do a clipping function), The part I'm stuck with is sorting the points counter clockwise.
If I have a triangle with 3 points the top point should be P1, the other 2 points are P2 and P3. So the next point should be P3 and the next one P2, I know that I should be able to do something using the angles of the points but I can't figure out how to do it, please help.
[editline][...]
Here's what I have which I think should sort them, however this only applies to 3 point polygons so it would not work if there were more points. [...]
[...][/QUOTE]
Whoops, I didn't see that part.
It depends on what you want to do, if you have a triangle-subdivision method already you can just run that and then check whether a triangle is oriented correctly if necessary I think.
Otherwise you probably have to count angles, to do that
1. rotate each edge segment into the space of the previous one (and the first into the space of the last one), so that you can
2. get the angle with atan2 and
3. add the angles together.
The sign tells you the winding order like in the previous example if you rotated the first vector 90° counter-clockwise.
[QUOTE=Tamschi;44335458]1. rotate each edge segment into the space of the previous one (and the first into the space of the last one), so that you can
2. get the angle with atan2 and
3. add the angles together.
The sign tells you the winding order like in the previous example if you rotated the first vector 90° counter-clockwise.[/QUOTE]
I don't understand what you mean by rotating each edge segment into the space of the previous one.
[QUOTE=Pat.Lithium;44336029]I don't understand what you mean by rotating each edge segment into the space of the previous one.[/QUOTE]
Rotate it so that the previous one is aligned for example along the x axis, then you can get the relative coordinates in the right angle.
It's easy if you think of the 2-vectors as [del]imaginary[/del]complex numbers, just divide the current segment by the previous one and you have the rotated version.
[QUOTE=Tamschi;44335458]I think the credentials are only for HTTP auth, what you need is a cookie.
You can get one by POSTing the login to Facepunch or ripping it out of the local browser data (which is definitely possible, you can open Firefox's SQLite database for example).
The proper way to do things like this would probably be to display an OAuth web UI, but Facepunch doesn't support that currently.
However, the [URL="http://lab.facepunch.com"]labpunch[/URL] API is far better suited to what you want to do, you even don't have to deal with cookies or scraping.
.[/QUOTE]
Doesn't look like it gives ratings to parse.
But it seems to be easier to use.
[code] SUBROUTINE RANDOM(r,i)
1 r=RAN1(i)
IF (r.eq.0.0.or.r.eq.1.0) goto 1
RETURN
END SUBROUTINE
!This subroutine uses 3 LCG's, 1 and 2 to generate an array R
!filled with 97 pseudo-random numbers.
!3 is used to pick a random number out of R
FUNCTION RAN1(IDUM)
DIMENSION R(97)
PARAMETER (M1=259200,IA1=7141,IC1=54773,RM1=3.8580247E-6)
PARAMETER (M2=134456,IA2=8121,IC2=28411,RM2=7.4373773E-6)
PARAMETER (M3=242000,IA3=4561,IC3=51349)
DATA IFF /0/ !declare IFF and set it to 0
IF (IDUM.LT.0.OR.IFF.EQ.0) THEN
IFF=1
IX1=MOD(IC1-IDUM,M1)
IX1=MOD(IA1*IX1+IC1,M1)
IX2=MOD(IX1,M2)
IX1=MOD(IA1*IX1+IC1,M1)
IX3=MOD(IX1,M3)
DO 11 J=1,97
IX1=MOD(IA1*IX1+IC1,M1)
IX2=MOD(IA2*IX2+IC2,M2)
!Add two random numbers to make it more random or
!something like that, ... VAGUE
R(J)=(FLOAT(IX1)+FLOAT(IX2)*RM2)*RM1
11 CONTINUE
IDUM=1
ENDIF
IX1=MOD(IA1*IX1+IC1,M1)
IX2=MOD(IA2*IX2+IC2,M2)
IX3=MOD(IA3*IX3+IC3,M3)
J=1+(97*IX3)/M3
IF(J.GT.97.OR.J.LT.1)read(*,*)
!Pick randomly chosen value out of R
RAN1=R(J)
R(J)=(FLOAT(IX1)+FLOAT(IX2)*RM2)*RM1
RETURN
END FUNCTION
[/code]
So this is a variant of [URL="http://nuclear.fis.ucm.es/wordpress/wp-content/uploads/2011/09/RandomNumbers.pdf"]ran1[/URL], it uses two linear congruential generators to generate two pseudorandom numbers, adds them together, stores it in an array of size 97 and picks a random number out of that array (using a third LCG).
At the moment it either gives values between 2e-37 and 1, or in other cases (that I can't reproduce) it gives back only two values (0.3 and 0.882 or something). So it's broken as fuck, it's written in F77 for 32 bit machines and I'm on x64 Win7.
The 2e-37 seems to hint at an integer overflow or something, the second case is even vaguer.
But that's not my question, my question is: when you call this function with exactly the same parameters, it outputs two different random numbers. But if I look at this code, I don't see how that's possible, there has to be some variable inside that function that somehow stays in scope when the function ends, and is used again when it is called a second time, intuitively it should be IX1 and IX2 as that's by definition the iterative aspect of a LCG that generates the sequence, but I don't immediately see them last beyond the RAN1() call...
Edit:
okay there is no such thing as variable scope in Fortran lol, every variable in that subroutine is there forever, which explains everything
Hey odd post requesting help here. Theres some slightly encrypted data in this code I have and I want to decipher it if possible. However I'm having troubles reading it. This is triggers from SC2 that was pulled in text from the map files.
[CODE]string gr8String_gf () {
int D7Badae;
int 7BADai;
// Variable Declarations
int lv_a;
string lv_value;
// Variable Initialization
lv_value = "00000000";
// Implementation
D7Badae = 8;
7BADai = 1;
lv_a = 1;
for ( ; ( (7BADai >= 0 && lv_a <= D7Badae) || (7BADai <= 0 && lv_a >= D7Badae) ) ; lv_a += 7BADai ) {
lv_value = StringReplace(lv_value, IntToString(RandomInt(1, 9)), lv_a, lv_a);
}
return lv_value;
}[/CODE]
What is the value of lv_value and gr8String_gf ?
The end number is 23164293 and its supposed to be (decrypted) 5.
[QUOTE=CaptainSnake;44340003]
What is the value of lv_value and gr8String_gf ?
[/QUOTE]
Can you be more specific? lv_value and gr8String_gf are the same because gr8String_gf() just returns whatever lv_value's final value is.
[QUOTE=CaptainSnake;44340003]Hey odd post requesting help here. Theres some slightly encrypted data in this code I have and I want to decipher it if possible. However I'm having troubles reading it. This is triggers from SC2 that was pulled in text from the map files.
[CODE]string gr8String_gf () {
int D7Badae;
int 7BADai;
// Variable Declarations
int lv_a;
string lv_value;
// Variable Initialization
lv_value = "00000000";
// Implementation
D7Badae = 8;
7BADai = 1;
lv_a = 1;
for ( ; ( (7BADai >= 0 && lv_a <= D7Badae) || (7BADai <= 0 && lv_a >= D7Badae) ) ; lv_a += 7BADai ) {
lv_value = StringReplace(lv_value, IntToString(RandomInt(1, 9)), lv_a, lv_a);
}
return lv_value;
}[/CODE]
What is the value of lv_value and gr8String_gf ?
The end number is 23164293 and its supposed to be (decrypted) 5.[/QUOTE]
Just run it? It's impossible to know without having [I]StringReplace[/I], [I]IntToString[/I] and [I]RandomInt[/I] too.
Also, if [I]RandomInt[/I] does what I think it does then the result is not a constant.
I can't run it because I can't recreate it in another SC2 map scenario. I'm looking at text while SC2 has its editor.
Also I have no idea what those verbs do but I have a feeling they were put there to mislead. Although the random assortment of numbers is highly suspicious, there must be a way for the map to decode them and come with the final number. Right now I'm just trying to follow the trail and hoping it leads somewhere.
I have a fairly simple question.
We are doing sorting algorithms in my C# class and I need to make an "optimized" bubble sort. As in, with the least amount of extra tests. This is my take on it, not sure if it is as "optimized" as it can get.
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sortTest
{
class Program
{
static void Main(string[] args)
{
int[] numArr = { 1, 2, 4, 6, 5, 4, 3, 8 };
OptBubSort(numArr);
for (int i = 0; i < numArr.Length; i++)
{
Console.WriteLine(numArr[i] + " ");
}
}
public static void OptBubSort(int[] numArr)
{
bool swapIsMade = true;
int Num1;
int Num2;
while (swapIsMade)
{
swapIsMade = false;
for (int i = 0; i < numArr.Length - 1; i++)
{
if (numArr[i] > numArr[i + 1])
{
Num1 = numArr[i+1];
Num2 = numArr[i];
numArr[i] = Num1;
numArr[i + 1] = Num2;
swapIsMade = true;
}
}
}
}
}
}
[/code]
[QUOTE=Rofl my Waff;44347329]I have a fairly simple question.
We are doing sorting algorithms in my C# class and I need to make an "optimized" bubble sort. As in, with the least amount of extra tests. This is my take on it, not sure if it is as "optimized" as it can get.
--code--
[/QUOTE]
You can keep track of the last time a swap was made, so that next time you go through the array you don't have to check to the end since you know that part is already sorted. I don't think you can do a similar thing for the beginning of the array but you can double check that.
Playing with OpenGL/GLSL, how do I debug shaders?
Sorry, you need to Log In to post a reply to this thread.