Here's my solution in Redcode:
org newcand base equ 10 limit equ 100 tries equ 50 stack dat 0 happy dat 1 cand dat 0 total dat 0 repeat dat 0 newcand mov.ba happy, cand mov #tries, repeat again mov #-1, total digits mov.ab cand, cand mod #base, cand div.a #base, cand mul.b cand, cand add.b cand, total jmn.a digits, cand jmz found, total mov.ba total, cand add.a #1, cand djn again, repeat nexthap seq #limit, happy jmp newcand, >happy dat 0 found mov.b happy, <stack writen mov.b @stack, <stack div #10, >stack mod #10, @stack add #48, @stack jmn writen, <stack add #1, stack wloop sts >stack, 0 jmn wloop, stack sts.a #10, 0 jmp nexthap
No comments:
Post a Comment