紧凑/短数字范围表示

紧凑/短数字范围表示

我搜索了一下,但找不到一个包来以紧凑/简短的形式生成数字范围。里面siunitx有一个\numrange命令,但这个功能似乎不存在。

解释:我想要一个类似\numberrange宏的东西,具有以下示例结果:

\numberrange{10}{20}     % result: 10--20
\numberrange{941}{948}   % result: 941--8
\numberrange{1001}{1020} % result: 1001--20
\numberrange{1001}{1200} % result: 1001--200
\numberrange{1001}{2001} % result: 1001--2001

换句话说,在范围的第二部分,只显示不同的数字。这是许多科学期刊中页面范围的常见表示...

如果已经准备好做这件事,那将为我节省一些重要的时间。

答案1

这是一个基于 LuaLaTeX 的解决方案。它提供了一个名为 的 LaTeX 宏\numberrange,该宏调用一个名为 的 Lua 函数numberrange来完成大部分工作。

默认情况下,\numberrange打印短划线右侧最少需要的数字;这可能最少为 1。如果您希望始终显示至少最后 2 位数字 -- 例如,如果您想要\numberrange{941}{948}返回“941-48”而不是“941-8” -- 您可以利用这个事实:该\numberrange宏带有一个可选参数,即要显示的最小数字。可选参数的默认值为 1。要输出“941--48”,您可以这样写\numberrange[2]{941}{948}

最后几点说明:

  • 的参数\numberange不必是整数常量;只要是评价按照Lua的语法规则转换为整数。

  • 如果两个必需参数\numberrange相等,\numberrange则打印一个数字(因为数字范围很简单)。如果第一个必需参数大于第二个,则宏会打印“哎呀!我又做了一次。”——参见这个答案寻找更短的替代方案——因为,大概,用户实际上并不想使用减少数字范围。

  • 没有执行真正强大的输入健全性检查。的参数\numberrange应该全部为正整数。如果不是这样,那么 Lua 函数将如何或何时崩溃就无从谈起了。换句话说,我假设的用户\numberrange是功能强大且负责任的人。我相信这并不算过分。


在此处输入图片描述

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{luacode} % for 'luacode' environment
\begin{luacode}
function numberrange ( m , x , y )
  local nx , ny , z
  
  -- Minimalist input sanity checks
  if x>y then return ( "Oops! I did it again." ) 
  elseif x==y then return ( x ) end  
  
  -- Convert x and y to string variables
  x  = tostring ( x )
  nx = #x
  y  = tostring ( y )
  ny = #y

  -- Initialize the output string variable
  z = y    

  -- Enter the recursion only if lengths of x and y are equal
  if ny == nx then 
    for i = 1 , nx-m do
       if x:sub ( i , i ) == y:sub ( i , i ) then
          z = z:sub ( 2 )      -- Drop the leading digit
       else
          break -- Terminate the for loop
       end
    end
  end

  -- Return the formatted result
  return ( x .. "--" .. z )
end
\end{luacode}

% LaTeX front-end macro takes 3 arguments; first arg is optional
\newcommand\numberrange[3][1]{\directlua{tex.sprint(numberrange(#1,#2,#3))}}

\begin{document}

\begin{tabular}{@{} ll @{}}
Input & Output \\
\hline
\verb+\numberrange{1}{1}+          & \numberrange{1}{1}    \\
\verb+\numberrange{1}{12}+         & \numberrange{1}{12}   \\
\verb+\numberrange{10}{20}+        & \numberrange{10}{20}  \\[0.75ex]
\verb+\numberrange{941}{948}+      & \numberrange{941}{948}      \\
\verb+\numberrange[2]{941}{948}+   & \numberrange[2]{941}{948}   \\
\verb+\numberrange{941}{959}+      & \numberrange{941}{959}      \\[0.75ex]
\verb+\numberrange[2]{1001}{1007}+ & \numberrange[2]{1001}{1007} \\
\verb+\numberrange{1001}{1021}+    & \numberrange{1001}{1021}    \\
\verb+\numberrange{1001}{1201}+    & \numberrange{1001}{1201}    \\
\verb+\numberrange{1001}{2001}+    & \numberrange{1001}{2001}    \\[0.75ex]
\verb+\numberrange{10}{5}+         & \numberrange{100}{99}
\end{tabular}

\end{document}

答案2

首先检查数字的长度是否不同,如果不同,则打印两者,不截断。否则,开始递归检查前几个数字,如果相等,则删除它们并重新开始,否则打印剩余部分。

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\numberrange}{mm}
 {
  \jander_numberrange:nn { #1 } { #2 }
 }

\cs_new_protected:Nn \jander_numberrange:nn
 {
  #1-- % print the first number and the dash
  \int_compare:nTF { \str_count:n { #1 } = \str_count:n { #2 } }
   {% equal number of digits
    \__jander_numberrange_strip:nn { #1 } { #2 }
   }
   {% different number of digits
    #2
   }
 }

\cs_new_protected:Nn \__jander_numberrange_strip:nn
 {
  \str_if_eq:eeTF { \str_head:n { #1 } } { \str_head:n { #2 } }
   {% equal digits, repeat
    \__jander_numberrange_strip:ee { \tl_tail:n { #1 } } { \tl_tail:n { #2 } }
   }
   {% different digits, print the rest
    #2
   }
 }
\cs_generate_variant:Nn \__jander_numberrange_strip:nn { ee }

\ExplSyntaxOff

\begin{document}

\begin{tabular}{ll}
Output & Expected \\
\hline
\numberrange{1}{12} & 1--12 \\
\numberrange{10}{20} & 10--20 \\
\numberrange{941}{948} & 941--8 \\
\numberrange{1001}{1020} & 1001--20 \\
\numberrange{1001}{1200} & 1001--200 \\
\numberrange{1001}{2001} & 1001--2001
\end{tabular}

\end{document}

在此处输入图片描述

可以添加一个测试来检验第二个数字是否大于第一个数字或者它们是否相同(在这种情况下只打印一个):

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\numberrange}{mm}
 {
  \int_compare:nTF { #1 <= #2 }
   {
    \jander_numberrange:nn { #1 } { #2 }
   }
   {Oops}
 }

\cs_new_protected:Nn \jander_numberrange:nn
 {
  #1 % print the first number and do nothing in case of equal numbers
  \int_compare:nF { #1 = #2 }
   {% print the dash
    --
    % check the numbers
    \int_compare:nTF { \str_count:n { #1 } = \str_count:n { #2 } }
     {% equal number of digits
      \__jander_numberrange_strip:nn { #1 } { #2 }
     }
     {% different number of digits
      #2
     }
   }
 }

\cs_new_protected:Nn \__jander_numberrange_strip:nn
 {
  \str_if_eq:eeTF { \str_head:n { #1 } } { \str_head:n { #2 } }
   {% equal digits, repeat
    \__jander_numberrange_strip:ee { \tl_tail:n { #1 } } { \tl_tail:n { #2 } }
   }
   {% different digits, print the rest
    #2
   }
 }
\cs_generate_variant:Nn \__jander_numberrange_strip:nn { ee }

\ExplSyntaxOff

\begin{document}

\begin{tabular}{ll}
Output & Expected \\
\hline
\numberrange{1}{1} & 1 \\
\numberrange{1}{12} & 1--12 \\
\numberrange{10}{20} & 10--20 \\
\numberrange{941}{948} & 941--8 \\
\numberrange{1001}{1020} & 1001--20 \\
\numberrange{1001}{1200} & 1001--200 \\
\numberrange{1001}{2001} & 1001--2001 \\
\numberrange{100}{99} & Oops
\end{tabular}

\end{document}

在此处输入图片描述

这是另一个版本,其中可以使用可选参数来设置第二部分的最小位数,灵感来自Mico 的回答

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\numberrange}{O{\c_max_int}mm}
 {
  \int_compare:nTF { #2 <= #3 }
   {
    \jander_numberrange:nnn { #1 } { #2 } { #3 }
   }
   {Oops}
 }

\cs_new_protected:Nn \jander_numberrange:nnn
 {% #1 = minimum number of digits in the second part
  % #2 = first number
  % #3 = second number
  #2 % print the first number and do nothing in case of equal numbers
  \int_compare:nF { #2 = #3 }
   {% print the dash
    --
    % check the numbers
    \int_compare:nTF { \str_count:n { #2 } = \str_count:n { #3 } }
     {% equal number of digits
      \__jander_numberrange_strip:nnn { #1 } { #2 } { #3 }
     }
     {% different number of digits
      #2
     }
   }
 }

\cs_new_protected:Nn \__jander_numberrange_strip:nnn
 {
  \bool_lazy_and:nnTF
   {% equal first digits
    \str_if_eq_p:ee { \str_head:n { #2 } } { \str_head:n { #3 } }
   }
   {% and number of digits greater than the minimum
    ! \int_compare_p:n { \tl_count:n { #3 } = #1 }
   }
   {% repeat
    \__jander_numberrange_strip:nee { #1 } { \tl_tail:n { #2 } } { \tl_tail:n { #3 } }
   }
   {% different digits, print the rest
    #3
   }
 }
\cs_generate_variant:Nn \__jander_numberrange_strip:nnn { nee }

\ExplSyntaxOff

\begin{document}

\begin{tabular}{ll}
Output & Expected \\
\hline
\numberrange{1}{1} & 1 \\
\numberrange{1}{12} & 1--12 \\
\numberrange{10}{20} & 10--20 \\
\numberrange{941}{948} & 941--8 \\
\numberrange[2]{941}{948} & 941--48 \\
\numberrange{1001}{1020} & 1001--20 \\
\numberrange[3]{1001}{1020} & 1001--020 \\
\numberrange{1001}{1200} & 1001--200 \\
\numberrange{1001}{2001} & 1001--2001 \\
\numberrange{100}{99} & Oops
\end{tabular}

\end{document}

在此处输入图片描述

答案3

#1编辑以处理 MWE 中的最后四种情况,包括和中的数字位数#2不同的情况以及的情况#1=#2

\documentclass{article}
\newcommand\numberrange[2]{#1--%
  \ifnum\numexpr0\countem#1\relax=\numexpr0\countem#2\relax\relax
    \ifnum#1=#2\relax
      #2%
    \else
      \striprange#1\relax#2\relax
    \fi  
  \else
    #2%
  \fi}
\def\striprange#1#2\relax#3#4\relax{%
  \ifnum#1=#3\relax\striprange#2\relax#4\relax\else#3#4\fi}
\def\countem#1#2\relax{+1%
  \if\relax#2\relax\else\countem#2\relax\fi}
\begin{document}
\numberrange{10}{20}     % result: 10--20

\numberrange{941}{948}   % result: 941--8

\numberrange{1001}{1020} % result: 1001--20

\numberrange{1001}{1200} % result: 1001--200

\numberrange{1001}{2001} % result: 1001--2001

\numberrange{1}{12}

\numberrange{11}{11}

\numberrange{11}{112}

\numberrange{11}{122}
\end{document}

在此处输入图片描述

答案4

为了好玩1 我写了一段繁琐的代码。

\numberrange{⟨amount of digits of 2nd number that shall at least be printed⟩}%
            {⟨1st number⟩}%
            {⟨2nd number⟩}

该例程的主循环是\UD@numberrangeloop

主循环\UD@numberrangeloop根据以下模式处理参数:

\UD@numberrangeloop{⟨least significant digit of 1st number not processed yet⟩}%
                   ⟨remaining digits of 1st number in reversed order⟩\bizarre
                   {⟨least significant digit of 2nd number not processed yet⟩}%
                   ⟨remaining digits of 2nd number in reversed order⟩\bizarre
                   {⟨2nd number, all digits in correct order⟩}%
                   {⟨amount of m corresponding to difference of amount of digits of 2nd number that shall at least be printed and digits gathered so far⟩}%
                   {⟨to-be printed digits of 2nd number gathered so far⟩}%
                   {⟨digits of 2nd number that need to be added to ⟨digits of 2nd number gathered so far⟩ if another pair of differing digits is found⟩}%
                   {⟨\@firstoftwo\@secondofto/\@secondoftwo\@firstoftwo - "flag" denoting whether collecting different digits or collecting equal digits⟩}%

\UD@numberrangeloop是一个循环,将第一个数字与第二个数字进行比较,从这些数字的最低有效数字开始,以这些数字的最高有效数字结束:

只要遇到不同的数字,第二个数字就会添加到⟨迄今为止收集到的第二个数字的待打印位数⟩
如果遇到相等的数字,循环将切换到将相等的数字添加到如果发现另一对不同的数字,则⟨需要添加到⟨到目前为止收集到的第二个数字的待打印数字⟩的第二个数字的数字⟩
只要遇到相同的数字,第二个数字就会被添加到如果发现另一对不同的数字,则⟨需要添加到⟨到目前为止收集到的第二个数字的待打印数字⟩的第二个数字的数字⟩
如果再次遇到不同的数字,如果发现另一对不同的数字,则⟨需要添加到⟨到目前为止收集到的第二个数字的待打印数字⟩的第二个数字的数字⟩添加到⟨迄今为止收集到的第二个数字的待打印位数⟩并且循环切换到收集不同的数字。

当处理完组成范围的数字之一的所有数字时,循环结束。

  • 如果由此得出两个数字的数字序列长度不同,则⟨第二个数字,所有数字顺序正确⟩已送达。

  • 如果由此得出第二个数字的数字序列比第一个数字的数字序列短,则将前导零添加到⟨目前已收集到的第二个数字⟩以确保两个数字序列的长度相等。

    否则,您无法区分
       “从 1002 到 1005”意义上的 1002--5

       “从 1002 向下到 5”意义上的 1002--5
    但您可以:在进一步的情况下,您得到:
       1002--5,意思是“从 1002 到 1005”
    在后一种情况下,您得到:
       1002--0005,意思是“从 1002 向下到 5”

第一个数左边的减号表示两个数都是负数。在这种情况下,第二个数的数位被省略。
第一个数左边的减号和右边的加号表示第一个数为负数,而第二个数为正数。在这种情况下,没有数位被省略。
仅在右边的数上有一个减号表示第一个数为正数,而第二个数为负数。在这种情况下,没有数位被省略。

如果⟨第一个数字⟩⟨第二个数字⟩位数少于 ⟨至少应打印第二个数字的位数⟩, 然后 ⟨至少应打印第二个数字的位数⟩不遵守,并且两个数字都打印所有数字。如果第二个数字的数字序列比第一个数字的数字序列短,则将第二个数字的前导零添加至该数字,以确保两个数字序列的长度相等。

\errorcontextlines=10000
\makeatletter
\@ifdefinable\UD@stopromannumeral{\chardef\UD@stopromannumeral=`\^^00}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
\newcommand\UD@Exchange[2]{#2#1}%


\newcommand\UD@plus{\ifvmode\leavevmode\fi\lower-.2\ht\strutbox\hbox{$\scriptscriptstyle(\kern-.15em+\kern-.15em)$}}
\newcommand\UD@minus{\ifvmode\leavevmode\fi\lower-.2\ht\strutbox\hbox{$\scriptscriptstyle(\kern-.15em-\kern-.15em)$}}

\newcommand\numberrange[3]{%
  \romannumeral
  \expandafter\UD@PassFirstToSecond\expandafter{\romannumeral\number\number#1 000}{%
    \expandafter\UD@PassFirstToSecond\expandafter{\number#3}{%
      \expandafter\UD@PassFirstToSecond\expandafter{\number#2}{%
         \UD@Initializenumberrangeloop
      }%
    }%
  }%
}%
\@ifdefinable\UD@reverseargloop{%
  \long\def\UD@reverseargloop#1#2\bizarre#3{%
    \ifcat$#2$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {\UD@Exchange{#3{}{}\bizarre}}{\UD@reverseargloop#2\bizarre{#1#3}}%
  }%
}%
\newcommand\UD@extractfirstcomponent[1]{%
  \UD@@extractfirstcomponent#1{}\bizarre
}%
\@ifdefinable\UD@@extractfirstcomponent{%
  \long\def\UD@@extractfirstcomponent#1#2\bizarre{#1}%
}%
\newcommand\UD@Initializenumberrangeloop[3]{%
  \expandafter\UD@Exchange\expandafter{%
    \romannumeral
    \if-\UD@extractfirstcomponent{#1}\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {%
      \if-\UD@extractfirstcomponent{#2}\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
      {%
        \expandafter\UD@PassFirstToSecond\expandafter{\@firstoftwo{}#2}{%
          \expandafter\UD@reverseargloop\@firstoftwo{}#2{}{}\bizarre{}{%
            \expandafter\UD@reverseargloop\@firstoftwo{}#1{}{}\bizarre{}{%
               \UD@numberrangeloop
            }%
          }%
        }{#3}{}{}{\@secondoftwo\@firstoftwo}%
      }{%
        \ifnum#2=0 \expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
        {%
          \expandafter\UD@stopromannumeral\expandafter-\expandafter-\romannumeral
          \expandafter\UD@leadingzeros\expandafter{\romannumeral\UD@reduce{#1}{-#2}}%
        }{%
          \UD@stopromannumeral--\UD@plus
        }%
        #2%
      }%
    }{%
      \if-\UD@extractfirstcomponent{#2}\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
      {%
        \@firstoftwo{\UD@stopromannumeral--\UD@minus}#2%
      }{%
        \UD@reverseargloop#2{}{}\bizarre{}{%
          \UD@reverseargloop#1{}{}\bizarre{}{%
             \UD@numberrangeloop
          }%
        }{#2}{#3}{}{}{\@secondoftwo\@firstoftwo}%
      }%
    }%
  }{%
   \if-\UD@extractfirstcomponent{#1}\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
   {%
     \UD@stopromannumeral\@firstoftwo\UD@minus#1%
   }{\UD@stopromannumeral#1}%
  }%
}%
\newcommand\UD@leadingzeros[1]{%
  \ifcat$#1$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {\UD@stopromannumeral}%
  {\expandafter\UD@leadingzeros\expandafter{\@firstoftwo{}#1}0}%
}%
\newcommand\UD@reduce[2]{%
  \ifcat$#1$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
  {\UD@stopromannumeral}{%
    \ifcat$#2$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {%
       \UD@stopromannumeral#1%
    }{%
       \expandafter\UD@PassFirstToSecond\expandafter{\@firstoftwo{}#2}{%
       \expandafter\UD@reduce\expandafter{\@firstoftwo{}#1}}%
    }%
  }%
}%
\@ifdefinable\UD@pumpup{%
  \long\def\UD@pumpup#1#2#3#4\bizarre{%
    \ifcat$#1$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi    
    {\UD@stopromannumeral--#2}{%
      \ifcat$#4$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi    
      {\UD@stopromannumeral--#2}%
      {\expandafter\UD@pumpup\expandafter{\@firstoftwo{}#1}{#3#2}#4\bizarre}%
    }%
  }%
}%
\@ifdefinable\UD@numberrangeloop{%
  \long\def\UD@numberrangeloop#1#2\bizarre#3#4\bizarre#5#6#7#8#9{%
    \ifcat$#2$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
    {%
      \ifcat$#4$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
      {%
        \ifcat$#7$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
        {%
          \UD@stopromannumeral
        }{%
          \UD@reverseargloop#8{}{}\bizarre{}{%
            \expandafter\UD@stopromannumeral
            \romannumeral
            \UD@pumpup{#6}{#7}%
          }%
        }%
      }{%
        \UD@stopromannumeral
        --#5%
      }%
    }{%
      \ifcat$#4$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
      {%
        \expandafter\UD@stopromannumeral\expandafter-\expandafter-\romannumeral
        \expandafter\UD@leadingzeros\expandafter{\@firstoftwo{}#2}#5%
      }{%
        \if#1#3\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
        #9%
        {% 
          \@firstoftwo#9{%
            \UD@numberrangeloop#1#2\bizarre#3#4\bizarre{#5}{#6}{#7}{}{\@secondoftwo\@firstoftwo}%
          }{%
            \expandafter\UD@PassFirstToSecond\expandafter{\romannumeral\UD@reduce{#6}{#8}}{%
              \UD@numberrangeloop#1#2\bizarre#3#4\bizarre{#5}}{#8#7}{}{\@firstoftwo\@secondoftwo}%
          }%
        }{%
          \@firstoftwo#9{%
            \ifcat$#6$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
            {\UD@PassFirstToSecond{}}%
            {\expandafter\UD@PassFirstToSecond\expandafter{\@firstoftwo{}#6}}%
            {\UD@numberrangeloop#2\bizarre#4\bizarre{#5}}{#3#7}{#8}{#9}%
          }{%
            \UD@numberrangeloop#2\bizarre#4\bizarre{#5}{#6}{#7}{#3#8}{#9}%
          }%
        }%
      }%
    }%
  }%
}%

\makeatother

\documentclass{article}

\begin{document}


\begin{tabular}{@{} ll @{}}
Input & Output \\
\hline
\verb+\numberrange{1}{1}{1}+          & \numberrange{1}{1}{1}    \\
\verb+\numberrange{1}{0}{0}+          & \numberrange{1}{0}{0}    \\
\verb+\numberrange{1}{1}{12}+         & \numberrange{1}{1}{12}   \\
\verb+\numberrange{1}{10}{20}+        & \numberrange{1}{10}{20}  \\
\verb+\numberrange{0}{0}{-948}+       & \numberrange{0}{0}{-948}      \\
\verb+\numberrange{0}{-948}{0}+       & \numberrange{0}{-948}{0}      \\
\verb+\numberrange{0}{0}{948}+        & \numberrange{0}{0}{948}      \\
\verb+\numberrange{0}{948}{0}+        & \numberrange{0}{948}{0}      \\
\verb+\numberrange{20}{941}{48}+     & \numberrange{20}{941}{48}      \\
\verb+\numberrange{20}{941}{8}+     & \numberrange{20}{941}{8}      \\
\verb+\numberrange{0}{941}{48}+     & \numberrange{0}{941}{48}      \\
\verb+\numberrange{0}{941}{8}+     & \numberrange{0}{941}{8}      \\
\verb+\numberrange{0}{-941}{948}+     & \numberrange{0}{-941}{948}      \\
\verb+\numberrange{0}{941}{-948}+     & \numberrange{0}{941}{-948}      \\
\verb+\numberrange{0}{-941}{-948}+    & \numberrange{0}{-941}{-948}      \\
\verb+\numberrange{0}{-948}{-941}+    & \numberrange{0}{-948}{-941}      \\
\verb+\numberrange{0}{948}{941}+      & \numberrange{0}{948}{941}      \\
\verb+\numberrange{0}{941}{948}+      & \numberrange{0}{941}{948}      \\
\verb+\numberrange{1}{941}{948}+      & \numberrange{1}{941}{948}      \\
\verb+\numberrange{2}{941}{948}+      & \numberrange{2}{941}{948}   \\
\verb+\numberrange{3}{941}{948}+      & \numberrange{3}{941}{948}   \\
\verb+\numberrange{4}{941}{948}+      & \numberrange{4}{941}{948}   \\
\verb+\numberrange{1}{941}{959}+      & \numberrange{1}{941}{959}      \\
\verb+\numberrange{1}{1001}{1007}+    & \numberrange{1}{1001}{1007} \\
\verb+\numberrange{1}{1001}{1021}+    & \numberrange{1}{1001}{1021}    \\
\verb+\numberrange{1}{1001}{1201}+    & \numberrange{1}{1001}{1201}    \\
\verb+\numberrange{1}{1001}{2001}+    & \numberrange{1}{1001}{2001}    \\
\verb+\numberrange{1}{10}{5}+         & \numberrange{1}{10}{5}           \\
\verb+\numberrange{1}{100}{99}+       & \numberrange{1}{100}{99}       \\
\verb+\numberrange{1}{-10}{-15}+         & \numberrange{1}{-10}{-15}           \\
\verb+\numberrange{1}{-10}{-5}+         & \numberrange{1}{-10}{-5}           \\
\verb+\numberrange{1}{-10}{5}+         & \numberrange{1}{-10}{5}           \\
\verb+\numberrange{1}{10}{-5}+         & \numberrange{1}{10}{-5}           \\
\verb+\numberrange{1}{-100}{-99}+       & \numberrange{1}{-100}{-99}       \\
\verb+\numberrange{1}{100100100}{200100100}+       & \numberrange{1}{100100100}{200100100}       \\
\verb+\numberrange{1}{234100234}{123100123}+       & \numberrange{1}{234100234}{123100123}       \\
\verb+\numberrange{1}{200100100}{200100100}+       & \numberrange{1}{200100100}{200100100}       \\
\verb+\numberrange{1}{-200100100}{-200100100}+       & \numberrange{1}{-200100100}{-200100100}       \\
\end{tabular}

\end{document}

在此处输入图片描述


1我说“为了好玩”,因为——让我们面对现实吧——与所有其他解决方案相比,我的这段代码太长且令人困惑,以至于任何人都不适合在日常生活中使用它。我写它更多的是出于顽固的固执:其他解决方案首先考虑高阶数字。我想看到探索到的所有可能性,一个首先考虑低阶数字的解决方案。;-)

相关内容