<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Advent of Code 2021 Day 25 - A SAS Solution in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Advent-of-Code-2021-Day-25-A-SAS-Solution/m-p/787385#M251579</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Merry Xmas to all and to all a good night!" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66960i0F03B21815ECF07E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AdventOfCodeHat.png" alt="Merry Xmas to all and to all a good night!" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Merry Xmas to all and to all a good night!&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Packages all wrapped, so figured I'd take a crack at the final Advent of Code problem. SAS solution below - check out Reddit for &lt;A href="https://www.reddit.com/r/adventofcode/comments/ro2uav/2021_day_25_solutions/" target="_self"&gt;Day 25 solutions in other programming languages&lt;/A&gt;. Merry Xmas!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* "Sea Cucumber" - Day 25 - Advent of Code 2021
  See https://adventofcode.com/2021/day/25 for problem statement;
  
data _null_;
array cell{137,139} $1. _temporary_;        * Holds map data (137 rows by 139 columns); 
array newcell{137,139} $1. _temporary_;     * Updates first applied to copy of map data ; 

do r=1 to dim(cell,1);                      * Read Day 25 data into array;
  infile '~/day25data.txt';
  input;
  do c=1 to dim(cell,2);
    cell(r,c)=substr(_infile_,c,1);
  end;
end; 

do loop=1 to 2000;                           * Stop after 2,000 tries, just in case an infinite loop; 
  moved=0;                                   * Count of how many sea cucumbers moved;
                                             * Copy original array to array that will be updated;
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); newcell(r,c)=cell(r,c); end; end; 

  do r=1 to dim(cell,1);                     * Update horizontal moves;
    do c=1 to dim(cell,2);
      if cell(r,c)='&amp;gt;' then do;              * Horizonal movement sea cucumber?;
        nc=ifn(c&amp;lt;dim(cell,2),c+1,1);         * Move if next cell unoccupied;
        if cell(r,nc)='.' then do; newcell(r,nc)='&amp;gt;'; newcell(r,c)='.'; moved+1; end;
        end;
    end;   
  end;   
                                             * Copy updated array back to original array; 
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); cell(r,c)=newcell(r,c); end; end;
  
  do c=1 to dim(cell,2);                     * Update vertical moves;
    do r=1 to dim(cell,1);
      if cell(r,c)='v' then do;              * Vertical movement sea cucumber?;
        nr=ifn(r&amp;lt;dim(cell,1),r+1,1);         * Move if next cell unoccupied;
        if cell(nr,c)='.' then do; newcell(nr,c)='v'; newcell(r,c)='.'; moved+1; end;
        end;
    end;   
  end;                                         
                                             * Copy updated array back to original array;
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); cell(r,c)=newcell(r,c); end; end;

  put loop= moved=;                          * Report iteration #, # of sea cucumbers moved;
  if moved=0 then stop;                      * Stop if no moves (iteration # is answer);
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Dec 2021 07:30:37 GMT</pubDate>
    <dc:creator>tc</dc:creator>
    <dc:date>2021-12-25T07:30:37Z</dc:date>
    <item>
      <title>Advent of Code 2021 Day 25 - A SAS Solution</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advent-of-Code-2021-Day-25-A-SAS-Solution/m-p/787385#M251579</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Merry Xmas to all and to all a good night!" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66960i0F03B21815ECF07E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AdventOfCodeHat.png" alt="Merry Xmas to all and to all a good night!" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Merry Xmas to all and to all a good night!&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Packages all wrapped, so figured I'd take a crack at the final Advent of Code problem. SAS solution below - check out Reddit for &lt;A href="https://www.reddit.com/r/adventofcode/comments/ro2uav/2021_day_25_solutions/" target="_self"&gt;Day 25 solutions in other programming languages&lt;/A&gt;. Merry Xmas!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* "Sea Cucumber" - Day 25 - Advent of Code 2021
  See https://adventofcode.com/2021/day/25 for problem statement;
  
data _null_;
array cell{137,139} $1. _temporary_;        * Holds map data (137 rows by 139 columns); 
array newcell{137,139} $1. _temporary_;     * Updates first applied to copy of map data ; 

do r=1 to dim(cell,1);                      * Read Day 25 data into array;
  infile '~/day25data.txt';
  input;
  do c=1 to dim(cell,2);
    cell(r,c)=substr(_infile_,c,1);
  end;
end; 

do loop=1 to 2000;                           * Stop after 2,000 tries, just in case an infinite loop; 
  moved=0;                                   * Count of how many sea cucumbers moved;
                                             * Copy original array to array that will be updated;
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); newcell(r,c)=cell(r,c); end; end; 

  do r=1 to dim(cell,1);                     * Update horizontal moves;
    do c=1 to dim(cell,2);
      if cell(r,c)='&amp;gt;' then do;              * Horizonal movement sea cucumber?;
        nc=ifn(c&amp;lt;dim(cell,2),c+1,1);         * Move if next cell unoccupied;
        if cell(r,nc)='.' then do; newcell(r,nc)='&amp;gt;'; newcell(r,c)='.'; moved+1; end;
        end;
    end;   
  end;   
                                             * Copy updated array back to original array; 
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); cell(r,c)=newcell(r,c); end; end;
  
  do c=1 to dim(cell,2);                     * Update vertical moves;
    do r=1 to dim(cell,1);
      if cell(r,c)='v' then do;              * Vertical movement sea cucumber?;
        nr=ifn(r&amp;lt;dim(cell,1),r+1,1);         * Move if next cell unoccupied;
        if cell(nr,c)='.' then do; newcell(nr,c)='v'; newcell(r,c)='.'; moved+1; end;
        end;
    end;   
  end;                                         
                                             * Copy updated array back to original array;
  do r=1 to dim(cell,1); do c=1 to dim(cell,2); cell(r,c)=newcell(r,c); end; end;

  put loop= moved=;                          * Report iteration #, # of sea cucumbers moved;
  if moved=0 then stop;                      * Stop if no moves (iteration # is answer);
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Dec 2021 07:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advent-of-Code-2021-Day-25-A-SAS-Solution/m-p/787385#M251579</guid>
      <dc:creator>tc</dc:creator>
      <dc:date>2021-12-25T07:30:37Z</dc:date>
    </item>
  </channel>
</rss>

