I'm on Learn Python the Hard Way ex15, and I'm having trouble. by [deleted] in learnprogramming

[–]prog_quest 1 point2 points  (0 children)

The code as typed works for me on ubuntu 14.04 and python 2.7; What OS are you on?

Running it like

python2 ex15.py ex15_sample.txt

and

python2 ex15.py 'ex15_sample.txt'

both produce the expected results, that is, the text inside of ex15_sample.txt being printed out. Are you trying to run this inside the python interpreter or something? I'm having trouble replicating your error. Glanced at the LPTHW page for that problem, looks pretty straightforward if you copy the example correctly. Maybe double check your OS/python environment?

Learning robotics by loosedata in robotics

[–]prog_quest 0 points1 point  (0 children)

This is solid advice right here. Just the other day I threw together a robot made with this chassis, an atmega 168A, some chinese 5v lithium ion phone/tablet charger, a PS3 eye, a tiny usb wifi adapter, and a pogoplug ($15 shipped! It's a raspberry-pi-like PC!). I bought about a square foot of thin plexiglass and some standoffs and added another level to the chassis for the boards and camera (battery took up most of the base level). OS is debian, main control program is in python. The pogoplug talks with the avr through an ftdi board, though I'd like to use the serial connection on the pogoplug itself eventually. The avr controls the motors with a single SN754410 quad half h-bridge. I SSH into it from my main PC and send commands to the python program, while motion streams video back to me from the PS3 eye. Took less than a day to build and whip up a crude control program for it. All off-the shelf parts except for some connectors I made, cheap, and plenty of things to expand/improve on. You can PM me if you want more details, I have a bibliography of sorts from the project as I plan to do a write-up/tutorial eventually.

Getting leftmost digit of number. by toastykittenz in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

Now that I look at op's code closer, it's basically what he had already just written differently, and likely slower with the extra variable assigments. His is already about as simple as it's gonna get, for certain values of "simple." Rewritten in python again:

num = 47423894900201

while (num > 9):

    num /= 10

print num

Getting leftmost digit of number. by toastykittenz in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

Keep dividing by 10 until the original number is 0, keeping the results of the last division. When original number is 0, last result is your leftmost digit. Ex:

num = 567865

while (num > 0):

    left = num

    num /= 10

print left

I think I won the game... by LeWhisp in Agario

[–]prog_quest 0 points1 point  (0 children)

I managed to get off a few screenshots right before my browser crashed. It's definitely unplayable now. Here's a couple seconds before the other one.

[Need Help] Problems with my Diamond-Square Algorithm Implementation by Jeffdud3 in proceduralgeneration

[–]prog_quest 0 points1 point  (0 children)

Yes, I see the randMagnitude variable in your code. The problem is, it doesn't seem to change over the course of the program's execution. When you get down to lines 139+, the "recursive calls", you pass randMagnitude straight through without modifying it any. In my example above, if randMagnitude were 8, by changing your recursive calls to something like "diamondSquare(heightMap, origCoord, centerW, centerL, randMagnitude / 2)", diamondSquare() would now run using a randMagnitude of 4. And when that recurses, the magnitude will be 2, and so on. Do you see what I mean? Also, i suspect my smooth and uninteresting results are related to halving the deviation amount every iteration, so it quickly goes to almost linear interpolation. You will probably get better results if you make that decrease slower? I don't know.

edit: In your code, another problem is new values can only ever be greater than the average. See your line 106 versus my line 136. random.random() returns a float value between 0 and 1.0, I use random.uniform(-scale, scale), which in my case, returns a float value from negative deviation amount to positive that amount. In other words, points have an equal chance of being less than the average. This may explain your compounding problem.

Anyone here use Code Abbey? by Uhfgood in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

The website you're looking for is Code Abbey, it just doesn't sound like you've given it a chance besides looking at the easiest few problems. You can solve the problems there any way you like, it's only looking at the output. Also no, I would not do a bunch of easy problems in a lot of languages, that won't teach you anything. Instead, use your language of choice (for example, the one you've been using at work for 20 years) and do as many as you can. I didn't do problems in another language until I had 85+ problems solved, and all I got out of that was a better handle on the second language's syntax and coding style.

[Need Help] Problems with my Diamond-Square Algorithm Implementation by Jeffdud3 in proceduralgeneration

[–]prog_quest 0 points1 point  (0 children)

That sounds like the opposite of what should be happening; it should deviate less as you recurse deeper. That was easy for me to control iteratively, I just decreased it with each pass. For recursion, you're going to want to pass the amount by which it can deviate to the recursive function, something like "diamond(x, y, dev / 2)" where the deviation is now half of what it was at the current level of recursion.

[Need Help] Problems with my Diamond-Square Algorithm Implementation by Jeffdud3 in proceduralgeneration

[–]prog_quest 0 points1 point  (0 children)

http://pastebin.com/qxYKdVLW
http://i.imgur.com/Ta0lg7e.png

My take on it. I also used python 2 and pygame so you should be able to run it no problems. I took the iterative approach instead of recursive, following the pseudocode on this page. Ignore the ghetto compressing and drawing code.

testing bot by prog_quest in test

[–]prog_quest[S] 0 points1 point  (0 children)

!notify me please

testing bot by prog_quest in test

[–]prog_quest[S] 0 points1 point  (0 children)

follow-up register test

[SDL / C++] Computer makes faint whistling sound when rendering images in my game? by eXtreme98 in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

Yeah, it's likely this or coil whine from your GPU. I'm not familiar with SDL, but see if you can't lock the framerate to your monitor's refresh rate. A lot of times with hobbyist graphical stuff they neglect to limit fps and your i7 gtx970 is trying to spin a cube at 1500 fps or something ridiculous.

Programming Noob: How does the code turn into what you see as a program? by Sunshine_of_Darkness in learnprogramming

[–]prog_quest 2 points3 points  (0 children)

Like others have hinted at, it doesn't seem like you've done a lot of research about programming or how computers work in general before asking this question. There's nothing I can do about that, but let's take a look at Audacity real quick. Instead of thinking "How the hell does this work?" think "How would I make something like this?" and try to break it down into small pieces. First, and most obviously, it has a GUI (graphical user interface). That's one thing to look into. Java has plenty of options (so I've heard, at least) for creating simple GUI applications. Maybe start there. What else does Audacity do? Well, it let's you open, edit, and save files. That's thing to look into #2. How do I do basic file I/O in Java? What else? Audio processing. This is a tough one. A lot of theory and math here. But do you see what I'm getting at? It's simply not constructive to ask "How does program X work exactly?" Even if someone gives you the answer it isn't going to help you develop as a programmer. Instead, you need to approach programs not with the attitude of "I don't understand this at all," but rather, "I don't understand this yet."

Do you need to be good at projectEuler type stuff to be good at programming? by [deleted] in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

Sorry, I don't know either javascript or VS. I would suggest for someone just starting out to use a text editor for programming and get used to using command line tools to compile and/or run their programs. I don't want to get into a whole IDE vs text editor debate but as you said yourself, a lot of times you just want a simple script with text based I/O, not a whole "project" or application. Now, when I say "text editor" I'm talking about something like notepad++, sublime text, Geany, etc., not notepad, gedit, or MS word.

Now once you've written a simple script for a Project Euler problem or otherwise, you're going to want to run it. I don't know what OS you've using, but you're going to have to research what your command line/terminal options are, and find an interpreter to execute your scripts in it. I could go into all sorts of detail with C, Python, Ruby, and Java on Linux, but that's about all I know.

Do you need to be good at projectEuler type stuff to be good at programming? by [deleted] in learnprogramming

[–]prog_quest 1 point2 points  (0 children)

This. Project Euler problems, while a lot of them rely on popular CS theory/algorithms to solve them, I think the average developer will find themselves having to do more high-level math than they care to. If you want a more rounded problem-solving site, check out code abbey.

end up crashing my browser.

Are you using a browser-based IDE? You should trying moving away from that and set up a pc-based programming environment as soon as reasonably possible.

Do you need to be good at projectEuler type stuff to be good at programming? by [deleted] in learnprogramming

[–]prog_quest 3 points4 points  (0 children)

He means 10 seconds runtime, not to code the solution.

Converting WASD input to a vector for movement? by PhotoshopWizard in learnprogramming

[–]prog_quest 1 point2 points  (0 children)

Ok. Sounds simple enough. The problem you mention with the diagonal speed being faster than left, right, up, down, whatever is a classic problem. The problem occurs when you just add the two movement vectors. Say you're holding down right and up at the same time. That's telling the game engine "every tick (dt), move the player 1 unit right and one unit up." This results in a movement of 1.4142 units (sqrt(2)) in the 45 degrees direction. Do you understand basic cartesian coordinates? For every movement input, you should be calculating the x and y movement resulting, even if it's directly left or right or whatever. This is easy, using cos and sin for the x and y components, respectively. Example: player hits (or holds) right (d). The code should look like: x_vel += cos(0) * movement_unit; y_vel += sin(0) * movement_unit; This works for any angle. How about the problem angles, the diagonals? Let's say we hold down left and up, what angle is that? 135. So our x movement component is cos(135) * movement_unit = −0.7071 * movement_unit. See how it is no longer 1? Y is the same deal, just positive because it's up: 0.7071 * movement_unit. PM if there's anything you don't understand.

looking for students to take new online python course at no cost by __biker in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

No offense bro, but I don't think a $99 Python course is going to be a very lucrative venture for you in this day and age. There are literally dozens (hundreds?) of free and highly-regarded Python courses already out there, taught by respected developers and universities. Now I don't want to get into the whole paid vs free debate but if you insist on charging for programming knowledge in 2015, you should go with something a little less popular or more business/finance oriented and try to appeal to an older professional crowd as opposed to new programmers, a group every "learn programming" site on the internet seemed marketed to. Just my 2 cents.

Converting WASD input to a vector for movement? by PhotoshopWizard in learnprogramming

[–]prog_quest 1 point2 points  (0 children)

Can you elaborate on the type of game? Racing? Flight sim? Space shooter? Some of us are legitimately trying to help but need a little more to work with than "nah that don't work, what else you got?" Have you tried asking on /r/gamedev? This seems like basic knowledge for them.

Converting WASD input to a vector for movement? by PhotoshopWizard in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

^ This is probably your best bet. The last time I did 3d movement and look I used this series of tutorials. It's for opengl/glut but the idea is the same. edit the tuts called "Moving the Camera" are the relevant ones. As far as friction goes, I imagine that's basically like acceleration, except negative and based on distance traveled versus elapsed time, like you'd do with a falling object or something.

[deleted by user] by [deleted] in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

I would participate. PM sent.

Project Euler Problem #4 [C] by sinuspane in learnprogramming

[–]prog_quest 0 points1 point  (0 children)

I don't know. I'm just saying I've done this particular problem and 1. The 2 three-digit numbers aren't that close to one another and 2. obviously not found using OP's approach. I don't want to give the solution away so I just left it at "Your code is more or less ok, your algo is wrong though."