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 »

Posts by jhnc‭

46 posts
71%
+3 −0
Challenges Identifying returning paths.

Perl, 122 bytes Reads line from stdin, exits 0 if true; 1 if false. perl -nE'@s=(0)x 3;map{@e=($x+=/x/-/X/,$y+=/y/-/Y/,$z+=/z/-/Z/);$c{"@s @e"}++;$c{"@e @s"}--;@s=@e}/./g;exit(%c<grep$_,%c)' ...

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

Answer
66%
+2 −0
Challenges Net​​ or​​ not?

Perl 5, 96 bytes Read stdin. Exits 1 if net, 0 if not. perl -00ae'@l=@r=map{++$c[$-[0]]while/#/g;y/#//||()}@F;@r>@c?@r:@l=@c;exit!grep$r[$_]>@l-2,0,-1' When oriented with longer side ver...

posted 4mo ago by jhnc‭  ·  edited 3mo ago by jhnc‭

Answer
66%
+2 −0
Challenges 5 by 5 knight's tour string validator

Perl 5, 93 bytes I am disappointed to discover that just doing the obvious coordinate calculations requires fewer bytes than my lookup table approach. 😢 Reads a string from stdin. Exits 0 if vali...

posted 4mo ago by jhnc‭  ·  edited 3mo ago by jhnc‭

Answer
66%
+2 −0
Challenges 24 game automated solver

Perl 5, 178 bytes Another brute-force approach. Reads line of space-separated digits from stdin. If possible, prints answer to stdout and exits 1. Otherwise prints nothing and exits 0. perl -aE...

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

Answer
66%
+2 −0
Challenges 24 game automated solver

Perl 5, 228 bytes Brute-force check. Reads line of space-separated digits from stdin. Prints answer to stdout. If empty output is permitted as "impossible", omit final say to save 10 bytes. per...

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

Answer
66%
+2 −0
Challenges Digits from words

Perl, 127 bytes Reads string on stdin; display appropriate integer on stdout perl -nE'%h=@a=o1te10el11twel12th3t2fo4f5si6s7e8n9=~/\D+|\d+/g;$"="|";/^(@a)/;$a=$h{$1}+10*/een/;say/y$|-(@a)/?10*$a+$...

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

Answer
66%
+2 −0
Challenges Single letter HTML

awk, 12 bytes Print nothing if false, 1 if true $0=/[abipq]/ replace input with result of match no match: assigns false (empty string) ⇒ default print action is skipped match: assigns tr...

posted 6mo ago by jhnc‭

Answer
66%
+2 −0
Challenges Coat of Many Colours

Perl, 111 bytes Function taking array of lowercase strings as argument and returning a sorted version. sub J{map{$k=lc;grep{!index$_,$k}@_}ReYGreeBrScBlaOcPeRubOlVFLiGoChMCreCriSiRoALeRusGreyPuWP...

posted 6mo ago by jhnc‭

Answer
66%
+2 −0
Challenges Pinwheel ​words

Perl, 223 bytes Reads single word from stdin. Prints rotated word. perl -ple'$n=length;$a=$_;$n==y/HINOSXZlosxzMWbqdphymwnu/HINOSXZlosxzWMqbpdyhwmun/||$n==($_=$a)=~y/AHIMOTUVWXYbdilmopqvwx/AHIMOT...

posted 6mo ago by jhnc‭

Answer
66%
+2 −0
Challenges How many odd digits?

Perl, 22 bytes perl -pe'$_=y/13579//' input as newline-separated list of (one or more) strings y returns the number of characters replaced or deleted Try it online!

posted 6mo ago by jhnc‭

Answer
66%
+2 −0
Challenges The 50 substrings that validate any string of Roman numerals

Python, 142 bytes import re r=lambda c:re.search(r'([CIMX])\1{3}|C[CM][DM]|C[DM]C|I[IX][VX]|I[VX]I|VI?[VX]|XC[CLX]|XLX|[DX]C?[DM]|[ILV][CDLM]|[ILX]X[CL]|',c)[0] almost same regex as my Per...

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

Answer
66%
+2 −0
Challenges The 50 substrings that validate any string of Roman numerals

Bash, 118 bytes same regex as my Perl answer the longer version here is pure bash, the short one calls out to POSIX(ish) utilities grep -Eo '([CIMX])\1{3}|C[CM][DM]|C[DM]C|I[IX][VX]|I[VX]I...

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

Answer
66%
+2 −0
Challenges Connected ​bits

Perl, 152 bytes Pass 64 character string of 1s and 0s on stdin. Zero exit means success; non-zero means failure. perl -ne's/.{8}\K/2/g;@g=/./g;sub c{my($i)=@_;$i<0||$i>71||$g[$i]-$v||($g[$...

posted 6mo ago by jhnc‭  ·  edited 3mo ago by jhnc‭

Answer
66%
+2 −0
Challenges The 50 substrings that validate any string of Roman numerals

Perl, 119 bytes Read a single Roman numeral on stdin (optionally newline-terminated). Outputs nothing unless one of the 50 strings is found, in which case it is printed (without trailing newline):...

posted 7mo ago by jhnc‭  ·  edited 6mo ago by jhnc‭

Answer
66%
+2 −0
Challenges Lone ​​​​​​ones

awk, 35 bytes Takes input as newline-separated list of binary strings. awk '{gsub(/11+|0+/,_);$0=length}1' strip all runs of 0s and two or more 1s print length of remaining string

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

Answer
60%
+1 −0
Challenges Find the garden of Eden

Perl, 80 bytes Naïve implementation of the suggested algorithm. sub g{pop until@_<3||$_[-3]+$_[-2]-$_[-1];shift until@_<3||$_[0]+$_[1]-$_[2];@_} Try it online!

posted 1mo ago by jhnc‭

Answer
60%
+1 −0
Challenges Expand a greyscale/colour hex code

Perl 5, 47 bytes Reads code from stdin (trailing newline is optional). Writes result to stdout. perl -pE's/#\K..?$/$&$&$&/;/.{5}/||s/\w/$&$&/g' printf %s '#ACF' | perl -pE'...

posted 4mo ago by jhnc‭  ·  edited 3mo ago by jhnc‭

Answer
60%
+1 −0
Challenges 5 by 5 knight's tour string validator

Perl 5, 121 bytes Reads a string from stdin. Exits 0 if valid tour, 1 if invalid. perl -ne'map{$h=~y/7-^/<-c/;$h.=q|A8>HL B79?IKM C8:<@FJLN D9;=GMO E:>HN |}1..5;map{exit(1)if$p&&a...

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

Answer
60%
+1 −0
Challenges Calculate the Z-array

Perl, 61 bytes Takes Perl list as argument; returns Perl list (in list context). sub z{map{$a=0;$a++while$a<@_&&$F[$a]==$_[$a];shift;$a}@F=@_} sub z { map { ...

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

Answer
60%
+1 −0
Challenges Is it a valid hidden word?

Perl, 113 bytes reads line from stdin formatted as the test cases. Exits with 1 valid or 0 if invalid. perl -lF,. -E'($_,$n)=@F;@r=map{$n=~s/.{$_}\K/.*/r}1..length$n-1;$"="|";exit(!/$n/&&...

posted 5mo ago by jhnc‭

Answer
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
60%
+1 −0
Challenges Single letter HTML

sed, 12 bytes Print nothing if true; newline if false. /[abipq]/d;x if match, delete and go to next line of input else swap input with empty hold space and print (gives newline)

posted 6mo ago by jhnc‭

Answer
60%
+1 −0
Challenges Create an Alphabet Diamond

Perl, 73 bytes $_="A$/";$b=A;$a=$b++,s|^| |gm,s| (.*$a)(.*$/)|$&$1$b$a$2$&| until/Z/;say Explanation: # initialise output string and replacement character $_ = "A$/"; $b = A; #...

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

Answer
60%
+1 −0
Challenges Truthify an array

Perl, 65 bytes Takes 2D array as input. Returns array of zero-indexed pairs. sub f{map{my$x=$_;map[$x,$_],grep$_[$x][$_],keys@{$_[$_]}}keys@_} Because f [[...],[...],...] is Perl syntax to...

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

Answer
60%
+1 −0
Challenges Merge two strings

Perl, 43 bytes Takes two strings with arbitrary content. Returns merged result. sub f{"@_"=~s/(.*)\K$"(?=\Q$_[1]\E$)\1//sr} Inspired by Wezl's sed regex. Try it online!

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

Answer