Created
January 23, 2021 10:13
-
-
Save zr-tex8r/2c6d03da847f4189b85e353ac717486e to your computer and use it in GitHub Desktop.
昇順の整数のリストが複数あったとき、それらの共通部分を抜き出すやつ(わかりにくい)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN | |
\newif\ifxx@ok | |
\newcommand*\xxLetIntersectionTo[2]{% | |
\let\xx@ret\relax | |
\@tfor\xx@l:=#2\do{% | |
\ifx\xx@ret\relax \edef\xx@ret{\xx@l}% | |
\else \xx@intersect@two \fi}% | |
\let#1\xx@ret} | |
\def\xx@head#1#2{\edef\xx@next{\noexpand\xx@head@a#2}\xx@next\relax#1} | |
\def\xx@head@a#1#2\relax#3{\def#3{#1}} | |
\def\xx@drop#1{\edef\xx@next{\noexpand\xx@drop@a{#1}}\xx@next#1} | |
\def\xx@drop@a#1{\expandafter\xx@drop@b\expandafter{\@gobble#1}} | |
\def\xx@drop@b#1#2{\def#2{#1}} | |
\def\xx@intersect@two{% | |
\let\xx@la\xx@ret \edef\xx@lb{\xx@l}\let\xx@ret\@empty\xx@oktrue | |
\@whilesw\ifxx@ok\fi{% | |
\ifx\xx@la\@empty \xx@okfalse | |
\else\ifx\xx@lb\@empty \xx@okfalse | |
\else \xx@head\xx@hda\xx@la \xx@head\xx@hdb\xx@lb | |
\ifnum\xx@hda<\xx@hdb \xx@drop\xx@la | |
\else\ifnum\xx@hda>\xx@hdb \xx@drop\xx@lb | |
\else \edef\xx@ret{\xx@ret{\xx@hda}}\xx@drop\xx@la \xx@drop\xx@lb | |
\fi\fi | |
\fi\fi}} | |
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END | |
\def\listA{{1}{2}{3}{4}{5}{6}{8}} | |
\def\listB{{1}{4}{8}} | |
\def\listC{{1}{2}{8}} | |
\xxLetIntersectionTo\listR{\listA\listB\listC} | |
\show\listR %==>{1}{8} | |
\stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment