• 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

maeh2k

Member
Code:
void gcd_lcm(int factor1, int factor2, int *gcd, int *lcm)
{
	*gcd = factor1 % factor2;
	if (gcd > 0)
	{
		gcd_lcm(factor1 = factor2, factor2 = *gcd, gcd, lcm);
	}
}

Before we get into the code, lets look into the algorithm. How exactly do you calculate the gcd? the lcm?

Lets look at what your algorithm does with gcd(3,6), gcd(6,3), and gcd(6, 4)

gcd(6,3)
1) *gcd = 0
2) !(0 > 0) -> done. (Well, that's not right)

gcd(3,6):
1) *gcd = 3
2) 3 > 0
3) gcd(6,3) => *gcd = 0

gcd(6,4)
1) *gcd = 2
2) 2 > 0
3) gcd(4,2)
4) *gcd = 0
5) !(0 > 0) => *gcd = 0
 

diaspora

Member
Before we get into the code, lets look into the algorithm. How exactly do you calculate the gcd? the lcm?

Lets look at what your algorithm does with gcd(3,6), gcd(6,3), and gcd(6, 4)

gcd(6,3)
1) *gcd = 0
2) !(0 > 0) -> done. (Well, that's not right)

gcd(3,6):
1) *gcd = 3
2) 3 > 0
3) gcd(6,3) => *gcd = 0

gcd(6,4)
1) *gcd = 2
2) 2 > 0
3) gcd(4,2)
4) *gcd = 0
5) !(0 > 0) => *gcd = 0

Example:

97 % 13 = 6
13 % 6 = 1
6 % 1 = 0

The GCD ought to be 1. I got it to work, but the main problem is that I can't have validation checks to reject floats using integer scanf.
 

Minamu

Member
Some friends and I have made a game in Visual Studio with C#/XNA. All that is left is to make an installer somehow. How does one go about making one of those? Granted, there's the publish function that creates some kind of installer that downloads the necessary files but is there another way that won't require an internet connection?
 

Fjolle

Member
Some friends and I have made a game in Visual Studio with C#/XNA. All that is left is to make an installer somehow. How does one go about making one of those? Granted, there's the publish function that creates some kind of installer that downloads the necessary files but is there another way that won't require an internet connection?

I think that WiX fits your requirements. But it's a bit confusing to get into :)
 

Minamu

Member
I think that WiX fits your requirements. But it's a bit confusing to get into :)
So perhaps the publish function is the way to go? It looks rather amateurish though and you can't really pick your installation path without some hassle. It looks bad imho :(
 

Thanks for the links. Unfortunately the first doesn't operate in the market that I need to and the other is a paid service (a very expensive one at that).

The problem was that the "Last Trade Date" of the Yahoo feed was returning a day from a few days ago, but if you looked at the historical data you'd see that the last day with any volume was over a week prior. I don't think the data from the feed was wrong, but I don't really have any explanation as to why the trade date would change with no volume being done.

Ended up grabbing a CSV of the historical data on Yahoo, finding the last day with a volume > 0, and using that day. I feel dirty.
 
Is there an AppleScript or something that I can hide certain files by their extension in a folder? I want to be able to toggle the files visibility while keeping other files of different extension visibility intact.
 
I find it totally worthwhile as just by using the examples on their site and adapting them, I was able to offload 90% of the CSS and Javascript work (for dropdowns or carousels) onto bootstrap. Moreover, from version 3 onwards, it is made for mobile too.

I agree, it's pretty great for easily getting a really nice looking site out there. I don't have great design sense, but without a lot of effort I can get a Bootstrapped site working that looks pretty nice (if somewhat generic). This lets me focus more of my time on stuff that I'm more interested in.

I've seen a lot of pushback from people I've worked with that it's too much trouble for what they'd use it for, but the grid system, helpers and js provide a decent enough framework for basic functionality implemented in as good a way as I'd probably be able to come up with.

The time saved is invaluable.
 

Magni

Member
This article needs to be required reading for anyone who will ever have to design anything that deals with peoples' names.

My friend will be spending 30+ hours in a shitty seat because American won't let her check in online since her last name is longer than what the textbox allows for. Shitty design, un-excusable from such a large company that deals with customers worldwide.

Her last name is 26 characters long for those wondering (Portuguese naming conventions make for rather long names by American standards).
 

usea

Member
I've seen a lot of pushback from people I've worked with that it's too much trouble for what they'd use it for, but the grid system, helpers and js provide a decent enough framework for basic functionality implemented in as good a way as I'd probably be able to come up with.

The time saved is invaluable.
There are a bunch of other options, many of which are more minimal css frameworks. Skeleton, Susy, Foundation, etc

http://www.webomelette.com/free-responsive-drupal-themes-css-frameworks
http://designinstruct.com/roundups/html5-frameworks/
 

John_B

Member
I want to update my database with some live sports scores from an api. I curl the json, compare it to my data, and update if it's not the same (there is no timestamp data in the json).

Questions:
1) Should the curl+compare process be run at a synchronized interval? Or would individual intervals be sufficient?
2) Should the update process be handled in a way that it would failsafe against two updates firing at the exact same time?
 
I'm finding it so hard to stay focused on my personal project. Actually, it's hard to focus at work, but not as hard as it is when I'm dedicating my free time to a project. It feels like such a promising idea, but it's so hard to stay motivated. Half the reason is that I'm teaching myself new stuff while I do it and it's really hard to see progress.

In the past month I didn't accomplish much. I found that my approach to security was hamfisted at best, consisting solely of a request interceptor that checked for a currently valid session. I didn't even have the ability to keep users logged in. So I decided to implement Spring Security 3.2.0.RC1 since I felt like 3.2 would probably be released soon (it was 3 days ago!). But I ran in to huge problems because my previous implementations of Spring had used a lot of XML based config mixed with the annotation based config. I basically decided to start from the ground up, redid the project, and switched to Maven from Ant. That had its own headaches since I had never used Maven, but I finally got it up and running, got all of the configuration switched to Java Based rather than XML based, and implemented Spring Security successfully.

I feel like I am finally at the point where I can continue making larger gains in progress, but I'm fighting with jQuery and javascript because I haven't used either extensively, or at all in the past two years so I forget a lot. Not a huge deal as they are easy to pick up. I am hoping that after the holidays are over I'll be back on track.

Still though, any tips for focusing on your side projects? I have a great concept and I want to stay motivated because I feel like someone is going to beat me to the punch if I don't.
 
Still though, any tips for focusing on your side projects? I have a great concept and I want to stay motivated because I feel like someone is going to beat me to the punch if I don't.

Store them on some visible place, like Desktop and once every while you are drunk look at that folder and swear that you are going to finish it someday.
 

Kansoku

Member
I need some help on an Android app I'm making.
I need to have 3 tabs in an activity that changes a TableLayout, but I'm not sure how to do it.
If I set the onClickListener for the tabs to be a method that checks which tab was clicked and then clear the TableLayout and re-populate it, would that work?

EDIT: Also forgot something. Is there a way to change the number of tabs depending on information stored in a database (and hide it in case it ends up with only one tab)?
 
I just finished my programming class and I'm wondering how to get the thing we used.

It was something called Putty.
I want it on my computer at home so I can mess around with programs. How can I get something like this?
 

maeh2k

Member
I logged into the network at school.

I'm sure they will delete my file soon though since I'm not a programming major.

When that happens, what do I log into?

Exactly what kind of programming do you want to do? What programming language are you learning? And how do you use putty at school?
 

pax217

Member
Sorry to hi-jack thread, but is there a networking one? I haven't been able to find it, but I've got quite the conundrum here and thought I'd ask GAF before I went out and started buying new stuff.
 

Tamanon

Banned
Sorry to hi-jack thread, but is there a networking one? I haven't been able to find it, but I've got quite the conundrum here and thought I'd ask GAF before I went out and started buying new stuff.

General tech support thread might be a good idea for that in Off Topic. I know there are some networking guys there.

My knowledge in it is purely theoretical thus far!
 

fader

Member
Alright, so I am starting with my programming electives and the entry class teaches Pascal. Anything I need to know before going in?
 

GabDX

Banned
Is Fortran worth learning? I already know Python and C++. Is the language still popular in physics and engineering?
 
Alright, so I am starting with my programming electives and the entry class teaches Pascal. Anything I need to know before going in?

Any idea what the curriculum is? Probably worth installing the compiler and learning some of the basics (e.g., displaying text, simple mathematical operations).

Is Fortran worth learning? I already know Python and C++. Is the language still popular in physics and engineering?

As far as I know Fortran is only seen in legacy systems where the effort and expense associated with a software rewrite is far too huge. Whenever I hear about coding in physics/engineering it's C/C++, python and matlab. Still, it's always worth learning stuff if you want to, regardless of the practical applications.
 

GabDX

Banned
Any idea what the curriculum is? Probably worth installing the compiler and learning some of the basics (e.g., displaying text, simple mathematical operations).



As far as I know Fortran is only seen in legacy systems where the effort and expense associated with a software rewrite is far too huge. Whenever I hear about coding in physics/engineering it's C/C++, python and matlab. Still, it's always worth learning stuff if you want to, regardless of the practical applications.

I see plenty of questions about Fortran on physicsforum.com but I have yet to meet anyone using it in my university. Most people seem to use C or (shudders) Matlab.

Its array operations seem very convenient but everything else is so awkward...
 

Tristam

Member
Back to working with Python after nearly a year of not touching it. I want to love it more than Perl, but (strange as this may sound) I find Perl's behavior much more predictable! I'm warming up with some basic coding exercises on pythonchallenge.com; below is a simple string decoding script:

Code:
# http://www.pythonchallenge.com/pc/def/map.html
string="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
alphabet=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
hash={}
i=0
j=0
for letter in alphabet:
	if len(alphabet)>(i+2):
		hash[letter]=alphabet[i+2]
	else:
		hash[letter]=alphabet[j]
		j+=1
	i+=1
for k,v in hash.iteritems():
	string=string.replace(k,v)
print string

I still can't figure out why the hell I end up just with a's and b's for my decoded string. When I print my hash, everything is correct; when I manually replace things, the decoding works. Why is the last for loop over the hash failing? I'm at my wits' end over something that ought to be ridiculously simple.

EDIT: Scratch this, I don't think there's anything wrong with Python; I think the puzzle's slightly more clever than I initially credited it.
EDIT: Scratch again, it's not that it's particularly clever--it's just that I wasn't quite thinking through the ramifications of calling the replace method on the string over and over...
 

Lathentar

Looking for Pants
You're just replacing letters in the string with letters you've already replaced. You should loop over the characters in string and replace them one at a time.
 
Hey guys, just want to see what's the best algorithm book so I can get a head start for my design and analysis of algorithms class. Just want to confirm, this is the must get Algorithms books, right? The one by Thomas H. Cormen:http://www.amazon.com/dp/0262033844/?tag=neogaf0e-20
I got Segwick's intro to algorithms in the summer since I wanted something for data structures and only read probably a fourth of the book. Maybe I should still use it? I'm also looking into The Algorithm Design Manual by Steven S Skiena.
 

Massa

Member
Hey guys, just want to see what's the best algorithm book so I can get a head start for my design and analysis of algorithms class. Just want to confirm, this is the must get Algorithms books, right? The one by Thomas H. Cormen:http://www.amazon.com/dp/0262033844/?tag=neogaf0e-20
I got Segwick's intro to algorithms in the summer since I wanted something for data structures and only read probably a fourth of the book. Maybe I should still use it? I'm also looking into The Algorithm Design Manual by Steven S Skiena.

I used Cormen, it's great.
 

maeh2k

Member
Hey guys, just want to see what's the best algorithm book so I can get a head start for my design and analysis of algorithms class. Just want to confirm, this is the must get Algorithms books, right? The one by Thomas H. Cormen:http://www.amazon.com/dp/0262033844/?tag=neogaf0e-20
I got Segwick's intro to algorithms in the summer since I wanted something for data structures and only read probably a fourth of the book. Maybe I should still use it? I'm also looking into The Algorithm Design Manual by Steven S Skiena.

Cormen's the best. But don't overdo it with getting a head start. You'll probably be fine just following the lecture. And since you already have an algorithm book, I'd be surprised if you really needed it at all.
I didn't need (or use) it at all for my algorithm classes, but it's nice t have as a reference when you want to look something up after the class.
 
I used Cormen, it's great.

Cormen's the best. But don't overdo it with getting a head start. You'll probably be fine just following the lecture. And since you already have an algorithm book, I'd be surprised if you really needed it at all.
I didn't need (or use) it at all for my algorithm classes, but it's nice t have as a reference when you want to look something up after the class.
Thanks for the input guys! Yeah, I probably won't need it but it seems like a good reference book to have around.
 
Does it have to be .NET? If you're willing to use a command line utility for it, wkhtmltopodf works great. I actually had to use it just last week.

Appreciate it, but yes unfortunately. We're thinking of just building a PHP web service for all our PSD PDF designs since there are some decent options we're already using for that side of the business.

Prince is amazing, but at a steep price.
 
Does anyone have any experience programming in R? Is it hard or pretty easy to get a hang of?

Also, is making GUIs in VBA really easy? I need to know it for modeling but it seems pretty straight forward for it's uses, you just want an easy way for people to enter their assumptions and then just use those variables in your calculations... Is there something I'm missing or is it really that easy?

Also, is there a way to learn MATLAB without the crazy costs for a subscription? Seems frustrating that there seems to be no way to learn it outside of college.
 
Figured this might be the best place to ask this.

Needing to setup a security system of sorts in my apartment. I'm going to get a sensor for the door/windows which trips an alarm, but I'm ideally wanting something to send an email and/or text to my phone so I can access a camera I'll be installing to see if it was a false alarm.

Would I need to use one of those small microprocessor boards to do this? I'd ideally like to have it standalone so it doesn't need to use the computer to send the message(s) to me.
 

smiggyRT

Member
Figured this might be the best place to ask this.

Needing to setup a security system of sorts in my apartment. I'm going to get a sensor for the door/windows which trips an alarm, but I'm ideally wanting something to send an email and/or text to my phone so I can access a camera I'll be installing to see if it was a false alarm.

Would I need to use one of those small microprocessor boards to do this? I'd ideally like to have it standalone so it doesn't need to use the computer to send the message(s) to me.

Wonder if the raspberry pi would be suitable for something like this, might be worth having a look around.
 

GabDX

Banned
Does anyone have any experience programming in R? Is it hard or pretty easy to get a hang of?

Also, is making GUIs in VBA really easy? I need to know it for modeling but it seems pretty straight forward for it's uses, you just want an easy way for people to enter their assumptions and then just use those variables in your calculations... Is there something I'm missing or is it really that easy?

Also, is there a way to learn MATLAB without the crazy costs for a subscription? Seems frustrating that there seems to be no way to learn it outside of college.

I did use R for a while. It was just for simple data analysis with little programming. I thought it was easy for the most part but almost everyone I talked to had never heard of it so I switched to Python.

As for Matlab, you can try Octave. It's designed to be a free clone of Matlab. It probably doesn't have all the toolboxes Matlab has but the core of the language is the same.
 

Rur0ni

Member
Any kernel/driver developers for Windows here? I'm interesting in learning more about this for possible future projects.
 
Top Bottom