SRL Archive - SRL Member+ Competitions

[COMP] Rapidus Computus


Daniel

2012-09-07 05:51:33

(courtesy of darling euphemism)



[INDENT]Welcome to Rapidus Computus, a Simba scripting competition designed to test how well you know Simba and how good you are at implementing solutions to challenging problems.

If you are the top monthly coder, you can win 1 MILLION RuneScape gold pieces!

Problems are released weekly. We are currently up to week #1.


[/INDENT]

Daniel

2012-09-16 05:30:20

Important Notes/Rules

[INDENT]NOTE: The contest rules are set by me (Daniel). I, alone, am responsible for the interpretation of the rules and of the contest questions, and I am fully responsible for clarifying or altering the rules or contest questions in unforeseen circumstances.



Eligibility:
  • This competition is for SRL Members and above only.

Submissions:

  • Solutions may only be submitted in Lape-compatible Pascal.
  • You should submit your solutions directly to me via the PM system before or on the due date.
  • You may submit solutions as many times as you like, however, only the last submission for each question will be judged.
  • You may not make any submissions past the due date.
  • The solution to each problem should be a single Simba script.

During the week:

  • You may use:
    • Simba with the Lape interpreter to debug/develop your solutions,
    • the templates provided below for aid,
    • any documentation in electronic/printed form, such as help files – this does not include source code,
  • You may not use:
    • compilers and/or interpreters that are not Lape-based,
    • the internet to ask for any help in regards to this competition (e.g. Stack Overflow, IM [IRC, Skype, MSN, etc], other forum members),
    • any source code in electronic/printed form that is not yours to begin with (e.g. methods in the SRL library), with the exception of the code templates provided,
    • other people for technical matters (e.g. How do you construct a for loop? What does this paragraph in the questions mean? How many bytes does an integer take up?)
  • You may not discuss the current week problems with others/other contestants.

Script Restrictions:

  • Contestants should write a Simba script to solve each problem,
  • Scripts should read input only from the input file(s) specified in the question statements, and should send output only to the output file(s) specified in the question statements. The input and output files should be assumed to be in the Simba application directory. Any output to the screen will be ignored, and no input from the keyboard/mouse will be supplied.
  • The format of the input file will be specified in each problem statement.
  • The desired format of the output file will also be specified in each problem statement. If you do not adhere to this output format, you get a zero mark for your solution,
  • Each solution should be a single Simba script compatible with the Lape interpreter,
  • You may only use the internal Simba/Lape methods specified in this post in your solution,
  • Contestants may be disqualified if their scripts:
    • attempt to read from or write to any files other than those specified in the problem statements,
    • attempt to make network connections,
    • contain any malicious code designed to harm or alter the judges’ computer(s),
    • otherwise attempt to subvert the judging system.
  • The source code for each solution must not exceed 40KiB (which I doubt will happen).

Time Limits:

  • Each script must run within the time limit specified in the question statement. If, during judgment day, a script does not run within the time limit for a particular input file, it will receive a score of zero for that input file,
  • Much of the judges’ input data will be far more taxing than the sample input given in the question statements, and may push your solution over the time limit. In this way, efficient solutions will be rewarded,
  • Judgment will be performed on a dedicated system running Lubuntu Linux 12.04 with 512MB RAM and a single core 1.5GHz processor, and all times are relative to this hardware/unit.

Judging:

  • Each question will be scored out of 100. Each question every week are of equal value.
  • Solutions will be compiled and run on the judges machine(s) using Simba build #1000 (GIT build #244, revision: 26a7790c7787d9e593ae2a5286e74bc4a06304b1, October 1st 2012).

  • Click here
    for the build.
  • The judges reserve the right to re-examine any contestant for any reason before declaring official results.
  • In the event of ties, the judges reserve the right to either declare ties or to rank students using alternate means (e.g. solution implementation, readability of code).
  • Results for a previous solution may not be immediately posted upon release of a new weeks set of questions.

[/INDENT]

Daniel

2012-09-16 05:33:07

Why Did I Score Zero?


[INDENT]Candidates sometimes score zero even though they believe that they have a working solution to a problem. Below are some of the common reasons that good solutions score zero.

Incorrect Input and Output Files:[INDENT] Each problem statement lists the names of its input and output files, similar to the example below:
[BANANA]Input File: zeroin.txt
Output File: zeroout.txt[/BANANA]

In this example, if you try to open any of:

  • “C:\mydir\zeroin.txt”
  • “/home/user/some-random-directory/zeroin.txt”
  • “input.txt”
then the file you are looking for will almost certainly not be on the judging machine and your program will score zero. Just open “zeroin.txt” without any additional directory information. The same goes for the output file.
[/INDENT]Keyboard and Mouse Input:[INDENT] Your solution should not be interactive. It should not have a graphical user interface. It should simply read from the input file, write to the output file, and exit. If your program requires any additional input from the user, it will not be supplied an you may exceed the time limit. Examples include:

  • “Please enter the following value…”
  • “Press any key to exit…”
  • Providing a form on which the user has to click a button to start the program.
[/INDENT]
Incorrect Output Format[INDENT] Each problem is very precise about how the output file should be formatted. Your score is assigned by a judging program which tries to automatically extract your solution from your output file. Every problem statement includes sample input and output files, as a way of illustrating these required formats. For example, if the sample output file contains the single line:

  • 8
then you should only output in that format, and not something like (which will almost certainly score zero):

  • The answer is 8.
  • “8”
[/INDENT][/INDENT]

Daniel

2012-09-16 05:35:46

The Leaderboard

[LEFT]

Overall:

  1. .
  2. .
  3. .
  4. .
  5. .


This Month:

  1. .
  2. .
  3. .
  4. .
  5. .


[/LEFT]

Daniel

2012-09-16 06:14:46

Allowed Methods



In your solution, you may only use the following in-built/internal Simba methods:

  • Abs
  • AppendFile
  • BoolToStr
  • CallProc
  • Ceil
  • Chr
  • CloseFile
  • Copy
  • Cos
  • CurrToStr
  • Dec
  • DecEx
  • Degrees
  • Delete
  • Distance
  • EndOfFile
  • Exp
  • FileExists
  • FilePointerPos
  • FileSize
  • FloatToStr
  • Floor
  • GetSystemTime
  • GetTickCount
  • GetTimeRunning
  • High
  • Inc
  • IncEx
  • InRange
  • Insert
  • Int
  • IntToHex
  • IntToStr
  • Length
  • Ln
  • log10
  • logn
  • Low
  • Lowercase
  • Max
  • MaxE
  • Min
  • MinE
  • OpenFile
  • Ord
  • PadL
  • PadR
  • Pos
  • PosEx
  • Radians
  • Random
  • RandomE
  • Randomize
  • ReadFileString
  • RewriteFile
  • Round
  • SetFileCharPointerPos
  • Sin
  • Sleep
  • Sqr
  • Sqrt
  • StringOfChar
  • StrToBool
  • StrToBoolDef
  • StrToCurr
  • StrToCurrDef
  • StrToFloat
  • StrToFloatDef
  • StrToInt
  • StrToIntDef
  • Tan
  • TerminateScript
  • Trim
  • TrimLeft
  • TrimRight
  • Trunc
  • UpCase
  • Uppercase
  • VarInRange
  • VarIsClear
  • VarIsEmpty
  • VarIsNull
  • VarToStr
  • VarToStrDef
  • VarType
  • Wait
  • WriteFileString

Daniel

2012-09-16 06:22:20

Solution Template

[LEFT]
program RapidusTemplate;

const
FILE_INPUT = '*in.txt'; // Input file.
FILE_OUTPUT = '*out.txt'; // Output file.

NEWLINE = #$A; // UNIX uses this as the newline character.

var
fileIn, fileOut: Integer;

begin
// Open the files for reading/writing.
fileIn := OpenFile(FILE_INPUT, True);
fileOut := RewriteFile(FIlE_OUTPUT, False);

{ Create solution here }

// Cleaning up.
CloseFile(fileIn);
CloseFile(fileOut);
end.
[/LEFT]

Daniel

2012-09-16 06:23:17

Sample Problems


[LEFT][LEFT]
  • The Tremendous Tak-Tak Tree
[/LEFT]
[INDENT][INDENT][BANANA]Input File: taktakin.txt
Output File: taktakout.txt
Time Limit: 10 seconds[/BANANA]


Life is simple in the isolated village of Tak-Tak. Free of the noise and bustle of modern life, the villagers spend their days indulging their two great loves: farming and cooking. Their vegetable fields grow strong and tall, and their delicious communal meals brighten many an evening.

In the centre of the village sits a great sprawling tree, whose long boughs provide shade during the hot summers. The fruit of the Tak-Tak tree (as it is affectionately known) is renowned for its sweet, succulent taste.

Unlike normal plants, the Tak-Tak tree is not affected by weather or seasons. Instead, its fruits grow according to the cycles of the moon. Every month when the full moon is at its highest, each fruit on the tree shimmers and turns into two fruits. When the sun rises the villagers wake to find the number of fruits on the tree has doubled.

The villagers are planning a huge feast for this year. On the day of the feast they will remove all the fruit except one from the tree. This to be divided equally between the village's eleven inhabitants, as they are a fair people. (No slicing or dicing is allowed - each villager must receive a whole number of fruits.) Afterwards the one remaining fruit on the Tak-Tak tree is left to begin the cycle anew.


If the villagers cannot evenly share the fruit with one left over, they shall wait until they can. They are very excited about the feast and would like to know how many full moons they must wait.


Input[INDENT]The input file will consist of a single integer, the number of fruits initially on the tree. This will be between 2 and 1,000,000 inclusive.
[/INDENT]Output[INDENT]The output file should consist of two integers separated by a space: the least number of full moons the villagers must wait until the feast is possible, and the number of fruits on the tree at that time.
You are guaranteed that it will eventually be possible to hold the feast.
[/INDENT]
Sample Input 1


  • [BANANA]23[/BANANA]
Sample Output 1

  • [BANANA]0 23[/BANANA]

Sample Input 2

  • [BANANA]17[/BANANA]
Sample Output 2

  • [BANANA]1 34[/BANANA]

Sample Input 3


  • [BANANA] 14[/BANANA]
Sample Output 3

  • [BANANA] 2 56[/BANANA]

Explanation
[INDENT]In the first example, 23 = 2 x 11 + 1 is a good number for a feast (if each villager receives two Tak-Tak fruits, one is left over as planned). Because of this they do not need to wait; they may start the feast straight away.

In the second example, 17 is not a good number for a feast. After one full moon, the number of fruits has doubled, becoming 34 = 3 x 11 + 1. This is a good number for a feast.

In the third example, 14 is not a good number for a feast. After two full moons, the number of fruits has quadrupled, becoming 56 = 5 x 11 + 1. This is a good number for a feast.

[/INDENT][/INDENT][/INDENT]
  • Counting to Infinity
[INDENT][INDENT][BANANA]Input File:countin.txt
Output File:countout.txt
Time Limit: 5 seconds[/BANANA]


Don't let the title fool you: in this problem, all your program needs to do is to count as high as ten thousand. Specifically, it must read in the integer n and list all the integers from 1 to n.


Input

[INDENT]The input file will consist of a single integer, n. It is guaranteed that 1 <= n <= 10,000.
[/INDENT]
Output
[INDENT]Your output file should consist of the integers from 1 to n in increasing order, separated by line breaks.
[/INDENT]

Sample Input

  • [BANANA]8[/BANANA]

Sample Output

  • [BANANA]1
  • 2 3 4 5 6 7 8[/BANANA]
[/INDENT][/INDENT]
  • A Dish Best Served Cold
[INDENT][INDENT][BANANA]Input File: dishin.txt
Output File: dishout.txt
Time Limit: 5 seconds[/BANANA]


You do not like statisticians, and statisticians do not like you. Ever since that life actuary kicked sand into your ice cream when you were four, you have waged a slowly escalating war against those number-crunching jerks. But all that is about to change.

After many sleepless nights you have conceived the ultimate revenge: beating them at their own game. Using your computer programming skills, you will write a freeware statistics package so thorough, so complete, that statisticians all around the world will be out of a job. It will be able to predict weather patterns, calculate life expectancies, and even play the perfect poker game.

First, though, you must implement word wrap. However, this task is rather finnicky, not very mathematical in nature, and ultimately not very important. More urgently, you also need to implement some basic data analysis. Specifically, you decide to write a test program that takes a data set (a list of integers) and calculates the following measures of spread:

  • Minimum - the smallest value in the list. For example, the minimum of the numbers {5, 6, 5, 3} is 3.
  • Maximum - the largest value in the list. For example, the maximum of the numbers {5, 6, 5, 3} is 6.
  • Mean (or average) - defined as the sum of everything in the list divided by the number of items in the list. For example, the mean of the numbers {5, 6, 5, 3} is (5+6+5+3)/4 = 19/4 = 4.75. However for simplicity you are asked to round all answers down to the nearest whole number. So the mean of the numbers {5, 6, 3, 3}, rounded down, is 4.

Input

[INDENT]The first line of input will consist of a single integer n (1 <= n <= 1,000), the size of your data set. The following n lines will describe the data set. Each of these lines contains an integer between 0 and 1,000,000 inclusive.
[/INDENT]
Output
[INDENT]The output file should consist of three integers separated by spaces: the minimum, maximum and mean of the data set.
[/INDENT]
Sample Input 1

  • [BANANA]6
  • 70 72 74 50 73 75[/BANANA]

Sample Output 1


  • [BANANA]50 75 69[/BANANA]

Sample Input 2


  • [BANANA]6
  • 100 200 200 200 200 1100[/BANANA]

Sample Output 2


  • [BANANA]100 1100 333[/BANANA]
[/INDENT][/INDENT][/LEFT]

Daniel

2012-09-16 06:31:27

This Weeks Problems


Week #1



Curry:[INDENT] [BANANA]Input File: curryin.txt
Output File: curryout.txt
Time Limit: 5 seconds[/BANANA]
[/INDENT][INDENT] You are at a very fancy dinner party with some very good friends, trying to eat a very hot curry. On your plate is a pile of curry, rice and vegetables. You are finding it quite difficult to eat, since the curry is too hot, the rice is too sticky and you don't like vegetables.

To work around this problem, you eat in such a way that each mouthful includes a scoop of two different items. For example, the first mouthful might include a scoop of curry with a scoop of rice. The next mouthful might include a scoop of rice with a scoop of vegetables. You cannot eat three scoops all at once, since your spoon is too small.

The danger with your plan is that you might not be able to finish your meal. At last week's dinner party you started off by eating all your curry and rice, which meant that you could not finish your vegetables since there was nothing left to eat them with. It was most embarrassing. Determined not to be humiliated again, you pull your laptop out of your bag and tap away secretly beneath the table, hoping to solve your eating problems for once and for all.

Your task is to work out how to eat your meal so that you eat as much total food as possible.
[/INDENT][INDENT]Input:[INDENT] There will be only one line of input. This line will contain the three integers c r v (each separated by a single space), representing the number of scoops of curry, rice and vegetables on your plate. You are guaranteed that 0 <= c,r,v <= 100,000.
[/INDENT]Output:[INDENT] The output must be a single line containing the integers x, y and z (separated by spaces), where:

  • x is the number of mouthfuls containing a scoop of rice with a scoop of vegetables;
  • y is the number of mouthfuls containing a scoop of curry with a scoop of vegetables;
  • z is the number of mouthfuls containing a scoop of curry with a scoop of rice.
You must choose x, y and z so that you eat the maximum total number of scoops possible. If there is more than one way of doing this, any solution will do. [/INDENT]
From: Sample Input #1
Sample Input:[INDENT] 5 6 9
[/INDENT]Sample Output:[INDENT] 5 4 1
[/INDENT]Explanation:[INDENT] You begin the meal with 5 scoops of curry, 6 scoops of rice and 9 scoops of vegetables. You start by taking five mouthfuls of rice with vegetables, leaving you with 5, 1 and 4 scoops of curry, rice and vegetables respectively. You then take four mouthfuls of curry with vegetables, leaving you with 1, 1 and 0 scoops of curry, rice and vegetables respectively. Finally you take one mouthful of curry with rice, and the meal is completely finished. [/INDENT]
From: Sample Input #2
[INDENT]Sample Input:[INDENT] 1 2 5
[/INDENT] Sample Output:
[/INDENT][INDENT][INDENT] 2 1 0
[/INDENT][/INDENT][INDENT] Explanation:[INDENT] Your second meal has 1, 2 and 5 scoops of curry, rice and vegetables respectively. This is a lot of vegetables, and you can't possibly finish them all. The solution above involves two mouthfuls of rice with vegetables and one mouthful of curry with vegetables. This completely finishes your curry and rice, but leaves you with two scoops of vegetables remaining. There is no other way of eating the meal that leaves less food at the end, and so 2 1 0 is your final output. [/INDENT][/INDENT]
Scoring:[INDENT] The score for each input file will be 100% if a correct solution is written to the output file and 0% otherwise.

[/INDENT][/INDENT]Chimpanzee:
[INDENT][BANANA]Input File: chimpin.txt
Output File: chimpout.txt
Time Limit: 2 seconds[/BANANA]

It has been a long hard day trekking through the jungle, and it is almost dark. Exhausted, you sit down to rest and pull a book from your backpack for some light reading. Suddenly, with an excited cry, a chimpanzee leaps from a nearby tree and snatches the book from your hands.

In horror you watch as the chimpanzee runs through the jungle in a spiral pattern, ripping pages from your book as it goes. Soon your horror gives way to curiosity as you contemplate the very precise spiral pattern that the chimpanzee is following.

Consider the jungle to be a grid of squares in a coordinate system, where you are sitting at square (0,0). The chimpanzee follows a tight spiral out from (0,0) as illustrated below:


The pages of your book are numbered from 0 upwards. At each square on the spiral, the chimpanzee tears a new page from your book. Thus page 0 is left at square (0,0), page 1 is at square (1,0), page 2 is at square (1,1), page 3 is at square (0,1), page 4 is at square (-1,1) and so on.

Fortunately you have also brought your laptop on your jungle trek. Pulling it from your bag and plugging it into a nearby power point, you sit down to write a program that will help you put the pages together in the correct order.

Your specific task is to write a program that reads in a pair of (x,y) coordinates and outputs which page the chimpanzee has left in that square.

Input:[INDENT] The input will consist of a single line containing integers x and y separated by a single space (-1000 <= x,y <= 1000).
[/INDENT]Output:[INDENT] Your output must be a single line containing a single integer, which is the page number that the chimpanzee left in square (x,y). You may assume that your book is very thick and the chimpanzee does not run out of pages.
[/INDENT]
From: Sample Input #1
Sample Input:[INDENT] -1 1
[/INDENT]Sample Output:[INDENT] 4[/INDENT]
From: Sample Input #2
Sample Input:[INDENT] 2 1
[/INDENT]Sample Output:[INDENT] 11[/INDENT]
Scoring:[INDENT] The score for each input file will be 100% if the correct answer is written to the output file and 0% otherwise.[/INDENT][/INDENT]