473,395 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Turing to C++ Program Problem

Hi guys. I'm practicing for the CCC, a programming competition. I got stuck on a problem, so I copied the problem's answer from turing into C++. When I run my program in C++ though, I get a different answer from the one in turing. I've been spending hours trying to find the difference between the turing answer and my C++ answer, but to no avail. So basically, I'm asking what's the difference between the turing and C++ program?

Correct Answer in Turing
Expand|Select|Wrap|Line Numbers
  1. function between (a, b, c : int) : boolean
  2.     result a <= b and b <= c
  3. end between
  4.  
  5. % this recursively tries every route to the end (7000)
  6. procedure findPath (distance : int)
  7.     if distance = 7000 then
  8.         % made it to the end!
  9.         % One more way to get there
  10.         ways := ways + 1
  11.         put ways
  12.  
  13.     else
  14.         % recursively try all motels that you can get to
  15.         for i : 1 .. size
  16. put i
  17.             if between (minn, motel (i) - distance, maax) then
  18.                 findPath (motel (i))
  19.             end if
  20.         end for
  21.     end if
  22. end findPath
My wrong answer in C++.
Expand|Select|Wrap|Line Numbers
  1. int truck(int distance)
  2. {if (distance == 7000)
  3. { pos=pos+1; cout<< pos << "pos"; }
  4. else
  5. for (int i=1;i<=motels.size();i++)
  6. cout << i;
  7.  
  8. if(minn <= motels[i] - distance && maxx >= motels[i] - distance)
  9. {truck(motels[i]);}
  10.  
  11.  }
  12.  
Feb 19 '08 #1
2 1775
Banfa
9,065 Expert Mod 8TB
What is the type of motels?

Have you forgotten that C/C++ arrays index from 0?
Feb 19 '08 #2
Thanks for the advice!

I think I've found the problem and it's different from what I described here, it's actually a different problem. The 2 codes are exactly the same, but I think Dev C++ Bloodshed has problems with recursion. I tracked the values of recursion for the turing and C++ one, they are the same numbers except the C++ starts getting different values after 20 numbers or so and stops early. I've heard of related problems with recursion where there are too much numbers for the IDE to keep track of, some stack/heap problem or the like. So, the code are exactly the same, and it's not my fault :). I'm going to a new IDE and the problem will be solved.
Feb 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Xah Lee | last post by:
is it possible to write python code without any indentation? Xah xah@xahlee.org http://xahlee.org/PageTwo_dir/more.html
0
by: Alex Vinokur | last post by:
C++ Simulator of a Nondeterministic Turing Machine has been added at : * http://alexvn.freeservers.com/s1/turing.html * http://sourceforge.net/projects/turing-machine/ Currently those sites...
0
by: Alex Vinokur | last post by:
C++ Simulator of a Universal Turing Machine can be downloaded at : * http://alexvn.freeservers.com/s1/utm.html * http://sourceforge.net/projects/turing-machine/ The program simulates a...
3
by: Kvele | last post by:
I'm just looking for Turing machine for divide two binary numbers by subtract. The input string of numbers can't be deleted. The result must contain arrear. I need list of states (or c source). For...
6
by: Terry Reedy | last post by:
http://campus.acm.org/public/pressroom/press_releases/3_2006/turing_3_01_2006.cfm Peter Naur was co-developer of Backus/Naur grammar notation, co-author and editor of the Algol 60 specification,...
1
by: roxorsoxor2345 | last post by:
I am very sorry if this is not the appropriate group to post this question. I currently have a program that tests strings to see if they are palindromes. My input file looks something like...
17
by: CoreyWhite | last post by:
So I'm reading books about perl, which may not be quite as powerful as C++ but at least has more power than C & is very easy to learn from the manuals. I'm also buying books on C++, and books...
11
by: lovecreatesbea... | last post by:
Ken Thompson mentioned a self-reproducing program that products an exact copy of its source code as output in his 1983 Turing paper, http://www.acm.org/classics/sep95/ . Can this be done in C? How...
2
by: david.didonato | last post by:
hi i search example or components, where i can generate Turing Numbers with ASP !!!! exists components ? thanks for help david
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.