[aklug] Re: How would you write "rebase" in...

From: Christopher Howard <christopher.howard@frigidcode.com>
Date: Tue Aug 02 2011 - 21:02:31 AKDT

On 08/02/2011 07:34 AM, Tim Johnson wrote:
> * Christopher Howard<christopher.howard@frigidcode.com> [110801 21:04]:
>> As a vain effort to fill the void left by my vacuous social-life, I want
>> to start an AKLUG series called "How would you write it in..." Basic
>> idea is this: I pick a function, usually a simple one, and every one on
>> the list shows how they would code that function in his or her favorite
>> programming or scripting language. Obviously, that precludes using a
>> built-in or standard function that does the same thing. Bonus points if
>> you can explain why you preferred to code it that way. (Simplicity,
>> performance, et cetera). Triple bonus points if you can explain how your
>> code works in at least semi-plain English.
>>
>> However, I am wondering if that is actually something other list members
>> would enjoy, or if I have simply been alone with my code interpreter for
>> too long and have lost all touch with reality. (Or both.) Bounce a reply
>> back to the list if you know you would participate.
> OK.

I've received three positive responses so far (two off-list). That's
border-line support, but enough that'd I'd be willing to give it a try
and hope for more participation. So here is the first challenge, adapted
from a text book programming problem:

Write a function called "rebase" which converts a decimal number to
other bases. The function shall take two parameters: a parameter "d"
representing the original decimal number, and a parameter "n"
representing the base to which to convert. The function shall return a
string representation of the converted number.

Challenge specific rules:
1. "d" and "n" shall be positive integers. (I.e., you don't need to
handle negative numbers or fractions.)
2. The function must handle all values of n >= 2 and n <= 36. You may go
higher if you wish.
3. Digits shall be represented in the return string by the characters
"0" .. "9" followed by "A".."Z". If you wish to handle higher bases you
can pick additional characters arbitrarily. Least significant digits on
the right.

General challenge rules:
1. There must be one interface function meeting the above definition,
but subordinate functions can be used.
2. You can include any functions, classes, and such like from your
language's base packages, standard libraries, or standard extensions,
but no others. Obviously, one of these functions cannot be used if it
already does what the challenge describes. Better to impress us with
your programming skills than the comprehensiveness of your base modules.
3. The function must be pure, i.e., cannot modify the value of variables
or references used as parameters.

-- 
frigidcode.com
theologia.indicium.us
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Tue Aug 2 21:02:04 2011

This archive was generated by hypermail 2.1.8 : Tue Aug 02 2011 - 21:02:04 AKDT