Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- \documentclass{article}
- \usepackage{ifthen}
- \usepackage{tikz}
- \newif\ifcontinue
- \makeatletter
- \newcount\parselinenumber
- \def\parseline#1{%
- \expandafter\parseline@i#1\relax
- }
- \def\parseline@i#1#2\relax{%
- \def\firstchar{#1}%
- \edef\numberpart{#2}%
- \parselinenumber=#2\relax
- }
- \begin{document}
- % Open the file
- \newread\myfile
- % \openin\myfile=example.txt
- \openin\myfile=input.txt
- % Read it
- \newtoks\content
- \newcount\position
- \newcount\tmp
- \position=50
- \newcount\onzero
- \onzero=0
- \newcount\overzero
- \overzero=0
- \newcount\nbtour
- \continuetrue
- \loop
- \read\myfile to \content
- \ifeof\myfile
- \continuefalse
- \else
- \parseline{\content}
- % I have read \content.
- % The chart is \firstchar, and the number is \numberpart.
- \def\Lchar{L}%
- \tmp=\the\position
- \pgfmathsetcount{\nbtour}{\numberpart/100}
- \advance\overzero by \nbtour
- \ifx\firstchar\Lchar
- % I avance by \numberpart.
- \advance \position by -\numberpart
- \pgfmathsetcount{\position}{\position+100*\nbtour}
- \else
- % I recule by \numberpart.
- \advance \position by \numberpart
- \pgfmathsetcount{\position}{\position-100*\nbtour}
- \fi
- \ifnum\position>100 % If we make one tour by going over 100
- \advance\overzero by 1
- \fi
- \ifnum\position<0 % If we make one tour by going unver 0
- \ifnum\tmp>0 % But only if we were not on 0 at previous step
- \advance\overzero by 1
- \fi
- \fi
- \pgfmathsetcount{\position}{Mod(\the\position,100)}
- \ifnum\position=0
- \advance\onzero by 1
- \advance\overzero by 1
- \fi
- \fi
- \ifcontinue
- \repeat
- \closein\myfile
- Part I : \the\onzero.
- Part II: \the\overzero.
- \vspace{\baselineskip}
- For part II, this should be optimized...
- What I'm doing here is count how many time we make full round, and adjust the position accordingly, then I treat the case if we are still over 100 or under 0.
- If we are still over 100, it is that we have one one more round, and then we count 1. If we are under 0, there are two cases : either we left from 0 (stored in \textbackslash\texttt{tmp}), and then did not pass over 0, either note, and then we pass one more time.
- \end{document}
Advertisement
Add Comment
Please, Sign In to add comment