Guest User

Untitled

a guest
Dec 4th, 2025
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 2.05 KB | None | 0 0
  1. \documentclass{article}
  2. \usepackage{ifthen}
  3. \usepackage{tikz}
  4. \newif\ifcontinue
  5. \makeatletter
  6. \newcount\parselinenumber
  7. \def\parseline#1{%
  8. \expandafter\parseline@i#1\relax
  9. }
  10. \def\parseline@i#1#2\relax{%
  11. \def\firstchar{#1}%
  12. \edef\numberpart{#2}%
  13. \parselinenumber=#2\relax
  14. }
  15.  
  16. \begin{document}
  17.  
  18. % Open the file
  19. \newread\myfile
  20. % \openin\myfile=example.txt
  21. \openin\myfile=input.txt
  22. % Read it
  23. \newtoks\content
  24.  
  25. \newcount\position
  26. \newcount\tmp
  27. \position=50
  28. \newcount\onzero
  29. \onzero=0
  30. \newcount\overzero
  31. \overzero=0
  32. \newcount\nbtour
  33.  
  34.  
  35. \continuetrue
  36. \loop
  37. \read\myfile to \content
  38. \ifeof\myfile
  39. \continuefalse
  40. \else
  41. \parseline{\content}
  42. % I have read \content.
  43. % The chart is \firstchar, and the number is \numberpart.
  44. \def\Lchar{L}%
  45. \tmp=\the\position
  46. \pgfmathsetcount{\nbtour}{\numberpart/100}
  47. \advance\overzero by \nbtour
  48. \ifx\firstchar\Lchar
  49. % I avance by \numberpart.
  50. \advance \position by -\numberpart
  51. \pgfmathsetcount{\position}{\position+100*\nbtour}
  52. \else
  53. % I recule by \numberpart.
  54. \advance \position by \numberpart
  55. \pgfmathsetcount{\position}{\position-100*\nbtour}
  56. \fi
  57. \ifnum\position>100 % If we make one tour by going over 100
  58. \advance\overzero by 1
  59. \fi
  60. \ifnum\position<0 % If we make one tour by going unver 0
  61. \ifnum\tmp>0 % But only if we were not on 0 at previous step
  62. \advance\overzero by 1
  63. \fi
  64. \fi
  65. \pgfmathsetcount{\position}{Mod(\the\position,100)}
  66. \ifnum\position=0
  67. \advance\onzero by 1
  68. \advance\overzero by 1
  69. \fi
  70. \fi
  71. \ifcontinue
  72. \repeat
  73. \closein\myfile
  74.  
  75. Part I : \the\onzero.
  76. Part II: \the\overzero.
  77.  
  78. \vspace{\baselineskip}
  79. For part II, this should be optimized...
  80. 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.
  81.  
  82. 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.
  83. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment