-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecret-entrance.tex
More file actions
97 lines (82 loc) · 2.29 KB
/
Copy pathsecret-entrance.tex
File metadata and controls
97 lines (82 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
\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}
% \tt
% 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
% Pointing \the\position.
\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
% (\the\position)
\fi
\ifcontinue
\repeat
% Finally close the file
\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}