Activity for jhnc
| Type | On... | Excerpt | Status | Date |
|---|---|---|---|---|
| Edit | Post #296527 | Initial revision | — | about 1 month ago |
| Answer | — |
A: 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! (more) |
— | about 1 month ago |
| Comment | Post #296463 |
Why does `[34,55]` result in `[0,1]` and not `[34,55]` ?
For the other ambiguous cases, are valid answers any consecutive pair? (more) |
— | about 1 month ago |
| Edit | Post #296210 |
Post edited: save byte in length test |
— | 3 months ago |
| Edit | Post #296205 |
Post edited: why did I think grouping assignments was shorter than doing individually?! borrow m90 idea |
— | 3 months ago |
| Edit | Post #296205 |
Post edited: why did I think grouping assignments was shorter than doing individually?! borrow m90 idea |
— | 3 months ago |
| Edit | Post #295613 |
Post edited: map to set arguments instead of writing out function call four times |
— | 3 months ago |
| Edit | Post #296211 |
Post edited: accessing @- for offset of match start saves 2 bytes; improve comments |
— | 3 months ago |
| Edit | Post #296211 |
Post edited: improve comments |
— | 4 months ago |
| Edit | Post #296211 |
Post edited: fixes typos in explanatory version |
— | 4 months ago |
| Edit | Post #296211 |
Post edited: rename variables to improve clarity; using array (@l) instead of scalar ($m) allows more efficient ternary |
— | 4 months ago |
| Edit | Post #296211 |
Post edited: we can get position without using explicit counter |
— | 4 months ago |
| Edit | Post #296211 |
Post edited: invert for/map nesting to allows reusing each row read for both computations |
— | 4 months ago |
| Edit | Post #296211 |
Post edited: -a saves loading manually; reordering map saves a character |
— | 4 months ago |
| Edit | Post #296211 | Initial revision | — | 4 months ago |
| Answer | — |
A: Net or not? [Perl 5], 96 bytes Read stdin. Exits 1 if net, 0 if not. ```bash 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 vertical as shown in the challenge: nets have height 4 or 5 nets never start or end wi... (more) |
— | 4 months ago |
| Edit | Post #296210 | Initial revision | — | 4 months ago |
| Answer | — |
A: 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' ``` ```bash printf %s '#ACF' | perl -pE' # if one or two digits, triplicate s/#\K..?$/$&$&$&/; # if only three digits,... (more) |
— | 4 months ago |
| Edit | Post #296205 |
Post edited: first abs() is not required since leading minus will be ignored in regex |
— | 4 months ago |
| Edit | Post #296202 |
Post edited: typo. `exit!say` was supposed to be `exit say` |
— | 4 months ago |
| Edit | Post #296202 |
Post edited: fix transcription error (-n -> -a); moving base case test inside map allows use of $_ so shorter; |
— | 4 months ago |
| Edit | Post #296205 | Initial revision | — | 4 months ago |
| Answer | — |
A: 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 valid tour, 1 if invalid. -6 bytes from @m90. ``` perl -ne'map{$=ord;$x=$%5;$y=int$/5;exit ... (more) |
— | 4 months ago |
| Edit | Post #296202 |
Post edited: $x / $y are only used once so my isn't needed |
— | 4 months ago |
| Edit | Post #296202 | Initial revision | — | 4 months ago |
| Answer | — |
A: 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'sub R{for my$i(0..$#-1){for my$j($i+1..$#){my@r=@;$a=splice@r,$j,1;$b=splice@r,$i,1;... (more) |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: "not space" is shorter than "not comma" and avoids $_[...] ambiguity as bonus |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: using delimited list gives simpler translation and regex by avoiding uc/lc issue |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: regex match is inefficient but needs fewer characters than building a hash |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: code to generate previous position data is shorter than using raw data |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: case-insensitive match obviates mapping lookup values to uppercase |
— | 4 months ago |
| Edit | Post #296199 |
Post edited: better lookup table splitting regex avoids while loop |
— | 4 months ago |
| Edit | Post #296199 | Initial revision | — | 4 months ago |
| Answer | — |
A: 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-^/HL B79?IKM C8:HN |}1..5;map{exit(1)if$p&&$h!/$\S$p/;$p=$}/./g' ``` ``` echo 'ALURYNEHSVKBITWPGDOXQFCJM' | perl -ne' # extend board: # 789:; # ?@ # ... (more) |
— | 4 months ago |
| Edit | Post #296189 |
Post edited: shorter success check |
— | 4 months ago |
| Edit | Post #296189 |
Post edited: less efficient but much shorter permutation generation |
— | 4 months ago |
| Edit | Post #296189 |
Post edited: alternate format string compaction scheme allows shorter expansion code |
— | 4 months ago |
| Edit | Post #296189 |
Post edited: no point allowing for arbitrary length of @F when code assumes exactly 4 elements |
— | 4 months ago |
| Edit | Post #296189 |
Post edited: some explanatory comments |
— | 4 months ago |
| Comment | Post #296189 |
you would run the code in the post with space-separated input as something like `echo 1 2 3 4 | perl -aE '...'`. The `-a` option causes autosplitting into array `@F`.
However, the tio.run version is slightly modified (eg. doesn't use `-E` so has to enable the say feature; overrides the `exit`;... (more) |
— | 4 months ago |
| Edit | Post #296189 | Initial revision | — | 4 months ago |
| Answer | — |
A: 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. ```none perl -aE'map{@o=/./g;for$f("15(26(374))","15((263)74)","(15(263))74","(152)6(374)"... (more) |
— | 4 months ago |
| Edit | Post #295964 |
Post edited: new TIO link with extra test case; previous revision mistakenly linked to out-of-date code |
— | 5 months ago |
| Edit | Post #295964 |
Post edited: slightly shorter non-zero search |
— | 5 months ago |
| Comment | Post #295964 |
possibly. If you concatenate the first false and true paths, for example, you get a false but unlike the other false test cases, it also has some zero counts. my revision mistakenly checked for "any zero" instead of "all zero" ( https://tio.run/##ZY9NboMwEIX3nGKKjAIFYjbdxHLKIuoJusBuq4ggN4pEEoRDZR... (more) |
— | 5 months ago |
| Edit | Post #295964 |
Post edited: oops. reverting. not using values only works because of the specific test cases |
— | 5 months ago |
| Edit | Post #295964 |
Post edited: |
— | 5 months ago |
| Edit | Post #295899 |
Post edited: actually remove the alternation... |
— | 5 months ago |
| Edit | Post #295899 |
Post edited: remove redundant alternation |
— | 5 months ago |
| Edit | Post #295906 |
Post edited: shorter unique matches |
— | 5 months ago |
