• What Do You Need Help With? V6
    7,544 replies, posted
Would it be possible to store some sort of UTC Timestamp in 2 bytes? I tried, but getting the precision right didn't work out very well. I know there should be 4 bytes, but I can't change the actual file format itself; I can, however, use whatever padding there is...
[QUOTE=CarLuver69;44280341]Would it be possible to store some sort of UTC Timestamp in 2 bytes? I tried, but getting the precision right didn't work out very well. I know there should be 4 bytes, but I can't change the actual file format itself; I can, however, use whatever padding there is...[/QUOTE] [url=https://stackoverflow.com/questions/595884/what-is-the-smallest-size-of-bytes-that-you-can-store-a-timestamp/595966#595966]No.[/url]
[QUOTE=Jookia;44280506][url=https://stackoverflow.com/questions/595884/what-is-the-smallest-size-of-bytes-that-you-can-store-a-timestamp/595966#595966]No.[/url][/QUOTE] Thanks so much for that! I tried looking for something like that myself but nothing came up. Oh well.
Hi, maybe you guys can help with something. I hope this is the right place to ask. I needed a simple program that "reconstructs" CSGO model files to be compatible with GMod, and in order to achieve that, you need to take the file ending with ".dx90.vtx", and create two copies of it, one ending with ".dx80.vtx" and the other one with simply ".vtx". For example, at the beginning you have "thing.dx90.vtx", and that file should be copied twice and renamed into "thing.dx80.vtx" and "thing.vtx". So I needed a program that could do that for all files automatically. GMod4Ever had written this into a .bat file: [code] @ECHO OFF title L4D2 VTX Constructor echo Initiating VTX re-construction... set /a count=0 for /r %%F in (.) do ( Pushd %%F for %%i in (*.*) do ( IF "%%~xi" == ".dx90.vtx" ( echo Fixing "%%~ni.mdl". COPY %%i "%%~ni.dx80.vtx" set /a count+=1 ) ) ) echo Reconstructed VTXes. Recommended to run cleaner.bat next. pause [/code] But for some reason, it doesn't work. Any ideas?
is it possible to declare a variable number of controls? something like [code] foreach ( string anotherButton in buttonList ) { Button anotherButton = new Button(); anotherButton.Text = anotherButton; } [/code] Except this gives a different meaning to 'anotherButton'... so I can't have a lot of buttons called another button. Y'know what I'm sayin'? This is C# by the way. Nvm figured it out. I did [code] List<Button> Facepunch = new List<Button>(); foreach ( string anotherButton in buttonList ) { Facepunch.Add(new Button); } [/code]
@Loadingue I already made an app that's supposed to do that, [URL="https://www.dropbox.com/s/iifzjjp02194lio/VTXr.zip"]here[/URL] [URL="https://www.dropbox.com/sh/2e4tbnahyun9jzs/cLKi8oyRk4"]Project files[/URL]
snip
V_[B]m[/B] = 1 + 1/(3^[B]m[/B]) + 1/(5^[B]m[/B]) + 1/(7^[B]m[/B]) + 1/(9^[B]m[/B]) + ... so in the formula itself V_2, V_4, etc. mean the following: V_[B]2[/B] = 1 + 1/(3^[B]2[/B]) + 1/(5^[B]2[/B]) + 1/(7^[B]2[/B]) + 1/(9^[B]2[/B]) + ... V_[B]4[/B] = 1 + 1/(3^[B]4[/B]) + 1/(5^[B]4[/B]) + 1/(7^[B]4[/B]) + 1/(9^[B]4[/B]) + ... ...
[QUOTE=cartman300;44286511]@Loadingue I already made an app that's supposed to do that, [URL="https://www.dropbox.com/s/iifzjjp02194lio/VTXr.zip"]here[/URL] [URL="https://www.dropbox.com/sh/2e4tbnahyun9jzs/cLKi8oyRk4"]Project files[/URL][/QUOTE] I'm not sure how to use this, the window instantly closes when I run it. When I use the 'DeBug' version though, it says "One of these directories does not exist! files files_2"
snip
[QUOTE=Hikjaf;44289586]How could I miss that, thanks. Picture is still not clear, can someone give me more pointers? What role does -pi/2<x<pi/2 play and what it means to my code?[/QUOTE] The secant function is equal to 1/cos(x). It has asymptotes in x=-Pi/2 and x=+Pi/2 and becomes negative outside that interval, and you don't want to evaluate the logarithm of a negative and/or undefined value (it is [I]not[/I] infinity!). So you restrict the domain to ]-Pi/2,+Pi,2[. If you graph it, you can see that the domain is actually larger, but it would output the same values, so it makes sense to just restrict the domain to the aforementioned interval. [IMG]http://puu.sh/7BvZ6.png[/IMG] By saying that the program should terminate when you enter x=2, it actually hints at restricting your input to the open interval ]-Pi/2,+Pi/2[, or if you want to make your life hard you can look at the graph again and figure which inputs are allowed, although that will complicate your code and probably is outside the scope of this exercise. So your program should have -user input checking (everywhere, but keep it reasonable, this is also a lesser priority than actually getting sensible output results) -two ways of calculating the output (which can also be specified with user input). As to the exact algorithm, that's kinda the point of the exercise and I wouldn't want to just give it because you won't learn anything from it. It's okay to write a program that shits itself on the first run, the debugging is equally part of the exercise and will force you to understand it thoroughly. Try to break it down in smaller simply arithmetic parts, write pseudo code and [URL="http://en.wikipedia.org/wiki/Rubber_duck_debugging"]use rubber duck debugging[/URL] if stuff doesn't work.
[QUOTE=Hikjaf;44289586]How could I miss that, thanks. Picture is still not clear, can someone give me more pointers? What role does -pi/2<x<pi/2 play and what it means to my code?[/QUOTE] It limits the absolute of the brackets to values smaller than 1, though I'm not quite sure if that's enough to make it converge. Might well be though. [editline]19th March 2014[/editline] See above, it does ensure convergence.
The range for x probably stems from the fact that this series was derived within a circle in the complex plane. These series only hold if you stay within a certain radius of convergence (which ends at the first pole,which is at +-Pi/2). Although my complex analysis is rusty and I still have to do a resit in august :(
snip
In CSharp how do I access an object created inside a class in another class? Public, etc doesn't seem to work. Here's some example code. [code] using Leap; namespace LeapMotion { class Leap { Controller controller = new Controller(); SampleListener listener = new SampleListener(); public Leap() { controller.AddListener(listener); } public string GetGesture() { //Can't do this because can't access it return listener.Frame.Gesture(); } ~Leap() { controller.RemoveListener(listener); controller.Dispose(); } } public class SampleListener : Listener { //Unable to access this Frame object Frame frame = new Frame(); public bool connected; public override void OnConnect(Controller controller) { connected = true; } public override void OnDisconnect(Controller controller) { connected = false; } public override void OnFrame(Controller controller) { frame = controller.Frame(); } } } [/code] Look at the comments.
[QUOTE=Hikjaf;44290575]Say user inputs x and number of iterations, say 5 iterations. Do I just calculate V_2(2x/pi)^2 + V_4(2x/pi)^2 + V_6(2x/pi)^2 + V_8(2x/pi)^2 + V_10(2x/pi)^2 ? Is that what is meant by iteration? Radian is 180/pi angle, pi is number. How exactly do I divide 2x by pi and is result supposed to be angle or number? V_m calculation goes indefinitely? Where it stops? You see my problem is not within my programming or algorithm scheming ability, I'm exceptionally good at them, it is my lack of advanced maths. I postponed my maths classes because I don't enjoy them.[/QUOTE] It's not really an iterative method in the usual sense of the word (well, compared to Newton's Method or Gauss-Seidel stuff). You can set up a loop to calculate each term and add it to the total sum, each extra term making the result more precise, so yes, what you said. V_m will have to end at some arbitrary m (or you could make it way more complicated by analysing its convergence depending on m), it's hard to say which one, for smaller m you will have to calculate more terms obviously. There will be some maximal m for which that series won't change much more due to floating point number representation, although that already might be overkill. The conversion methods between angle and radians are easily found on Google. Also, to be honest, Taylor series aren't advanced maths and I suggest you attend those classes because they're important, given the trouble you have with this exercise.
@JakeAM Try this [code] using Leap; namespace LeapMotion { class Leap { Controller controller = new Controller(); SampleListener listener = new SampleListener(); public Leap() { controller.AddListener(listener); } public string GetGesture() { //Can't do this because can't access it return listener.frame.Gesture(); // frame isn't capital in SampleListener class } ~Leap() { controller.RemoveListener(listener); controller.Dispose(); } } public class SampleListener : Listener { //Unable to access this Frame object public Frame frame = new Frame(); // You forgot to put public here public bool connected; public override void OnConnect(Controller controller) { connected = true; } public override void OnDisconnect(Controller controller) { connected = false; } public override void OnFrame(Controller controller) { frame = controller.Frame(); } } } [/code]
Can anyone give me a quick insight into the problem i'm having. I'm using for the first time a compact database built into the project with a dataset (C#), done following a tutorial and it works fine (Insert, Update, Delete all good). But I cannot use visual studio (2012)'s 'preview data' function or even refresh the database connection without the database being wiped I know the inserts are persisting because if I add a user and run, then remove the 'add user' line and print the contents of the users table fetched with a table adapter, it showes the user I added before, thanks
I'm stuck and need help guys [code]using namespace std; #include <lab29.h> #include <iostream> int findI(const vector<char>& v) { int j = 0; for (vector<char>::const_iterator i = v.end()-1; i >= v.begin(); --i) { if(*(i-1) < *i) { cout << *(i-1) << " is less than " << *i << endl; j = distance(v.begin(), i); cout << "Returning " << j << endl; return j; } else { cout << *(i-1) << " is not less than " << *i << endl; continue; } } return j; } int findJ(const vector<char>& v, int i) { int j=0; for (vector<char>::const_iterator k = v.end()-1; k >= v.begin(); --k) { if(*(k-i) < *k) { cout << *k << " is greater than " << *(k - i) << endl; j = distance(v.begin(), k); cout << "Returning " << j << endl; return j; } else { cout << *k << " is not greater than " << *(k-i) << endl; continue; } } return j; } ostream& operator<<(ostream& os, const vector<char>& v) { for(uint i=0; i<v.size(); i++) { os << v[i]; } return os; } [/code] It's an implementation but what the entire code does is it takes in the [code]const vector<char>& v[/code] and derives all possible permutations by using findI and findJ. What findI does is iterate through the vector from the end to the beginning and checks to see if any element in the vector is less than the neighbor to its right. It returns that value and is then put into the findJ function which similarly iterates through the [code]const vector<char>& v[/code] except this time it's looking for the first element that is bigger than the I value. When I run the code however, it loops infinitely giving this output: [code]abc b is less than c Returning 2 c is greater than a Returning 2 abc b is less than c Returning 2 c is greater than a Returning 2 [/code] It's expected to output: [code] abc acb bac bca cab cba[/code] It gets to the second permutation fine (albeit not printing it) but then instead of checking 'b' against 'a' in the third permutation (since it's supposed to go from right to left) it skips 'b' and checks 'c' against 'a' then gets stuck in an infinite loop. I need help on fixing this or ideas on how to do this better or anything would help really.
In my csharp windows application I have a settings form. How can I have all the settings affect variables in another derived class and also only set these when the user presses apply?
[QUOTE=JakeAM;44297890]In my csharp windows application I have a settings form. How can I have all the settings affect variables in another derived class and also only set these when the user presses apply?[/QUOTE] You could have the settings contain setters and getters for those values, but you can't point to properties directly since they are not actual single members (in C#). You also can't take references to fields directly using documented parts of the language. What I would do is build the settings dynamically: If you annotate properties or fields in static classes, you can then enumerate all of them at runtime. You can give the attribute some information about the organization of settings, so that you can for example build groups or pages automatically from categories. If you want to tweak the layout manually the getter/setter method definitely is the way to go though, you can also shorten it a bit using Reflection and Expressions (if that's available) since you can extract the underlying property/field from an expression like [code]() => Class.FieldOrProperty[/code]. [editline]edit[/editline] You'll need some kind of cache where the modified values are stored until they are applied. Doing that manually would be really tedious, so I recommend either generating the settings dialogue from the affected values or making prototypes that you can instantiate for the different settings manually. (The latter might be more or less work than implementing the generator once for all necessary types, it depends on the amount and variety of settings you have.)
[QUOTE=WitheredGryphon;44294275]I'm stuck and need help guys [code]using namespace std; #include <lab29.h> #include <iostream> int findI(const vector<char>& v) { int j = 0; for (vector<char>::const_iterator i = v.end()-1; i >= v.begin(); --i) { if(*(i-1) < *i) { cout << *(i-1) << " is less than " << *i << endl; j = distance(v.begin(), i); cout << "Returning " << j << endl; return j; } else { cout << *(i-1) << " is not less than " << *i << endl; continue; } } return j; } int findJ(const vector<char>& v, int i) { int j=0; for (vector<char>::const_iterator k = v.end()-1; k >= v.begin(); --k) { if(*(k-i) < *k) { cout << *k << " is greater than " << *(k - i) << endl; j = distance(v.begin(), k); cout << "Returning " << j << endl; return j; } else { cout << *k << " is not greater than " << *(k-i) << endl; continue; } } return j; } ostream& operator<<(ostream& os, const vector<char>& v) { for(uint i=0; i<v.size(); i++) { os << v[i]; } return os; } [/code] It's an implementation but what the entire code does is it takes in the [code]const vector<char>& v[/code] and derives all possible permutations by using findI and findJ. What findI does is iterate through the vector from the end to the beginning and checks to see if any element in the vector is less than the neighbor to its right. It returns that value and is then put into the findJ function which similarly iterates through the [code]const vector<char>& v[/code] except this time it's looking for the first element that is bigger than the I value. When I run the code however, it loops infinitely giving this output: [code]abc b is less than c Returning 2 c is greater than a Returning 2 abc b is less than c Returning 2 c is greater than a Returning 2 [/code] It's expected to output: [code] abc acb bac bca cab cba[/code] It gets to the second permutation fine (albeit not printing it) but then instead of checking 'b' against 'a' in the third permutation (since it's supposed to go from right to left) it skips 'b' and checks 'c' against 'a' then gets stuck in an infinite loop. I need help on fixing this or ideas on how to do this better or anything would help really.[/QUOTE] I couldn't really figure out your attempt, so made a fresh implementation based on the algorithm, it might help you to fix your code:[cpp]#include <iostream> #include <string> #include <algorithm> template<typename It> It findI(It begin, It end) { for (auto i = end - 2; i >= begin; --i) if (*i < *(i + 1)) return i; return end; } template<typename It, typename T> It findJ(It begin, It end, const T& i) { for (auto k = end - 1; k >= begin; --k) if (*k > i) return k; return begin; } int main() { std::string v{"abc"}; std::cout << v << std::endl; for (;;) { auto i = findI(std::begin(v), std::end(v)); if (i == std::end(v)) break; auto j = findJ(std::begin(v), std::end(v), *i); std::iter_swap(i, j); std::reverse(i + 1, std::end(v)); std::cout << v << std::endl; } }[/cpp]Output:[code]abc acb bac bca cab cba[/code]
[QUOTE=Dienes;44301301]I couldn't really figure out your attempt, so made a fresh implementation based on the algorithm, it might help you to fix your code:[cpp]#include <iostream> #include <string> #include <algorithm> template<typename It> It findI(It begin, It end) { for (auto i = end - 2; i >= begin; --i) if (*i < *(i + 1)) return i; return end; } template<typename It, typename T> It findJ(It begin, It end, const T& i) { for (auto k = end - 1; k >= begin; --k) if (*k > i) return k; return begin; } int main() { std::string v{"abc"}; std::cout << v << std::endl; for (;;) { auto i = findI(std::begin(v), std::end(v)); if (i == std::end(v)) break; auto j = findJ(std::begin(v), std::end(v), *i); std::iter_swap(i, j); std::reverse(i + 1, std::end(v)); std::cout << v << std::endl; } }[/cpp]Output:[code]abc acb bac bca cab cba[/code][/QUOTE] [code]int findI(const vector<char>& v) { for (vector<char>::const_iterator i = v.end() - 2; i >= v.begin(); --i) if(*i < *(i+1)) return distance(v.begin(), i); return v.size(); } int findJ(const vector<char>& v, int i) { for(vector<char>::const_iterator k = v.end() - 1; k >= v.begin(); --k) if (*k > v[i]) return distance(v.begin(), k); return v[0]; } ostream& operator<<(ostream& os, const vector<char>& v) { for(uint i=0; i<v.size(); i++) os << v[i]; return os; }[/code] God thanks so much, this problem has been giving me so much trouble for no reason.
[QUOTE]call a method that returns 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] [CODE] public static void main(String[] args) { ArrayList<Country> countryList = new ArrayList(); readFile(countryList); displayCountryList(countryList); findLargestPopulation(countryList); public static void findLargestArea(ArrayList<Country> countryList) { int k = 0; double tMax = 0; for (int i = 0; i < countryList.size(); i++) { if (countryList.get(i).getArea() > tMax) { tMax = countryList.get(i).getArea(); k = i; } } System.out.printf("Largest area: " + countryList.get(k).getCountryName() + " with " + df.format(countryList.get(k).getArea()) + " square feet" + "\n"); }[/CODE] Then my class [CODE]public boolean largerArea(Country b) { return this.area > b.getArea(); }[/CODE] Maybe I'm not thinking outside the box enough, but how do I compare [I]without[/I] comparing them directly? Do I use the Comparable class?
[QUOTE=blacksam;44313353][CODE] public static void main(String[] args) { ArrayList<Country> countryList = new ArrayList(); readFile(countryList); displayCountryList(countryList); findLargestPopulation(countryList); public static void findLargestArea(ArrayList<Country> countryList) { int k = 0; double tMax = 0; for (int i = 0; i < countryList.size(); i++) { if (countryList.get(i).getArea() > tMax) { tMax = countryList.get(i).getArea(); k = i; } } System.out.printf("Largest area: " + countryList.get(k).getCountryName() + " with " + df.format(countryList.get(k).getArea()) + " square feet" + "\n"); }[/CODE] Then my class [CODE]public boolean largerArea(Country b) { return this.area > b.getArea(); }[/CODE] Maybe I'm not thinking outside the box enough, but how do I compare [I]without[/I] comparing them directly? Do I use the Comparable class?[/QUOTE] I know this is not specific and I'm thinking in C++ here since I haven't done Java since High School, but what we do is if we needed to compare something we would use the binary operators like '&' and '|' to return binary values of strings / integers. Then we could easily compare the two binary values because one's value will have either more or less bits in it depending on the size and length.
How on Earth should I keep my game engine structured? Right now it [i]works[/i], but it's unorganized and messy. Can anyone point to some reading material on this?
[QUOTE=Dr. Evilcop;44316183]How on Earth should I keep my game engine structured? Right now it [i]works[/i], but it's unorganized and messy. Can anyone point to some reading material on this?[/QUOTE] What works for me is i name stuff nicely and categorize in folders based on what stuff does or where it belongs.
[QUOTE=cartman300;44316283]What works for me is i name stuff nicely and categorize in folders based on what stuff does or where it belongs.[/QUOTE] I do all the superficial stuff like that already. I mean more the structure of the code itself.
[QUOTE=WitheredGryphon;44315922]I know this is not specific and I'm thinking in C++ here since I haven't done Java since High School, but what we do is if we needed to compare something we would use the binary operators like '&' and '|' to return binary values of strings / integers. Then we could easily compare the two binary values because one's value will have either more or less bits in it depending on the size and length.[/QUOTE] That's a neat tid bit, so forgive me for abusing these next sentences, but without using the main can you return a highest value from a list of objects? I thought brute force would do the trick, so I just set K to that position. But I'm not allowed to do that in main. When do I use the comparable class then?
[QUOTE=blacksam;44316947]That's a neat tid bit, so forgive me for abusing these next sentences, but without using the main can you return a highest value from a list of objects? I thought brute force would do the trick, so I just set K to that position. But I'm not allowed to do that in main. When do I use the comparable class then?[/QUOTE] Like I said I haven't used Java in forever so forgive me if I butcher what I say. What I would do is create a method taking the list of objects as input that would return the highest value (if you are comparing ints, have it return int, if strings then have it return strings, if you want it to print from that statement then make it void) [code]int highVal(list<int> sampleList) { return highest; }[/code] I'm not sure how Java does it, but in C++ we use Iterators to loop through a list so: [code] int highVal(list<int> sampleList) { int highest = 0; for(list<int>::iterator it = sampleList.begin(); it != sampleList.end(); sampleList++) { } return highest; } [/code] 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. [editline]Edited:[/editline] Can anyone see any way to optimize this? Running time is currently at 4.2 seconds at 1 million elements: [code] #include <vector> #include <algorithm> #include <iostream> using namespace std; void sieveOfEratosthenes(vector<bool>& prime) { vector<bool>::iterator n = prime.end(), p = prime.begin(), i, k, j; for (i = p; i != n; ++i) *i = true; for (k = p + 2; k != n; ++k) if (*k == true) for(j = k; j <= n; j += distance(p, k)) if(j != k) *j = false; } void printPrimes(const vector<bool>& prime, ostream& os) { vector<bool>::const_iterator n = prime.end(), p = prime.begin(), k; for(k = p + 2; k != n; ++k) if(*k == true) os << distance(p, k) << '\n'; } [/code]
Sorry, you need to Log In to post a reply to this thread.