Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Number of sides on a polygon

Perl, 102 bytes perl -nE'%h=@a=de0hen1u1d2tri3t4pe5hex6h7se7o8e9n9i20=~/\D+|\d+/g;$"="|";say/^(@a)/?$h{$1}+10*/dec/:4' perl -nE' # split bareword into list of non-digits and digits # ...

posted 5mo ago by jhnc‭  ·  edited 5mo ago by jhnc‭

Answer
#2: Post edited by user avatar jhnc‭ · 2026-04-19T01:52:30Z (5 months ago)
shorter unique matches
  • # Perl, 104 bytes
  • ```sh
  • perl -nE'@a=%h=de0hen1u1d2tri3te4pe5hex6h7sep7o8e9n9i20=~/\D+|\d+/g;$"="|";say/^(@a)/?$h{$1}+10*/dec/:4'
  • ```
  • ```sh
  • perl -nE'
  • # split bareword into list of non-digits and digits
  • # initialise mapping table %h from list
  • # initialise regex alternation list @a from %h
  • @a = %h = de0hen1u1d2tri3te4pe5hex6h7sep7o8e9n9i20 =~ /\D+|\d+/g;
  • # set array->string interpolation character for use in regex
  • $"="|";
  • say
  • /^(@a)/ # if prefix match
  • ? $h{$1} # map to number
  • + 10*/dec/ # add ten if string contains "dec"
  • : 4 # else assume is 4
  • '
  • ```
  • [Try it online!][TIO-mns0wj7o]
  • [TIO-mns0wj7o]: https://tio.run/##XZDJboMwGITvfgqEiLKXJZAN0ebQx4haufAHrBDbtY3UJe2jl5olbZzbzOdhsIeDKKO6kmAdAKtKgDWU@H0Yo7RgJx6jkfM8c3LGsnHiPo3uJmNra4322XTsxogLQtXBsgdzP5LWIMis@b1lzy5fxPUOJ4MiycArgPqVnwVKkIWCkENUwNuyWEngK7aGDd2QwEu@3f3j9KzL3Tx27MQ@27G@i/7tDo/dB6f4dPyvqe9N3AxSdxvWta7DNC9B32mBtMkZbeVrhTNBSqxA4FKTsCOXbIgUKIG7dIgEpOr/SOqo6KTQE7xUstUc66oSSpYLfGrJkai@TGAOH6TqMAeq@uoI6Vf2eqk1vxyskLw2LL3oNQJKoTcbRBn90/rNvfY93UWvvI8q02bsygbNMvKIyRVr1zJ9s4gZ6mcySPs6MxZ10CDNu83UsmU3gN92rTpokGYdM7VumQHa2czUpoMGISmTvQs89MO4IozKek5/AQ "Perl 5 – Try It Online"
  • # Perl, 102 bytes
  • ```sh
  • perl -nE'%h=@a=de0hen1u1d2tri3t4pe5hex6h7se7o8e9n9i20=~/\D+|\d+/g;$"="|";say/^(@a)/?$h{$1}+10*/dec/:4'
  • ```
  • ```sh
  • perl -nE'
  • # split bareword into list of non-digits and digits
  • # initialise regex alternation list @a from list
  • # initialise mapping table %h from @a
  • %h = @a = de0hen1u1d2tri3t4pe5hex6h7se7o8e9n9i20 =~ /\D+|\d+/g;
  • # set array->string interpolation character for use in regex
  • $"="|";
  • say
  • /^(@a)/ # if prefix match
  • ? $h{$1} # map to number
  • + 10*/dec/ # add ten if string contains "dec"
  • : 4 # else assume is 4
  • '
  • ```
  • [Try it online!][TIO-mo53z5i4]
  • [TIO-mo53z5i4]: https://tio.run/##XZDJboMwGITvfgqEiLKXJZAN0ebQx4haufAHrBDbtY3UJe2jl5olbZzbzOdhsIeDKKO6kmAdAKtKgDWU@H0Yo7RgJx6jkfM8c3LGsnHiPo3uJmNra4322XTsxogLQtXBsgdzP5LWIMis@b1lzy5fxPWgSHY4ycArgPqVnwVKkIUKOUQFvC2LlYQVW8OGbkjgJd/u/nF61tVuHjt2Yp/tWN9E/3SHx@6DU3w6/tfU9yZuBqm7Detal2Gal6BvtEDa5Iy28rXCmSAlViBwqUnYkUs2RAqUwF06RAJS9X8kdVR0UugBXirZao51VQklywU@teRIVF8mMIcPUnWYA1V9dYT0I3u91JpfDlZIXhuWXvQaAaXQmw2ijP5p/eZe@57uolfeR5VpM3Zlg2YZecTkirVrmb5ZxAz1MxmkfZ0ZizpokObdZmrZshvAb7tWHTRIs46ZWrfMAO1sZmrTQYOQlMneBR76YVwRRmU9p78 "Perl 5 – Try It Online"
#1: Initial revision by user avatar jhnc‭ · 2026-04-09T22:05:34Z (5 months ago)
# Perl, 104 bytes

```sh
perl -nE'@a=%h=de0hen1u1d2tri3te4pe5hex6h7sep7o8e9n9i20=~/\D+|\d+/g;$"="|";say/^(@a)/?$h{$1}+10*/dec/:4'
```

```sh
perl -nE'
    # split bareword into list of non-digits and digits
    # initialise mapping table %h from list
    # initialise regex alternation list @a from %h
    @a = %h = de0hen1u1d2tri3te4pe5hex6h7sep7o8e9n9i20 =~ /\D+|\d+/g;

    # set array->string interpolation character for use in regex
    $"="|";

    say
        /^(@a)/       # if prefix match
        ? $h{$1}      #   map to number
          + 10*/dec/  #   add ten if string contains "dec"
        : 4           # else assume is 4
'
```


[Try it online!][TIO-mns0wj7o]

[TIO-mns0wj7o]: https://tio.run/##XZDJboMwGITvfgqEiLKXJZAN0ebQx4haufAHrBDbtY3UJe2jl5olbZzbzOdhsIeDKKO6kmAdAKtKgDWU@H0Yo7RgJx6jkfM8c3LGsnHiPo3uJmNra4322XTsxogLQtXBsgdzP5LWIMis@b1lzy5fxPUOJ4MiycArgPqVnwVKkIWCkENUwNuyWEngK7aGDd2QwEu@3f3j9KzL3Tx27MQ@27G@i/7tDo/dB6f4dPyvqe9N3AxSdxvWta7DNC9B32mBtMkZbeVrhTNBSqxA4FKTsCOXbIgUKIG7dIgEpOr/SOqo6KTQE7xUstUc66oSSpYLfGrJkai@TGAOH6TqMAeq@uoI6Vf2eqk1vxyskLw2LL3oNQJKoTcbRBn90/rNvfY93UWvvI8q02bsygbNMvKIyRVr1zJ9s4gZ6mcySPs6MxZ10CDNu83UsmU3gN92rTpokGYdM7VumQHa2czUpoMGISmTvQs89MO4IozKek5/AQ "Perl 5 – Try It Online"