Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 15th, 2005, 12:12 PM   #1
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
Lightbulb Fun little programming challenge

OK, this one is pretty easy - but it makes you think and it's a nice break from the day.

Write a program that takes in 3 values: distance(eg. miles), efficiency(eg. miles/gallon), and current fuel(eg. gallons). Your program must give a response (in English) stating whether or not the person has enough fuel to make it on this trip. Now the catch: you cannot use conditionals in your code (if, switch, etc) - no decision logic whatsoever.

Post your solutions, it will be interesting to see what people come up with. (I have solved this and I will post my code after there are some correct responses)
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 15th, 2005, 12:52 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Not sure if this is correct, but here you go... a PHP command line program attached to avoid spoilers.
Attached Files
File Type: zip gas.zip (509 Bytes, 23 views)
__________________

tempest is offline   Reply With Quote
Old Jul 15th, 2005, 1:10 PM   #3
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
You want to make the the response a "yes" or "no" type of English response - no numbers.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 15th, 2005, 3:35 PM   #4
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
entry .... hope I did the right thing ... been a bad week for me ... it's perl btw
Attached Files
File Type: txt script.txt (227 Bytes, 32 views)
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Old Jul 15th, 2005, 4:01 PM   #5
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
You are using decision logic there with the regular expressions (looking for the - sign). No conditional expressions whatsoever allowed! Only mathematical computations and outputting strings.

I'll give a hint...

make the output something like:
You will make it.
You will not make it.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 15th, 2005, 4:13 PM   #6
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
post yours ...
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Old Jul 15th, 2005, 4:21 PM   #7
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
I'm not quite sure how you would go about writing this without useing at least one conditional. How do you choose the output??
hoffmandirt is offline   Reply With Quote
Old Jul 15th, 2005, 4:28 PM   #8
EverLearning
Hobbyist Programmer
 
EverLearning's Avatar
 
Join Date: May 2005
Location: Indiana
Posts: 130
Rep Power: 4 EverLearning is on a distinguished road
Have not had time to work this out, perhaps later tonight.
But there may be something in the fact that in logic these two statemens are logically equivalent:

P -> Q (P implies Q, i.e. conditional)
P' | Q ((not P) or Q)

Hmmm ... maybe i am on a tangent but i'll think about that!
__________________
got math? yumm...

"All men by nature desire to know" -Aristotle, Metaphysics
EverLearning is offline   Reply With Quote
Old Jul 15th, 2005, 4:31 PM   #9
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
here you go... (C++)

it's very evil.
Attached Files
File Type: txt pf_gas.txt (448 Bytes, 46 views)
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Jul 15th, 2005, 4:37 PM   #10
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
shenanigans
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC