Author Topic: [ENDED] Code Golf Contest #3  (Read 13242 times)

0 Members and 1 Guest are viewing this topic.

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Code Golf Contest #3
« Reply #15 on: July 31, 2014, 02:56:23 am »
I agree, the program shouldn't check for the range of the input and just give undefined results in those cases (in this case, input<2). The contest here is to see how small a program could be without giving an error in the valid input range.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Code Golf Contest #3
« Reply #16 on: August 02, 2014, 01:06:57 pm »
Only 3 more days for the contest! Submit your entries and challenge ideas now!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Code Golf Contest #3
« Reply #17 on: August 02, 2014, 01:22:04 pm »
Well, I'm going to be gone for a few days, so I'll post my suggestion for the next one now. I'm assuming no one else is going to post a perl solution.

It would go as follows:

For a given string input consisting of only uppercase letters and numbers, add the ASCII value of each alphabetical character (that's 65-90 for uppercase A-Z) and subtract every number. Display the result, but printed vertically with each digit on a new line.

You CAN end up with a negative number, in which case the first line should have a - sign.

Example:
Input: "A45FTUX"
Internal Math: (65 - 4 - 5 + 70 + 84 + 85 + 88 = 383)
Output:
3
8
3

A negative example:
Input: 99A874512995
Internal math:(-9-9+65-8-7-4-5-1-2-9-9-5)
Output:
-
3

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Code Golf Contest #3
« Reply #18 on: August 02, 2014, 04:22:20 pm »
Nice challenge! I might use it. I already have a 140 byte solution in TI-BASIC, assuming ENTER must be pressed after each digit, and the numbers and negative sign are aligned to the right.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline willrandship

  • Omnimagus of the Multi-Base.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2953
  • Rating: +98/-13
  • Insert sugar to begin programming subroutine.
    • View Profile
Re: Code Golf Contest #3
« Reply #19 on: August 02, 2014, 06:08:36 pm »
I don't know about pressing enter after every key. I'm pretty sure I specified a string for input...:P Better pull out that sub( command.

Aligning to the right is fine, as long as it's vertical.

FWIW I have a 75 byte perl version.

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Code Golf Contest #3
« Reply #20 on: August 02, 2014, 09:03:05 pm »
I don't know about pressing enter after every key. I'm pretty sure I specified a string for input...:P Better pull out that sub( command.

Aligning to the right is fine, as long as it's vertical.

FWIW I have a 75 byte perl version.

And I do have a string for input. It's just, for displaying the final numbers...
Eh, I'll show you:
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Code Golf Contest #3
« Reply #21 on: August 03, 2014, 07:14:56 pm »
Bump.

Last day for submissions! Be swift with any works in progress!
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?

Offline 3298

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +1/-0
    • View Profile
Re: Code Golf Contest #3
« Reply #22 on: August 04, 2014, 05:58:30 am »
Now I want to see the competing entries in Java and Haskell. I especially want to know how I could have saved more space in Java. It's probably the number input - I parsed a command-line parameter using Integer.parseInt.
Also:
Quote from: JWinslow23
SysRPL
RankUserSizeDate
1329859.5 (don't ask me why; I'm going off of what he said)7/31/2014 5:18:48 PM
:evillaugh: That half-byte comes from the 4-bit processor SysRPL is designed for. Many things there have odd sizes, and when you have an odd number of nibbles, you get ... you guessed it, half bytes.

In case anyone wants to check it, you'll need to set up an emulator and install a development tool on it. The remaining part of the post is a tutorial for that.
A ready-to-use emulator comes with the free Windows-based IDE Debug4x (get it at http://www.debug4x.com/). The emulator is in the subdirectory "Emu" of the installation directory. Start it, and it will ask for a KML script. This defines the look of the emulator, the key positions, and a few other things. The pre-installed KML script "Eric's Real 50G" should do the trick. I don't know whether the emulator only shows the screen afterwards (haven't used it in a while), but if it does, search the menus at the top for the option to show the entire calculator. The first step with the calculator should be to switch it to RPN mode (answer the "Try to recover memory?" question with No (the F6 key), confirm the "Memory cleared" message with ENTER, press the MODE key, then the +/- key, and finally the ENTER key).
Next step: SysRPL development stuff. The compiler is already installed, you just have to unlock it. But you need something providing the names of commands, otherwise you can only use UserRPL commands or nameless pointers. A library providing the names is called "extable". I'm using the one from http://www.hpcalc.org/details.php?id=3940 (there is a file called "extable2.lib" in that archive, that's the right one). Drag the file into the emulator's screen, and something should appear behind the "1:". You just put the library on the stack. Now push the 0 and press ENTER. The library shifts up to level 2 of the stack, and the 0 appears on level 1. Now press the STO key. The stack should be empty now. Press and hold (this is done by right-clicking on the button instead of left-clicking) the ON key, and push C. This reboots the calculator and finishes the library installation. Now, unlock the compiler. Enter this without the quotes: "256 ATTACH". Don't forget to press the ENTER key at the end to execute the command. (Edit: I forgot to mention that you need to know how to enter the space here. In the bottom row you find a key labeled SPC, that's the space key.)
Now everything is set up. For ease of use, start the text editor this way: Put an empty string on the stack (the double quotes you need for that are present as a shifted function of the multiplication key), then press the down arrow. Enter the source code I gave you (Alpha-lock can be done with two presses on the Alpha key, a third press disables Alpha mode again). If you are missing a few special characters, use the char browser (CHARS is a shifted function of a key in the fourth row; be sure to disable alpha-lock before). Due to some weird requirement from the compiler, the last two chars must be a newline and an @ char, so add these. ENTER exits the editor and replaces the empty string on the stack with the contents of the editor. If you need to edit it again, the down arrow key puts you back in the editor.
Now we compile the source. Simply issue the ASM command with the source on stack level 1. If there are no errors, the source will be replaced by the compiled code (which looks like "FlashPtr External External ..." - that's perfectly normal). With the compiled code on level 1, you can check its size with the BYTES command (takes any object on level 1, gives a checksum on level 2 and the size in bytes on level 1). Or you can give it a parameter (enter the number on the stack, followed by the SWAP command to put it above the program) and run the program with the EVAL key. If you want to do both, these commands are helpful: DUP pushes a duplicate of level 1 (use this to avoid having to enter the source twice), DROP drops level 1, and CLEAR drops everything.
Be extra careful when running the program, no parameters or parameters of the wrong type will crash the calculator because I omitted the necessary checks for that. The input number must be an infinite-precision integer in this case, which is printed and entered as simply a number. Real numbers have a period somewhere, and they are not accepted.
« Last Edit: August 04, 2014, 06:12:01 am by 3298 »

Offline JWinslow23

  • Coder Of Tomorrow
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 556
  • Rating: +43/-6
  • I make quality calculator games...when I have time
    • View Profile
Re: Code Golf Contest #3
« Reply #23 on: August 04, 2014, 05:38:29 pm »
Thanks for the clarification.

And now, the contest is over! The results are in the OP, and the newest contest is here.
Did you know that "Ammonia Gas" rearranged is "As Omnimaga"?
Click here for the only set of games you'll ever need
= ?