Advent of Code 2024 day 9, RPG edition

​[[{“value”:”This is the nineth day of Advent of Code, let’s solve today’s puzzles with RPG.
The puzzle as well as the input data are available here.
The code is available here.
Part 1
We are provided with a (stream) file containing a disk map. It is a single line containing alternatively files and free space sizes (one digit for each).
We need to defragment the disk by moving blocks from files at the end of the disk to the free space at the begining of the disk.
We then need to calculate the filesystem checksum (see the puzzle for the exact definition).
As usual, we read the input file with QSYS2.IFS_READ_UTF8 table function.
We defragment and compute the checksum in one pass by processing the disk map from both ends: we process alternatively the files from the lelft and fill the free space with blocks from the right.
Here is the RPG code for part 1:
**free
ctl-opt dftactgrp(*no); // We’re using procedure so we can’t be in the default activation group

dcl-pi *n;
input char(50);
end-pi;

dcl-c LENGTH 19999;

dcl-s fileName varchar(50);
dcl-s data char(LENGTH);
dcl-s position int(10) inz(0);
dcl-s leftID int(10) inz(0);
dcl-s rightID int(10) inz(9999);
dcl-s leftIndex int(10) inz(1);
dcl-s rightIndex int(10) inz(19999);
dcl-s leftCount int(3);
dcl-s rightCount int(3);
dcl-s i int(3);

dcl-s result int(20) inz(0);

fileName = %trim(input);

// Read the input data from the IFS, concatenating all lines
exec sql select line into :data from table(qsys2.ifs_read_utf8(path_name => :fileName));

leftCount = %int(%subst(data:1:1));
rightCount = %int(%subst(data:19999:1));

dow leftIndex < rightIndex;
for i = 1 to leftcount;
result += position*leftID;
position += 1;
endfor;

leftIndex += 1;
leftCount = %int(%subst(data:leftindex:1));
for i = 1 to leftCount;
if rightCount = 0;
rightIndex -= 2;
rightCount = %int(%subst(data:rightIndex:1));
rightID -= 1;
endif;
result += position*rightID;
rightCount -= 1;
position += 1;
endfor;
leftIndex += 1;
leftCount = %int(%subst(data:leftIndex:1));
leftID += 1;
enddo;

for i = 1 to rightCount;
result += position*rightID;
position += 1;
endfor;

snd-msg *info ‘Result: ‘ + %char(result) %target(*pgmbdy:1); // Send message with answer

*inlr = *on;
return;
Part 2
In part 2, we change the defragmentation rules:

we can only move a whole file from the end of the disk to a free space
we start moving files from the end of the disk
we move a file to the leftmost free space big enough for the file
if there is no free space for a file, it is not moved at all

We solve this puzzle in 3 passes:

we compute the initial begining position of each file
we perform the actual defragmentation be changing the begining position of each file
we compute the checksum

**free
ctl-opt dftactgrp(*no); // We’re using procedure so we can’t be in the default activation group

dcl-pi *n;
input char(50);
end-pi;

dcl-c LENGTH 19999;

dcl-s fileName varchar(50);
dcl-s data char(LENGTH);
dcl-s position int(10) inz(0);
dcl-s leftID int(10) inz(0);
dcl-s rightID int(10) inz(9999);
dcl-s leftIndex int(10) inz(1);
dcl-s rightIndex int(10) inz(19999);
dcl-s leftCount int(3);
dcl-s rightCount int(3);
dcl-s i int(5);
dcl-s j int(5);
dcl-s positions int(10) dim(10000);
dcl-s fillings int(10) dim(9999);

dcl-s result int(20) inz(0);

fileName = %trim(input);

// Read the input data from the IFS, concatenating all lines
exec sql select line into :data from table(qsys2.ifs_read_utf8(path_name => :fileName));

// Calculate initial position of each File
for i = 1 to 10000;
positions(i) = position;
if i < 10000;
position += %int(%subst(data:2*(i-1)+1:1))+%int(%subst(data:2*(i-1)+2:1));
endif;
endfor;

// Defragment
for i = 19999 downto 3 by 2;
rightCount = %int(%subst(data:i:1));
j = 2;
leftCount = %int(%subst(data:j:1));
dow j<=i and rightCount > leftCount;
j += 2;
leftCount = %int(%subst(data:j:1));
enddo;
if leftCount >= rightCount;
positions(%div(i+1:2)) = positions(%div(j:2))+%int(%subst(data:j-1:1))+fillings(%div(j:2));
fillings(%div(j:2)) += rightCount;
leftCount -= rightCount;
%subst(data:j:1) = %char(leftCount);
endif;
endfor;

// Compute checksum
for i = 1 to 10000;
position = positions(i);
for j = 1 to %int(%subst(data:2*(i-1)+1:1));
result += (i-1)*position;
position += 1;
endfor;
endfor;

snd-msg *info ‘Result: ‘ + %char(result) %target(*pgmbdy:1); // Send message with answer

*inlr = *on;
return;”}]] Read More 

Dell And Big Blue Call It Quits On Storage Driver Support For IBM i Timothy Prickett Morgan

​[[{“value”:”It looks like IBM and sometime rival Dell Technologies are having a tiff over the licensing of technology that allows disk arrays descended from the venerable Symmetrix arrays created by EMC more than three decades ago to link to descendants of the AS/400 platform and OS/400 operating systems created three and a half decades ago.
The fallout from what we presume is that a technology licensing fee agreement between Dell and IBM is similar, we think, to the one between IBM and the company that owns Information Builders. In October 2023, out of the blue, IBM announced that it was …
The post Dell And Big Blue Call It Quits On Storage Driver Support For IBM i appeared first on IT Jungle.”}]] Read More 

How ERP Giants Are Building GenAI Into Their Products Alex Woodie

​[[{“value”:”We are still near the top of Gartner’s hype curve when it comes to generative AI. Larger companies that have discipline and money, and startups with time and ambition, are finding success with GenAI, but many organizations are still in the planning and roll-out phase. The same could be said for ERP vendors, who have started their GenAI journeys but are expected to ramp up adoption significantly in the years to come.
Since the dawn of the mainframe age, computers have automated the work that was previously done by people. Large armies of file clerks were no longer needed once …
The post How ERP Giants Are Building GenAI Into Their Products appeared first on IT Jungle.”}]] Read More 

Happy Holidays From All Of Us To All Of You Timothy Prickett Morgan

​[[{“value”:”Every year has its own twists, turns, and challenges for any company and for the people who comprise that company. Over the years, we have had our share of adversity. 2019 and 2020 and 2024 were tough years for us, and we are all frankly happy to have pushed through the to end of this one so we can hit reset and attack 2025 with the usual vim and vigor.
No matter where you are, everybody gets their turn with adversity, and if hard times have come to you, we just want to know that we feel you. Do your …
The post Happy Holidays From All Of Us To All Of You appeared first on IT Jungle.”}]] Read More 

IBM i PTF Guide, Volume 26, Number 47 Doug Bidwell

​[[{“value”:”Just a reminder: For the first time in a long, long while there are pre-requisites for a Technology Refresh. Sorting out the contingencies will keep us busy for a while. Here’s the word from IBM: OSP-Technology Refresh : Prereq licensed internal code PTFs, which you can find out more about at this link. These are the pre-reqs for the Technology Refreshes:

IBM i 7.5: SJ02898
IBM i 7.4: SJ02897

Now there is another issue you need to be aware of. Specifically: Potential to render new Feature Code EN24 / EN26 CCIN EC2A adapters inoperable, which you can find out …
The post IBM i PTF Guide, Volume 26, Number 47 appeared first on IT Jungle.”}]] Read More 

Verified by MonsterInsights