Skip to main content
Shortened by 2 characters, updated explanation; added 62 characters in body
Source Link

M (MUMPS) - 7272 70

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TRW:r=+r*r'=i*'$TR(i,0689),i'=r,r=+r W "."

Most built-in commands and functions in M have abbreviated versions. I've used the full names below.

READ n - Read a string from the keyboard and store it in n.

FOR i=0:1:n - Loop from zero to n, incrementing i by 1 each time. (The remainder of the line constitutes the body of the loop.)

WRITE !,i - Print a newline followed by the value of i.

SET r=$TRANSLATE($REVERSE(i),69,96)) - Reverse i, replace nines with sixes and sixes with nines, and store that in r

IF - Exactly what it sounds like (multiple comma-separated arguments are ANDed together).

'$TRANSLATEWRITE:r=+r*r'=i*'$TRANSLATE(i,0689) - Remove all zeros, sixes, eights, and nines from i, and see if there's anything left (' "." is the logical negation operator)

i'=r - Check that i isn't the same as it's flipped version r

  • : - Denotes a postconditional expression, so the WRITE command is only executed if r=+r*r'=i*'$TRANSLATE(i,0689) evaluates to a truthy value.
  • r=+r - Check that r doesn't have a leading zero. The unary + operator converts a string to a number, which strips leading zeroes if there are any.
  • * - Multiplication operator. M has no order of operations; all binary operators are evaluated in the order they appear from left to right.
  • r'=i - Check that i isn't the same as it's flipped version r.
  • '$TRANSLATE(i,0689) - Remove all zeros, sixes, eights, and nines from i, and check that there's nothing left. (' is the logical negation operator.)
  • "." - Finally the argument to the WRITE command (a literal string).

r=+r - Check that r doesn't haveEdit: Made it a leading zero. The unary +little shorter by abusing the multiplication operator converts a string to a number, which strips leading zeroes if there are any. Previous version:

WRITE "." - Print a dot.

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TR(i,0689),i'=r,r=+r W "."

M (MUMPS) - 72

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TR(i,0689),i'=r,r=+r W "."

Most built-in commands and functions in M have abbreviated versions. I've used the full names below.

READ n - Read a string from the keyboard and store it in n

FOR i=0:1:n - Loop from zero to n, incrementing i by 1 each time

WRITE !,i - Print a newline followed by the value of i

SET r=$TRANSLATE($REVERSE(i),69,96)) - Reverse i, replace nines with sixes and sixes with nines, and store that in r

IF - Exactly what it sounds like (multiple comma-separated arguments are ANDed together)

'$TRANSLATE(i,0689) - Remove all zeros, sixes, eights, and nines from i, and see if there's anything left (' is the logical negation operator)

i'=r - Check that i isn't the same as it's flipped version r

r=+r - Check that r doesn't have a leading zero. The unary + operator converts a string to a number, which strips leading zeroes if there are any.

WRITE "." - Print a dot.

M (MUMPS) - 72 70

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) W:r=+r*r'=i*'$TR(i,0689) "."

Most built-in commands and functions in M have abbreviated versions. I've used the full names below.

READ n - Read a string from the keyboard and store it in n.

FOR i=0:1:n - Loop from zero to n, incrementing i by 1 each time. (The remainder of the line constitutes the body of the loop.)

WRITE !,i - Print a newline followed by the value of i.

SET r=$TRANSLATE($REVERSE(i),69,96)) - Reverse i, replace nines with sixes and sixes with nines, and store that in r.

WRITE:r=+r*r'=i*'$TRANSLATE(i,0689) "."

  • : - Denotes a postconditional expression, so the WRITE command is only executed if r=+r*r'=i*'$TRANSLATE(i,0689) evaluates to a truthy value.
  • r=+r - Check that r doesn't have a leading zero. The unary + operator converts a string to a number, which strips leading zeroes if there are any.
  • * - Multiplication operator. M has no order of operations; all binary operators are evaluated in the order they appear from left to right.
  • r'=i - Check that i isn't the same as it's flipped version r.
  • '$TRANSLATE(i,0689) - Remove all zeros, sixes, eights, and nines from i, and check that there's nothing left. (' is the logical negation operator.)
  • "." - Finally the argument to the WRITE command (a literal string).

Edit: Made it a little shorter by abusing the multiplication operator. Previous version:

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TR(i,0689),i'=r,r=+r W "."
Source Link

M (MUMPS) - 72

R n F i=0:1:n W !,i S r=$TR($RE(i),69,96) I '$TR(i,0689),i'=r,r=+r W "."

Most built-in commands and functions in M have abbreviated versions. I've used the full names below.

READ n - Read a string from the keyboard and store it in n

FOR i=0:1:n - Loop from zero to n, incrementing i by 1 each time

WRITE !,i - Print a newline followed by the value of i

SET r=$TRANSLATE($REVERSE(i),69,96)) - Reverse i, replace nines with sixes and sixes with nines, and store that in r

IF - Exactly what it sounds like (multiple comma-separated arguments are ANDed together)

'$TRANSLATE(i,0689) - Remove all zeros, sixes, eights, and nines from i, and see if there's anything left (' is the logical negation operator)

i'=r - Check that i isn't the same as it's flipped version r

r=+r - Check that r doesn't have a leading zero. The unary + operator converts a string to a number, which strips leading zeroes if there are any.

WRITE "." - Print a dot.