LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-04-2009, 07:43 AM   #1
jokar.mohsen
Member
 
Registered: Jul 2008
Location: Tehran
Posts: 441

Rep: Reputation: 22
Unhappy Python Or c Or C++


hi user i want write this program with python or c++.but i have some problem.can you help me?

you have a list of different cakes to make,each requering a certain amount of time to bake,you also have exactly 3 ovens to bake the cakes in,and each oven can only bake on cake at time.assuming that the time requered to take a cake out and put another one in is negligble,can you determine that smallest amount of time you will need to spend baking,given the list of cakes to make?

Input:
the input test file will contain multiple cases,with each case on a single line.the line begins with an integer n(where 1<=n<=40),the number of cakes to bake.fllowing are n integer t1,...,tn(where 1<=ti<=30),indicating the time in minutes required to bake each of your cakes.end-of-input is marked by a single line containing 0;do not process this line.for example

1 30
3 15 10 20
5 6 7 8 9 10
0

output:
30
20
15
 
Old 05-04-2009, 07:53 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.

Above is our standard homework response......

The key point is that you have not shown us what work you have done. You also say that you "have some problem", but you don't say what it is.......

I can give one easy answer: Since this is obviously just a programming exercise, Python will be much easier.

Last edited by pixellany; 05-04-2009 at 07:59 AM.
 
Old 05-04-2009, 08:33 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by pixellany View Post
Since this is obviously just a programming exercise, Python will be much easier.
1) Since the actual programming would be trivial in any programming language you know, the language you know best will be easier. (I could code this in Python, but would find it much easier in C++, Java or even C).

Reading the input is the only part where the choice of language makes even a moderate difference. I expect that if you know Python fairly well (I don't) reading the input should be easier in Python.

2) The algorithm design should be separate work from the coding. There is an obvious "brute force" algorithm, that makes the algorithm design trivial. Up to about 18 cakes the "brute force" algorithm would take so little time to run that you wouldn't have any reason to work hard to design an algorithm that runs faster. But at 40 cakes, I don't think the "brute force" algorithm would be usable.

So start by deciding how good an algorithm you need. Then design the algorithm. Then select a language and write your code.

Last edited by johnsfine; 05-04-2009 at 08:37 AM.
 
Old 05-04-2009, 10:18 AM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by pixellany View Post
Per the LQ Rules, please do not post homework assignments verbatim.
Here is the irritating thing; it's not a verbatim post of a homework assignment. Enough care has not been taken for it to be accurate.

If the OP is asking for general advice on the selection of the easiest language for a problem like this, I don't have a problem with that (its Python, if you don't know any of the languages well; if this is a learning excercise, there may be a case for choosing one that you don't currently know, but the easiest is still python, but, in learning, the easiest isn't always the only valid selection). If what is being asked for is anything more like a worked out solution, that would be against the prohibition on just doing people's homework for them.
 
Old 05-04-2009, 10:26 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
you have a list of different cakes to make,each requering a certain amount of time to bake,you also have exactly 3 ovens to bake the cakes in,and each oven can only bake on cake at time.assuming that the time requered to take a cake out and put another one in is negligble,can you determine that smallest amount of time you will need to spend baking,given the list of cakes to make?

Input:
the input test file will contain multiple cases,with each case on a single line.the line begins with an integer n(where 1<=n<=40),the number of cakes to bake.fllowing are n integer t1,...,tn(where 1<=ti<=30),indicating the time in minutes required to bake each of your cakes.end-of-input is marked by a single line containing 0;do not process this line.for example
This looks like cut and paste to me---most likely homework, but I suppose there could be another explanation.....

Also note that OP did NOT ask which language to use. (I want to program this.....but I have some problem")

All this aside, we DO give benefit of the doubt. I hope that jokar will post back and clarify his/her intentions and respond to the advice we have already given.
 
Old 05-05-2009, 02:25 AM   #6
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by pixellany View Post
This looks like cut and paste to me---most likely homework, but I suppose there could be another explanation.....
Given the roughly 27 grammar/spelling/formatting errors (many repeated), I was hoping that it wasn't a cut 'n paste, as that would raise other issues.

Quote:
Also note that OP did NOT ask which language to use. (I want to program this.....but I have some problem")
No, I was noting that the OP could have been asking 'which language would be the best choice for this type of problem', which would be legitimate, but didn't make that clear (that's another, and more important, error, if anyone is still counting!).
 
Old 05-07-2009, 05:59 AM   #7
amysaraantony
Member
 
Registered: Apr 2009
Posts: 42

Rep: Reputation: 16
Quote:
Originally Posted by jokar.mohsen View Post
hi user i want write this program with python or c++.but i have some problem.can you help me?

you have a list of different cakes to make,each requering a certain amount of time to bake,you also have exactly 3 ovens to bake the cakes in,and each oven can only bake on cake at time.assuming that the time requered to take a cake out and put another one in is negligble,can you determine that smallest amount of time you will need to spend baking,given the list of cakes to make?

Input:
the input test file will contain multiple cases,with each case on a single line.the line begins with an integer n(where 1<=n<=40),the number of cakes to bake.fllowing are n integer t1,...,tn(where 1<=ti<=30),indicating the time in minutes required to bake each of your cakes.end-of-input is marked by a single line containing 0;do not process this line.for example

1 30
3 15 10 20
5 6 7 8 9 10
0

output:
30
20
15


My answer to you on this is pretty simple. The problem can be solved in any of the programming languages you specified. Choose one that you're comfortable with and jump right into the world of programming!


Debian

Last edited by amysaraantony; 05-15-2009 at 08:17 PM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make python programs run without entering the command python? trist007 Programming 5 03-22-2009 08:21 PM
LXer: Review: Programming in Python 3: A Complete Introduction to the Python Language LXer Syndicated Linux News 0 01-26-2009 04:50 AM
python update - Unable to load GTK2 Python bindings: No module named gtk itpedersen Linux - Software 2 10-03-2008 03:44 AM
LXer: Move to python 2.4 / Changing the packaging style for python packages LXer Syndicated Linux News 0 06-13-2006 07:54 PM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration