Skip to main content
added 496 characters in body
Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

K (ngn/k), 37 bytes

{+/x{{(a~&\a)|a~|\a:10\x}(1+)/x+1}\0}

Try it online!

{ } is a function with argument x

x{ }\0 applies the {} on 0 x times, preserving the intermediate results

(1+) is the successor function

{ }(1+)/x+1 applies the successor function starting from x+1 until the {} returns true

10\x are the decimal digits of x

a: assign to a

|\ is the max-scan (partial maxima) of a

&\ analogously, is the min-scan

a~|\a does a match its max-scan?

| or

a~&\a its min-scan?

+/ sum

K (ngn/k), 37 bytes

{+/x{{(a~&\a)|a~|\a:10\x}(1+)/x+1}\0}

Try it online!

K (ngn/k), 37 bytes

{+/x{{(a~&\a)|a~|\a:10\x}(1+)/x+1}\0}

Try it online!

{ } is a function with argument x

x{ }\0 applies the {} on 0 x times, preserving the intermediate results

(1+) is the successor function

{ }(1+)/x+1 applies the successor function starting from x+1 until the {} returns true

10\x are the decimal digits of x

a: assign to a

|\ is the max-scan (partial maxima) of a

&\ analogously, is the min-scan

a~|\a does a match its max-scan?

| or

a~&\a its min-scan?

+/ sum

Source Link
ngn
  • 15.3k
  • 2
  • 43
  • 87

K (ngn/k), 37 bytes

{+/x{{(a~&\a)|a~|\a:10\x}(1+)/x+1}\0}

Try it online!