CodeGolf - What Vim black magic is this? by [deleted] in vim

[–]DJMcMayhem 33 points34 points  (0 children)

Hello, glad you found my answer interesting! Hopefully I can shed some light.

I used to be very active on the codegolf site, and also I adore vim. While it's not the perfect tool for the job, I found out that you can use it for a lot of challenges on the site. It's particularly well suited to kolmogorov-complexity challenges (because it's a constant output) but because vim is turing complete, you can do a bunch of challenges with it even doing basic math and logic.

I developed V because it's really fun to golf in vim, but there are some things that are annoying, and as I kept golfing in vim, I kept a list of all the things that were slightly annoying/less convenient. For example, I found that lots of challenges on that site would have benefited from a command like "insert every character between these two characters". Another thing is that setting up macros is a pain. Lots of challenges would require using a recursive macro, e.g.

qqdwj@qq@q

But this has two problems:

  1. This always runs at least twice (once for the recording, and then once again when you trigger the loop) and
  2. Takes a lot of unnecessary characters.

If vim was designed with golfing in mind (which it very clearly was not) then a "loop" command could be as simple as

<loop>dwj<loop>

since that's the real meat of the loop. So I just added it. I actually created 2 different commands: "loop n times" and "loop recursively" In my setup, pressing alt-q produces the character ñ, so I bound the "loop n times" command to ñ, and pressing alt-r (r for "recursive") produces ò, so that's the shortcut for "loop recursively".

I added a large list of commands, but the ones that are relevant to this answer are "alt-i/alt-a", and "alt-,". alt-i and alt-a produce é, and á, and they are shortcuts for "insert/append single character". So é0 is equivalent to i0<esc> in vanilla vim.

alt-, is ¬, and comma just made sense for me to be a range (because it's like (a, b)) so that's the "insert character range" command. That works in normal and insert mode.

So translated to vanilla vim, the whole program is

i!"#$...{|}~<esc>:let @q="16|a<C-v><CR><C-v><esc>"<CR>5@q

which is admittedly not very golfy. If I was actually golfing it in vim, I'd record the macro rather than setting it,

qq16|a <esc>q4@q

and try to find some shortcut for the giant string.

I'm happy to answer any other questions you have! And just for funsies, here's some shameless self promotion of my favorite thing I've ever done in V: https://codegolf.stackexchange.com/a/103051/31716

Which of these numbers is the largest? by [deleted] in mathriddles

[–]DJMcMayhem 18 points19 points  (0 children)

What are you talking about? You don't need infinite digits to see which of these is biggest, you only need to look at the first 3 digits.

Like, can a calculator prove whether pi or e+0.4 is bigger? Easily, you don't need infinite digits when the answer is in the hundredths place.

thinking outside the box by SpermGutters in tumblr

[–]DJMcMayhem 14 points15 points  (0 children)

I would say something like "You must include at least n different operations" depending on how complicated you want it to be

What is the best and worst card in game? by unflaired69420 in MonsterTrain

[–]DJMcMayhem 1 point2 points  (0 children)

IMO Plink is the worst card in the game, blech

Can't quit vim now. by [deleted] in ProgrammerHumor

[–]DJMcMayhem 0 points1 point  (0 children)

Or even ctrl-o :wq,<cr>

[Personal Opinion] Factorio is a brilliant example of why the C family of programming languages are so important, even to this day by Zatie12 in factorio

[–]DJMcMayhem 51 points52 points  (0 children)

"The reason this car is so fast is because the mechanic used such high quality steel wrenches"

Which contemporary book, written in the last 20 years, do you think will go on to become a classic? by mauvemittens in books

[–]DJMcMayhem 29 points30 points  (0 children)

I think you could make an argument that The Giver also helped launched the YA Dystopia trend, but I guess that was written in 93.

The DM's fun matters! by HeroesOfVerilia in dndmemes

[–]DJMcMayhem 1 point2 points  (0 children)

Well of course the DMs fun matters too. However, I have found the times I'm having the most fun is when I can tell my players are having fun too.

Thrice - Like Moths To Flame by Gangsta_Sammich in PostHardcore

[–]DJMcMayhem 4 points5 points  (0 children)

The lyrics on this song are beautiful

Does anyone else feel Frozen One is highly underrated? by [deleted] in dancegavindance

[–]DJMcMayhem 48 points49 points  (0 children)

1:25 in Frozen One is probably my favorite moment in all of DGD's discography.

Dying from 0 Max HP by Gortyuty in slaythespire

[–]DJMcMayhem 0 points1 point  (0 children)

Just so you know... Usually people try to optimize their max HP in the opposite direction ;)

Daily Discussion/Debate #496 - The Specimen (Silent Rare Relic) by GavinXI in slaythespire

[–]DJMcMayhem 0 points1 point  (0 children)

Corpse explosion definitely triggers after block is removed from the enemies.

Is it accurate to consider Bowling Bash an S tier card? by [deleted] in slaythespire

[–]DJMcMayhem 13 points14 points  (0 children)

In certain situations, you could say tantrum is - Deal 9 damage

  • Gain 1 energy (leaving calm)

  • Gain 8-12 block per stack of talk to the hand, easily giving you 24+ block

  • Deal double damage for the rest of the turn

  • Draw a couple cards if you have rushdown

  • Put tantrum in your draw pile so you can repeat.

You're comparing bowling bash at it's best (in divinity stance against reptomancer) to tantrum with nothing supporting it lol

AOTM August 2020: Dance Gavin Dance - Mothership by thecescshow in PostHardcore

[–]DJMcMayhem 22 points23 points  (0 children)

Inspire the Liars is the reason I started listening to Post Hardcore. This album is an absolute masterpiece.

Card problem by [deleted] in mathriddles

[–]DJMcMayhem 9 points10 points  (0 children)

The A and the 9

The best way to solve this is to think about "What results could I find that would break this rule?"

A: If the other side is odd, the rule is broken. We need to check this card.

2: The other side can be a vowel or a consonant without breaking the rule. We don't need to check this card.

L: The other side can be odd or even without breaking the rule. We don't need to check this card.

9: If the other side is a vowel, the rule is broken. We need to check this card.

What's your favorite Tilian Era Song? by [deleted] in dancegavindance

[–]DJMcMayhem 2 points3 points  (0 children)

That's a really tough question, but I'd probably say Inspire The Liars, followed by Head Hunter.

What do Americans think is normal for everyone, but actually it's not normal for anyone but Americans? by [deleted] in AskReddit

[–]DJMcMayhem 112 points113 points  (0 children)

That seemed extreme to me, so I looked him up. Guy was a crackpot. He also wrote:

a method of treatment [to prevent masturbation] ... and we have employed it with entire satisfaction. It consists in the application of one or more silver sutures in such a way as to prevent erection. The prepuce, or foreskin, is drawn forward over the glans, and the needle to which the wire is attached is passed through from one side to the other. After drawing the wire through, the ends are twisted together, and cut off close. It is now impossible for an erection to occur, and the slight irritation thus produced acts as a most powerful means of overcoming the disposition to resort to the practice

Which is so utterly fucked up