-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem31.cmd
More file actions
109 lines (78 loc) · 1.76 KB
/
Problem31.cmd
File metadata and controls
109 lines (78 loc) · 1.76 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
101
102
103
104
105
106
107
108
109
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Project Euler Problem 31
:: How many different ways can £2 be made using any number of coins?
SET _P=200
CALL :200Pence %_P% _Result
ECHO:%_Result%
GOTO :EOF
:200Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-200,0) DO (
CALL :100Pence %%G _100Count
SET /A _Count+=_100Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:100Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-100,0) DO (
CALL :50Pence %%G _50Count
SET /A _Count+=_50Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:50Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-50,0) DO (
CALL :20Pence %%G _20Count
SET /A _Count+=_20Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:20Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-20,0) DO (
CALL :10Pence %%G _10Count
SET /A _Count+=_10Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:10Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-10,0) DO (
CALL :5Pence %%G _5Count
SET /A _Count+=_5Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:5Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
FOR /L %%G IN (%_Pence%,-5,0) DO (
CALL :2Pence %%G _2Count
SET /A _Count+=_2Count
)
ENDLOCAL & SET %2=%_Count%
GOTO :EOF
:2Pence
SETLOCAL EnableDelayedExpansion
SET _Pence=%1
SET _Count=0
:: We are totally taking advantage of CMD's ignorance of
:: floating point numbers here.
SET /A _Count=_Pence/2
SET /A _Count+=1
ENDLOCAL & SET %2=%_Count%
GOTO :EOF