Skip to main content
VisualMelon's user avatar
VisualMelon's user avatar
VisualMelon's user avatar
VisualMelon
  • Member for 10 years, 5 months
  • Last seen this week
  • Europe
comment
Code Golf: Your own horizontal pet ASCII snake
$l=3;0..29|%{$a[$l-1][$_]=0;$l=($l-1),$l,($l+1)|?{$_%6}|Rand‌​om} saves 3 bytes also; that join at the end is crazy!
comment
Code Golf: Your own horizontal pet ASCII snake
$a=[Array](1..5|%{,(,' '*30)})
awarded
awarded
awarded
comment
Remove redundant parentheses
If you're happy to use a default alias (%) you can knock a few bytes off the pwsh: ($p="($args)")-split''|%{$p=$p-replace'\((\(((\()|[^)]|(?<-3‌​>.))*\))\)','$1'};$p‌​-replace'^.|.$'
awarded
comment
Can the 🐸 visit all the 🪷?
@tsh yes, this script generates examples where you have to visit one node at least length/2+1 times: gist.github.com/VisualMelon/50ad520ad47ad58be8cd1e4ba0e36bb9 - code has additional notes, but basically it builds a binary tree where the leaves take you back to the root of the binary tree: this means you have to traverse the tree as many times as there are leaves (and there are length/2+1 leaves).
awarded
awarded
awarded
awarded
comment
ASCII art is ready for take-off
@AdmBorkBork I wonder if that is version specific, because a script on my machine is editing the environment's $i.
comment
ASCII art is ready for take-off
@Veskah yeah, but it assumes that $i is left uninitialized, or initialised to 0 explicitly, and I'd personally rather not make that assumption ;) (if you run the script twice from the same session, it will produce incorrect results)
comment
ASCII art is ready for take-off
Adding 3 bytes so that $i is initialised (param($n,$i)) I get 120 bytes: tio.run/…
comment
ASCII art is ready for take-off
You can trade the quoted addition for raw text: ' '*($n+1)+"|" -> ' '*$n+" |"? Also, I think you can shave quite a handful of bytes by switching to inlined expressions in some of the strings, e.g. ($x=''+'-'*++$i+'')` -> ($x="*$('-'*++$i)*") ($(stuff) is cheaper than the "+stuff+"). Inlining the extra '-' there also means you can use $i instead of 2*$n, and --$i instead of ($i-2) later on. You can also assign $x in the loop to save 2 bytes.
comment
Programmer's Garden
I can't seem to get this to run correctly (ValueError: not enough values to unpack (expected 3, got 1), python 3.6.6); can you provide a TIO link or some description on how to run it. I think it might be bending the rules by assuming the input is all on one line, but I wasn't entirely clear about that in the question so I won't complain.
comment
Programmer's Garden
I like the ~H trick; I can't test this now, but I'll try to do so later today.
comment
Brute-force the switchboard
Last couple of hints (I should be asleep...) 8. Changing to s+="\n\n" and removing s="" gives you one of the outputs straight away: you just have to find a way to terminate the loop sooner (left as an exercise). 9. You can save a few bytes by re-computing m every time: added over-head of m=1, but removes the ternary (so you can use m*=2) and means you can remove j completely (replace 1<<j++ with m). Should get you down to 159. (I'm a C#er, I would never post a Java answer! and anyway, nothing I've done is original; it's just golfing your method)
comment
Brute-force the switchboard
@Marco13 indeed, they are classic tricks, but all applicable here specifically. I won't spoil the fun by giving you my 172 byte solution based on them (BTW, it think yours is 192, not 191, but I don't know how the lambda counting works: I'm opposed to it in any case).
1
2 3 4 5
20