Skip to main content
added 161 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 2020 19 bytes

l_$_W=),\0=i>_W<W%+=\ci>_W<W%+=

Test suite.Test suite.

Explanation

The basic idea is to find the minimum and maximum digit, then create a Giza number from those and then check that it's equivalent to the input.

l       e# Read input.
_$      e# Get a sorted copy of the input.
_W=     e# Get its last character, i.e. the maximum digit M.
),      e# Get a string with all characters from the null byte up to M.
\0=\c      e# Get the first character of the sorted string, i.e. the minimum
        e# character m.
i>      e# Convert to its character code and discard that many leading
        e# characters from the string we generated before. Now we've got
        e# a string with all digits from m to M, inclusive.
_W<W%+  e# Palindromise it, by appending a reversed copy without M.
=       e# Check that it's equal to the input.

Instead of the minimum character, we can also use the first character, for the same byte count:

l_:e>),1$ci>_W<W%+=

CJam, 20 bytes

l_$_W=),\0=i>_W<W%+=

Test suite.

Explanation

The basic idea is to find the minimum and maximum digit, then create a Giza number from those and then check that it's equivalent to the input.

l       e# Read input.
_$      e# Get a sorted copy of the input.
_W=     e# Get its last character, i.e. the maximum digit M.
),      e# Get a string with all characters from the null byte up to M.
\0=     e# Get the first character of the sorted string, i.e. the minimum
        e# character m.
i>      e# Convert to its character code and discard that many leading
        e# characters from the string we generated before. Now we've got
        e# a string with all digits from m to M, inclusive.
_W<W%+  e# Palindromise it, by appending a reversed copy without M.
=       e# Check that it's equal to the input.

CJam, 20 19 bytes

l_$_W=),\ci>_W<W%+=

Test suite.

Explanation

The basic idea is to find the minimum and maximum digit, then create a Giza number from those and then check that it's equivalent to the input.

l       e# Read input.
_$      e# Get a sorted copy of the input.
_W=     e# Get its last character, i.e. the maximum digit M.
),      e# Get a string with all characters from the null byte up to M.
\c      e# Get the first character of the sorted string, i.e. the minimum
        e# character m.
i>      e# Convert to its character code and discard that many leading
        e# characters from the string we generated before. Now we've got
        e# a string with all digits from m to M, inclusive.
_W<W%+  e# Palindromise it, by appending a reversed copy without M.
=       e# Check that it's equal to the input.

Instead of the minimum character, we can also use the first character, for the same byte count:

l_:e>),1$ci>_W<W%+=
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 20 bytes

l_$_W=),\0=i>_W<W%+=

Test suite.

Explanation

The basic idea is to find the minimum and maximum digit, then create a Giza number from those and then check that it's equivalent to the input.

l       e# Read input.
_$      e# Get a sorted copy of the input.
_W=     e# Get its last character, i.e. the maximum digit M.
),      e# Get a string with all characters from the null byte up to M.
\0=     e# Get the first character of the sorted string, i.e. the minimum
        e# character m.
i>      e# Convert to its character code and discard that many leading
        e# characters from the string we generated before. Now we've got
        e# a string with all digits from m to M, inclusive.
_W<W%+  e# Palindromise it, by appending a reversed copy without M.
=       e# Check that it's equal to the input.