-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02-no-math.tex
More file actions
100 lines (84 loc) · 2.13 KB
/
Copy path02-no-math.tex
File metadata and controls
100 lines (84 loc) · 2.13 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
98
99
100
\documentclass{article}
\usepackage{xparse}
\newcommand{\minThree}[3]{%
\ifnum#1<#2
\ifnum#1<#3
#1
\else
#3
\fi
\else
\ifnum#2<#3
#2
\else
#3
\fi
\fi
}
\newcounter{resultI}
\newcounter{resultII}
\newcounter{minArea}
\newcounter{minPerimeter}
\newcounter{paper}
\newcounter{ribbon}
\newcommand{\calculateAndSetCounter}[1]{%
% Split the string at 'x' and convert each part to a number
\def\temp##1x##2x##3\relax{%
\newcount\l
\newcount\w
\newcount\h
\l=##1
\w=##2
\h=##3
\newcount\areaOne
\newcount\areaTwo
\newcount\areaThree
\newcount\perimeterOne
\newcount\perimeterTwo
\newcount\perimeterThree
\newcount\volume
%
\areaOne=\numexpr\l*\w\relax
\areaTwo=\numexpr\w*\h\relax
\areaThree=\numexpr\h*\l\relax
%
\perimeterOne=\numexpr 2*\l + 2*\w \relax
\perimeterTwo=\numexpr 2*\w + 2*\h \relax
\perimeterThree=\numexpr 2*\h + 2*\l \relax
\volume=\numexpr \l*\w*\h \relax
%
% Here: \the\l, \the\w, \the\h\par
\setcounter{minArea}{\minThree{\the\areaOne}{\the\areaTwo}{\the\areaThree}}
\setcounter{minPerimeter}{\minThree{\the\perimeterOne}{\the\perimeterTwo}{\the\perimeterThree}}
\setcounter{resultI}{\numexpr 2*\l*\w + 2*\w*\h + 2*\h*\l + \theminArea \relax}%
\setcounter{resultII}{\numexpr \theminPerimeter + \the\volume \relax}%
}%
% Expand the argument before calling \temp
\expandafter\temp#1\relax
% \theresultI,%
}
\ExplSyntaxOn
% variables
\ior_new:N \g__sergiokapone_count_ior
\int_new:N \l__sergiokapone_count_int
% user level commands
\NewDocumentCommand{\wrappingPaper}{ m }
{
\ior_open:Nn \g__sergiokapone_count_ior {#1}
\ior_map_inline:Nn \g__sergiokapone_count_ior
{
\int_incr:N \l__sergiokapone_count_int
\calculateAndSetCounter{##1}
\addtocounter{paper}{\theresultI}
\addtocounter{ribbon}{\theresultII}
% Cumulative~total:~\thepaper\par
}
Part~1:~\thepaper\par
Part~2:~\theribbon\par
}
\ExplSyntaxOff
\begin{document}
Day 2: I Was Told There Would Be No Math
% \wrappingPaper{example.txt}
\wrappingPaper{input.txt}
\end{document}