Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

2 of 2
added 268 characters in body
brhfl
  • 1.5k
  • 11
  • 14

dc, (削除) 164 (削除ここまで) 162 bytes

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzS zzS?zzzzzzzzzzzzS$zzzzzzzzzzzzzzzzzzzzzzzzzzzzzPzzzzzzzzzzzzzzzzSwzzzzzzzzzzzzzzzPzzzzzzzzSLzPzPzzzzPL$PL PLwPzPzzzzPLLPAI*PL?P

Try it online!

There's likely a better/more interesting approach. I tried using the ASCII+256 trick that dc has, but that outputs additional characters as well (even if they're non-printing), and once I got to 'o', the wonderfully prime 111, I ran into trouble even getting a value of 111+(multiple of 256) that factored cleanly. So here's a fairly straightforward (albeit golfed where possible) solution:

In dc, z is a command that pushes the stack depth onto the stack. That means we can use it as an increment. This is how I create most of my ASCII values for this challenge (printed with P), which I push onto named stacks with S and pop back onto the main stack with L.

dc lets you use the hex values A-F even when the input radix is decimal (default). (削除) Luckily, our first letter, 72, is a multiple of 12, so I save a byte or two here by multiplying 6*12 and printing immediately (zzzzzzzC*P). (削除ここまで) My 164-byte version used multiplication early on to get 72 ('H'), which was mildly clever but a holdover from an earlier attempt, and a waste of bytes. Now, I start by incrementing and saving the space, the exclamation point, and the comma, which are out of order, and therefore can't be printed yet. Next, I come to the 'H', which I print immediately, before I get to 'W', which I must save for later.

I simply print when I hit the 'e', then I increment up to 'l'. I print two of those and save one. When I make it to 'o', I first thought I'd have to save one of those for later, but everything is kind of in order at this point. I print an 'o', retrieve my comma, space, and 'W' from earlier, and now I'm right back to 'o'. I print this, and increment a few up to the highest necessary value, 'r' (114), which I print before loading and printing the 'l' I tucked away earlier.

Almost done! 'd' is ASCII value 100, which is easily made by multiplying 10*10 (fewer bytes than having stored it earlier and loading it now). Hex value A is 10, as is our input radix which we can retrieve with the command I. Multiply those, print, and then load and print our exclamation point from earlier. Hello, World!

brhfl
  • 1.5k
  • 11
  • 14

AltStyle によって変換されたページ (->オリジナル) /