You are here:   ArielOrtiz.com > Programming Languages > The Moronic Cowmpouter

The Moronic Cowmpouter

Objectives

During this activity:

This activity helps the student develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.

Activity Description

This activity will count as the third quarter term exam.

Individually or in pairs, solve the following problem using one of these programming languages: Scala, JRuby, Clojure or Groovy.

Some crazy cows tried to build a calculating engine (yes, it's a cowmpouter) using binary numbers (base 2) but instead built one based on base negative 2. They were quite pleased since numbers expressed in base -2 do not have a sign bit.

You know number bases have place values that start at 1 (base to the 0 power) and proceed right-to-left to base^1, base^2, and so on. In base -2, the place values are 1, -2, 4, -8, 16, -32, ... (reading from right to left). Thus, counting from 1 goes like this: 1, 110, 111, 100, 101, 11010, 11011, 11000, 11001, and so on.

Negative numbers are also represented with 1's and 0's but no sign. Consider counting from -1 downward: 11, 10, 1101, 1100, 1111, and so on.

Please help the cows convert ordinary decimal integers to their counterpart representation in base -2.

Taken from: Sphere Online Judge.

Define a function called cow that when called with an integer number n as its argument (-2,000,000,000 ≤ n ≤ 2,000,000,000), returns a string of 1's and 0's with the expected conversion. For example (syntax may vary depending on the chosen language):

> cow(-13)
"110111"

Deliverables

Place your solution in a single file called cow.ext (the extension depends on the chosen programming language: .scl, .rb, .clj or .groovy) and deliver it using the Online Assignment Delivery System (SETA). No activity will be accepted through e-mail or any other means.

IMPORTANT: All the program source files must include at the top the authors' personal information (name and student id) within comments.

Due date: Monday, April 20, before noon. The program will be assesed during class on that same date.

Evaluation

This activity will be evaluated using the following criteria:

-10 The program doesn't contain within comments the authors' personal information.
10 The program contains syntax errors.
DA The program was plagiarized.
20-50 The program doesn't work, but it seams that some significant amount of time was spent in it.
60-90 The program works, but has some flaws.
100 The program works as requested.
© 1996-2009 by Ariel Ortiz (ariel.ortiz@itesm.mx)
Made with Django | Licensed under Creative Commons | Valid XHTML | Valid CSS