2
\$\begingroup\$

What general tips do you have for golfing in 1+? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to 1+ (e.g. "remove unnecessary whitespace" is not an answer).

Please post one tip per answer.

\$\endgroup\$
  • \$\begingroup\$ This 1+? \$\endgroup\$ – Unrelated String Sep 24 at 4:45
  • \$\begingroup\$ @UnrelatedString Yes. \$\endgroup\$ – HighlyRadioactive Sep 24 at 4:45
  • 3
    \$\begingroup\$ Are there actually any answers on this site that use 1+? I'm all for tips pages, but they don't seem necessary if no-one has ever even used the language here. \$\endgroup\$ – caird coinheringaahing Sep 24 at 8:17
  • \$\begingroup\$ @cairdcoinheringaahing Oops. I will do it, then. (Though, because it's a Turing-tarpit, it would be very hard to do simple tasks for usual languages, e. g. ROT13.) \$\endgroup\$ – HighlyRadioactive Sep 24 at 9:45
  • 5
    \$\begingroup\$ @TwilightSparkle Why is that hosted on Tumblr??? That's bizarre. Here's a Gist: gist.github.com/DJMcMayhem/c7186ae2890b5c8a54e38ba7a595a7d5 \$\endgroup\$ – DJMcMayhem Sep 24 at 14:40
2
\$\begingroup\$

Subroutines can have empty names

(|1+1<) is a valid definition for a subroutine, invoked as ().

\$\endgroup\$
  • \$\begingroup\$ Excellent! I haven't thought of that. \$\endgroup\$ – HighlyRadioactive Oct 6 at 1:37
1
\$\begingroup\$

Instead of pushing 0 and compare, do something to other numbers

As 1 is the only literal in 1+ and there's no minus operation, pushing 0 would be expensive (11+1<). A better choice would be change other numbers, so 1 becomes a "relative" 0. For example, if you want to flip a bit, instead of 11+1<<, you can 1+1<.

\$\endgroup\$
0
\$\begingroup\$

Instead of exchange and compare, arrange the stack carefully

You don't have to take all input at the beginning of the program. For example, to truthify the input, you can 1.< instead of .1^<.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.