├── .gitignore ├── LICENSE ├── ProjectEuler.sln ├── ProjectEuler.tspproj ├── ProjectEuler ├── POUs │ ├── PRG_TEST.TcPOU │ ├── Problems │ │ ├── Base │ │ │ ├── FbProblemSolverBase.TcPOU │ │ │ └── IProblemSolver.TcIO │ │ ├── Problem1.TcPOU │ │ ├── Problem2.TcPOU │ │ └── Problem3.TcPOU │ └── Tests │ │ └── FbProblemTester.TcPOU ├── PlcTestTask.TcTTO ├── ProjectEuler.plcproj └── ProjectEuler.tpr ├── README.md └── _Config └── PLC └── ProjectEuler.xti /.gitignore: -------------------------------------------------------------------------------- 1 | # gitignore template for TwinCAT3 2 | # website: https://www.beckhoff.com/twincat3/ 3 | # 4 | # Recommended: VisualStudio.gitignore 5 | 6 | # TwinCAT files 7 | *.tpy 8 | *.tclrs 9 | *.compiled-library 10 | *.compileinfo 11 | # Don't include the tmc-file rule if either of the following is true: 12 | # 1. You've got TwinCAT C++ projects, as the information in the TMC-file is created manually for the C++ projects (in that case, only (manually) ignore the tmc-files for the PLC projects) 13 | # 2. You've created a standalone PLC-project and added events to it, as these are stored in the TMC-file. 14 | *.tmc 15 | *.tmcRefac 16 | *.library 17 | *.project.~u 18 | *.tsproj.bak 19 | *.xti.bak 20 | LineIDs.dbg 21 | LineIDs.dbg.bak 22 | _Boot/ 23 | _CompileInfo/ 24 | _Libraries/ 25 | _ModuleInstall/ 26 | 27 | ## Ignore Visual Studio temporary files, build results, and 28 | ## files generated by popular Visual Studio add-ons. 29 | ## 30 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 31 | 32 | # User-specific files 33 | *.rsuser 34 | *.suo 35 | *.user 36 | *.userosscache 37 | *.sln.docstates 38 | 39 | # User-specific files (MonoDevelop/Xamarin Studio) 40 | *.userprefs 41 | 42 | # Mono auto generated files 43 | mono_crash.* 44 | 45 | # Build results 46 | [Dd]ebug/ 47 | [Dd]ebugPublic/ 48 | [Rr]elease/ 49 | [Rr]eleases/ 50 | x64/ 51 | x86/ 52 | [Ww][Ii][Nn]32/ 53 | [Aa][Rr][Mm]/ 54 | [Aa][Rr][Mm]64/ 55 | bld/ 56 | [Bb]in/ 57 | [Oo]bj/ 58 | [Ll]og/ 59 | [Ll]ogs/ 60 | 61 | # Visual Studio 2015/2017 cache/options directory 62 | .vs/ 63 | # Uncomment if you have tasks that create the project's static files in wwwroot 64 | #wwwroot/ 65 | 66 | # Visual Studio 2017 auto generated files 67 | Generated\ Files/ 68 | 69 | # MSTest test Results 70 | [Tt]est[Rr]esult*/ 71 | [Bb]uild[Ll]og.* 72 | 73 | # NUnit 74 | *.VisualState.xml 75 | TestResult.xml 76 | nunit-*.xml 77 | 78 | # Build Results of an ATL Project 79 | [Dd]ebugPS/ 80 | [Rr]eleasePS/ 81 | dlldata.c 82 | 83 | # Benchmark Results 84 | BenchmarkDotNet.Artifacts/ 85 | 86 | # .NET Core 87 | project.lock.json 88 | project.fragment.lock.json 89 | artifacts/ 90 | 91 | # ASP.NET Scaffolding 92 | ScaffoldingReadMe.txt 93 | 94 | # StyleCop 95 | StyleCopReport.xml 96 | 97 | # Files built by Visual Studio 98 | *_i.c 99 | *_p.c 100 | *_h.h 101 | *.ilk 102 | *.meta 103 | *.obj 104 | *.iobj 105 | *.pch 106 | *.pdb 107 | *.ipdb 108 | *.pgc 109 | *.pgd 110 | *.rsp 111 | *.sbr 112 | *.tlb 113 | *.tli 114 | *.tlh 115 | *.tmp 116 | *.tmp_proj 117 | *_wpftmp.csproj 118 | *.log 119 | *.tlog 120 | *.vspscc 121 | *.vssscc 122 | .builds 123 | *.pidb 124 | *.svclog 125 | *.scc 126 | 127 | # Chutzpah Test files 128 | _Chutzpah* 129 | 130 | # Visual C++ cache files 131 | ipch/ 132 | *.aps 133 | *.ncb 134 | *.opendb 135 | *.opensdf 136 | *.sdf 137 | *.cachefile 138 | *.VC.db 139 | *.VC.VC.opendb 140 | 141 | # Visual Studio profiler 142 | *.psess 143 | *.vsp 144 | *.vspx 145 | *.sap 146 | 147 | # Visual Studio Trace Files 148 | *.e2e 149 | 150 | # TFS 2012 Local Workspace 151 | $tf/ 152 | 153 | # Guidance Automation Toolkit 154 | *.gpState 155 | 156 | # ReSharper is a .NET coding add-in 157 | _ReSharper*/ 158 | *.[Rr]e[Ss]harper 159 | *.DotSettings.user 160 | 161 | # TeamCity is a build add-in 162 | _TeamCity* 163 | 164 | # DotCover is a Code Coverage Tool 165 | *.dotCover 166 | 167 | # AxoCover is a Code Coverage Tool 168 | .axoCover/* 169 | !.axoCover/settings.json 170 | 171 | # Coverlet is a free, cross platform Code Coverage Tool 172 | coverage*.json 173 | coverage*.xml 174 | coverage*.info 175 | 176 | # Visual Studio code coverage results 177 | *.coverage 178 | *.coveragexml 179 | 180 | # NCrunch 181 | _NCrunch_* 182 | .*crunch*.local.xml 183 | nCrunchTemp_* 184 | 185 | # MightyMoose 186 | *.mm.* 187 | AutoTest.Net/ 188 | 189 | # Web workbench (sass) 190 | .sass-cache/ 191 | 192 | # Installshield output folder 193 | [Ee]xpress/ 194 | 195 | # DocProject is a documentation generator add-in 196 | DocProject/buildhelp/ 197 | DocProject/Help/*.HxT 198 | DocProject/Help/*.HxC 199 | DocProject/Help/*.hhc 200 | DocProject/Help/*.hhk 201 | DocProject/Help/*.hhp 202 | DocProject/Help/Html2 203 | DocProject/Help/html 204 | 205 | # Click-Once directory 206 | publish/ 207 | 208 | # Publish Web Output 209 | *.[Pp]ublish.xml 210 | *.azurePubxml 211 | # Note: Comment the next line if you want to checkin your web deploy settings, 212 | # but database connection strings (with potential passwords) will be unencrypted 213 | *.pubxml 214 | *.publishproj 215 | 216 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 217 | # checkin your Azure Web App publish settings, but sensitive information contained 218 | # in these scripts will be unencrypted 219 | PublishScripts/ 220 | 221 | # NuGet Packages 222 | *.nupkg 223 | # NuGet Symbol Packages 224 | *.snupkg 225 | # The packages folder can be ignored because of Package Restore 226 | **/[Pp]ackages/* 227 | # except build/, which is used as an MSBuild target. 228 | !**/[Pp]ackages/build/ 229 | # Uncomment if necessary however generally it will be regenerated when needed 230 | #!**/[Pp]ackages/repositories.config 231 | # NuGet v3's project.json files produces more ignorable files 232 | *.nuget.props 233 | *.nuget.targets 234 | 235 | # Microsoft Azure Build Output 236 | csx/ 237 | *.build.csdef 238 | 239 | # Microsoft Azure Emulator 240 | ecf/ 241 | rcf/ 242 | 243 | # Windows Store app package directories and files 244 | AppPackages/ 245 | BundleArtifacts/ 246 | Package.StoreAssociation.xml 247 | _pkginfo.txt 248 | *.appx 249 | *.appxbundle 250 | *.appxupload 251 | 252 | # Visual Studio cache files 253 | # files ending in .cache can be ignored 254 | *.[Cc]ache 255 | # but keep track of directories ending in .cache 256 | !?*.[Cc]ache/ 257 | 258 | # Others 259 | ClientBin/ 260 | ~$* 261 | *~ 262 | *.dbmdl 263 | *.dbproj.schemaview 264 | *.jfm 265 | *.pfx 266 | *.publishsettings 267 | orleans.codegen.cs 268 | 269 | # Including strong name files can present a security risk 270 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 271 | #*.snk 272 | 273 | # Since there are multiple workflows, uncomment next line to ignore bower_components 274 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 275 | #bower_components/ 276 | 277 | # RIA/Silverlight projects 278 | Generated_Code/ 279 | 280 | # Backup & report files from converting an old project file 281 | # to a newer Visual Studio version. Backup files are not needed, 282 | # because we have git ;-) 283 | _UpgradeReport_Files/ 284 | Backup*/ 285 | UpgradeLog*.XML 286 | UpgradeLog*.htm 287 | ServiceFabricBackup/ 288 | *.rptproj.bak 289 | 290 | # SQL Server files 291 | *.mdf 292 | *.ldf 293 | *.ndf 294 | 295 | # Business Intelligence projects 296 | *.rdl.data 297 | *.bim.layout 298 | *.bim_*.settings 299 | *.rptproj.rsuser 300 | *- [Bb]ackup.rdl 301 | *- [Bb]ackup ([0-9]).rdl 302 | *- [Bb]ackup ([0-9][0-9]).rdl 303 | 304 | # Microsoft Fakes 305 | FakesAssemblies/ 306 | 307 | # GhostDoc plugin setting file 308 | *.GhostDoc.xml 309 | 310 | # Node.js Tools for Visual Studio 311 | .ntvs_analysis.dat 312 | node_modules/ 313 | 314 | # Visual Studio 6 build log 315 | *.plg 316 | 317 | # Visual Studio 6 workspace options file 318 | *.opt 319 | 320 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 321 | *.vbw 322 | 323 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 324 | *.vbp 325 | 326 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 327 | *.dsw 328 | *.dsp 329 | 330 | # Visual Studio 6 technical files 331 | *.ncb 332 | *.aps 333 | 334 | # Visual Studio LightSwitch build output 335 | **/*.HTMLClient/GeneratedArtifacts 336 | **/*.DesktopClient/GeneratedArtifacts 337 | **/*.DesktopClient/ModelManifest.xml 338 | **/*.Server/GeneratedArtifacts 339 | **/*.Server/ModelManifest.xml 340 | _Pvt_Extensions 341 | 342 | # Paket dependency manager 343 | .paket/paket.exe 344 | paket-files/ 345 | 346 | # FAKE - F# Make 347 | .fake/ 348 | 349 | # CodeRush personal settings 350 | .cr/personal 351 | 352 | # Python Tools for Visual Studio (PTVS) 353 | __pycache__/ 354 | *.pyc 355 | 356 | # Cake - Uncomment if you are using it 357 | # tools/** 358 | # !tools/packages.config 359 | 360 | # Tabs Studio 361 | *.tss 362 | 363 | # Telerik's JustMock configuration file 364 | *.jmconfig 365 | 366 | # BizTalk build output 367 | *.btp.cs 368 | *.btm.cs 369 | *.odx.cs 370 | *.xsd.cs 371 | 372 | # OpenCover UI analysis results 373 | OpenCover/ 374 | 375 | # Azure Stream Analytics local run output 376 | ASALocalRun/ 377 | 378 | # MSBuild Binary and Structured Log 379 | *.binlog 380 | 381 | # NVidia Nsight GPU debugger configuration file 382 | *.nvuser 383 | 384 | # MFractors (Xamarin productivity tool) working folder 385 | .mfractor/ 386 | 387 | # Local History for Visual Studio 388 | .localhistory/ 389 | 390 | # BeatPulse healthcheck temp database 391 | healthchecksdb 392 | 393 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 394 | MigrationBackup/ 395 | 396 | # Ionide (cross platform F# VS Code tools) working folder 397 | .ionide/ 398 | 399 | # Fody - auto-generated XML schema 400 | FodyWeavers.xsd 401 | 402 | # VS Code files for those working on multiple tools 403 | .vscode/* 404 | !.vscode/settings.json 405 | !.vscode/tasks.json 406 | !.vscode/launch.json 407 | !.vscode/extensions.json 408 | *.code-workspace 409 | 410 | # Local History for Visual Studio Code 411 | .history/ 412 | 413 | # Windows Installer files from build outputs 414 | *.cab 415 | *.msi 416 | *.msix 417 | *.msm 418 | *.msp 419 | 420 | # JetBrains Rider 421 | *.sln.iml 422 | *.bak 423 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Gerhard Barteling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ProjectEuler.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{DFBE7525-6864-4E62-8B2E-D530D69D9D96}") = "ProjectEuler", "ProjectEuler.tspproj", "{A2A135E6-6F47-4F68-A67E-4D4DE911B884}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|TwinCAT CE7 (ARMV7) = Debug|TwinCAT CE7 (ARMV7) 11 | Debug|TwinCAT OS (ARMT2) = Debug|TwinCAT OS (ARMT2) 12 | Debug|TwinCAT RT (x64) = Debug|TwinCAT RT (x64) 13 | Debug|TwinCAT RT (x86) = Debug|TwinCAT RT (x86) 14 | Release|TwinCAT CE7 (ARMV7) = Release|TwinCAT CE7 (ARMV7) 15 | Release|TwinCAT OS (ARMT2) = Release|TwinCAT OS (ARMT2) 16 | Release|TwinCAT RT (x64) = Release|TwinCAT RT (x64) 17 | Release|TwinCAT RT (x86) = Release|TwinCAT RT (x86) 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 21 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 22 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 23 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 24 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 25 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 26 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 27 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 28 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 29 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 30 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 31 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 32 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 33 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 34 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 35 | {A2A135E6-6F47-4F68-A67E-4D4DE911B884}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 36 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT CE7 (ARMV7).ActiveCfg = Debug|TwinCAT CE7 (ARMV7) 37 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT CE7 (ARMV7).Build.0 = Debug|TwinCAT CE7 (ARMV7) 38 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT OS (ARMT2).ActiveCfg = Debug|TwinCAT OS (ARMT2) 39 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT OS (ARMT2).Build.0 = Debug|TwinCAT OS (ARMT2) 40 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT RT (x64).ActiveCfg = Debug|TwinCAT RT (x64) 41 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT RT (x64).Build.0 = Debug|TwinCAT RT (x64) 42 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT RT (x86).ActiveCfg = Debug|TwinCAT RT (x86) 43 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Debug|TwinCAT RT (x86).Build.0 = Debug|TwinCAT RT (x86) 44 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT CE7 (ARMV7).ActiveCfg = Release|TwinCAT CE7 (ARMV7) 45 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT CE7 (ARMV7).Build.0 = Release|TwinCAT CE7 (ARMV7) 46 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT OS (ARMT2).ActiveCfg = Release|TwinCAT OS (ARMT2) 47 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT OS (ARMT2).Build.0 = Release|TwinCAT OS (ARMT2) 48 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT RT (x64).ActiveCfg = Release|TwinCAT RT (x64) 49 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT RT (x64).Build.0 = Release|TwinCAT RT (x64) 50 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT RT (x86).ActiveCfg = Release|TwinCAT RT (x86) 51 | {8AD0DC8C-310E-4027-B1D3-29818216D553}.Release|TwinCAT RT (x86).Build.0 = Release|TwinCAT RT (x86) 52 | EndGlobalSection 53 | GlobalSection(SolutionProperties) = preSolution 54 | HideSolutionNode = FALSE 55 | EndGlobalSection 56 | GlobalSection(ExtensibilityGlobals) = postSolution 57 | SolutionGuid = {F411F6A0-813C-4CE5-BB2F-1C6A356EC2A0} 58 | EndGlobalSection 59 | EndGlobal 60 | -------------------------------------------------------------------------------- /ProjectEuler.tspproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/PRG_TEST.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Problems/Base/FbProblemSolverBase.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 24 | 25 | _complete, result => _tempResult); 39 | 40 | IF _complete THEN 41 | _state := _state + 1; 42 | _again := TRUE; 43 | _result := _tempResult; 44 | _busy := FALSE; 45 | _done := TRUE; 46 | END_IF 47 | 48 | Resetting: 49 | IF NOT Execute THEN 50 | ResetAction(complete => _complete); 51 | 52 | IF _resetDoneOnFallingEdgeExecute THEN 53 | _done := FALSE; 54 | END_IF 55 | 56 | IF _complete THEN 57 | _state := 0; 58 | _again := TRUE; 59 | END_IF 60 | ELSE 61 | _resetDoneOnFallingEdgeExecute := TRUE; 62 | END_IF 63 | END_CASE 64 | UNTIL NOT _again 65 | END_REPEAT]]> 66 | 67 | 68 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 90 | 91 | 92 | 93 | 94 | 95 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 126 | 127 | 128 | 129 | 130 | 131 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Problems/Base/IProblemSolver.TcIO: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Problems/Problem1.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 18 | 19 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Problems/Problem2.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 20 | 21 | 4000000 THEN 31 | EXIT; 32 | ELSIF _term3 MOD 2 = 0 THEN 33 | _sum := _sum + _term3; 34 | END_IF 35 | 36 | _term1 := _term2; 37 | _term2 := _term3; 38 | END_WHILE 39 | 40 | result := LINT_TO_STRING(_sum); 41 | complete := TRUE;]]> 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Problems/Problem3.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 20 | 21 | 4 THEN 50 | _maxPrime := _n; 51 | END_IF 52 | 53 | result := ULINT_TO_STRING(_maxPrime); 54 | complete := TRUE;]]> 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /ProjectEuler/POUs/Tests/FbProblemTester.TcPOU: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 9 | 10 | 19 | 20 | 21 | 28 | 29 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ProjectEuler/PlcTestTask.TcTTO: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 10000 6 | 20 7 | 8 | PRG_TEST 9 | 10 | {2eec26ad-d551-48ea-983f-2e25eb6e6de2} 11 | {b0c24802-cd93-4d13-a641-5627544263ac} 12 | {b2ae7d60-e820-46b6-b86e-54a362907241} 13 | {88d97447-4dda-4e6c-8036-ddddca18aeaf} 14 | {aa1b0318-0299-4784-99db-d58715da7182} 15 | 16 | -------------------------------------------------------------------------------- /ProjectEuler/ProjectEuler.plcproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1.0.0.0 4 | 2.0 5 | {8ad0dc8c-310e-4027-b1d3-29818216d553} 6 | True 7 | true 8 | true 9 | false 10 | ProjectEuler 11 | 3.1.4023.0 12 | {a14f11cd-117d-4b3b-9a69-177a8c03c4ab} 13 | {ed3e4405-f1a8-456a-a6d9-8d82f34c7654} 14 | {432759dc-4b76-4e3a-8629-da07680333a3} 15 | {a33994c8-51a7-4dcf-bf40-982b627b1bf5} 16 | {c325270e-e45f-47be-944c-af793666a540} 17 | {c39d63fd-8f71-4c8c-8cec-f49389211933} 18 | Open source 19 | false 20 | Project Euler 21 | 1.0.0 22 | ProjectEuler 23 | Open source contributers. 24 | Open source project to solve Project euler problems with TwinCAT. 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | Code 35 | 36 | 37 | Code 38 | 39 | 40 | Code 41 | 42 | 43 | Code 44 | 45 | 46 | Code 47 | 48 | 49 | Code 50 | 51 | 52 | Code 53 | 54 | 55 | Code 56 | 57 | 58 | 59 | 60 | Tc2_Standard, * (Beckhoff Automation GmbH) 61 | Tc2_Standard 62 | 63 | 64 | Tc2_System, * (Beckhoff Automation GmbH) 65 | Tc2_System 66 | 67 | 68 | Tc2_Utilities, * (Beckhoff Automation GmbH) 69 | Tc2_Utilities 70 | 71 | 72 | Tc3_Module, * (Beckhoff Automation GmbH) 73 | Tc3_Module 74 | 75 | 76 | TcUnit, * (www.tcunit.org) 77 | TcUnit 78 | 79 | 80 | 81 | 82 | Content 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | "<ProjectRoot>" 91 | 92 | {40450F57-0AA3-4216-96F3-5444ECB29763} 93 | 94 | "{40450F57-0AA3-4216-96F3-5444ECB29763}" 95 | 96 | 97 | ActiveVisuProfile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AAAAFAAAADQAAAAAAAADQHh8tINAhIhoCRSMkAtAAJRoFRQoLBAMAAAADAAAAAAAAAAoAAADQJgutAAAAANADAS0n0CgBLRHQKQEtENAAJRoFRQoLBAMAAAADAAAAAAAAAAoAAADQJgutAQAAANADAS0n0CgBLRHQKQEtEJoqKwFFAAEC0AABLSzQAAEtF9AAHy0t0C4vGgPQMAutAQAAANAxC60XAAAA0DIarQDQMy8aA9AwC60CAAAA0DELrQMAAADQMhqtANA0Gq0A0DUarQA= 99 | 100 | 101 | {192FAD59-8248-4824-A8DE-9177C94C195A} 102 | 103 | "{192FAD59-8248-4824-A8DE-9177C94C195A}" 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | System.Collections.Hashtable 113 | {54dd0eac-a6d8-46f2-8c27-2f43c7e49861} 114 | System.String 115 | 116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /ProjectEuler/ProjectEuler.tpr: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Problem1Test 6 | _expected 7 | _expectedResult 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TwinCAT meets Project Euler 2 | Welcome at the open source repository TwinCAT meets project Euler! 3 | This repository contains a TwinCAT project written in Structured Text which solves [Project Euler](https://projecteuler.net/) problems. 4 | I created this repository because I thought it would be fun to see how far _**we**_ can come with Structured Text. 5 | But mostly because I hope that we learn some cool ST tips and tricks from each other while solving the problems. We perhaps might need some additional math functions/libraries as well.. 6 | 7 | ## How does it work 8 | The project is a TwinCAT stand alone PLC project. The PLC project contains a base function block named '[FbProblemSolverBase](ProjectEuler/POUs/Problems/Base/FbProblemSolverBase.TcPOU)' which contains the base logic. The results are verified with [TCUnit](https://tcunit.org) in the main program 'PRG_TEST'. 9 | 10 | #### FbProblemSolverBase 11 | FbProblemSolverBase is loosely based on PLCOpens ETRIG pattern and implements some logic to control states like 'Busy' and 'Done' and has a 'Execute' property to start the problem solving process. The results are returned with a STRING property called: 'Result'. 12 | 13 | #### Problem solver function blocks 14 | All new problem solving function blocks should inherit from FbProblemSolverBase. In the new problem solving function block base simply call the base function block: 15 | ``` 16 | Super^(); 17 | ``` 18 | 19 | The problem solving logic should be implemented in the overriden method: 'CyclicAction'. This action will be called cyclic until the output parameter: 'complete' is set the true. 20 | ``` 21 | METHOD PROTECTED CyclicAction 22 | VAR_OUTPUT 23 | complete : BOOL; 24 | result : STRING; 25 | END_VAR 26 | ``` 27 | ``` 28 | // Logic 29 | result := '123'; 30 | complete := TRUE; 31 | ``` 32 | In case a function block needs specific cleanup after the process has completed, override the method 'ResetAction' and implement any cleanup actions here. This may take more than one cycle. As with the 'CyclicAction' this is controlled with the output parameter 'Complete'. 33 | 34 | #### Testing 35 | This project uses TCUnit to verify the results. Because the structure of the problem solving function blocks is the same, the testing can be done with one function block: '[FbProblemTester](ProjectEuler/POUs/Tests/FbProblemTester.TcPOU)'. This function block uses FB_init to acquire the function block to test and the expected result as STRING. 36 | To add a new problem in the test sequence just add them in the variable list of 'PRG_TEST': 37 | ``` 38 | PROGRAM PRG_TEST 39 | VAR 40 | _problem1 : Problem1; 41 | _problem1Test : FbProblemTester(_problem1, '233168'); 42 | _problem2 : Problem2; 43 | _problem2Test : FbProblemTester(_problem2, '4613732'); 44 | END_VAR 45 | ``` 46 | 47 | #### Project structure 48 | ``` 49 | /- Project 50 | /- - POUs 51 | /- - - Problems 52 | /- - - - Base 53 | /- - - - - FbProblemSolverBase 54 | /- - - - - IProblemSolver 55 | /- - - - Problem1 (FB) 56 | /- - - - Problem2 (FB) 57 | /- - - - ........ (FB) 58 | /- - - - Add your new problem here (FB) 59 | /- - - Tests 60 | /- - - - FbProblemTester (FB) 61 | /- - - PRG_TEST (PRG) 62 | ``` 63 | 64 | ![project overview](https://user-images.githubusercontent.com/33071638/146077237-5340e938-023c-4fb5-a119-54aaaae6c4d2.PNG) 65 | 66 | ## How can I run it 67 | This project is a stand alone project. To run it download the project and either in de same solution or in a different solution create a TwinCAT XAE project matching your hardware. Import the stand alone project as described [here](https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/4278074763.html&id=) and you should be ready to run the PLC project! 68 | 69 | ## Can I contribute 70 | Yes! The purpose of this project is to have some fun with Structured Text and learn from each other. Everyone is welcome to solve a problem. 71 | To solve a Project Euler problem follow these steps: 72 | 1. Clone this repository 73 | 2. Add a new function block which inherits from FbProblemSolverBase. 74 | 3. Pick your problom from [Project Euler](https://projecteuler.net/) and implement your solution in the method Cyclic action. 75 | 4. Add your function block to the test sequence in PRG_TEST 76 | 5. Verify that all tests pass. 77 | 6. Open a pull request with your additions. 78 | -------------------------------------------------------------------------------- /_Config/PLC/ProjectEuler.xti: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | --------------------------------------------------------------------------------