Levenshtein距离和OEIS(警察)


16

这是警察的帖子。该强盗后在这里


您的任务是采用整数输入N并按顺序OEIS A002942输出第N个数字。

该序列由向后写的平方数组成:

1, 4, 9, 61, 52, 63, 94, 46, 18, 1, 121, 441, ...

请注意,前导零被修剪掉了(100变为1,而不是001)。将其连接成一个字符串(或一个长数字给出):

1496152639446181121441

您应在此字符串/数字中输出第N个数字。您可以选择将N设为0索引或1索引(请说明您选择了哪一个)。

测试用例(1索引):

N = 1,      ==> 1
N = 5,      ==> 1
N = 17,     ==> 1   <- Important test case! It's not zero.
N = 20,     ==> 4
N = 78,     ==> 0
N = 100,    ==> 4

您的代码应适用于最大N = 2 ^ 15的数字(除非您的语言默认无法处理32位整数,在这种情况下N可以更低)。


警察:

您必须用相同的语言编写两个执行相同功能的函数/程序。您必须发布其中一个功能/程序,以及已编写的两个功能/程序之间的Levenshtein距离。Levenshtein距离以字符为单位(因此,加上两个字节的字符将得出LD = 1)。

未公开的代码不能超过原始解决方案的长度(但可以是相同大小)。强盗将尝试编写与您给定的Levenshtein距离完全相同的代码(只要它可以工作,它就可以与未公开的代码不同)。

获胜者将是Levenshtein距离最低的完整作品。

您可以在这里查看Levenshtein距离!


如果您提交的内容连续7天未破解,则可以显示您编写的替代代码并将其标记为安全。



是的,我将其添加到规则中。:)
Stewie Griffin's

您谈论脚本,但是我认为这是默认程序或函数
凯文·克鲁伊森

是的,默认为所有内容:)
Stewie Griffin's

您如何处理评论和空格,我看到了一些奇怪的东西。
魔术章

1
“您的代码应该适用于N = 2 ^ 15的数字”->但其中一个测试用例要大得多。274164盒是否必要?
汤姆·卡彭特

Answers:


6

LD = 13的Haskell 破裂

((snd.span(<'1').reverse.show.(^2)=<<[1..])!!)

在线尝试!

我仔细检查了前导零是否已修剪;)

说明:

                    [1..]     -- for each element in [1,2,3,4,5,...]
                 =<<          -- apply the following functions 
             (^2)             -- square [1,4,9,16,25,...]
           show.              -- convert to string ["1","4","9","16","25",...]
       reverse.               -- reverse ["1","4","9","61","52",...,"001",...]
   span(<'1').                -- split into leading zeros and remainder [("","1"),("","4"),...,("00","1"),...]
  snd.                        -- only keep remainder ["1","4","9","61","52",...,"1",...]
                              -- and concatenate the result "1496152..."
((                       )!!) -- index into the sequence


3

cQuents 0,LD = 1,破解

":\r$*$

在线尝试!

我以为这对前导零不起作用,但实际上可以-cQuents中的反向函数编码为int(reversed(str(n)))

说明

"         Concatenate sequence together, get nth term in the string instead of the sequence
 :        Mode: Sequence: given input n, output the nth term, 1-indexed
          Each term in the sequences equals:
  \r      reverse(
    $*$           the index * the index
                  or
    $$            the index * the index
                   ) (implicit)


@Laikoni是的,cQuents像Mathematica一样执行隐式乘法,但是您不需要空格。添加说明。
斯蒂芬

3

JavaScript(ES6),LD = 103(已破解

使用如此高的Levenshtein距离可能不是最佳策略,但是无论如何,让我们尝试一下。

n => { for(i = 0, str = ''; i <= n; i++) { str += +[...i * i + ''].reverse().join(''); } return str[n]; }

测试用例

预期的解决方案

$=>eval(atob`Wy4uLkFycmF5KCQrMSldLm1hcCgoXyxpKT0+K1suLi5pKmkrJyddLnJldmVyc2UoKS5qb2luYGApLmpvaW5gYFskXQ`)

编码部分:

[...Array($+1)].map((_,i)=>+[...i*i+''].reverse().join``).join``[$]

反转后该条带前导0吗?
Erik the Outgolfer

@EriktheOutgolfer是的。一元+可确保将反转的字符串强制为数字。
Arnauld

1
喔...哇,那比我想的要难。
魔术章鱼缸

破解
林恩

3

Python 2,104字节,LD = 21 无效且已破解

d=lambda y:y if'0'!=str(y)[-1]else d(y/10)
lambda n:''.join([str(d(x*x))[::-1]for x in range(1,n)])[n-1]

PS是否允许无限制的空白和注释?如果是这样,这将不难破解。


1
“未公开的代码不能超过原始解决方案。”
Khuldraeseth na'Barya

@Scrooble我看到了,但是我认为制作一个比这个短得多的程序并不困难。已经在python 3中完成了另一个回答,它已经在python 2中工作了,所以他们需要添加的只是一串\ns(大约50)
dylnan

50个换行符不会超过Levenshtein距离21吗?
Khuldraeseth na'Barya

@Scrooble您说得很对,我感到困惑,并且错误地考虑了该问题。谢谢
dylnan '17

1
输入低于5
Leo时

3

6502机器代码(C64),LD = 1(破解

00 C0 20 FD AE A0 00 99 5B 00 C8 20 73 00 90 F7 99 5B 00 A2 0B CA 88 30 09 B9
5B 00 29 0F 95 5B 10 F3 A9 00 95 5B CA 10 F9 A9 00 A0 03 99 69 00 88 10 FA A0
20 A2 76 18 B5 E6 90 02 09 10 4A 95 E6 E8 10 F4 A2 03 76 69 CA 10 FB 88 F0 11
A2 09 B5 5C C9 08 30 04 E9 03 95 5C CA 10 F3 30 D6 A2 03 B5 69 95 57 CA 10 F9
A9 01 85 FB A2 03 A9 00 95 FB CA D0 FB A2 03 B5 FB 95 22 95 26 CA 10 F7 A9 00
A2 03 95 69 CA 10 FB A0 20 A2 02 46 25 76 22 CA 10 FB 90 0C A2 7C 18 B5 AA 75
ED 95 ED E8 10 F7 A2 7D 06 26 36 AA E8 10 FB 88 10 DD A0 0B A9 00 99 5A 00 88
D0 FA A0 20 A2 09 B5 5C C9 05 30 04 69 02 95 5C CA 10 F3 06 69 A2 FD 36 6D E8
D0 FB A2 09 B5 5C 2A C9 10 29 0F 95 5C CA 10 F4 88 D0 D7 E0 0A F0 05 E8 B5 5B
F0 F7 09 30 99 5B 00 C8 E8 E0 0B F0 04 B5 5B 90 F1 88 B9 5B 00 C9 30 F0 F8 A2
7C 18 B5 DB E9 00 95 DB E8 10 F7 90 14 88 30 05 B9 5B 00 D0 EA A2 7C F6 7F D0
03 E8 10 F9 4C 73 C0 B9 5B 00 4C D2 FF

在线演示,用法:sys49152,n此处n为0索引输入。


对于最后一个测试用例,您需要一点耐心,因为这台性能不佳的机器必须进行数百万次的位移位和加法运算才能为您提供结果;)

这里的语言是机器代码,因此LD是以这种格式进行度量的-尽管如此,还是要从头开始,这是ca65汇编程序源代码中的程序:

NUMSIZE         = 4     ; 32 bit integers ...
NUMSTRSIZE      = 11    ; need up to 11 characters for 0-terminated string

.segment "ZPUSR": zeropage
v_x:            .res    NUMSIZE         ; next number to be squared

.segment "ZPFAC": zeropage
v_n:            .res    NUMSIZE         ; input index (0-based), counts down
nc_string:      .res    NUMSTRSIZE      ; string buffer for numbers

.segment "ZPTMP": zeropage
mpm_arg1:       .res    NUMSIZE         ; arg1 for multiplication
mpm_arg2:       .res    NUMSIZE         ; arg2 for multiplication

.segment "ZPFAC2": zeropage
mpm_res:        .res    NUMSIZE         ; numeric result (mult and str convert)

; load address for creating a C64 .PRG file:

.segment "LDADDR"
                .word   $c000

.code

; first read number from command argument and convert to unsigned
; integer in little-endian:

                jsr     $aefd
                ldy     #$00
rn_loop:        sta     nc_string,y
                iny
                jsr     $73
                bcc     rn_loop
                sta     nc_string,y
                ldx     #NUMSTRSIZE
stn_copybcd:    dex
                dey
                bmi     stn_fillzero
                lda     nc_string,y
                and     #$f
                sta     nc_string,x
                bpl     stn_copybcd
stn_fillzero:   lda     #$0
                sta     nc_string,x
                dex
                bpl     stn_fillzero
                lda     #$0
                ldy     #(NUMSIZE-1)
stn_znumloop:   sta     mpm_res,y
                dey
                bpl     stn_znumloop
                ldy     #(NUMSIZE*8)
stn_loop:       ldx     #($81-NUMSTRSIZE)
                clc
stn_rorloop:    lda     nc_string+NUMSTRSIZE+$80,x
                bcc     stn_skipbit
                ora     #$10
stn_skipbit:    lsr     a
                sta     nc_string+NUMSTRSIZE+$80,x
                inx
                bpl     stn_rorloop
                ldx     #(NUMSIZE-1)
stn_ror:        ror     mpm_res,x
                dex
                bpl     stn_ror
                dey
                beq     main
stn_sub:        ldx     #(NUMSTRSIZE-2)
stn_subloop:    lda     nc_string+1,x
                cmp     #$8
                bmi     stn_nosub
                sbc     #$3
                sta     nc_string+1,x
stn_nosub:      dex
                bpl     stn_subloop
                bmi     stn_loop

main:
                ldx     #(NUMSIZE-1)
argloop:        lda     mpm_res,x
                sta     v_n,x
                dex
                bpl     argloop
                lda     #$01
                sta     v_x
                ldx     #(NUMSIZE-1)
                lda     #$00
initxloop:      sta     v_x,x
                dex
                bne     initxloop

mainloop:

; prepare arguments for multiplication:

                ldx     #(NUMSIZE-1)
sqrargloop:     lda     v_x,x
                sta     mpm_arg1,x
                sta     mpm_arg2,x
                dex
                bpl     sqrargloop

; do multiplication:

                lda     #$00
                ldx     #(NUMSIZE-1)
mul_clearloop:  sta     mpm_res,x
                dex
                bpl     mul_clearloop
                ldy     #(NUMSIZE*8)
mul_loop:       ldx     #(NUMSIZE-2)
                lsr     mpm_arg1+NUMSIZE-1
mul_rorloop:    ror     mpm_arg1,x
                dex
                bpl     mul_rorloop
                bcc     mul_noadd
                ldx     #($80-NUMSIZE)
                clc
mul_addloop:    lda     mpm_arg2+NUMSIZE+$80,x
                adc     mpm_res+NUMSIZE+$80,x
                sta     mpm_res+NUMSIZE+$80,x
                inx
                bpl     mul_addloop
mul_noadd:      ldx     #($81-NUMSIZE)
                asl     mpm_arg2
mul_rolloop:    rol     mpm_arg2+NUMSIZE+$80,x
                inx
                bpl     mul_rolloop
                dey
                bpl     mul_loop

; convert result to string:

                ldy     #NUMSTRSIZE
                lda     #$0
nts_fillzero:   sta     nc_string-1,y
                dey
                bne     nts_fillzero
                ldy     #(NUMSIZE*8)
nts_bcdloop:    ldx     #(NUMSTRSIZE-2)
nts_addloop:    lda     nc_string+1,x
                cmp     #$5
                bmi     nts_noadd
                adc     #$2
                sta     nc_string+1,x
nts_noadd:      dex
                bpl     nts_addloop
                asl     mpm_res
                ldx     #($ff-NUMSIZE+2)
nts_rol:        rol     mpm_res+NUMSIZE,x       ; + $100 w/o zp wraparound
                inx
                bne     nts_rol
                ldx     #(NUMSTRSIZE-2)
nts_rolloop:    lda     nc_string+1,x
                rol     a
                cmp     #$10
                and     #$f
                sta     nc_string+1,x
nts_rolnext:    dex
                bpl     nts_rolloop
                dey
                bne     nts_bcdloop
nts_scan:       cpx     #(NUMSTRSIZE-1)
                beq     nts_copydigits
                inx
                lda     nc_string,x
                beq     nts_scan
nts_copydigits: ora     #$30
                sta     nc_string,y
                iny
                inx
                cpx     #(NUMSTRSIZE)
                beq     strip0loop
                lda     nc_string,x
                bcc     nts_copydigits

; search for first non-0 character from the end of the string:

strip0loop:     dey
                lda     nc_string,y
                cmp     #$30
                beq     strip0loop

; decrement n for each digit:

founddigit:
                ldx     #($80-NUMSIZE)
                clc
decnloop:       lda     v_n+NUMSIZE+$80,x
                sbc     #$00
                sta     v_n+NUMSIZE+$80,x
                inx
                bpl     decnloop
                bcc     foundresult

                dey
                bmi     next_x
                lda     nc_string,y
                bne     founddigit

; increment x to calculate next square number:

next_x:
                ldx     #($80-NUMSIZE)
incxloop:       inc     v_x+NUMSIZE-$80,x
                bne     incxdone
                inx
                bpl     incxloop
incxdone:       jmp     mainloop

foundresult:    lda     nc_string,y
                jmp     $ffd2

...这是链接器脚本 ld65

MEMORY {
  LDADDR: start = $bffe, size = 2;
  CODE: start = $c000, size = $1000;
  ZPTMP: start = $0022, size = $0008;
  ZPFAC: start = $0057, size = $000f;
  ZPFAC2: start = $0069, size = $0004;
  ZPUSR: start = $00fb, size = $0004;
}

SEGMENTS {
  LDADDR: load = LDADDR;
  CODE: load = CODE;
  ZPTMP: load = ZPTMP, type = zp;
  ZPFAC: load = ZPFAC, type = zp;
  ZPFAC2: load = ZPFAC2, type = zp;
  ZPUSR: load = ZPUSR, type = zp;
}

破解(我相信)
乔。

@乔 是的,已编辑。
菲利克斯·帕尔姆


2

Java 8,(177字节)LD = 92(@Arnauld破解

我已经使用了此在线LD计算器。

n->{String r="",t=r;for(int i=1,j;r.length()<=n+1;i++)if(Math.sqrt(i)%1==0){for(t="",j=(i+"").length();j>0;t+=(i+"").charAt(--j));r+=t.replaceAll("^0+","");}return r.charAt(n);}

如果您只是打高尔夫球,这可能不太难。:)

说明:

在这里尝试。

n->{                             // Method with integer parameter and character return-type
  String r="",                   //  Result-String, starting empty
         t=r;                    //  Temp-String, starting empty
  for(int i=1,j;                 //  Index-integers
      r.length()<=n+1;i++)       //  Loop (1) as long as the length is at least n+1
    if(Math.sqrt(i)%1==0){       //   If the current number `i` is a perfect square:
      for(t="",                  //    Reset the temp-String to empty
          j=(i+"").length();     //    Set `j` to the length of the current number
          j>0;                   //    Inner loop (2) as long as `j` is larger than 0
        t+=                      //     Append the temp-String with:
           (i+"").charAt(--j)    //     The digit of integer `i` at index `j-1`
                                 //     (by first decrease `j` with 1 with `--j`)
      );                         //    End of inner loop (2)
      r+=t                       //    And then append the temp-String to the result-String
          .replaceAll("^0+","");}//    after we've removed any leading zeroes
                                 //  End of loop (1) (implicit / single-line body)
  return r.charAt(n);            //  Return the `n`'th character of the result-String
}                                // End of method


意的解决方案:n->{String r="";for(int i=1;r.length()<=n+1;r+=new Long(new StringBuffer(i*i+++"").reverse()+""));return r.charAt(n);}118个字节,92 LD
凯文Cruijssen


2

6502机器代码(C64),LD = 1,安全

00 C0 20 FD AE A0 00 99 5B 00 C8 20 73 00 90 F7 99 5B 00 A2 0B CA 98 88 30 09
B9 5B 00 29 0F 95 5B 10 F2 95 5B CA 10 FB A0 20 A2 76 18 B5 E6 90 02 09 10 4A
95 E6 E8 10 F4 A2 03 76 69 CA 10 FB 88 F0 11 A2 09 B5 5C C9 08 30 04 E9 03 95
5C CA 10 F3 30 D6 A2 03 B5 69 95 57 CA 10 F9 A9 01 85 FB A2 03 A9 00 95 FB CA
D0 FB A2 03 B5 FB 95 22 95 26 CA 10 F7 A9 00 A2 03 95 69 CA 10 FB A0 20 A2 02
46 25 76 22 CA 10 FB 90 0C A2 7C 18 B5 AA 75 ED 95 ED E8 10 F7 A2 7D 06 26 36
AA E8 10 FB 88 10 DD A2 0B A9 00 95 5A CA D0 FB A0 20 A2 09 B5 5C C9 05 30 04
69 02 95 5C CA 10 F3 06 69 A2 FD 36 6D E8 D0 FB A2 09 B5 5C 2A C9 10 29 0F 95
5C CA 10 F4 88 D0 D7 E8 B5 5B F0 FB 09 30 99 5B 00 C8 E8 E0 0B F0 04 B5 5B 90
F1 88 B9 5B 00 C9 30 F0 F8 A2 7C 18 B5 DB E9 00 95 DB E8 10 F7 90 14 88 30 05
B9 5B 00 D0 EA A2 7C F6 7F D0 03 E8 10 F9 4C 68 C0 B9 5B 00 4C D2 FF

在线演示,用法:sys49152,n此处n为0索引输入。


预期解决方案:(差异)

 B9 5B 00 29 0F 95 5B 10 F2 95 5B CA 10 FB A0 20 A2 76 18 B5 E6 90 02 09 10 4A
-95 E6 E8 10 F4 A2 03 76 69 CA 10 FB 88 F0 11 A2 09 B5 5C C9 08 30 04 E9 03 95
+95 E6 E8 10 F4 A2 03 76 69 CA 10 FB 88 F0 11 A2 09 B5 5C C9 08 90 04 E9 03 95
 5C CA 10 F3 30 D6 A2 03 B5 69 95 57 CA 10 F9 A9 01 85 FB A2 03 A9 00 95 FB CA

30(操作码bmi)被替换为90(操作码bcc)。这对应于汇编器源代码中的以下部分:

stn_subloop:    lda     nc_string+1,x
                cmp     #$8
                bmi     stn_nosub       ; use bcc here for same result
                sbc     #$3
                sta     nc_string+1,x

之所以有效,是因为该代码检查数字是否小于8。该cmp指令为此执行减法运算,并相应地设置标志。因此,如果累加器保持的数字小于8,则该下溢,清除进位标志,因此正确的转移指令的确是bccbmi(在负数时分支)在原始代码中也一样,因为比较的数字足够小,所以$80-$ff当发生下溢时,相减的结果最终在负数范围()中。

在线演示


这是我以前提交的文章的改进/精简版本。在减少大小的其他技巧中,它删除了所包含的无用代码,并允许一种“简单” *)破解。总而言之,大小减小了16个字节。这次,要找到与LD 1等效的程序应该有点困难:)

*)当然,可能还有很多工作要做:)

再次,这是ca65汇编程序源,以帮助您开始使用代码:

NUMSIZE         = 4     ; 32 bit integers ...
NUMSTRSIZE      = 11    ; need up to 11 characters for 0-terminated string

.segment "ZPUSR": zeropage
v_x:            .res    NUMSIZE         ; next number to be squared

.segment "ZPFAC": zeropage
v_n:            .res    NUMSIZE         ; input index (0-based), counts down
nc_string:      .res    NUMSTRSIZE      ; string buffer for numbers

.segment "ZPTMP": zeropage
mpm_arg1:       .res    NUMSIZE         ; arg1 for multiplication
mpm_arg2:       .res    NUMSIZE         ; arg2 for multiplication

.segment "ZPFAC2": zeropage
mpm_res:        .res    NUMSIZE         ; numeric result (mult and str convert)

; load address for creating a C64 .PRG file:

.segment "LDADDR"
                .word   $c000

.code

; first read number from command argument and convert to unsigned
; integer in little-endian:

                jsr     $aefd
                ldy     #$00
rn_loop:        sta     nc_string,y
                iny
                jsr     $73
                bcc     rn_loop
                sta     nc_string,y
                ldx     #NUMSTRSIZE
stn_copybcd:    dex
                tya
                dey
                bmi     stn_fillzero
                lda     nc_string,y
                and     #$f
                sta     nc_string,x
                bpl     stn_copybcd
stn_fillzero:   sta     nc_string,x
                dex
                bpl     stn_fillzero
                ldy     #(NUMSIZE*8)
stn_loop:       ldx     #($81-NUMSTRSIZE)
                clc
stn_rorloop:    lda     nc_string+NUMSTRSIZE+$80,x
                bcc     stn_skipbit
                ora     #$10
stn_skipbit:    lsr     a
                sta     nc_string+NUMSTRSIZE+$80,x
                inx
                bpl     stn_rorloop
                ldx     #(NUMSIZE-1)
stn_ror:        ror     mpm_res,x
                dex
                bpl     stn_ror
                dey
                beq     main
stn_sub:        ldx     #(NUMSTRSIZE-2)
stn_subloop:    lda     nc_string+1,x
                cmp     #$8
                bmi     stn_nosub
                sbc     #$3
                sta     nc_string+1,x
stn_nosub:      dex
                bpl     stn_subloop
                bmi     stn_loop

main:
                ldx     #(NUMSIZE-1)
argloop:        lda     mpm_res,x
                sta     v_n,x
                dex
                bpl     argloop
                lda     #$01
                sta     v_x
                ldx     #(NUMSIZE-1)
                lda     #$00
initxloop:      sta     v_x,x
                dex
                bne     initxloop

mainloop:

; prepare arguments for multiplication:

                ldx     #(NUMSIZE-1)
sqrargloop:     lda     v_x,x
                sta     mpm_arg1,x
                sta     mpm_arg2,x
                dex
                bpl     sqrargloop

; do multiplication:

                lda     #$00
                ldx     #(NUMSIZE-1)
mul_clearloop:  sta     mpm_res,x
                dex
                bpl     mul_clearloop
                ldy     #(NUMSIZE*8)
mul_loop:       ldx     #(NUMSIZE-2)
                lsr     mpm_arg1+NUMSIZE-1
mul_rorloop:    ror     mpm_arg1,x
                dex
                bpl     mul_rorloop
                bcc     mul_noadd
                ldx     #($80-NUMSIZE)
                clc
mul_addloop:    lda     mpm_arg2+NUMSIZE+$80,x
                adc     mpm_res+NUMSIZE+$80,x
                sta     mpm_res+NUMSIZE+$80,x
                inx
                bpl     mul_addloop
mul_noadd:      ldx     #($81-NUMSIZE)
                asl     mpm_arg2
mul_rolloop:    rol     mpm_arg2+NUMSIZE+$80,x
                inx
                bpl     mul_rolloop
                dey
                bpl     mul_loop

; convert result to string:

                ldx     #NUMSTRSIZE
                lda     #$0
nts_fillzero:   sta     nc_string-1,x
                dex
                bne     nts_fillzero
                ldy     #(NUMSIZE*8)
nts_bcdloop:    ldx     #(NUMSTRSIZE-2)
nts_addloop:    lda     nc_string+1,x
                cmp     #$5
                bmi     nts_noadd
                adc     #$2
                sta     nc_string+1,x
nts_noadd:      dex
                bpl     nts_addloop
                asl     mpm_res
                ldx     #($ff-NUMSIZE+2)
nts_rol:        rol     mpm_res+NUMSIZE,x       ; + $100 w/o zp wraparound
                inx
                bne     nts_rol
                ldx     #(NUMSTRSIZE-2)
nts_rolloop:    lda     nc_string+1,x
                rol     a
                cmp     #$10
                and     #$f
                sta     nc_string+1,x
nts_rolnext:    dex
                bpl     nts_rolloop
                dey
                bne     nts_bcdloop
nts_scan:       inx
                lda     nc_string,x
                beq     nts_scan
nts_copydigits: ora     #$30
                sta     nc_string,y
                iny
                inx
                cpx     #(NUMSTRSIZE)
                beq     strip0loop
                lda     nc_string,x
                bcc     nts_copydigits

; search for first non-0 character from the end of the string:

strip0loop:     dey
                lda     nc_string,y
                cmp     #$30
                beq     strip0loop

; decrement n for each digit:

founddigit:
                ldx     #($80-NUMSIZE)
                clc
decnloop:       lda     v_n+NUMSIZE+$80,x
                sbc     #$00
                sta     v_n+NUMSIZE+$80,x
                inx
                bpl     decnloop
                bcc     foundresult

                dey
                bmi     next_x
                lda     nc_string,y
                bne     founddigit

; increment x to calculate next square number:

next_x:
                ldx     #($80-NUMSIZE)
incxloop:       inc     v_x+NUMSIZE-$80,x
                bne     incxdone
                inx
                bpl     incxloop
incxdone:       jmp     mainloop

foundresult:    lda     nc_string,y
                jmp     $ffd2

...这是以下链接器的脚本ld65

MEMORY {
  LDADDR: start = $bffe, size = 2;
  CODE: start = $c000, size = $1000;
  ZPTMP: start = $0022, size = $0008;
  ZPFAC: start = $0057, size = $000f;
  ZPFAC2: start = $0069, size = $0004;
  ZPUSR: start = $00fb, size = $0004;
}

SEGMENTS {
  LDADDR: load = LDADDR;
  CODE: load = CODE;
  ZPTMP: load = ZPTMP, type = zp;
  ZPFAC: load = ZPFAC, type = zp;
  ZPFAC2: load = ZPFAC2, type = zp;
  ZPUSR: load = ZPUSR, type = zp;
}

认为它没有裂痕:)
乔。

@乔 好吧,如果您坚持要说的话-非常感谢,我对此进行了编辑。
Felix Palmen '17





0

C ++,LD = 159

0索引,输入argv[1],在GCC 7.2.0上编译

#import<bits/stdc++.h>
char*h,b[1<<17],*q=b;int x,y;main(int,char**j){sscanf(j[1],"%d",&y);do{x++;q+=sprintf(h=q,"%d",x*x);while(*--q==48);std::reverse(h,++q);}while(q-b<=y);b[y+1]=0,printf(b+y);}

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.