EXAPUNKS
评价数不足
EVEN OR ODD? (SPLIT NUMBERS INTO EVEN AND ODD.)
   
奖励
收藏
已收藏
取消收藏
文件大小
发表于
1.731 KB
2019 年 2 月 21 日 下午 4:36
1 项改动说明 ( 查看 )

订阅以下载
EVEN OR ODD? (SPLIT NUMBERS INTO EVEN AND ODD.)

描述
Split the numbers in your Inbox (file 200) into even and odd, creating a new file in the respective hosts. The numbers must be sorted in ascending order. Leave no trace.


This is a fairly simple challenge. My personal best is 45 lines of code, but can you do better?
11 条留言
Xenofix 2023 年 1 月 20 日 下午 4:43 
I liked that little challenge. After small optimization for cycles I've got 1580/60/39
Trobby 2021 年 6 月 2 日 上午 4:45 
Something that i thought was incredibly simple, turned out to be quite complex due to the nuances of the file structure, like everything being unsorted. Very cool.
Do name your hosts in english please. I kept getting confused whether dispari was odd or even, and putting in the wrong links.

Cycles 1717, size 78, activity 71
LINK 800
LINK 3
MAKE;400 EVEN
DROP
LINK -1
LINK -3
MAKE;401 ODD
DROP
LINK -1

GRAB 200
MARK LOOP
COPY F M
TEST EOF
FJMP LOOP
COPY -9999 M
KILL
DROP
;SORT
MODE
REPL ODD

;EVEN
LINK -3
GRAB 401
REPL WRITE
JUMP SORT

MARK ODD
LINK 3
GRAB 400
REPL WRITE

;SORT
MARK SORT
TEST F < X
FJMP SORTNEXT
SEEK -1
COPY F X
MARK SORTNEXT
TEST EOF
FJMP SORT
;I FORGOT WHERE IS IT
SEEK -9999
MARK FINDAGAIN
TEST F = X
FJMP FINDAGAIN
SEEK -1
VOID F
COPY X M
SEEK -9999
TEST EOF
TJMP DONE
COPY F X
TEST EOF
FJMP SORT
COPY X M
MARK DONE
KILL
WIPE
HALT


MARK WRITE
MAKE
MARK WRITELOOP
COPY M F
JUMP WRITELOOP
flowflow 2019 年 8 月 26 日 下午 8:55 
@visualrob: General idea is to have an incrementing counter X from -100 up to 401, which covers the range of all possible test case numbers. Two empty files, 400 and 401 are created. The counter is compared and REPLed with all entries in the file - if a match is found, the REPLed EXA doesn't crash and writes to the end of either 400 or 401 depending on its parity.

When the whole file is read, the counter is incremented by 1 and a test is done if X < 401. This serves two purpose: first to differentiate 400 and 401, and secondly to crash the EXA when 401 is reached. GRAB X is then used and the test result between 400/401 tells it to link to the correct host output.

LINK 800
COPY -100 X
MAKE
DROP
MAKE
DROP
GRAB 200

MARK START
TEST F = X
REPL WRITER
TEST EOF
FJMP START
TEST X < 401
REPL END
ADDI X 1 X
SEEK -9999
TJMP START

MARK END
GRAB X
MULI 6 T T
SUBI T 3 T
LINK T

;====

MARK WRITER
DIVI T T T
MODI X 2 T
ADDI 400 T T
GRAB T
SEEK 9999
COPY X F
RevengeFromMars 2019 年 8 月 26 日 下午 1:07 
I used 123 lines of code and 2013 cycles. I almost never optimize for fewest lines of code. Well, unless I'm playing TIS-100 and I'm forced to. ;-) In real life, faster code almost always makes more sense than smaller code.

The PARI/DISPARI was no problem. If I can solve Zachtronics games, I can figure stuff like that out. ;-)
visualrob  [作者] 2019 年 8 月 26 日 下午 12:29 
@flowflow: is there a way to look at your solution? It would be very instructive!
visualrob  [作者] 2019 年 8 月 26 日 下午 12:28 
@RevengeFromMars: "leave no trace" means you have to leave everything as it was at the start. Since you start with the file 200 in the INBOX, you have to leave it there (otherwise people will know you meddled with it).

How many lines of code did it take?

PS: Sorry for "PARI" and "DISPARI", I didn't notice I left them in Italian :)
zapakh 2019 年 8 月 19 日 上午 7:36 
You can always use the SHOW GOAL button if in doubt about which files should end up where.
RevengeFromMars 2019 年 8 月 18 日 上午 11:44 
I figured it out - apparently I wasn't supposed to delete the original file? Isn't that "leaving a trace"?
RevengeFromMars 2019 年 8 月 18 日 上午 11:38 
I'm confused - I've done exactly as required, creating the even file in "pari" and the odd one in "dispari", no other files or EXAs remain, yet I'm not being credited with a win because "leave no trace" isn't checked. Am I supposed to put the two files somewhere else?
flowflow 2019 年 8 月 9 日 上午 7:40 
A little better in size: down to 62763/29/3.