CS 202 - "Runlong" contest results (HW 3, problem 1d)

Newest results :
  1. 41,099 steps - Gabby Beaulieu
  2. 30,072 steps - Kai DeLorenzo
  3. 25,468 steps - Guanghan Pan (a)
  4. 24,310 steps - Guanghan Pan (b)
  5. 10,177 steps - Roger Dai
Join the fun! New entries accepted anytime!


The Runlong Hall of Fame (> 10,000 steps)

  1. 41,099 steps - Gabby Beaulieu - Spring 2018
  2. 30,072 steps - Kai DeLorenzo - Spring 2018
  3. 28,622 steps - Chris Matteri - Fall 2012
  4. 25,468 steps - Guanghan Pan - Spring 2018
  5. 20,258 steps - Scott Wehrwein - Spring 2011
  6. 20,065 steps - Carrick Detweiler - Spring 2002
  7. 18,036 steps - Dan Chan - Fall 2012
  8. 14,786 steps - Aaron Kano-Bower - Fall 2012
  9. 13,225 steps - Daniel Leiter - Fall 2003
  10. 12,769 steps - Tim Bahls - Fall 2004
  11. 12,194 steps - Tianxiao Wang - Fall 2007
  12. 11,545 steps - Graeme Conell - Spring 2002
  13. 10,177 steps - Roger Dai - Spring 2018
The Ultimate Runlong Hall of Fame (> 10,000 steps with initially random memory and accumulator):
  1. 30,072 steps - Kai DeLorenzo - Spring 2018
  2. 28,622 steps - Chris Matteri - Fall 2012
  3. 24,310 steps - Guanghan Pan - Spring 2018
  4. 17,474 steps - Scott Wehrwein - Spring 2011
  5. 14,786 steps - Aaron Kano-Bower - Fall 2012


Original results:

Most of you submitted correct solutions for the runlong problem, that is, programs that run for at least 25 steps without encountering a "bneg" instruction and stop by executing the "halt" command. A few others either executed a "bneg" instruction, had the IC overflow past 0x1f, or went into an infinite loop. Some tried to provide more than 24 instructions, but recall that the entire program needs to fit into the 24 bytes of ROM. The programs that worked correctly and ran for at least 25 steps are:

2875 steps #1 tianxingd.hex          31 steps  zeinhorn.hex
2429 steps    schar2.hex             31 steps  tianshengs.hex
1731 steps #2 gpan.hex               31 steps  pfricke.hex
 961 steps #3 elneary.hex            31 steps  eemerson.hex
 326 steps    schar1.hex             31 steps  ascannell.hex
 189 steps #4 roehmler.hex           31 steps  aronoh.hex
 149 steps #5 mingfangz.hex          31 steps  angulumbi.hex
  91 steps    mczekanski.hex         31 steps  afarley.hex
  90 steps    gbeaulieu.hex          30 steps  tmonaco.hex
  75 steps    cbintz.hex             30 steps  mvangemeren.hex
  51 steps    hmound.hex             30 steps  mpolito.hex
  49 steps    cbirdsey.hex           30 steps  bchoe.hex
  47 steps    hevans.hex             29 steps  csutton.hex
  45 steps    abaskin.hex            27 steps  nalbers.hex
  44 steps    cblondin.hex           26 steps  cdiprinzio.hex	
  39 steps    kevinc.hex             25 steps  zlevitt.hex	
  32 steps    sjordan.hex            25 steps  nroleary.hex	
  32 steps    mbock.hex              25 steps  kristines.hex	
  32 steps    lfriedrich.hex         25 steps  jravishankar.hex	
  32 steps    jenglish.hex           25 steps  fsullivan.hex	
  32 steps    enakagawa.hex          25 steps  batwood.hex	
				     25 steps  aturcios.hex     

Congratulations to all, and especially to Roger, Guanghan, Emma, Trey, and Melody, the top five finishers of the first round of the contest, all of whom achieved over 100 steps. Guanghan and Emma beat my own entry schar1.hex, and Roger even beat my entry schar2.hex! :)

There are many ways to solve this problem, but all involve writing "self-modifying code". That is, your program has to store some instructions in RAM and then execute them. In the simplest case the program stores the instruction "halt" in the last byte of RAM (0x1f) as follows:

0: 0x82  b 2         /* jump around the next instruction */
1: 0xff              /* the opcode for halt - not executed */
2: 0x01  ld A, 1     /* load the opcode for halt... */
3: 0x7f  st A, 0x1f  /* ...and store it at the end of RAM */

This program runs for 31 steps (assuming the RAM is initially all 0, which you should not generally assume). Most steps execute opcode 0x00, i.e., the "harmless" opcode "ld A, 0". To get 32 steps you have to disguise the data (i.e., the halt opcode) using instructions, for example as the difference of two harmless opcodes. To run for more than 32 steps, you need to implement some sort of self-modifying loop. There are many possibilities, including the following two:


Contest extension!

Now that you see what's possible, and also have an idea of how it could be done, can you beat the current front-runner, and perhaps make it into the "runlong hall of fame" (> 10,000 steps)?

I'll accept new entries anytime, for the rest of the semester. Simply email me the text file with the opcodes in hex.