<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Zapwai</title>
    <description>The latest articles on DEV Community by Zapwai (@zapwai).</description>
    <link>https://dev.to/zapwai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1008799%2Fecbe55d2-f667-4fc6-ab65-defc5f23eadc.jpeg</url>
      <title>DEV Community: Zapwai</title>
      <link>https://dev.to/zapwai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zapwai"/>
    <language>en</language>
    <item>
      <title>Steam on Slackware Linux</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Fri, 09 May 2025 07:36:52 +0000</pubDate>
      <link>https://dev.to/zapwai/steam-on-slackware-linux-2b5b</link>
      <guid>https://dev.to/zapwai/steam-on-slackware-linux-2b5b</guid>
      <description>&lt;p&gt;&lt;a href="https://store.steampowered.com/" rel="noopener noreferrer"&gt;Steam&lt;/a&gt; uses 32-bit libraries, but we're on a 64-bit system. Here is the absolute fastest guide to get you up and running in &lt;a href="http://www.slackware.com/" rel="noopener noreferrer"&gt;Slackware64&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three Step Guide for Installing Steam on Slackware
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install Slackpkg+ and Enable Multilib&lt;/li&gt;
&lt;li&gt;&lt;code&gt;slackpkg install multilib&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;slackpkg install steamclient&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;[If you do not want to install slackpkg+, then the &lt;a href="http://www.slackware.com/~alien/multilib/README" rel="noopener noreferrer"&gt;multilib documentation&lt;/a&gt; can explain how to download and install the -compat32 packages (or build them yourself)]&lt;/p&gt;

&lt;p&gt;1) To install &lt;a href="https://slakfinder.org/slackpkg+.html" rel="noopener noreferrer"&gt;slackpkg+&lt;/a&gt; download and &lt;code&gt;installpkg&lt;/code&gt; from sourceforge or from &lt;a href="https://alien.slackbook.org/blog/mirror-for-slackpkg-and-slakfinder/" rel="noopener noreferrer"&gt;AlienBOB&lt;/a&gt;. (It's also available at Slackware Mirrors under /slackware/slackware64-current/extra)&lt;/p&gt;

&lt;p&gt;We make three changes to the config file &lt;code&gt;/etc/slackpkg/slackpkgplus.conf&lt;/code&gt;&lt;br&gt;
(Note that we leave &lt;code&gt;ALLOW32BIT=off&lt;/code&gt;)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uncomment the line &lt;code&gt;PKGS_PRIORITY = (multilib)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add (or uncomment) the multilib repo location&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;MIRRORPLUS['multilib']=https://slackware.nl/people/alien/multilib/current/&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add multilib to your REPOPLUS line:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;REPOPLUS=( slackpkgplus restricted multilib alienbob )&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;My config looks like this:&lt;br&gt;
&lt;code&gt;PKGS_PRIORITY=( multilib restricted  )&lt;br&gt;
REPOPLUS=( slackpkgplus restricted multilib alienbob )&lt;br&gt;
MIRRORPLUS['multilib']=https://slackware.nl/people/alien/multilib/current/&lt;br&gt;
MIRRORPLUS['alienbob']=https://slackware.nl/people/alien/sbrepos/current/x86_64&lt;br&gt;
MIRRORPLUS['restricted']=https://slackware.nl/people/alien/restricted_sbrepos/current/x86_64&lt;br&gt;
MIRRORPLUS['slackpkgplus']=https://slackware.nl/slackpkgplus/&lt;br&gt;
SBO['current']=https://github.com/Ponce/slackbuilds&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2) Now that slackpkg+ has been configured we update and install multilib packages.&lt;br&gt;
&lt;code&gt;slackpkg update&lt;/code&gt;&lt;br&gt;
&lt;code&gt;slackpkg install multilib&lt;/code&gt;&lt;br&gt;
For me this was 273 packages. In my case one of them (LLVM, roughly a 200Mb file) kept timing out, so I downloaded and installed that one manually.&lt;/p&gt;

&lt;p&gt;3) You could now build steam yourself from a &lt;a href="https://slackbuilds.org/repository/15.0/games/steam/" rel="noopener noreferrer"&gt;SlackBuild&lt;/a&gt;, or just install a pre-made package courtesy of AlienBOB:&lt;br&gt;
&lt;code&gt;slackpkg install steamclient&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You have now installed Steam. (I had to reboot for Steam to recognize my controller.)&lt;/p&gt;



&lt;p&gt;If you neglect to install the multilib -compat32 packages, instead of games you will enjoy some errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flo9p8z1bryej3ohw8c0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flo9p8z1bryej3ohw8c0z.png" alt="Missing 32-bit Libraries Error" width="800" height="341"&gt;&lt;/a&gt;&lt;br&gt;
Slackware warns that you may need 32-bit libraries, and Steam alerts that you are missing libGL.so.1 and libdrm.so.2. The terminal may emit some gory details:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dlmopen /home/zapwai/.local/share/Steam/ubuntu12_32/steamui.so failed: libGL.so.1: wrong ELF class: ELFCLASS64
dlmopen steamui.so failed: libGL.so.1: wrong ELF class: ELFCLASS64
Failed to load steamui.so - dlerror(): (null)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  My Beloved Windows Game Refuses to Install?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzgw4u0u12k3q9w2663y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxzgw4u0u12k3q9w2663y.png" alt="Image description" width="800" height="366"&gt;&lt;/a&gt;&lt;br&gt;
In that case you should right-click the game in your library, select properties, then click the Compatibility tab. Click "Force the use of a specific Steam Play compatibility tool".&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjend4il6o07puyo9p5wc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjend4il6o07puyo9p5wc.png" alt="Image description" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This turns on Proton Hotfix and almost always works. (For Risk of Rain 2 I had to explicitly turn on Proton 9.0)&lt;/p&gt;


&lt;h2&gt;
  
  
  Help! Steam Can't See My Games!
&lt;/h2&gt;

&lt;p&gt;Normally when you go to Steam Settings &amp;gt; Storage you can click on the Local Drive button and add a new folder. Useful if you have a drive full of games.&lt;/p&gt;

&lt;p&gt;In my case I had them installed under another &lt;a href="https://ubuntu.com/" rel="noopener noreferrer"&gt;Linux&lt;/a&gt; distribution. The files owner was &lt;code&gt;username:1000&lt;/code&gt; instead of &lt;code&gt;username:users&lt;/code&gt;, and in the terminal Steam was griping about permissions. So Steam client just ignored me if I added the location.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kf.kio.widgets: Failed to convert QUrl("file:///media/hd1/home/zapwai/snap/steam/common/.local/share/Steam/steamapps/common/Steam.dll") to canonical path
Couldn't write /boot/efi/.steam_exec_test.sh: Permission denied
Couldn't write /media/hd0/.steam_exec_test.sh: Permission denied
Couldn't write /media/hd1/.steam_exec_test.sh: Permission denied
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Digging around online, I found that one cause could be not having exec set for the drive in &lt;code&gt;/etc/fstab&lt;/code&gt;. But my fstab settings were fine, containing the line:&lt;br&gt;
&lt;code&gt;/dev/nvme0n1p2     /media/hd1  ext4  rw,auto,user,exec  0  0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I attempted to create and add myself to the group 1000, with no success.&lt;/p&gt;

&lt;p&gt;I could just &lt;code&gt;chmod 777&lt;/code&gt; on the path to my Steam games, but I looked for a better solution and discovered &lt;code&gt;setfacl&lt;/code&gt;. This allowed me to give rwx permissions to only one extra user.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setfacl -R -m u:zapwai:rwx /media/hd1/home/zapwai/snap/steam/common/.local/share/Steam&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I gave myself executable permissions on the rest of the path just in case&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo setfacl -m u:zapwai:x /media/hd1
sudo setfacl -m u:zapwai:x /media/hd1/home
sudo setfacl -m u:zapwai:x /media/hd1/home/zapwai
sudo setfacl -m u:zapwai:x /media/hd1/home/zapwai/snap  [etc.]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Et Voilà, Steam can now see my preinstalled games.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Few More Bugs
&lt;/h2&gt;

&lt;p&gt;This time Straima worked, but last year I needed this in the launch options:&lt;br&gt;
&lt;code&gt;PROTON_USE_WINED3D=1 %command%&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Dungeons of Dredmor has crackling audio. Removing this file fixes it.&lt;br&gt;
&lt;code&gt;~/.steam/steam/steamapps/common/Dungeons\ of\ Dredmor/x86/libopenal.so.1&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Postscript
&lt;/h2&gt;

&lt;p&gt;I also added Battle.net launcher as a non-steam game so I can run it without installing Wine directly.&lt;/p&gt;

</description>
      <category>slackware</category>
      <category>linux</category>
      <category>gaming</category>
      <category>steam</category>
    </item>
    <item>
      <title>Not Quite a Quine</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Tue, 10 Sep 2024 15:54:39 +0000</pubDate>
      <link>https://dev.to/zapwai/not-quite-a-quine-fon</link>
      <guid>https://dev.to/zapwai/not-quite-a-quine-fon</guid>
      <description>&lt;h2&gt;
  
  
  Weekly Challenge 286
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-286/" rel="noopener noreferrer"&gt;Challenge 286&lt;/a&gt; - &lt;a href="https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-286/zapwai" rel="noopener noreferrer"&gt;My Solutions&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Task One&lt;/strong&gt; Self Spammer&lt;br&gt;
Create a program that randomly prints one word of its own script / source code. (A word is anything between white-space, and every word must be printed with some positive probability.)&lt;br&gt;
e.g. 'print(" hello ")' does not work, because print(" and ") will never be displayed. (An empty script counts, but is a rather sad example.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Task Two&lt;/strong&gt; Order Game&lt;br&gt;
You are given a list of integers whose length is a power of two. Successively select the min, then max, then min, etc. of each pair of entries.&lt;br&gt;
e.g. given (0, 5, 3, 2):&lt;br&gt;
min(0,5) = 0 &amp;amp; max(3,2) = 3 =&amp;gt; new list is (0, 3):&lt;br&gt;
min(0,3) = 0 =&amp;gt; ans: 0&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution to task one&lt;/strong&gt;&lt;br&gt;
I thought of this question in February. In January, after I had burnt myself out on &lt;a href="https://adventofcode.com/" rel="noopener noreferrer"&gt;Advent of Code&lt;/a&gt;, I went back and was trying &lt;a href="https://theweeklychallenge.org/" rel="noopener noreferrer"&gt;Perl Weekly Challenges&lt;/a&gt; from the very beginning - the first few weeks - from a few years before I joined. &lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-004/" rel="noopener noreferrer"&gt;Week four&lt;/a&gt;, for example, had a challenge to print π to as many digits &lt;em&gt;as the size of your script&lt;/em&gt;. One of the more beautiful challenges I have seen.&lt;/p&gt;

&lt;p&gt;Then I was tinkering with a basic TCP server / client in Perl, and I just wanted the server to output something. A normal person would just print "Hello, World" or 'foo' or '42' or something. Spamming a word every second seemed like a nice test. So I thought: How about a script that prints a random word from itself, then I have the server call it every second?&lt;/p&gt;

&lt;p&gt;Anyway, my intention on this challenge was simply for people to read the file, but I will be very impressed if someone takes a more quine-like approach! (A &lt;a href="http://www.madore.org/~david/computers/quine.html" rel="noopener noreferrer"&gt;quine&lt;/a&gt; is a program which prints its own source - but opening a file to read the source code is considered cheating.)&lt;/p&gt;

&lt;p&gt;P.S.&lt;br&gt;
Hello jo-37! (How did you know I would be reading your script?)&lt;/p&gt;

&lt;p&gt;After reviewing others solutions, I've noticed three or four very short ones (especially using raku) that just slurp and spit out a random word.&lt;/p&gt;

&lt;p&gt;So far only one person treated it like a quine and did &lt;em&gt;not&lt;/em&gt; use an open or a slurp command! Shout-out to W. Luis Mochán (wlmb) for his &lt;a href="https://github.com/zapwai/perlweeklychallenge-club/blob/master/challenge-286/wlmb/perl/ch-1.pl" rel="noopener noreferrer"&gt;inspired solution&lt;/a&gt;. He took advantage of the somewhat weak probability constraint and made an array containing any of the symbols being used in the script. Very elegant.&lt;/p&gt;

&lt;p&gt;(P.P.S. Tim King made a quine as well!)&lt;/p&gt;

&lt;p&gt;Here was my first shot at a script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open my $fh, "&amp;lt;$0";
my @words;
while (&amp;lt;$fh&amp;gt;) {
    push @words, split " ", $_;
}
close $fh;
print $words[int rand(@words)]."\n";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Javascript I continued my "just read the file" cheat by having an HTML file that asks you to upload a file, and then you can upload the HTML file itself. &lt;/p&gt;

&lt;p&gt;I like this challenge because it's basic but still self-referential. It requires opening a file and producing a random number, which is generally useful in any language.&lt;/p&gt;

&lt;p&gt;Fairly concise in Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import random
fil=open("286-1.py","r") 
words=fil.read().split()
print(words[random.randint(0,len(words)-1)])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It inspired me to do some code golf in Perl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;open(FILE,"&amp;lt;$0");
$/=undef;
@words=split(" ",&amp;lt;FILE&amp;gt;);
print($words[int(rand($#words+1))]."\n");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only five "words"!&lt;/p&gt;

&lt;p&gt;In my solution I did a &lt;code&gt;split&lt;/code&gt;. But another natural solution I thought of would be to pick a random byte and then figure out what word you have landed in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution to task two&lt;/strong&gt;&lt;br&gt;
The trickiest part for me was getting the bounds correct; Making sure that I covered every entry after dividing the length of the array by two. Naturally when I did this in R I forgot that the indexing begins at 1 and fought with it for a few minutes. [I'm used to Perl so I got that immediately, but other languages use the actual length rather than the convenient "length minus one" given by $#ints]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.38;
use List::Util qw( min max );
my @ints = (2, 1, 4, 5, 6, 3, 0, 2);
proc(@ints);
@ints = (0, 5, 3, 2);
proc(@ints);
@ints = (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8);
proc(@ints);

sub proc(@ints) {
    say "Input: \@ints = (".join(", ", @ints).")";
    while (scalar @ints &amp;gt; 2) {
    my @L;
    for my $i (0 .. ($#ints - 1)/2) {
       if ($i % 2 == 0) {
        push @L, min($ints[2*$i], $ints[2*$i + 1]);
       } else {
        push @L, max($ints[2*$i], $ints[2*$i + 1]);
       }
    }
    @ints = @L;
    }
    say "Output: " . min(@ints);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>perl</category>
    </item>
    <item>
      <title>Lost Connections and Making Changes</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Mon, 02 Sep 2024 16:38:56 +0000</pubDate>
      <link>https://dev.to/zapwai/lost-connections-and-making-changes-anp</link>
      <guid>https://dev.to/zapwai/lost-connections-and-making-changes-anp</guid>
      <description>&lt;h2&gt;
  
  
  Weekly Challenge 285
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-285/" rel="noopener noreferrer"&gt;Challenge 285&lt;/a&gt; - &lt;a href="https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-285/zapwai" rel="noopener noreferrer"&gt;My Solutions&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Task One&lt;/strong&gt;: No Connection&lt;br&gt;
Given a list of routes, find the destination with no outgoing connection.&lt;br&gt;
For example, given [B, C] [D, B] [C, A] we have routes&lt;br&gt;
B -&amp;gt; C -&amp;gt; A&lt;br&gt;
D -&amp;gt; B -&amp;gt; C -&amp;gt; A&lt;br&gt;
C -&amp;gt; A&lt;br&gt;
Output: A&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Task Two&lt;/strong&gt;: Making Change&lt;br&gt;
Compute the number of distinct ways to make change for a given amount. (Using Pennies, Nickels, Dimes, Quarters, and Half-Dollars.)&lt;br&gt;
There are two ways to make change for 9 cents (N + 4P or 9P).&lt;br&gt;
There are three ways to make change for 10 cents (2N, N + 5P, or 10P).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Solution to task one&lt;/strong&gt;&lt;br&gt;
I make two lists, in-routes and out-routes, and then I see if there is an out that is not also an in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.38;
my @routes = (["B","C"], ["D","B"], ["C","A"]);
proc(@routes);
@routes = (["A","Z"]);
proc(@routes);

sub proc(@routes) {
    print "Input: ";
    print join(",", @{$routes[$_]})," " for (0 .. $#routes);
    print "\n";
    my @in;
    my @out;
    foreach (@routes) {
    push @in, ${$_}[0];
    push @out, ${$_}[1];
    }
    my $ans = "a";
    for my $needle (@out) {
    my $found = 0;
    for my $hay (@in) {
        if ($needle eq $hay) {
        $found = 1;
        last;
        }
    }
    if ($found == 0) {
        $ans = $needle;
    }
    }
    say "Output: $ans";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Solution to task two&lt;/strong&gt;&lt;br&gt;
This challenge was inspired by an analysis book of Pólya. (Problems and Theorems in Analysis) The first question is to count the number of ways to make change for a dollar, which is arduous. It's a trivial task for a computer, though.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.38;
my $amt = $ARGV[0] // 100;
my $cnt = 0;
for my $h (0 .. $amt/50) {
    for my $q (0 .. $amt/25) {
    for my $d (0 .. $amt/10) {
        for my $n (0 .. $amt/5) {
        for my $p (0 .. $amt) {
            if (tally($p, $n, $d, $q, $h) == $amt) {
            $cnt++;
            }
        }
        }
    }
    }
}
say "There are $cnt ways to make change for $amt cents";
sub tally($p, $n, $d, $q, $h) { $p + 5*$n + 10*$d + 25*$q + 50*$h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have used a for loop for each coin, in a stunning display of brute force.&lt;/p&gt;

&lt;p&gt;P.S.&lt;br&gt;
The original question was to be done by hand; In a manner similar to the above code, you could first divide to find the max possible number of pennies, nickels, etc that can be used. Then split into cases (i.e. H = 0, 1, or 2; Q = 0, 1, 2, 3, or 4; etc.)&lt;/p&gt;

&lt;p&gt;The second question in Pólya's book asks for a function whose coefficients A_n (in a series expansion) would equal the number of ways to make change for n cents.&lt;/p&gt;

&lt;p&gt;The concept there is that if you took a product like (1 + x + x^2 + x^3 + ... )(1 + x^5 + x^10 + x^15 + ...) the resulting series has coefficients which provide the number of ways to "make change" using pennies and nickels. (That is, a term like x^6 in our product could only have come from x * x^5 or from x^6 * 1, coinciding with the two unique ways we can make change for 6 cents.)&lt;/p&gt;

&lt;p&gt;So theoretically, one could form the correct product (using &lt;em&gt;five&lt;/em&gt; such factors, since there are five coins) - then expand and find the coefficient of the 100th term in order to find the number of ways to make change for 100 cents. That's easier said than done, however.&lt;/p&gt;

</description>
      <category>perl</category>
    </item>
    <item>
      <title>Weekly Challenge 202</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Mon, 30 Jan 2023 20:03:40 +0000</pubDate>
      <link>https://dev.to/zapwai/weekly-challenge-202-59md</link>
      <guid>https://dev.to/zapwai/weekly-challenge-202-59md</guid>
      <description>&lt;p&gt;&lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-202/" rel="noopener noreferrer"&gt;Challenge 202&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My answers will also be on &lt;a href="https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-202/zapwai" rel="noopener noreferrer"&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task One
&lt;/h2&gt;

&lt;p&gt;Given a list of integers, write a script to print 1 if there are THREE consecutive odds in the given array, otherwise print 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task Two
&lt;/h2&gt;

&lt;p&gt;In a list of altitudes, return the first widest valley.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution to Task One
&lt;/h2&gt;

&lt;p&gt;On this I return 0 if there aren't three neighboring odds, otherwise pass through to check that they are consecutive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
my @array1 = (1,5,3,6);
my @array2 = (2,6,3,5);
my @array3 = (1,2,3,4);
my @array4 = (2,3,5,7);
my @test = (\@array1, \@array2,\@array3,\@array4);    
sub are_three_odds {
    my @list = @_;
    my @ind;
    for (0 .. $#list - 2) {
    push @ind, $_ if ( ($list[$_] % 2 == 1) &amp;amp;&amp;amp; ($list[$_ + 1] % 2 == 1) &amp;amp;&amp;amp; ($list[$_ + 2] % 2 == 1) );
    }
    return 0 unless (@ind);
    foreach (@ind) {
    my @set = ($list[$_],$list[$_+1],$list[$_+2]);
    @set = sort {$a &amp;lt;=&amp;gt; $b} @set;
    if ( ($set[2] - $set[1]) == ($set[1] - $set[0])) {
        return 1;
    }
    }
    return 0;
}

for (0 .. $#test) {
    my @array = @{$test[$_]};
    say "Input: (".join(",",@array).")";
    say "Output: " . are_three_odds(@array);
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution to Task Two
&lt;/h2&gt;

&lt;p&gt;This I was able to manage with a few flags and one pass of the array. Once we stop increasing, the valley is over. Push all valleys to a collection then return the longest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
my @array1 = (1, 5, 5, 2, 8);
my @array2 = (2,6,8,5);
my @array3 = (9,8,13,13,2,2,15,17);
my @array4 = (2,1,2,1,3);
my @array5 = (1,3,3,2,1,2,3,3,2);
my @test = (\@array1,\@array2,\@array3,\@array4,\@array5);
for my $ref (@test) {
    my @array = @$ref;
    my @valley;           # push an array ref to each valley here.
    my $begin_index = 0;
    my $incr_flag = 0;      # flag after descent is complete.
    for (0 .. $#array - 1) {
    if ($incr_flag) {
        if ( $array[$_ + 1] &amp;lt; $array[$_] ) {
        push @valley, [ @array[$begin_index .. $_] ];
        $begin_index = $_;
        for my $i (1 .. $_) { # check if it was level
            if ( $array[$_] == $array[$_ - $i] ) {
            $begin_index--;
            } else {
            last;
            }
        }
        $incr_flag = 0;
        }
    } else {
        if ( $array[$_ + 1] &amp;gt; $array[$_] ) {
        $incr_flag = 1;
        }
    }
    }
    push @valley, [ @array[$begin_index .. $#array] ];
    my $max = 0;
    my $ind;
    for (0 .. $#valley) {
    if (scalar @{$valley[$_]} &amp;gt; $max) {
        $max = scalar @{$valley[$_]};
        $ind = $_;
    }
    }
    say "Input: @array";
    say "Output: @{$valley[$ind]}";
    say "-" x 10;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cryptocurrency</category>
      <category>crypto</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Weekly Challenge 201</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Wed, 25 Jan 2023 01:19:58 +0000</pubDate>
      <link>https://dev.to/zapwai/weekly-challenge-201-1ibc</link>
      <guid>https://dev.to/zapwai/weekly-challenge-201-1ibc</guid>
      <description>&lt;p&gt;&lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-201/" rel="noopener noreferrer"&gt;Challenge 201&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Task One
&lt;/h2&gt;

&lt;p&gt;You are given an array of unique numbers. Write a script to find out all missing numbers in the range 0..$n where $n is the array size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task Two
&lt;/h2&gt;

&lt;p&gt;Write a script to determine the number of ways of putting $n pennies in a row of piles of ascending heights from left to right. i.e. &lt;em&gt;List all distinct partitions of n.&lt;/em&gt;&lt;br&gt;
&lt;a href="https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-201/zapwai" rel="noopener noreferrer"&gt;My solutions on github&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution to Task One
&lt;/h2&gt;

&lt;p&gt;At first I thought there was a typo because there are always going to be &lt;em&gt;some&lt;/em&gt; missing numbers. Taking advantage of smart match:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
no warnings "experimental";
my @array = (0,1,3);
my @list;
say "Input: (" . join(",",@array).")";
print "Output: ";
for (0..scalar @array) {
    push @list, $_ unless ($_ ~~ @array);
}
say join(",", @list);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I figured this was ripe for a one-liner:&lt;br&gt;
&lt;code&gt;print for grep {!($_ ~~ @ARGV)} (0 .. @ARGV)&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution to Task Two
&lt;/h2&gt;

&lt;p&gt;This took a lot of debugging. More smart match action. I chose to start with the largest partition of n (1 + 1 + ... + 1 = n) and started adding each pair of terms, including it in our  collection if it was an ascending sequence. This was my third attempt: I initially started from the bottom (starting with n and subtracting to create (1, n-1) and (2, n-2) etc.); then I considered generating all possible partitions and filtering the ascending ones.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
no warnings "experimental";
my $n = $ARGV[0] || 5;
say "Input: \$n = $n";
print "Output: " ;
my @set = (join(" ",(1) x $n));
my $i=-1;
do {
    $i++;
    rout($set[$i]);
    @set = grep { defined($_) } @set;    
} until (length $set[$i] &amp;lt;= 3);
my $length = @set;
do {
    rout($set[$i]);
    $i++;
} while ($i &amp;lt; $length);
push @set, $n;
say scalar @set;
say foreach @set;
sub rout {
    my $s = shift;
    my @a = split(" ", $s);
    return "no" if (@a &amp;lt;= 2);
    if ($a[$#a] != 1) {
    for (1 .. @a - 2) {
        my $str = chonk($_, @a);
        push @set, $str unless ($str ~~ @set);
    }
    }
    my $str = chonk(0, @a);
    push @set, $str unless ($str ~~ @set);
}
sub chonk {         #add two elems, given offset.
    my ($offset, @a) = @_;
    my $num = $a[$#a - $offset] + $a[$#a - $offset - 1];
    splice @a, $#a - $offset - 1, 2, $num;
    my $bad_cnt;
    for (1.. $#a) {
    $bad_cnt++ if ($a[$_ - 1] &amp;gt; $a[$_]);
    }
    return if ($bad_cnt);
    return join(" ",@a);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>perl</category>
    </item>
    <item>
      <title>Weekly Challenge 200</title>
      <dc:creator>Zapwai</dc:creator>
      <pubDate>Mon, 16 Jan 2023 21:15:44 +0000</pubDate>
      <link>https://dev.to/zapwai/weekly-challenge-200-1o38</link>
      <guid>https://dev.to/zapwai/weekly-challenge-200-1o38</guid>
      <description>&lt;p&gt;I've been doing &lt;a href="https://theweeklychallenge.org/" rel="noopener noreferrer"&gt;The Weekly Challenge&lt;/a&gt; for a few weeks now, I thought this one was tricky/fun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://theweeklychallenge.org/blog/perl-weekly-challenge-200/" rel="noopener noreferrer"&gt;Challenge 200&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Task One
&lt;/h2&gt;

&lt;p&gt;An integer array is called &lt;em&gt;arithmetic&lt;/em&gt; if it has at least 3 elements and the differences between any three consecutive elements are the same. Write a script to find all Arithmetic Slices for the given array of integers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Task Two
&lt;/h2&gt;

&lt;p&gt;A seven segment display is an electronic component, usually used to display digits. Write a program that accepts any natural number and draws it as an ASCII seven segment display.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/manwar/perlweeklychallenge-club/tree/master/challenge-200/zapwai" rel="noopener noreferrer"&gt;My solutions on github&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution to Task One
&lt;/h2&gt;

&lt;p&gt;Initially I was constructing the slices during one pass of the array, but decided to create a list of start/end points to make the logic easier.&lt;br&gt;
As we traverse the list, if a difference is detected that's identical to the previous, we push the starting index to the begin array. When the difference between list elements becomes different again, the ending index is pushed to the end array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
my @array = (1,2,3,4);
#my @array = (1,2,3,5,7,9,10,11,14);
#my @array = (1,2,3,5,7,9,10,11,14,5,32,33,40,43,46,49);

sub wrap {
    my @array = @_;
    "(" . join(",", @array).")"
}

# return all sets of size 3+
sub bundle {
    my $len = @_;
    my $str; 
    unless (@_ &amp;lt; 4) {
    do {
        $len--;
        for (0 .. @_ - $len) {
        my @list;
        for my $i ($_ .. $_ + $len - 1) {
            push @list, $_[$i];
        }
        $str .= wrap(@list).", ";
        }
    } while ($len &amp;gt; 3);
    }
    $str .= wrap(@_);    
    print $str;
}

say "Input: \@array = " . wrap(@array);
if ($#array &amp;lt; 2) {
    say "Output: No slice found."; exit;
}

# indices as we traverse list
my $begin = 0;
my $end = 0;            

my @begin;
my @end;

$begin[0] = 0 if ($array[2] - $array[1] == $array[1] - $array[0]);
for my $i (0 .. $#array - 2) {
    next if ($i &amp;lt; $end);
    $begin = $i;
    my $diff = $array[$i + 1] - $array[$i];
    for my $j ($i + 1 .. $#array - 1) {
    if ($array[$j + 1] - $array[$j] == $diff) {
        $end = $j + 1;
        push @begin, $begin unless ($begin[$#begin] == $begin);
    } else {
        last if (($end == 0) or ($end[$#end] == $end));
        push @end, $end;
        last;
    }
    }
}
push @end, $end if (@begin != @end);
print "Output: ";
for my $i (0 .. $#begin - 1) {
    bundle @array[$begin[$i] ..  $end[$i]];
    print ", ";
}
bundle @array[$begin[$#begin] ..  $end[$#begin]];
say;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I converted this solution to Raku, I had to address the numerical use of an uninitialized value. Perl did not mind &lt;code&gt;($end[$#end] == $end)&lt;/code&gt; where the end array is empty, but in Raku I decided to initialize the arrays to avoid the "Use of Nil in numeric context" warning. Part of the Raku code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my $begin = 0;
my $end = 0;            

my @begin = (-1);
my @end = (-1);

@begin[1] = 0 if (@array[2] - @array[1] == @array[1] - @array[0]);
loop (my $i = 0; $i &amp;lt; @array.elems - 2; $i++) {
    next if ($i &amp;lt; $end);
    $begin = $i;    
    my $diff = @array[$i + 1] - @array[$i];
    loop (my $j = $i + 1; $j &amp;lt; @array.elems - 1; $j++) {
    if (@array[$j + 1] - @array[$j] == $diff) {
        $end = $j + 1;
        push @begin, $begin unless (@begin.tail == $begin);
    } else {
        last if (($end == 0) or (@end.tail == $end));
        push @end, $end;
        last;
    }
    }
}
push @end, $end if (@begin.elems != @end.elems);
print "Output: ";

shift @begin;
shift @end;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Solution to Task Two
&lt;/h2&gt;

&lt;p&gt;This was a fun one. Initially I wrote it with newlines so it only printed one digit. Then I modified it by adding a newline_flag to determine if we're on the final digit and require a newline character printed instead of a space.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use v5.30.0;
my @truth = qw( 1110111 0010010 1011101 1011011 0111010 1101011 0101111 1010010 1111111 1111010 );
my $N = $ARGV[0] || 200;

my $vert = 2;
my $horiz = 2*$vert + 1;

sub hor {
    my ($newline_flag, $i, @a) = @_;
    if ($a[$i]) {
    print " ";
    print "-" x $horiz;
    ($newline_flag) ? { say " " } : { print " " };
    } else {
    ($newline_flag) ? { say " " x $horiz } : { print " " x ($horiz + 2) }
    }
}

sub ver {
    my ($newline_flag, $i, @a) = @_;

    if ($a[$i]) {
    print "|";
    } else {
    print " ";
    }
    print " " x $horiz;
    if ($a[$i + 1]) {
    ($newline_flag) ? { say "|" } : { print "|" };  
    } else {
    ($newline_flag) ? { say " " } : { print " " };  
    }
}

sub d {
    my @num = @_;
    my $last = pop @num;
    foreach (@num) {
    my @a = split("", $truth[$_]);
    hor(0,0, @a);
    }
    my @b = split("", $truth[$last]);    
    hor(1,0, @b);

    my $N = $vert;
    do {
    $N--;    
    foreach (@num) {
        my @a = split("", $truth[$_]);
        ver(0,1, @a);
    }
    ver(1,1,@b);
    } while ($N &amp;gt; 0);

    foreach (@num) {
    my @a = split("", $truth[$_]);
    hor(0,3, @a);
    }
    hor(1,3, @b);

    $N = $vert;
    do {
    $N--;    
    foreach (@num) {
        my @a = split("", $truth[$_]);  
        ver(0,4, @a);
    }
    ver(1,4, @b);
    } while ($N &amp;gt; 0);

    foreach (@num) {
    my @a = split("", $truth[$_]);  
    hor(0,6, @a);   
    }
    hor(1,6, @b);
}

my @nums = split("",$N);
d(@nums);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Converting this to Raku, I had some issues with the ternary operator, and had some bugs with the split operator until I added the :skip-empty option. e.g. &lt;code&gt;my @a = split("", @truth[$_], :skip-empty);&lt;/code&gt;&lt;/p&gt;

</description>
      <category>perl</category>
      <category>raku</category>
    </item>
  </channel>
</rss>
