Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 10-12-2014, 05:21 AM   #26
daveT
S.A.G.E. Master
 
daveT's Avatar
 
Join Date: Jun 2005
Location: Why didn't I use Clojure instead?
Posts: 21,800
Re: Programming homework and newbie help thread

I do know why. I changed your raw_input() to input(). If you convert it back, you won't get the error.
daveT is offline   Reply With Quote
Old 10-12-2014, 05:29 AM   #27
pewpewpew
journeyman
 
Join Date: Dec 2013
Posts: 293
Re: Programming homework and newbie help thread

my hero Thanks for all the help
pewpewpew is offline   Reply With Quote
Old 10-12-2014, 05:45 AM   #28
daveT
S.A.G.E. Master
 
daveT's Avatar
 
Join Date: Jun 2005
Location: Why didn't I use Clojure instead?
Posts: 21,800
Re: Programming homework and newbie help thread

coolio. Just note that the newest has a slight change in it. I sort of messed up the ordering.
daveT is offline   Reply With Quote
Old 10-14-2014, 11:38 PM   #29
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

They just tossed a sample selection sort algorithm into this chapter about arrays. Think I'm having a panic attack trying to understand wtf is going on in this program.
Anais is offline   Reply With Quote
Old 10-21-2014, 03:15 PM   #30
tm33
newbie
 
Join Date: Aug 2012
Posts: 34
Re: Programming homework and newbie help thread

Hi, after 3 days of trying really hard, I decided that i need help. Let's have a cube and two points A[x1,y1,z1], B[x2,y2,z2]. I need to calculate the shorthest path between these two points. The path has to be on surface of the cube. If the two points are on the same side, then it is easy. I managed to write a code for situation when they are on the opposite sides. It is somehow working altough it has probably some flaws. But I just can't figure out, what to do when they are on adjacent sides. Obviously I tried using Pythagorean equation in a lot of different ways, but there was always some hole in my code. If you could please just give me some advice. Thank you
tm33 is offline   Reply With Quote
Old 10-21-2014, 04:39 PM   #31
e i pi
veteran
 
e i pi's Avatar
 
Join Date: Feb 2010
Location: ☃
Posts: 2,230
Re: Programming homework and newbie help thread

Can you solve it with pen & pencil? I guess the key insight for adjacent sides is that if you flatten out the sides it is just a normal shortest path problem. So if you have points (0,a,b) and (c,1,d) for a 1x1x1 cube you will have to travel over the (0,1,z) edge. So you get the distance from both points to the edge and add them and that is one side of the triangle. Then for the lines you drew to the edge, the distance between these two lines along the edge is another side of the triangle. Then you have enough info to use trig to get the angle from one point to another relative to the shared edge.

Coding this sounds like a pain in the ass. Sorry

edit: Just noticed you only wanted to calculate the distance not produce some equation to describe the path. In this case its just pythagorean with the two found sides.

Last edited by e i pi; 10-21-2014 at 04:51 PM. Reason: bla
e i pi is offline   Reply With Quote
Old 10-21-2014, 07:48 PM   #32
RoundTower
ɹǝʍoʇpunoɹ
 
RoundTower's Avatar
 
Join Date: Feb 2005
Location: soah made my profile
Posts: 14,560
Re: Programming homework and newbie help thread

I think there are cases where the points are on adjacent sides but the shortest path takes you over a third side. Actually I thought there were some weird paths when you are on opposite sides too.
RoundTower is offline   Reply With Quote
Old 10-21-2014, 08:18 PM   #33
e i pi
veteran
 
e i pi's Avatar
 
Join Date: Feb 2010
Location: ☃
Posts: 2,230
Re: Programming homework and newbie help thread

Ah didn't think too hard about this one. Looked into it and apparently it's a well known problem,

http://mathworld.wolfram.com/SpiderandFlyProblem.html
e i pi is offline   Reply With Quote
Old 10-21-2014, 08:23 PM   #34
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 21,793
Re: Programming homework and newbie help thread

RT: Yeah, you're right.



The shortest path here will actually involve going over the top face.
jjshabado is offline   Reply With Quote
Old 10-21-2014, 08:23 PM   #35
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 21,793
Re: Programming homework and newbie help thread

Hah, turns out it takes me at least 5 minutes to draw a ****ty cube.
jjshabado is offline   Reply With Quote
Old 10-21-2014, 08:25 PM   #36
e i pi
veteran
 
e i pi's Avatar
 
Join Date: Feb 2010
Location: ☃
Posts: 2,230
Re: Programming homework and newbie help thread

So I guess you have to iterate through these http://en.wikipedia.org/wiki/Hexomino

this looks like a major headache. glad I didn't go to school for compsci
e i pi is offline   Reply With Quote
Old 10-21-2014, 08:35 PM   #37
spaceman Bryce
anything you guys want
 
spaceman Bryce's Avatar
 
Join Date: Dec 2005
Location: kansas
Posts: 15,859
Re: Programming homework and newbie help thread

ok so! I already made this program and submitted it about a week ago. I got a 13/15 I didnt know about how to include the category ticket limit into my program. the first spoiler is my assignment and then the second spoiler is the program i make all by myself How do i fixn it?


Spoiler:



Spoiler:
spaceman Bryce is offline   Reply With Quote
Old 10-21-2014, 09:07 PM   #38
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 21,793
Re: Programming homework and newbie help thread

Nice. You can use [ code ] tags to keep formatting of your code.

I think the easiest way to fix your program is to move the money logic completely out of your loop. You're keeping track of the number of people in each category anyway - so just use those numbers (checking for your ticket limit) after the loop to do one money calculation.

Edit: My bad, I see you have to display the running total. If you've already covered helper methods I'd just create a method that takes in your current counts of users and spits out a ticket amount.
jjshabado is offline   Reply With Quote
Old 10-21-2014, 09:29 PM   #39
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

rather, for anything even kinda long, you probably should:

Spoiler:
Anais is offline   Reply With Quote
Old 10-21-2014, 10:31 PM   #40
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?
Anais is offline   Reply With Quote
Old 10-21-2014, 10:49 PM   #41
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 21,793
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Anais View Post
anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?

It's been a long time since I've written C++ but I'd guess it's a memory/pointer/reference issue. Can you post the code?
jjshabado is offline   Reply With Quote
Old 10-21-2014, 10:54 PM   #42
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,894
Re: Programming homework and newbie help thread

Quote:
Originally Posted by Anais View Post
anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?
Uninitialized return value would be my guess or you are clobbering some data due to a bug are my guesses. Post the code.
adios is offline   Reply With Quote
Old 10-21-2014, 11:11 PM   #43
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,894
Re: Programming homework and newbie help thread

In C, how would you dynamically allocate 1K bytes and have them all be zero with one standard C library call?
adios is offline   Reply With Quote
Old 10-21-2014, 11:31 PM   #44
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

It's a good night. New function is outputting a string a ╠╠╠╠╠╠╠╠

what even is that?

Quote:
Originally Posted by adios View Post
Uninitialized return value would be my guess or you are clobbering some data due to a bug are my guesses. Post the code.
The weird part is that MY code is returning the proper values. The part that's supposed to be returning a 0 is what the teacher wrote. And it returns 99 or 100.

THIS IS ALL SOMEONE ELSE'S FAULT!

function code below:

Spoiler:


we're supposed to compare two character arrays and see if they are the same, or if they are or are not entered in alphabetical order, and give a return indicating which.
Anais is offline   Reply With Quote
Old 10-21-2014, 11:37 PM   #45
KatoKrazy
veteran
 
KatoKrazy's Avatar
 
Join Date: Jan 2009
Posts: 3,164
Re: Programming homework and newbie help thread

Index will never be \0 you meant to check if the values in the arrays at index are \0
KatoKrazy is offline   Reply With Quote
Old 10-21-2014, 11:45 PM   #46
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

My man!
Anais is offline   Reply With Quote
Old 10-22-2014, 03:41 PM   #47
adios
Carpal \'Tunnel
 
Join Date: Sep 2002
Location: Russian Troll
Posts: 20,894
Re: Programming homework and newbie help thread

Quote:
Originally Posted by KatoKrazy View Post
Index will never be \0 you meant to check if the values in the arrays at index are \0
Actually due to his bug(s) it could.

@anais - notice that your code can return an uninitialized value and probably does. If none of the if conditions hold. The pro tip is to initialize a return value in a variable at the beginning of the function then modify it in the code.

Last edited by adios; 10-22-2014 at 03:48 PM.
adios is offline   Reply With Quote
Old 10-22-2014, 06:24 PM   #48
Anais
Carpal \'Tunnel
 
Anais's Avatar
 
Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

Oh, so like put an int final = 0;, then modify that with the if statements, then return final?

That makes sense.

Also, I figured out why I was getting those weird ascii 204 characters in another program. Forgot to assign a null character to the end of a char array and it was spitting out weird garbage.

Ugh, c++ is such a pita.
Anais is offline   Reply With Quote
Old 10-23-2014, 11:16 AM   #49
jmakin
 
jmakin's Avatar
 
Join Date: Jan 2008
Location: Streaming
Posts: 25,228
Re: Programming homework and newbie help thread

If you don't put a null character at the end of a c string, it doesn't know when to stop reading data and is likely just pulling whatever random crap is in memory.

I always add an arbitrary return value at the end of my function, if i have a bunch of if statements like you do, even if you're confident there's no way it'll be reached. Most IDEs will warn you if you don't do this. Pretty sure java won't even compile if you don't do that.
jmakin is offline   Reply With Quote
Old 10-23-2014, 12:05 PM   #50
KatoKrazy
veteran
 
KatoKrazy's Avatar
 
Join Date: Jan 2009
Posts: 3,164
Re: Programming homework and newbie help thread

Ugh, two tests today. Thankfully Theory of Algorithms test is supposed to be much easier than the first one.
KatoKrazy is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 03:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online