Skip to main content
edited tags
Link
Wezl
  • 1.5k
  • 17
  • 46
add clarifications from comments
Source Link
Wezl
  • 1.5k
  • 17
  • 46

Your job is to write a function/program \$F\$ that takes a positive integer \$n\$ and generates a code fragment \$F(n)\$ (not necessarily in the same language). The outputted code fragments must have the following properties:

  • \$F(n)\$ as a full program must output the number \$n\$.
  • \$F(a)+\!\!\!+\,F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).

Your job is to write a function/program \$F\$ that takes a positive integer \$n\$ and generates a code fragment \$F(n)\$. The outputted code fragments must have the following properties:

  • \$F(n)\$ as a program must output the number \$n\$.
  • \$F(a)+\!\!\!+\,F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).

Your job is to write a function/program \$F\$ that takes a positive integer \$n\$ and generates a code fragment \$F(n)\$ (not necessarily in the same language). The outputted code fragments must have the following properties:

  • \$F(n)\$ as a full program must output the number \$n\$.
  • \$F(a)+\!\!\!+\,F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).
Became Hot Network Question
MathJax spacing
Source Link
Adám
  • 31.8k
  • 4
  • 131
  • 293
  • \$F(n)\$ as a program must output the number \$n\$.
  • \$F(a)+\!\!\!+F(b)\$\$F(a)+\!\!\!+\,F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).
  • \$F(n)\$ as a program must output the number \$n\$.
  • \$F(a)+\!\!\!+F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).
  • \$F(n)\$ as a program must output the number \$n\$.
  • \$F(a)+\!\!\!+\,F(b)\$ as a program (where \$+\!\!+\$ means concatenation) must output \$a+b\$ if \$a≥b\$, \$b−a\$ otherwise.
  • This must extend to any number of code fragments emitted by your program in the way that \$b−a\$ cases take precedence (think of an arithmetic expression with +s and -s, but the two sides of -s are flipped and it has higher precedence than +).
    • You do not need to consider the cases where three consecutive input numbers are strictly increasing (the equivalent arithmetic expression has two consecutive -s).
added 10 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 485
Loading
Tweeted twitter.com/StackCodeGolf/status/1369166086546087936
added 35 characters in body
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 485
Loading
Post Reopened by user202729, Bubbler, The Fifth Marshal, Manish Kundu, Sisyphus
To OP: Tried to clarify the task with a complete rewrite. Please review (you can roll back if necessary)
Source Link
Bubbler
  • 79.3k
  • 5
  • 162
  • 485
Loading
added 27 characters in body
Source Link
user202729
  • 17.6k
  • 2
  • 39
  • 71
Loading
added 22 characters in body
Source Link
user202729
  • 17.6k
  • 2
  • 39
  • 71
Loading
Post Closed as "Needs details or clarity" by Noodle9, caird coinheringaahing, Kirill L., rydwolf, Luis Mendo
add a hopefully simpler explanation
Source Link
Wezl
  • 1.5k
  • 17
  • 46
Loading
deleted 39 characters in body
Source Link
pxeger
  • 25.3k
  • 4
  • 59
  • 146
Loading
Source Link
Wezl
  • 1.5k
  • 17
  • 46
Loading