Page 1 of 1

Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Wed Dec 03, 2014 12:54 pm
by cfbsoftware
A $US50 Amazon Gift Voucher will be awarded to the person who can rewrite the following module so that it produces the same results but executes in the least amount of time:

Code: Select all

MODULE Quiz;

VAR
  a1*, a2*: ARRAY 1000 OF INTEGER;
  i: INTEGER;

PROCEDURE Init*;
BEGIN
  FOR i := 0 TO LEN(a1) - 1 DO 
    a1[i] := i;
    a2[i] := i
  END
END Init;

END Quiz.
The Terms and Conditions are (amended 6 Dec 2014):

1. You cannot use any IMPORT statements.
2. Your submitted code must compile without modification on any version v5.1 or later of any edition of Astrobe. (amended 12 Dec 2014)
3. When linked with the QuizTimer program below your code must run on any supported development board with at least 16K of RAM.
4. The interface as it appears to a client module must remain unchanged.
5. Your solution must be posted as a reply to this topic.
6. A maximum of two attempts per person are allowed.
7. If the execution time of two solutions are identical the prize will be awarded to the solution with the smallest generated code size.
8. If two solutions are identical in size and execution time the prize will be awarded to the one that was submitted earliest.
9. These conditions are subject to change if the need arises.
10. Any attempts considered to be cheating will be disqualified.
11. The judge's decision is final.


The closing time for entries is midnight GMT on 31st Dec 2014.

The following additional conditions apply to all entries received after 12 Noon GMT on 6 Dec 2014:
12. The generated code size of the compiled module must be no larger than the original.
13. No person can win more than one prize.
14. The program used to time the results is:

Code: Select all

MODULE QuizTimer;

IMPORT Out, Timer, Main, Quiz;

BEGIN
  Timer.Init(Timer.uSecs);
  Timer.Start();
  Quiz.Init();
  Out.Int(Timer.Elapsed(), 0); 
  Out.Ln
END QuizTimer.
Good luck!

Re: Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Sat Dec 06, 2014 12:06 pm
by cfbsoftware
Not exactly what I had in mind ;)

If nobody can beat Alex's time there will be a second prize of a $US50 Amazon Gift Voucher awarded to the person who submits the fastest module which as well as being faster than the original is also no bigger (code size) than the original.

I have also had to amend the rules - see below for details.

Re: Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Sat Dec 06, 2014 5:04 pm
by Alexander Shiryaev

Code: Select all

MODULE Quiz;

  VAR a1*, a2*: ARRAY 1000 OF INTEGER;
      
  PROCEDURE* Init*;
    VAR i: INTEGER;
  BEGIN i := 1000;
    REPEAT DEC(i);
      a1[i] := i;
      a2[i] := i
    UNTIL i = 0
  END Init;

END Quiz.

Re: Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Mon Dec 08, 2014 8:43 am
by pahihu
MODULE Quiz;

VAR
a1*, a2*: ARRAY 1000 OF INTEGER;

PROCEDURE* Init*;
CONST N = LEN(a1) - 1;
VAR i: INTEGER;
BEGIN
FOR i := 0 TO N DO
a1 := i;
a2 := i
END
END Init;

Re: Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Fri Dec 12, 2014 9:48 am
by dsar
I'm not sure if I'm qualified to partecipate because I don't have Astrobe and neither a platform to test the code.

Code: Select all

MODULE Quiz;

VAR
  a1*, a2*, init: ARRAY 1000 OF INTEGER;
  i: INTEGER;

PROCEDURE Init*;
BEGIN
  a1 := init;
  a2 := init
END Init;

BEGIN
  FOR i := 0 TO LEN(init) - 1 DO
    init[i] := i
  END
END Quiz.
The idea is to have an already initialized array (initialized during the initialization of the program), after that the other ones are initialized with a simple array assignment (that in ARM is efficient and fast)

Re: Oberon Competition - Win a $US50 Amazon Gift Voucher

Posted: Thu Jan 01, 2015 11:37 am
by cfbsoftware
The competition has now ended. For comparison purposes all of the entries were compiled using Astrobe for Cortex-M3 v5.2 and executed on an LPC1769 running @120MHz. The resulting times (in uSecs) and the code size (in bytes) for each of the entries in order of submission are:

Code: Select all

                            
Submitted by                Time              Size
Original                     695               160
Iljin                        115             24536
Shiryaev                     167                64
Pahihu                       194                72
Dsar                         167               188
Consequently, congratulations go to the two winners: AlexIljin (fastest) and Alexander Shiryaev (fastest/smallest). They will be contacted shortly to arrange delivery of their prizes.

However, there is at least one better solution in the fastest/smallest category: 126 uSecs/92 bytes. It takes advantage of the fact that it is more efficient to access array variables in leaf procedures via parameters rather than globals:

Code: Select all

MODULE Quiz;

  VAR a1*, a2*: ARRAY 1000 OF INTEGER;
      
  PROCEDURE* Run(VAR a1, a2: ARRAY OF INTEGER);
    VAR i: INTEGER;
  BEGIN i := LEN(a1);
    REPEAT DEC(i);
      a1[i] := i;
      a2[i] := i
    UNTIL i = 0
  END Run;

  PROCEDURE Init*;
  BEGIN
    Run(a1, a2);
  END Init;
  
END Quiz.