-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem44.cmd
More file actions
65 lines (50 loc) · 1016 Bytes
/
Problem44.cmd
File metadata and controls
65 lines (50 loc) · 1016 Bytes
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
@ECHO OFF
SETLOCAL EnableDelayedExpansion
:: Project Euler Problem 44
:: Find the pair of pentagonal numbers, Pj and Pk, for which their sum and
:: difference are pentagonal.
:: Force. Brute force.
SET _j=1
SET _Seed=0
SET _Start=0
SET _Answer=-1
:Loop
SET /A _Pj=_j*3
SET /A _Pj-=1
SET /A _Pj*=_j
SET /A _Pj/=2
SET /A _SeedChk=_Seed/2
IF %_j% GEQ %_SeedChk% CALL :Seed
ECHO:J=%_j%, Seed=%_Seed%
SET /A _KEnd=_j-1
FOR /L %%K IN (1,1,%_KEnd%) DO (
SET /A _Pk=%%K*3
SET /A _Pk-=1
SET /A _Pk*=%%K
SET /A _Pk/=2
SET /A _Sum=_Pj+_Pk
IF DEFINED _!_Sum! (
SET /A _Diff=_Pj-_Pk
IF DEFINED _!_Diff! (
SET _Answer=!_Diff!
GOTO EndLoop
)
)
)
SET /A _j+=1
GOTO Loop
:EndLoop
ECHO:%_Answer%
GOTO :EOF
:Seed
SET /A _End=_Start+100
FOR /L %%G IN (%_Start%,1,%_End%) DO (
SET /A _P=%%G*3
SET /A _P-=1
SET /A _P*=%%G
SET /A _P/=2
SET _!_P!=!_P!
SET _Seed=%%G
)
SET _Start=%_End%
GOTO :EOF