• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=WhatTheEf;39687661]Yep. Any way of fixing the problem?[/QUOTE] It's an issue with the pre 12.11 drivers. Try upgrading your drivers.
[QUOTE=elevate;39675344]Any way of simplifying verbose code like this? [cpp] if (((lumpName[0] == 'E') && (isdigit(lumpName[1])) && (lumpName[2] == 'M') && (isdigit(lumpName[3])) && (lumpName[4] == '\0') && (lumpName[5] == '\0') && (lumpName[6] == '\0') && (lumpName[7] == '\0')) [/cpp][/QUOTE] If I was in that situation, the first thing I would do is put all of those C strings into std::strings. Then you wouldn't need to worry about all of the trailing nulls and could just use length().
[quote]Write a static method that, given an array of integers, returns the longest sequence of (strictly) increasing integers. Note, the integers in the sequence do need to be in order, but they do not need to be sequential. So, in the array [1, 4, 9, 2, 6, 7, 3, 5, 8, 10], the answer is 6, due to the sequence 1, 2, 3, 5, 8, 10 (all in order from the original array, just not sequential in the original array). Your solution should be recursive. One straightforward approach will use a helper method with two additional parameters: a starting index, and the maximum value used in a sequence built before that index so far. For this approach, the base case should be clear. To think about the problem recursively, consider several scenarios: is the value at the starting index larger than the minimum value used so? If not, what do we do? If so, we have two choices: use the value in that first spot, or don't use it. Either way, you are left with a recursive call. You may assume that Integer.MIN_VALUE is smaller than any value in your array.[/quote] So I got this prompt for my homework and many of my classmates are just confounded. I'm really am confused because I understand that you can check for a element but, How would you check from left to right to see if it's in order like for to say "1,2,3,5,8,10" from that list of array, But [1, [B]4[/B], [B]9[/B], 2, [B]6[/B], [B]7[/B], 3, 5, 8, 10] The ones i bold, how would check to skip over it to calculate the strictly increasing indexes?
[QUOTE=pyschomc;39692325]So I got this prompt for my homework and many of my classmates are just confounded. I'm really am confused because I understand that you can check for a element but, How would you check from left to right to see if it's in order like for to say "1,2,3,5,8,10" from that list of array, But [1, [B]4[/B], [B]9[/B], 2, [B]6[/B], [B]7[/B], 3, 5, 8, 10] The ones i bold, how would check to skip over it to calculate the strictly increasing indexes?[/QUOTE] After the part where you pick the number to start with: Iterate through the array with a regular for loop (ignoring the ones that are before the number you already have) Check which one of the following numbers is the lowest, which in this case is '2'. Iterate again, now starting from pos 5 of the array (the '6', aka the index of the lowest, + 1) check which of the following numbers is the lowest. Etc. [b]edit:[/b]Obviously you will want to make the start number picker recursive too. In case the array starts with the highest number, or the array ends with the lowest. The easiest way would just try this for EVERY number, but you could also just check if the number you are looking at, is actually higher than one of the previous ones. (Ex: (3,1,2,5,6), if you iterate through them all it'd be pointless to do this again for 2, 5 and 6, since they are not the first of the list.)
Could I perhaps ask a question a friend had about XNA game studio? He's made his background image an object of the sprite class. It's not showing up, however and he's just getting a purple background? Sorry if this isnt really the place to ask. :l
[QUOTE=Kirovich;39692721]Could I perhaps ask a question a friend had about XNA game studio? He's made his background image an object of the sprite class. It's not showing up, however and he's just getting a purple background? Sorry if this isnt really the place to ask. :l[/QUOTE] I seem to remember that being an issue with transparency
[QUOTE=Richy19;39692805]I seem to remember that being an issue with transparency[/QUOTE] How would he go about fixing that?
I'm still not getting anywhere :_: So far i wrote a pseudocode for iteration but I want to make it a pseudo code for recursive.. [editline]24th February 2013[/editline] Wait here's the code how would I convert this into recursion? [code] public static int helper(int[] seq) { int[]E=new int[seq.length]; E[0]=1; //base case for(int i=1;i<E.length;i++){ int MAX=0; for(int j=0;j<i;j++){ if(seq[j]<seq[i]&&E[j]>MAX){ MAX=E[j]; } } E[i]=MAX+1; } int MIN=0; for(int i=0;i<E.length;i++){ if(E[i]>MIN){ MIN=E[i]; } } return(MIN); }[/code]
[QUOTE=pyschomc;39697474]I'm still not getting anywhere :_: So far i wrote a pseudocode for iteration but I want to make it a pseudo code for recursive.. [editline]24th February 2013[/editline] Wait here's the code how would I convert this into recursion? [code] public static int helper(int[] seq) { int[]E=new int[seq.length]; E[0]=1; //base case for(int i=1;i<E.length;i++){ int MAX=0; for(int j=0;j<i;j++){ if(seq[j]<seq[i]&&E[j]>MAX){ MAX=E[j]; } } E[i]=MAX+1; } int MIN=0; for(int i=0;i<E.length;i++){ if(E[i]>MIN){ MIN=E[i]; } } return(MIN); }[/code][/QUOTE] I'm pretty sure your code is already recursive. [editline]24th February 2013[/editline] But please dear god don't use capitals for variable names unless they're finals, use some fucking spaces and use a whiteline here and there.
Good day. I have been given another programming related exercise. I must generate a dynamic array with a length of 0<N<101. Then I must populate the array with random numbers 0<=M<=1'000'000. Then I must print this array as it is ( numbers in random number as they were declared into the array) and after that I must print the array sorted using some sorting algorithm. Now I have figured out most but populating the array with numbers. [code] srand(time(0)); //seeding the random number generator for (i=0; i<N; i++) // for when i is less than number inputted by user { jada[i] = (rand() % 1000000+ 0); // This should theoretically populate the array with number within 0 and 1'000'000 std::cout << jada [i] << ", "; // This should then print the numbers of the array. } [/code] Now the problem is that the random numbers go only as high as 32'767 or Rand_max as I read. I have not found a solution how to populate my array with numbers >32'767 I have tried dividing the rand or multiplying different rands but I either exceed the 1'000'000 limit or I never get any number below 1'000 or etc etc. Any ideas how I should proceed ?
Try dividing the result of rand by RAND_MAX, then multiplying by 1000000. [cpp]double r = rand()/RAND_MAX; jada[i] = r*1000000;[/cpp]
[QUOTE=MakeR;39700876]Try dividing the result of rand by RAND_MAX, then multiplying by 1000000. [/QUOTE] This populates the whole array with 0's.
Cast RAND_MAX to a double.
And that did it. Thank you very much !
[QUOTE=valiant1k;39701263]And that did it. Thank you very much ![/QUOTE] Just remember that the product of the division of two integers in C(++) is always an integer, and so if you get a remainder (in this case the remainder is the entire number) it will be truncated and you will be left with zero. If either number is a float/double, the result will follow suit.
What's a good lua bridge/interpreter for .net/C#? LuaInterface seems to be popular but it's old and from what I see no longer supported. Are there any active projects that are not in heavy alpha/beta stage?
[QUOTE=Rayjingstorm;39701409]Just remember that the product of the division of two integers in C(++) is always an integer, and so if you get a remainder (in this case the remainder is the entire number) it will be truncated and you will be left with zero. If either number is a float/double, the result will follow suit.[/QUOTE] But there are functions that get the remainder for you - or you could use the modulo operator to get it. If you need the remainder.
Hey guys, I just want some quick advice for a random 2d terain generator. Its fairly simple since it has to work with pen drawings of terrain sections I make. The algorythm for puzzeling the panels together works, but I'm obviously stuck with the problem of filling in the space below the panels so that hills don't look like bridges of glass panels. I could create a mesh that has the same width as the panel, and extend it down to the ground level, but might there be a more efficient way?
[QUOTE=mobrockers2;39699842]I'm pretty sure your code is already recursive. [editline]24th February 2013[/editline] But please dear god don't use capitals for variable names unless they're finals, use some fucking spaces and use a whiteline here and there.[/QUOTE] Really ? Everyone in my class say it's a iteration ,not recursive
I would say its iterative, your not using recursion anywhere in the code
[QUOTE=MakeR;39700876]Try dividing the result of rand by RAND_MAX, then multiplying by 1000000. [cpp]double r = rand()/RAND_MAX; jada[i] = r*1000000;[/cpp][/QUOTE] [cpp]jada[i] = rand() % 1000001;[/cpp] Assuming RAND_MAX is sufficiently larger than 1000000.
[QUOTE=Larikang;39702768][cpp]jada[i] = rand() % 1000001;[/cpp] Assuming RAND_MAX is sufficiently larger than 1000000.[/QUOTE] It is 32,767 apparently though. [editline]24th February 2013[/editline] That's why he can't get any random numbers above that.
I don't know what the standard is, but this is from my stdlib.h [cpp] /* The largest number rand will return (same as INT_MAX). */ #define RAND_MAX 2147483647 [/cpp] Is it any different in c++?
[QUOTE=Rayjingstorm;39703592]I don't know what the standard is, but this is from my stdlib.h [cpp] /* The largest number rand will return (same as INT_MAX). */ #define RAND_MAX 2147483647 [/cpp] Is it any different in c++?[/QUOTE] It's compiler (and platform) specific, but guaranteed to be at least 32,767.
Hello I got it to work :) in [code] if(a.length == i) { return max; } else { if(a[i] < min) { min = a[i]; current = 1; } else { if(a[i]<a[i-1]) { min = a[i]; current = 2+counter; counter++; } else { current++; } if(current > max) { max = current; } } return helper(i+1, max, min, current, a, counter); } there[/code] Recursive form :)
[QUOTE=pyschomc;39708406]Hello I got it to work :) in /code] Recursive form :)[/QUOTE] Can I have the complete source code (project) for scientific reasons?
[url]http://facepunch.com/showthread.php?t=1249482[/url] Anyone please? I need to solve this asap.
[del]LOVE/Lua/LUBE here I've tried setting up with both LUBE 1.0 and the current dev version, in both LOVE and just plain Lua (the below code) [code]local Class = require "hump.class" require "LUBE" local user = lube.udpClient()[/code] [I]attempt to call field 'udpClient' (a nil value)[/I] anyone with experience in LUBE point out what I'm doing wrong? here's a working implementation of LUBE with the same class lib I'm using: [URL]https://github.com/Nevon/cardboard/blob/master/main.lua#L181[/URL][/del] this turned out to be an incompatibility between LUBE and the latest revision of HUMP.class aaaaand unrelated to networking, just LOVE/Lua and classes (using the HUMP.class lib again) say I have this [CODE]local Player = Class{} function Player:init(uid) self.uid = uid self.pos = Vector() self.vel = Vector() self.acc = Vector() self.dir = 0 self.scale = 3 end function Player:update(dt) self.vel = self.vel + self.acc*dt self.pos = self.pos + self.vel*dt end function Player:draw(img) love.graphics.draw(img.img, self.pos.x, self.pos.y, self.dir, self.scale, self.scale, img.w / 2, img.h / 2) end LocalPlayer = Class{} LocalPlayer:include(Player) function LocalPlayer:init(uid, pos) Player.init(self, uid) self.pos = pos self.fwd = Vector(1, 0) end[/CODE] and then wish to add a LocalPlayer to an array in main, like so: [CODE]universe[uid] = LocalPlayer(uid, Vector(x, y))[/CODE] how come the inheritance isn't being satisfied? if I was to just use a variable like so: p = LocalPlayer(uid, Vector(x, y)) then I can use the object fine and all of its parent's fields exist and are initilised (so, for example, p.acc is a vector representing (0,0) but when I want to instead use this object in a table (I'm meaning to index a couple of players so I can just iterate through them to update them all), these fields are not initilised? I'm not sure what gives :c
I implemented the Fix your timestep thing with the following: [csharp] // Take note of the delta time double deltaTime = (Environment.TickCount - startTime) / 1000.0; startTime = Environment.TickCount; if (deltaTime > 0.25) deltaTime = 0.25; // Only update if in focus, if not dont waste resources if (focused) { Globals.Accumulator += deltaTime; while (Globals.Accumulator>=Globals.Delta) { Update (); Globals.Accumulator -= Globals.Delta; } } // Clear the window window.Clear (); // Draw all elements to the screen Draw (); // Finally, display the rendered frame on screen window.Display ();[/csharp] then in my object class: [csharp] public class PhysicsObject : GameObject { protected Util.Vector2F velocity, direction, force; protected float mass = 1.0f; public PhysicsObject () { velocity = new Util.Vector2F(); direction = new Util.Vector2F(); force = new Util.Vector2F(); } public void ApplyForce(Util.Vector2F force){ this.force += force; } public override void Update() { force /= mass; velocity += force * Globals.Delta; position += velocity * Globals.Delta; oldPosition = position; } public override void Draw(){ drawPosition = Util.Vector2F.Interpolate(oldPosition, position, (float)(Globals.Accumulator/Globals.Delta)); } [/csharp] And use it as: [csharp]SFML.Graphics.CircleShape shape = new SFML.Graphics.CircleShape(20); HGC.Abstracts.PhysicsObject pO = new HGC.Abstracts.PhysicsObject(); public Game () { } public override void Init() { pO.Position = new HGC.Util.Vector2F(-100, 300); } public override void Update() { pO.ApplyForce(new HGC.Util.Vector2F(9.8f, 0)); pO.Update(); } public override void Draw() { pO.Draw(); shape.Position = new SFML.Window.Vector2f(pO.DrawPosition.X, pO.DrawPosition.Y); window.Draw(shape); }[/csharp] but it looks kinda laggy, and not quite right, isthere anything I can do to fix this?
Is there something similar to endl for input to check the next line of a file? Like instead of [i]while (database >> n >> f >> l >> p >> b >> t)[/i], it would just be [i]while (database >> n >> (what I'm asking for like endl))[/i].
Sorry, you need to Log In to post a reply to this thread.