• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

NetMapel

Guilty White Male Mods Gave Me This Tag
About to start learning Classes now in Python on Codecademy. My body is ready, but is my mind ready ? I've been told to get ready to get my mind blown, haha.
 

Ryan_

Member
hey guys

I'm getting into web development, more specifically Ruby on Rails.
You think there might be something I can code that would benefit NeoGAF? Or any other niche. I don't wanna keep on building the nth blog/twitter/reddit-clone but preferrable something that people could actually use.
Maybe some clan/guild like page?

About to start learning Classes now in Python on Codecademy. My body is ready, but is my mind ready ? I've been told to get ready to get my mind blown, haha.

if you need any help, I'd be happy to explain it to you :)
 

Makai

Member
hey guys

I'm getting into web development, more specifically Ruby on Rails.
You think there might be something I can code that would benefit NeoGAF? Or any other niche. I don't wanna keep on building the nth blog/twitter/reddit-clone but preferrable something that people could actually use.
Maybe some clan/guild like page?
_____ quoted you notifier.
 
hey guys, I have a question.

We're getting into templates and iterators

I need to make an iterator of a RingBuffer. Basically the ringbuffer is an object that has an array of some size, and when you go through it and reach the end you simply loop back around to the front.

I'm confused on one part of an iterator, does it have access to the data members of the object it's iterating? For instance, I need to make it so when the iterator hits the end of the array it loops back around, but I can't do that without the "begin" and "end" functions of the actual RingBuffer object.

Thanks all

Also I know I made a post a while back about struggling with some stuff, but I actually got a co-op with a local company for the summer/fall semester with some pretty good pay I think, so I guess I'm not as bad as I thought XD
 

Majestad

Banned
So guys I have a basic program. Is like a text adventure game (in java) where you choose between two dialogue options and they take you to different places. Very basic since this is the first time I've tried programming.

Is there a way to, once I get to last part of the game, re-start it without having to run the code again?

Basically the game is something like this:

Code:
        _ R1 _
       /      \
    R2          R3
   /  \        /  \
 R4    R5    R6    R7
 /\    /\    /\    /\
E1 E2 E3 E4 E5 E6 E7 E8

So, when you are in the last room, say E1, how can I go back to R1? A simple solution would be appreciated, and assume I don't know any advanced java.
 

Ledbetter

Member
We've been working this week with Prolog on my AI class.

The language itself is kinda simple, but honestly, trying to come with a decent way to 'solve' something there messes up with my mind. I blame my procedural way of thinking :(

This made me realize how important is the choice of the programming paradigm by newcomers to programming and how, at least my university, treat this issue lightly, by letting teachers teach whatever they want, and not explaining why the students are learning that way.
 

Makai

Member
So guys I have a basic program. Is like a text adventure game (in java) where you choose between two dialogue options and they take you to different places. Very basic since this is the first time I've tried programming.

Is there a way to, once I get to last part of the game, re-start it without having to run the code again?

Basically the game is something like this:

Code:
        _ R1 _
       /      \
    R2          R3
   /  \        /  \
 R4    R5    R6    R7
 /\    /\    /\    /\
E1 E2 E3 E4 E5 E6 E7 E8

So, when you are in the last room, say E1, how can I go back to R1? A simple solution would be appreciated, and assume I don't know any advanced java.
You need to make a binary search tree. Traverse up to each parent node until you reach the start.

Another way would be to make a variable that stores the starting room and set the current room to the starting room.
 

JeTmAn81

Member
Why is it so hard to find database people who know how to create stored procedures. Are sprocs really that rare?

Stored procedures aren't hard. They're literally just regular SQL statements after a parameter list. I'd say if you don't know how to write a stored procedure you probably don't know SQL at all.
 

Zoe

Member
Stored procedures aren't hard. They're literally just regular SQL statements after a parameter list. I'd say if you don't know how to write a stored procedure you probably don't know SQL at all.

I guess SQL is just so accessible these days that most peopl in tech have written a select query or two, and that tricks them into thinking that they "know" SQL. Every person we've interviewed so far has the experience written on their resume, but nobody has come close to passing my test :(
 

JeTmAn81

Member
I guess SQL is just so accessible these days that most peopl in tech have written a select query or two, and that tricks them into thinking that they "know" SQL. Every person we've interviewed so far has the experience written on their resume, but nobody has come close to passing my test :(

The more complicated I find myself getting with a stored procedure, the more likely I am to do that thing in a regular programming language instead. I almost never use cursors, for instance. What kind of tasks are you asking them to do with their stored procedures?
 

Zoe

Member
The more complicated I find myself getting with a stored procedure, the more likely I am to do that thing in a regular programming language instead. I almost never use cursors, for instance. What kind of tasks are you asking them to do with their stored procedures?

That's the thing--there's only one task, and it's not even that difficult in my mind. It's just a simple select with joins that you'd imagine would feed into a report. The only trick I slipped in there was allowing for null parameters.

The other tasks had to do with text parsing, normalization, or aggregation. The aggregation one was the only one that had some degree of success with everyone.
 

Majestad

Banned
You need to make a binary search tree. Traverse up to each parent node until you reach the start.

Another way would be to make a variable that stores the starting room and set the current room to the starting room.

How would I do that if you don't mind explaining?
 

Makai

Member
How would I do that if you don't mind explaining?
Well it's hard to say since I don't know what your program looks like, but I can make some guesses.

You have a class named Room, which stores its name and references to neighboring rooms. You have a class named Game, which stores all of the rooms and the current room. Game has a field called currentRoom and a field called startRoom. To reset, set the currentRoom to the startRoom.
Code:
class Game
{
    List<Room> rooms = new List<Room>();
    Room startRoom = rooms[0];
    Room currentRoom = startRoom;

    public void setCurrentRoom(Room room)
    {
        currentRoom = room;
    }

    public void reset()
    {
        setCurrentRoom(startRoom);
    }
}

If you are a total beginner, you might want to run through a tutorial first

https://www.codecademy.com/learn/learn-java
 

Koren

Member
Is there a way to, once I get to last part of the game, re-start it without having to run the code again?
How do you know the state of the game? How the game know what to ask/do next?

Or is it a kinda stateless game, a giant calling tree, where functions are calling other functions, all functions corresponding to a nore in your even tree?

It's difficult to answer your question without knowing how you wrote your game, but yes, it's doable.
 

Ryan_

Member
That's what makes it an interesting and possibly useful project.

That being said, I don't see a way to do it that doesn't increase NeoGAF servers load. :/

Hm, does NeoGAF have an API one could use for that?

EDIT: nvm, you probably need to use Nokogiri for that
 
That's what makes it an interesting and possibly useful project.

That being said, I don't see a way to do it that doesn't increase NeoGAF servers load. :/

Yeah, you can't, but doing searches every ~5 minutes shouldn't too be too bad of a load... but then again it could be if thousands of peeps were using it all the time
 

Ryan_

Member
Yeah, you can't, but doing searches every ~5 minutes shouldn't too be too bad of a load... but then again it could be if thousands of peeps were using it all the time

But how would you start building something like that? Forgive me but I am still in my early stages :) I would love to make something GAF related tho.

Also, any other ideas or open source projects are always welcome
 

Koren

Member
Yeah, you can't, but doing searches every ~5 minutes shouldn't too be too bad of a load...
Depends on how you do a search...

For a given post in a given thread, loading a couple of pages and checing for possible replies is something (you can probably lower the load by using HTTP headers to know whether pages changed, too), but if without the list of the posts/threads you want to follow, you need to load all threads? Or use Neogaf search functions to get your recent posts (probably better, but still...)?

Do ToS allow this, btw?


Curiously enough, I had to grab a bunch of documentation files, but it was tooking me too much time. I've finally written the couple dozen lines in Python that perform a Google search, find the file in the results, then download it (with resume if the connexion is lost in the middle of a download).

Someone asked earlier why Python can be mind-blowing. I don't know, I'm not even a great fan of Python for large projects, but the standard library is insanely useful for menial tasks like this (and I'm pretty sure my solution is more complex than it should, and proper Google API is probably better than parsing the HTML result of a normal search)
 

ssharm02

Banned
I have two primitive arrays each containing a unique 4 digit number. if all the numbers are the same 2222 is printed, if they are different 0000 is printed. however if two numbers are same but in the wrong position 2211 would be printed. or if the numbers are just wrong it would be 2200 etc

having difficulty writing this with for loop. some help would be appreciated

Code:
    for (int i = 0; i < array1.length; i++) {
        for (int j = 0; j < array2.length; j++) {
            for (int k = 0; k < results.length; k++) {
            if (array1[i]==array2[j]){
                results[i] = 2;
                if (array1[i] != array2[j])
                    results[i] = 0;
                
                }
                
            }
    }
 

Somnid

Member
Depends on how you do a search...

For a given post in a given thread, loading a couple of pages and checing for possible replies is something (you can probably lower the load by using HTTP headers to know whether pages changed, too), but if without the list of the posts/threads you want to follow, you need to load all threads? Or use Neogaf search functions to get your recent posts (probably better, but still...)?

Do ToS allow this, btw?


Curiously enough, I had to grab a bunch of documentation files, but it was tooking me too much time. I've finally written the couple dozen lines in Python that perform a Google search, find the file in the results, then download it (with resume if the connexion is lost in the middle of a download).

Someone asked earlier why Python can be mind-blowing. I don't know, I'm not even a great fan of Python for large projects, but the standard library is insanely useful for menial tasks like this (and I'm pretty sure my solution is more complex than it should, and proper Google API is probably better than parsing the HTML result of a normal search)

Make an extension that picks up posts as your browse. Since it's a server based project you can essentially just crowdsource most of the database at no cost.
 

luoapp

Member
I have two primitive arrays each containing a unique 4 digit number. if all the numbers are the same 2222 is printed, if they are different 0000 is printed. however if two numbers are same but in the wrong position 2211 would be printed. or if the numbers are just wrong it would be 2200 etc

having difficulty writing this with for loop. some help would be appreciated

having difficulty understanding your problem
 

luoapp

Member
could this work?
Code:
for (int i = 0; i < userarray.length; i++) 
{
        results[i]=0;  
        for (int j = 0; j < cpuarray.length; j++) 
        {
            if (userarray[i]==cpuarray[j])
            {
                if (i==j) results[i] = 2;
                else results[i] = 1;
                break;
            }
        }
}
 

ssharm02

Banned
could this work?
Code:
for (int i = 0; i < userarray.length; i++) 
{
        results[i]=0;  
        for (int j = 0; j < cpuarray.length; j++) 
        {
            if (userarray[i]==cpuarray[j])
            {
                if (i==j) results[i] = 2;
                else results[i] = 1;
                break;
            }
        }
}

good code! makes sense but it keeps returning 0000s if i try 1234 and 4321



Nm problem on my end, working now!! Thnx a lot bro
 

Two Words

Member
I'm having trouble making a class iterable in Java. I have to do it for a project, and I've never really used iterators much. Basically, the project is an ArrayOfLists class. The class contains an array list of Element objects. I made Element a private static inner class of ArrayOfLists. Element contains a linked list and an int called lastIndex. The idea is that each element of the array list contains linked lists and the concatination of the linked lists is the data structure that we are making. The elements' lastIndex variable represents the index number of the last element in the linked list, but the number is correct as if all of the linked lists are concatinated.

I'm running into syntax errors and I'm not entirely sure the best way to do this generically.
 

JeTmAn81

Member
I'm having trouble making a class iterable in Java. I have to do it for a project, and I've never really used iterators much. Basically, the project is an ArrayOfLists class. The class contains an array list of Element objects. I made Element a private static inner class of ArrayOfLists. Element contains a linked list and an int called lastIndex. The idea is that each element of the array list contains linked lists and the concatination of the linked lists is the data structure that we are making. The elements' lastIndex variable represents the index number of the last element in the linked list, but the number is correct as if all of the linked lists are concatinated.

I'm running into syntax errors and I'm not entirely sure the best way to do this generically.

If your Element class is static, how can you instantiate it to add an Element to the array list? Also, be strict with your capitalization of class types and data structures when describing a problem like this since Element vs. element is a big difference.
 

Two Words

Member
Never mind, I figured it out. Ugh, I hate dealing with bugs that are largely syntax issues. I had the wrong idea. I was trying to iterate on the elements on the array list, when I should have been iterating on the concatenated linked list.

If your Element class is static, how can you instantiate it to add an Element to the array list? Also, be strict with your capitalization of class types and data structures when describing a problem like this since Element vs. element is a big difference.

It being a static class within my ArrayOfLists class doesn't mean I cannot instantiate it.
 

Two Words

Member
I'm no Java expert so I don't understand how that works. You don't mean a static variable rather than a static class, right?

Static member variables and inner static classes have differences. I think you're applying the logic to static member variables to static inner classes.
 
But how would you start building something like that? Forgive me but I am still in my early stages :) I would love to make something GAF related tho.

Also, any other ideas or open source projects are always welcome

Depends on how you do a search...

For a given post in a given thread, loading a couple of pages and checing for possible replies is something (you can probably lower the load by using HTTP headers to know whether pages changed, too), but if without the list of the posts/threads you want to follow, you need to load all threads? Or use Neogaf search functions to get your recent posts (probably better, but still...)?

Do ToS allow this, btw?


Curiously enough, I had to grab a bunch of documentation files, but it was tooking me too much time. I've finally written the couple dozen lines in Python that perform a Google search, find the file in the results, then download it (with resume if the connexion is lost in the middle of a download).

Someone asked earlier why Python can be mind-blowing. I don't know, I'm not even a great fan of Python for large projects, but the standard library is insanely useful for menial tasks like this (and I'm pretty sure my solution is more complex than it should, and proper Google API is probably better than parsing the HTML result of a normal search)

Make an extension that picks up posts as your browse. Since it's a server based project you can essentially just crowdsource most of the database at no cost.

To be honest I would just use the built-in GAF search (for unique user names just querying "quote username" (like "quote PetriP-TNT") is enough to get the replies) and check for changes against the previous search results. For more complex usernames (as in not technically complex, but say something like "search" or "library" or "mario" as an username doesn't really work) you will need to go through some other hoops though.
 

Somnid

Member
To be honest I would just use the built-in GAF search (for unique user names just querying "quote username" (like "quote PetriP-TNT") is enough to get the replies) and check for changes against the previous search results. For more complex usernames (as in not technically complex, but say something like "search" or "library" or "mario" as an username doesn't really work) you will need to go through some other hoops though.

NeoGaf Search sucks though, I mean it's even throttled to keep regular users from using it, so not only is it not performant enough, it's probably not appreciated if an automated service uses it.
 
NeoGaf Search sucks though, I mean it's even throttled to keep regular users from using it, so not only is it not performant enough, it's probably not appreciated if an automated service uses it.

Yeah, I forgot that @_Ryan wanted to make it for public consumption, not as an learning experience.
 

Two Words

Member
This is strange. I have to use an older version of g++ for a school assignment, and it is giving me issues. I have a to_string() pure virtual function in my abstract class and each of the subclasses implement it. It simply returns a string that the class builds out of info on the object. I am getting the following g++ error.

"‘to_string’ is not a member of ‘std’"

But why does that matter? It's my method. I'm not trying to call some already made method. I made the method. Why isn't the compiler simply using the method that I made? Do I have to use an ostringstream instead? I've never used it, so I'm trying to read into it.
 
This is strange. I have to use an older version of g++ for a school assignment, and it is giving me issues. I have a to_string() pure virtual function in my abstract class and each of the subclasses implement it. It simply returns a string that the class builds out of info on the object. I am getting the following g++ error.

"‘to_string’ is not a member of ‘std’"

But why does that matter? It's my method. I'm not trying to call some already made method. I made the method. Why isn't the compiler simply using the method that I made? Do I have to use an ostringstream instead? I've never used it, so I'm trying to read into it.

Without seeing the code, it's hard to say, but it looks like you're writing

Code:
std::to_string()

somewhere. Is this right?
 

Two Words

Member
Without seeing the code, it's hard to say, but it looks like you're writing

Code:
std::to_string()

somewhere. Is this right?
virtual std::string to_string() = 0;

This is in my abstract class, and all of the subclasses implement it. Is it not simply a method called "to_string() that will return a string of some kind?
 

Two Words

Member
Without seeing the code, it's hard to say, but it looks like you're writing

Code:
std::to_string()

somewhere. Is this right?

Wait wait wait, yes. I totally misconstrued own to_string() method with the std::to_string() line I used within it. I was wondering what was going on.

Edit:
Okay I've fixed it now. Sorry about that. I guess I just let myself get hung up on interpreting the error as if the compiler wasn't even trying to use my to_string method, and didn't realize it was complaining about a line within the to_string() method that actually used std::to_string().
 

Dreadr

Banned
I'm a freshman Computer Science student and never really programmed before. Oh boy, the first semester was a ride (together with proof-based / pure Mathematics, wth). So we started with a niche programming language and Matlab (for Linear Algebra) and now in the second semester we use mostly Java. I don't have problems switching the languages, syntax is relatively trivial, just leave the doc open and you're doing fine. Now the problem-solving is the tricky part. Especially if you have to learn that skill from scratch, along with analytical-thinking to prove some silly stuff.

We just had an assignment to program a trivial ray tracer with path-sampling. You would define vector calculation rules as well as a sphere and ray data structure, consisting of vectors, and creating a camera from where the rays are being shot.

You would then recursively implement the trace algorithm up to depth n, so you'd shoot n-rays at each pixel location, test if an intersection occurs, reflect the ray randomly and apply the recursion n-depth times. If you hit a light source, you would then calculate the color of the pixel of the first sphere + light intensities and color multipliers from the spheres down the recursion. If you don't reach a sphere with light emission, the pixel would get the color black (that's because ray tracing has that noise if you don't render it to extinction, respectively use some tricks).

It was a 10 hour hell to program that thing.

Ultimately I learned A LOT and it makes fun, too! It's like, applying the abstract mathematical concepts learned so far, with the difference, that they start to make sense this way, lol. Next step is to optimise and parallelize (and get the concurrency right) the program in the following months, since it only runs on one thread so far, and if you know raytracing, you know it's sloooooooow. Can't wait!
 

JeTmAn81

Member
NeoGaf Search sucks though, I mean it's even throttled to keep regular users from using it, so not only is it not performant enough, it's probably not appreciated if an automated service uses it.

Yeah I always just use Google for searching GAF, it's pretty effective
 

Mepsi

Member
Hi GAF,
Don't know if this is the right place to be asking this but hopefully you can help anyway.
I've been job searching for a while now and have had a fantastic opportunity as a PHP developer come up, the thing is, I don't really know any PHP. The company I'm working for know this and want to spend time training me up to scratch as they are impressed with my past programming experience.

I don't think it's fair though that I should be learning it solely on the job. I'm after some solid resources to learn as much as I can before I begin, I'm looking for any sort of recommended books and online resources that I can get the most out of, thanks =].
 

NotBacon

Member
Hi GAF,
Don't know if this is the right place to be asking this but hopefully you can help anyway.
I've been job searching for a while now and have had a fantastic opportunity as a PHP developer come up, the thing is, I don't really know any PHP. The company I'm working for know this and want to spend time training me up to scratch as they are impressed with my past programming experience.

I don't think it's fair though that I should be learning it solely on the job. I'm after some solid resources to learn as much as I can before I begin, I'm looking for any sort of recommended books and online resources that I can get the most out of, thanks =].

If you just want to get up to speed on syntax, https://learnxinyminutes.com/ is pretty nice.
 

zeemumu

Member
Can someone here walk me through how big O notation works? I understand that it's basically how long it would take the program to get though everything but how would you do something like showing that n is O(nlogn)?
 
Top Bottom