Skip to main content
Commonmark migration
Source Link

#APL (24)

APL (24)

{(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A}

This is a function that takes a string and returns two values, the value and the base.

      {(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A} 'DEADBEEF'
3735928559 16

Explanation:

  • ⎕D,⎕A: digits followed by letters
  • D←⍵⍳⍨: store in D the 1-based index of each character of ⍵ in the string of digits followed by letters
  • B←⌈/D: store in B the highest value in D. (which is the base to use)
  • (B⊥D-1): subtract 1 from each value in D (making them the values of the digits), and decode them as a base-B number.

#APL (24)

{(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A}

This is a function that takes a string and returns two values, the value and the base.

      {(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A} 'DEADBEEF'
3735928559 16

Explanation:

  • ⎕D,⎕A: digits followed by letters
  • D←⍵⍳⍨: store in D the 1-based index of each character of ⍵ in the string of digits followed by letters
  • B←⌈/D: store in B the highest value in D. (which is the base to use)
  • (B⊥D-1): subtract 1 from each value in D (making them the values of the digits), and decode them as a base-B number.

APL (24)

{(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A}

This is a function that takes a string and returns two values, the value and the base.

      {(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A} 'DEADBEEF'
3735928559 16

Explanation:

  • ⎕D,⎕A: digits followed by letters
  • D←⍵⍳⍨: store in D the 1-based index of each character of ⍵ in the string of digits followed by letters
  • B←⌈/D: store in B the highest value in D. (which is the base to use)
  • (B⊥D-1): subtract 1 from each value in D (making them the values of the digits), and decode them as a base-B number.
Source Link
marinus
  • 31.2k
  • 7
  • 71
  • 112

#APL (24)

{(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A}

This is a function that takes a string and returns two values, the value and the base.

      {(B⊥D-1),B←⌈/D←⍵⍳⍨⎕D,⎕A} 'DEADBEEF'
3735928559 16

Explanation:

  • ⎕D,⎕A: digits followed by letters
  • D←⍵⍳⍨: store in D the 1-based index of each character of ⍵ in the string of digits followed by letters
  • B←⌈/D: store in B the highest value in D. (which is the base to use)
  • (B⊥D-1): subtract 1 from each value in D (making them the values of the digits), and decode them as a base-B number.