Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Coding challenge

Author
Message
ZKAT8IT
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location:
Posted: 14th Sep 2006 23:22 Edited at: 15th Sep 2006 00:37
Ok, my Perl teacher assigned this as the first homework assigment. Which I've been programming for a while, and only took me about 45 min to figure out. But I thought it was hard for the rest of the class who had never programmed before. So I thought I'd post it as a challenge to see how well you guys do.

[Edit] Some people weren't clear on the original instructions. So let me be more specific.

[Edit] You must stick by Perl rules also, so using data types to truncate decimal values and sych are not allowed. Perl variables change type depending on what you put in them so what is normall an Int variable can easily become a Float. Therefor, use Floats for any variables you use that hold numbers. ( This makes Kentaree's answer invalid )

Problem:
Make a program using DBP or any language of your choice that lets you input a 5 digit number, then it prints each individual digit. You may ONLY use basic math operations (+ - * / Mod ). Variables of course may be used, and the Print command to print results to screen, and Input to grab the number, and Suspend For Key to stop the program so the results are viewable. No arrays, string operations, no If-Then statements, no Loops allowed, no bitshifting either.

If you do try, please post the approximate time it took you to solve this.

Kentaree
22
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 15th Sep 2006 00:03
Took me 5 minutes to work out the algorithm, as you saw Took me a bit longer to code up as 1. Used to java, 2. wrote it according to the rules and then decided it'd be better in a for loop, not remembering that was against the rules

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Sep 2006 02:57 Edited at: 15th Sep 2006 02:58
Your class sounds kinda unorganized. Students choose their lanuage of choice but must follow Pearl rules? Course needs better structuring. Sounds more of a math challenge than coding.

Took about 5 minutes for me as well. I'm assuming I can use the command INT? (returns integer part of a float)

It was a little tricky, but it should help students recognize patterns. Should we post how we did it?

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
ZKAT8IT
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location:
Posted: 15th Sep 2006 03:05 Edited at: 15th Sep 2006 03:10
Phaelax. It's a Perl class. We're using Perl. I'm just allowing you guys to use any language following the rules provided to see if you can do it, since I assumed you didn't want to be forced to use DBP. No, you can not use the INT command. Read the rules more closely. You're not allowed to use anything other than what is specified which is + - * / Mod, Print, Input, Suspend For Key ( Similiar commands for other languages ), any variables used may be strings or Floats, no using integers to truncate floats since Perl's variables change data types depending on what you put in them ( I didn't make the language, I just use it ). Yes, please post how you did it also.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Sep 2006 03:07 Edited at: 15th Sep 2006 03:09
Ah ok, gotcha. But INT is technically a math command. It's not casting or using a different data type to truncate decimals.
Hmm, well now I'm not sure. Never used pearl either.

No INT, but DB only returns floats if something in the equation used a float specifically. So if I make "number" a float, this won't work now.


"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
ZKAT8IT
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location:
Posted: 15th Sep 2006 03:15 Edited at: 15th Sep 2006 03:16
Phaelax: yeah, DBP is weird about data types being floats or integers. Which is why I added the rules that any numbers/variables used should be Floats. So add .0 to any number used and # to variable names.

Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 15th Sep 2006 14:37
this is what i could figure out. It only works with whole numbers though


ZKAT8IT
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location:
Posted: 15th Sep 2006 21:40
Cave Man: The number input will be a whole number. But for any operations used must be Floats. So you followed the rules properly. How long did it take you to figure it out?

Login to post a reply

Server time is: 2024-11-17 14:29:19
Your offset time is: 2024-11-17 14:29:19