Posts by jhnc
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)' ...
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...
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...
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...
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...
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+$...
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...
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...
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...
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!
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...
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...
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[$...
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):...
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
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!
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'...
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...
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 { ...
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/&&...
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 # ...
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)
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; #...
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...
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!
