[QUOTE=swift and shift;34282650]I find that recursion is often a really nice way of breaking up a problem.
gcc can do tail call optimization anyway, so deliberately avoiding recursion is premature optimization[/QUOTE]
It's not an issue of deliberately avoiding recursion. In this specific case the problem is actually stated more clearly as a loop (at least in my opinion). Writing it recursively does not make the code significantly more terse/clear.
Additionally, depending on a specific compiler optimization becomes an issue of portability when compiling code without that feature is likely to result in a binary that is unstable. That one function could use well over 1kB in the unoptimized recursive form (on the order of tens or so bytes for register storage, args, local vars, return pointer, all multiplied by the 32 bits the function has to iterate through), which is absurd for a function that just produces a string of 32 characters. This function might be OK because the n in O(n) stack space is small (just 32), but it could quickly become unacceptable if n was much larger. IMHO, it is only acceptable to write recursive functions when you can assume practical limits on the depth of the recursion -- like tree traversal, which is O(log n) (assuming it is balanced).
So I figured out how to solve it without using strings. I still appreciate all your help.
[cpp]
#include <iostream>
#include <string>
using namespace std;
int convertToBinary(int);
int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}
int convertToBinary(int n)
{
if (n == 0)
return 0;
return 10*convertToBinary(n/2) + n%2;
}
[/cpp]
[QUOTE=Leonmyster;34285306]So I figured out how to solve it without using strings. I still appreciate all your help.
[cpp]
#include <iostream>
#include <string>
using namespace std;
int convertToBinary(int);
int main()
{
int n;
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
while (n != 0)
{
int binary = convertToBinary(n);
cout << "The binary of integer " << n << " is " << binary << ".\n";
cout << "Enter non-zero integer or 0 to stop: ";
cin >> n;
}
cout << "Bye!\n";
}
int convertToBinary(int n)
{
if (n == 0)
return 0;
return 10*convertToBinary(n/2) + n%2;
}
[/cpp][/QUOTE]
an int can store a max of 11 'binary' bits
God, C programmers are weird.
[code]
public static String toBinary(int i)
{
String out = "";
for (int b=0; b<32; b++)
{
if ((i & (1<<b)) == 0) out += '0';
else out += '1';
}
return out;
}
[/code]
EDIT: Oh, so it has to recurse? I should probably read before I code.
I'm looking to render objects with multiple sub-meshes.
Should I create a single vertex-array for the model, and then just store multiple index-lists for the sub-meshes? Or should I store a single vertex array and a single index-list and then just store the start/stop for the sub-mesh? (I could see this creating a problem if the index list wasn't carefully built)
I'm looking for more generalities of rendering 'models' that support multiple sub objects (with multiple sub-groups) than anything language specific.
I just don't get how complicated rendering works. :v:
I found this image [img_thumb]http://puu.sh/dOBL[/img_thumb] I know it is for website design but what I like is that thing on the top right is there anything like that for visual studio? I could of sworn I have seen some pictures of it in an older thread but can't remember where, would help me a ton!
[QUOTE=TH3_L33T;34287871]I found this image [img_thumb]http://puu.sh/dOBL[/img_thumb] I know it is for website design but what I like is that thing on the top right is there anything like that for visual studio? I could of sworn I have seen some pictures of it in an older thread but can't remember where, would help me a ton![/QUOTE]
I don't use visual studio myself but I've heard it said that MetalScroll is the visual studio equivalent for the code minimap feature in Sublime Text.
[url=http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef]Productivity Power Tools[/url] also has that type of a scrollbar.
RockScroll only works on 2005 and 2008 apparently, you must get the adding that trobmaister12 just linked to.
It crashed VS the first time it opened, now it seems to be working, however I disabled everything cept the mapping scrollbar.
[QUOTE=Smashmaster;34287105]God, C programmers are weird.
[code]
public static String toBinary(int i)
{
String out = "";
for (int b=0; b<32; b++)
{
if ((i & (1<<b)) == 0) out += '0';
else out += '1';
}
return out;
}
[/code]
EDIT: Oh, so it has to recurse? I should probably read before I code.[/QUOTE]
god C# programmers are weird
[img]http://i.imgur.com/ENBoY.png[/img]
So I have to make a program which uses MySQL,
You input into the program your login and password, it needs to check if that user exists in a MySQL database.
Anyone got any pointers on how to do this safely?
[QUOTE=marcin1337;34291535]So I have to make a program which uses MySQL,
You input into the program your login and password, it needs to check if that user exists in a MySQL database.
Anyone got any pointers on how to do this safely?[/QUOTE]
Minimum security would be store hashes instead of passwords.
You can also read up on salting, wich is a commonly used technique to improve the security of hashed passwords.
[QUOTE=Lord Ned;34287856]I'm looking to render objects with multiple sub-meshes.
Should I create a single vertex-array for the model, and then just store multiple index-lists for the sub-meshes? Or should I store a single vertex array and a single index-list and then just store the start/stop for the sub-mesh? (I could see this creating a problem if the index list wasn't carefully built)
I'm looking for more generalities of rendering 'models' that support multiple sub objects (with multiple sub-groups) than anything language specific.
I just don't get how complicated rendering works. :v:[/QUOTE]
I'm no expert but any of those things work. (Sub) models are really just a convention in your code, when it comes down to it, you're sending a command to draw a range of data. If it's convenient to put the whole thing in 1 vertex buffer and 1 index buffer, then go for it. If you're asking whether you can render an entire model of sub models in one go, then not really. You're almost definitely going to need to change something between draw calls otherwise they may as well be one model.
[QUOTE=Philly c;34292722]I'm no expert but any of those things work. (Sub) models are really just a convention in your code, when it comes down to it, you're sending a command to draw a range of data. If it's convenient to put the whole thing in 1 vertex buffer and 1 index buffer, then go for it. If you're asking whether you can render an entire model of sub models in one go, then not really. You're almost definitely going to need to change something between draw calls otherwise they may as well be one model.[/QUOTE]
Well my current theory is this:
Each object in 3ds Max exports as an individual object to the SMD file format. This object counts as a 'bone', so the mesh can be keyframe-moved and you don't need to spend your time making a bone, rigging it and animating the bone. This is just a uh 'feature' of the SMD format I guess, so it stays. I think it'd be more work to find a way to merge all of the meshes anyways.
Then within each object, each texture gets exported as a different sub-mesh (the object id stays the same, but the material on the triangle changes). Because of this each object can have sub-meshes. The theory in the end is that you'll draw a model, and lookup it's material, draw the sub-mesh, etc.
I don't know if the final vertex count would be drastically different from storing individual vertex buffers - I imagine most of the time a vertex comes to a point where it switches texture it's probably got a different normal anyways so they're really two vertexes (that just happen to overlap).
At this point it's easier to store an individual vertex list per sub-mesh, because that's how I read the SMD's. I guess I'll move forward with that and see how that goes.
[QUOTE=Tamschi;34292474]Minimum security would be store hashes instead of passwords.
You can also read up on salting, wich is a commonly used technique to improve the security of hashed passwords.[/QUOTE]
How safe would it be if I did it like this;
in C#
Client connects to SQLDatabase;
Using SQLDatabase;
Select login,password,( information about client ,IMPORTANT and private ) from Register
where login = sLogin and password = sPassword;
if recieve( Empty set (0.00 sec) )
Please Retry
else
it will use the info recieved
[QUOTE=marcin1337;34293890]How safe would it be if I did it like this;
in C#
Client connects to SQLDatabase;
Using SQLDatabase;
Select login,password,( information about client ,IMPORTANT and private ) from Register
where login = sLogin and password = sPassword;
if recieve( Empty set (0.00 sec) )
Please Retry
else
it will use the info recieved[/QUOTE]
That works for the login (if sPassword is the hash).
If you want to protect the stored data, you can encrypt it with a key that is unique for every user and can't be derived from any information in the database.
This is used in the industry to prodect stored data against employees and can be used to secure data where the database can be accessed by SQL.
Encryption also helps with SQL injection and other attacks where the database is queried. (Sony didn't use encryption for most data, so passwords and personal data were immediately available to the hackers once they knew about the exploit and the table names.)
Make sure your whole authentication system runs through SSL. Without a secure transmission line, you can't do any real authentication because you can't trust that your Javascript has made it to the client without interception.
Make sure you only store/transmit passwords as [i]salted[/i] hashes. An unsalted hash is as good as the password itself. If you use unsalted hashes, an attacker can grab the hash and use it in any other site which uses unsalted hashes without modification.
Is anyone here interested in making some graphics for the game I'm working on?
It's a version of an old viking game called [URL="http://en.wikipedia.org/wiki/Hnefatafl"]Hnefatafl[/URL].
Something like this, but from a top-down perspective:
[B](Not my game)[/B]
[IMG]http://img.squakenet.com/snapshot/4923/8588-KingsTableTheLegendofRagnarok.jpg[/IMG]
Resources
A blank stone tile
One tile called the throne. The kings starting position.
A corner tile which the "King" is trying to get to.
A tile to mark the starting positions of whites pieces.
A tile to mark blacks starting position
A black piece
A white piece
Whites king piece
Currently I just use some simple grey tiles and Fleur-de-li's in different colors for the pieces :(
[QUOTE=marcin1337;34291535]So I have to make a program which uses MySQL,
You input into the program your login and password, it needs to check if that user exists in a MySQL database.
Anyone got any pointers on how to do this safely?[/QUOTE]
If you do it like this, you can't release it to the public, the MySQL database login information would be accessable to everybody.
Hey guys, I'm writing a piece of code in the Processing thing that runs on Java that holds down certain letter on the keyboard using the "Robot" class. The issue I am having is that, while the keys can get pressed, and held down, the keyRelease function DOES NOT WORK, it just causes the button to be held down. I've searched online and cannot find help. This is the last piece of a fairly exciting project so I'd like it working. Here is my code that isn't working:
void draw()
{
while (mainSerial.available() > 0)
{
int byteData = mainSerial.read();
//ADD CONTROL COOOOODE
//println("RUNNING");
/*if(byteData == 127)
{
println("A has been Pressed!");
}*/
//println(byteData);
String stringConvert = binary(byteData,8);
//println(stringConvert);
if(stringConvert.charAt(0) == '0')
{
controller.keyPress(KeyEvent.VK_Z);
//println("BOOBEES");
}
else
{
controller.keyRelease(KeyEvent.VK_Z);
}
Thanks guys
[QUOTE=ROBO_DONUT;34295937]Make sure you only store/transmit passwords as [i]salted[/i] hashes. An unsalted hash is as good as the password itself.[/QUOTE]
So is a salted hash, if that's what you're transmitting for authentication purposes. The point of hashing is that an attacker who steals a copy of the database can't learn the secret string that he must send as part of a login, because he can't reverse the hash function. If your site expects the user to send the hash (salted or not) rather than the real password, the attacker [i]does[/i] know that, and can send it.
[i]Store[/i] salted hashes in the database. [i]Transmit[/i] actual passwords (protected by SSL) over the network, to be hashed on the server and then compared against the stored value.
You can hash a hash, though, so you could do challenge-response auth without ever transmitting the plaintext password, which was sort of my point. i.e. you store the salted hash of the password in the database, send the client a unique per-session salt, have the client compute the password hash with the static site-specific salt, then again with the challenge per-session salt, and send that back to auth. No plaintext in the database, no plaintext transmitted, and an intercepted hash wouldn't be useful because it's tied to that one session.
The weak link, then, becomes the client-side Javascript, which could be intercepted/modified without SSL. And if you're using SSL, plaintext isn't much of a concern anyway.
So I don't really know what my point is. I'd probably just do it anyway and layer security on top of security because I'm irrational.
What's a clear way of removing multiple elements in an array?
For a school assignment I have to make a class that holds an array of integers, and add methods that add to it, remove etc. Kinda like an ArrayList. The problem, however, is they want me to make a removeAll(int val) method that removes all occurrences of val from the list. For example, removeAll(4) would change
{1, 2, 4, 6, 3, 4, 4, 6, 5, 6, 4} to
{1, 2, 6, 3, 6, 5, 6, 0, 0, 0, 0}.
For my regular remove() method, I'm using Apache Common's Lang ArrayUtils class to remove the element. Removing all elements with it doesn't work fully, for some reason. My current plan of attack is to find out how many times val appears in the array, and then call ArrayUtils.remove() that many times. But it gives me weird results, for instance shrinking the array. Any other way to attack this? I can't use ArrayList supposedly, and I doubt they'll check if I am or not, but it would be nice to figure out how to do this the way they want me to.
Just bought two books, C# 4.0 Pocket Reference and SQL in 10 Minutes.
[QUOTE=Blueridge;34301779]What's a clear way of removing multiple elements in an array?
For a school assignment I have to make a class that holds an array of integers, and add methods that add to it, remove etc. Kinda like an ArrayList. The problem, however, is they want me to make a removeAll(int val) method that removes all occurrences of val from the list. For example, removeAll(4) would change
{1, 2, 4, 6, 3, 4, 4, 6, 5, 6, 4} to
{1, 2, 6, 3, 6, 5, 6, 0, 0, 0, 0}.
For my regular remove() method, I'm using Apache Common's Lang ArrayUtils class to remove the element. Removing all elements with it doesn't work fully, for some reason. My current plan of attack is to find out how many times val appears in the array, and then call ArrayUtils.remove() that many times. But it gives me weird results, for instance shrinking the array. Any other way to attack this? I can't use ArrayList supposedly, and I doubt they'll check if I am or not, but it would be nice to figure out how to do this the way they want me to.[/QUOTE]
Do a loop, remove all the values that you need to. However are you sure you're supposed to turn them into 0's? What if one of your values was a 0.
Anyways, after you remove the values, you could sort it. [URL="http://rosettacode.org/wiki/Sorting_algorithms/Quicksort"]QuickSort [/URL]is a nice one ;)
[QUOTE=Topgamer7;34288311]RockScroll only works on 2005 and 2008 apparently, you must get the adding that trobmaister12 just linked to.
It crashed VS the first time it opened, now it seems to be working, however I disabled everything cept the mapping scrollbar.[/QUOTE]
I ended up disabling half the stuff... as much as I like the new Document Well 2010 Plus tabs, it was a bit buggy on my system so I reverted to the old tabs.
Quick Find/Triple Click are amazingly useful though. And I set the scroll bar not to map mode, but to paint over the scrollbar with changes/caret location/find results/etc.
Thanks for the tips guys, I'm going to be in charge of making a megaupload type software for clients to check their status/ upload files.
Need all the security I can get!
I have like 4 months to do this though :D
[QUOTE=ROBO_DONUT;34300329]You can hash a hash, though, so you could do challenge-response auth without ever transmitting the plaintext password, which was sort of my point. i.e. you store the salted hash of the password in the database, send the client a unique per-session salt, have the client compute the password hash with the static site-specific salt, then again with the challenge per-session salt, and send that back to auth. No plaintext in the database, no plaintext transmitted, and an intercepted hash wouldn't be useful because it's tied to that one session.
The weak link, then, becomes the client-side Javascript, which could be intercepted/modified without SSL. And if you're using SSL, plaintext isn't much of a concern anyway.
So I don't really know what my point is. I'd probably just do it anyway and layer security on top of security because I'm irrational.[/QUOTE]
Wuala probably hashes passwords twice, at least that's the sanest approach for clientside symmetric encryption.
Helps with plausible deniability too :v:
What is so funny about my post :D?
[QUOTE=marcin1337;34304978]What is so funny about my post :D?[/QUOTE]
have you been living under a rock
Sorry, you need to Log In to post a reply to this thread.