text:
Boustrophedonise
Related but very different.
A boustrophedon is a text where every other line of writing is flipped or reversed, with reversed letters.
In this challenge, we will just reverse every other line, but leave the actual characters used intact. You may chose which lines to reverse, as long as it is every other one.
You may take the text in any suitable format as long as you support zero or more lines of printable ASCII, each with zero or more characters.
Examples:
["Here are some lines","of text for you","to make a","boustrophedon"]:

["Here are some lines","uoy rof txet fo","to make a","nodehportsuob"] or ["senil emos era ereH","of text for you","a ekam ot","boustrophedon"]

["My boustrophedon"]:

["My boustrophedon"] or ["nodehportsuob yM"]

[]:
[]

["Some text","","More text","","","Last bit of text"]:

["Some text","","More text","","","txet fo tib tsaL"] or ["txet emoS","","txet eroM","","","Last bit of text"]

Can't understand if return and input need to be text separated lines or it can be a file or a list of lines.

@sergiol Default PPCG I/O rules apply.

Can my code behave inconsistently, i.e. sometimes start reversing from the first line and sometimes from the second?

@EriktheOutgolfer Yes, I asked about this earlier and the wording of "You may chose which lines to reverse, as long as it is every other one." was actually changed to what it is now to make it general enough for that behaviour.

More answer than upvotes...

Perhaps a good testcase: ["Some text","","More text","","","Last bit of text"]

@totallyhuman Yes, as per OP.

How does the last example work? "Last bit of text" is never reversed and "More text" always is.

@CJDennis Fixed.

Related

APL (Dyalog Classic), 4 bytes
⊢∘⌽\

The input is a vector of character vectors.
⌽ is a function that reverses a vector (when ⌽ is applied monadically).
⊢ is "dex" - a function that returns its right argument. When composed (∘) with another function f it forces the latter to be monadic as A ⊢∘f B is equivalent to A ⊢ (f B) and therefore f B.
\ is the scan operator. g\A B C ... is the vector A (A g B) (A g (B g C)) ... where g is applied dyadically (infix notation). Substituting ⊢∘⌽ for g it simplifies to:
A (A ⊢∘⌽ B) (A ⊢∘⌽ (B ⊢∘⌽ C)) ...
A (⌽B) (⌽⌽C) ....
A (⌽B) C ....

The reversals at even positions (or odd, depending on how you count) cancel out.
Try it online!

That’s literally ]&|.&.>/\ for those who can read J.

This is really clever.

Haskell, 26 bytes
zipWith($)l
l=id:reverse:l

Try it online! Usage example: zipWith($)l ["abc","def","ghi"] yields ["abc","fed","ghi"].
Explanation:
l is an infinite list of functions alternating between the identity function and the reverse function.
The main function zips l and the input list with the function application $, that is for an input ["abc", "def", "ghi"] we get [id$"abc", reverse$"def", id$"ghi"].

Husk, 4 bytes
z*İ_

Takes and returns a list of strings (the interpreter implicitly joins the result by newlines before printing).
The first string is reversed.
Try it online!
Explanation
z*İ_  Implicit input.
  İ_  The infinite list [-1,1,-1,1,-1,1..
z     Zip with input
 *    using multiplication.

In Husk, multiplying a string with a number repeats it that many times, also reversing it if the number is negative.

the special case of * with negatives should be added to the docs.

JavaScript (ES6), Firefox, 43 bytes
This version abuses the sort algorithm of Firefox. It generates garbage on Chrome and doesn't alter the strings at all on Edge.
a=>a.map((s,i)=>[...s].sort(_=>i&1).join``)

Test cases

let f =

a=>a.map((s,i)=>[...s].sort(_=>i&1).join``)

console.log(f(["Here are some lines","of text for you","to make a","boustrophedon"]))
console.log(f(["My boustrophedon"]))
console.log(f([]))

Or Try it online! (SpiderMonkey)

JavaScript (ES6), 45 bytes
a=>a.map(s=>(a^=1)?s:[...s].reverse().join``)

Test cases

let f =

a=>a.map(s=>(a^=1)?s:[...s].reverse().join``)

console.log(f(["Here are some lines","of text for you","to make a","boustrophedon"]))
console.log(f(["My boustrophedon"]))
console.log(f([]))

Haskell, 27 bytes
foldr((.map reverse).(:))[]

Try it online!
Haskell, 30 bytes
f(a:b:c)=a:reverse b:f c
f a=a

Try it online!
Recursion FTW.

Perl 5, 17 + 2 (-pl) = 19 bytes
odd lines reversed
$_=reverse if$.%2

even lines reversed
$_=reverse if$|--

After @Martin's comment : input needs to have a trailing linefeed.
try it online

APL (Dyalog Unicode), 10 bytes
⌽¨@{2|⍳≢⍵}

Works both ways:
Try it online! with ⎕IO←1
Try it online! with ⎕IO←0
How it works:
⌽¨@{2|⍳≢⍵} ⍝ tacit prefix fn
   {   ≢⍵} ⍝ Length of the input
      ⍳    ⍝ generate indexes from 1 (or 0 with ⎕IO←0)
    2|     ⍝ mod 2; this generates a boolean vector of 0s (falsy) and 1s (truthy)
  @        ⍝ apply to the truthy indexes...
⌽¨         ⍝ reverse each element

05AB1E, 5 4 bytes
εNFR

Try it online!
Explanation
ε     # apply to each element (row)
 NF   # index times do:
   R  # reverse

R, 85 bytes
for(i in seq(l<-strsplit(readLines(),"")))cat("if"(i%%2,`(`,rev)(l[[i]]),"\n",sep="")

Try it online!
Input from stdin and output to stdout.
Each line must be terminated by a linefeed/carriage return/CRLF, and it prints with a corresponding newline. So, inputs need to have a trailing linefeed.

I like what you did with the function names in the if. It's less fun, but '(' could be c for -2 bytes. Also, \n can be an actual new line for -1.

K (oK), 17 14 bytes
Solution:
@[;&2!!#x;|]x:

Try it online!
Example:
@[;&2!!#x;|]x:("this is";"my example";"of the";"solution")
("this is"
"elpmaxe ym"
"of the"
"noitulos")

Explanation:
Apply reverse at odd indices of the input list:
@[;&2!!#x;|]x: / the solution
            x: / store input as variable x
@[;      ; ]   / apply @[variable;indices;function] (projection)
          |    / reverse
       #x      / count (length) of x, e.g. 4
      !        / til, !4 => 0 1 2 3
    2!         / mod 2, 0 1 2 3 => 0 1 0 1
   &           / where true, 0 1 0 1 => 1 3

Notes:

switched out &(#x)#0 1 for &2!!#x to save 3 bytes

APL (Dyalog), 12 bytes
⍳∘≢{⌽⍣⍺⊢⍵}¨⊢

Try it online!

Jelly, 5 4 bytes
U¹ƭ€

Try it online!
Thanks HyperNeutrino for -1 bytes! (actually because I never knew how ƭ works due to lack of documentation, this time I got lucky)

Tried ¦ with m (7 bytes). s2U2¦€;/ is also 7 bytes.

Python 2, 40 36 bytes
-4 bytes thanks to @Mr.Xcoder
def f(k):k[::2]=map(reversed,k[::2])

Try it online!
Outputs by modifying the input list

Python 2, 43 bytes
f=lambda k,d=1:k and[k[0][::d]]+f(k[1:],-d)

Try it online!

J, 9 bytes
(,|.&.>)/

Reduce from right to left, reversing all strings in the result and prepending the next string as is.
Try it online!
We can do 6 using ngn’s approach, but there will be extra spaces:
]&|./\

Try it online!

Alumin, 66 bytes
hdqqkiddzhceyhhhhhdaeuzepkrlhcwdqkkrhzpkzerlhcwqopshhhhhdaosyhapzw

Try it online!
FLAG: h
hq
  CONSUME A LINE
  qk
  iddzhceyhhhhhdaeuze
  pk
  rlhcw
  REVERSE STACK CONDITIONALLY
  dqkkrhzpkzerlhcwqops

  OUTPUT A NEWLINE
  hhhhhdao
syhapzw

@totallyhuman This is actually my language.

T-SQL, 65 bytes
Our standard input rules allow SQL to input values from a pre-existing table, and since SQL is inherently unordered, the table must have row numbers to preserve the original text order.
I've defined the table with an identity column so we can simply insert lines of text sequentially (not counted toward byte total):
CREATE TABLE t
    (i int identity(1,1)
    ,a varchar(999))

So to select and reverse alternating rows:
SELECT CASE WHEN i%2=0THEN a
ELSE reverse(a)END
FROM t
ORDER BY i

Note that I can save 11 bytes by excluding the ORDER BY i, and that is likely to return the list in the original order for any reasonable length (it certainly does for the 4-line example). But SQL only guarantees it if you include the ORDER BY, so if we had, say, 10,000 rows, we would definitely need this.

V, 4 bytes
òjæ$

Try it online!
ò      ' <M-r>ecursively (Until breaking)
 j     ' Move down (breaks when we can't move down any more)
  æ$   ' <M-f>lip the line to the end$

Perl 6, 44 bytes
lines.map: ->\a,$b?{a.put;.flip.put with $b}

Try it
lines               # get the input as a list of lines
.map:
-> \a, $b? {        # $b is optional (needed if there is an odd number of lines)
  a.put;            # just print with trailing newline
  .flip.put with $b # if $b is defined, flip it and print with trailing newline
}

Comma delimited:
Stax, 12 bytes
ü«äì╠▒╕█╬pεû

Run and debug it
input: ABC,def,GHI,jkl,MNO,pqr,STU
Newline delimited:
Stax, 8 bytes
Çε÷┘)¼M@

Run and debug it
input:
ABC
def
GHI
jkl
MNO
pqr
STU

output for both:
CBA
def
IHG
jkl
ONM
pqr
UTS

Brachylog, 4 bytes
i↔ⁱ⁾

Try it online!
Doesn't feel entirely honest to call this generator a 4-byter considering it costs 3 more bytes to actually use it.
i       Take an element from the input paired with its 0-index,
 ↔ ⁾    and reverse the element
  ⁱ     repeatedly
   ⁾    a number of times equal to the index.

C#, 64 54 + 18 bytes
Try It Online!
a=>a.Select((x,i)=>i%2<1?x:string.Concat(x.Reverse())).ToArray()

Saved 10 bytes by returning IEnumerable

Pyth, 6 bytes
.e@_Bb

Try it here!

.e ~ Enumerated map. k is the index, b is the current element.

_Bb ~ Bifurcate b with its reverse.

@ ~ Modular index in ^ with k.

Alice, 13 bytes
M%/RM\
d&\tO/

Try it online!
Input via separate command-line arguments. Reverses the first line (and every other line after that).
Explanation
       At the beginning of each loop iteration there will always be zero
       on top of the stack (potentially as a string, but it will be
       converted to an integer implicitly once we need it).
M      Push the number of remaining command-line arguments, M.
%      Take the zero on top of the stack modulo M. This just gives zero as
       long as there are arguments left, otherwise this terminates the
       program due to the division by zero.
/      Switch to Ordinal mode.
t      Tail. Implicitly converts the zero to a string and splits off the
       last character. The purpose of this is to put an empty string below
       the zero, which increases the stack depth by one.
M      Retrieve the next command-line argument and push it as a string.
/      Switch back to Cardinal mode.
d      Push the stack depth, D.
&\R    Switch back to Ordinal mode and reverse the current line D times.
O      Print the (possibly reversed) line with a trailing linefeed.
\      Switch back to Cardinal mode.
       The instruction pointer loops around and the program starts over
       from the beginning.

Python 2, 45 bytes
lambda k:[r[::i%-2|1]for i,r in enumerate(k)]

Try it online!
Python 2, 46 bytes
f=lambda k:k and[k[0][::len(k)%-2|1]]+f(k[1:])

Try it online!

Actually, 7 bytes
;r'R*♀ƒ

Explanation:
;r'R*♀ƒ
;r       range(len(input))
  'R*    repeat "R" n times for n in range
     ♀ƒ  call each string as Actually code with the corresponding input element as input (reverse each input string a number of times equal to its index)

Try it online!

Tcl, 61 bytes
proc B L {lmap e $L {expr [incr i]%2?"$e":"[string rev $e]"}}

Try it online!

Standard ML (MLton), 51 bytes
fun$(a::b::r)=a::implode(rev(explode b)):: $r| $e=e

Try it online! Usage example: $ ["abc","def","ghi"] yields ["abc","fed","ghi"].
Explanation:
$ is a function recursing over a list of strings. It takes two strings a and b from the list, keeps the first unchanged and reverses the second by transforming the string into a list of characters (explode), reversing the list (rev), and turning it back into a string (implode).

+1, not enough ML solutions imo

Stacked, 18 bytes
[{x i:x$revi*}map]

Try it online!
This simply reverses each string in the array according to its position.
Alternative, 24 bytes
[:#':>#,tr[...$rev*]map]

Same approach, but generates indices manually.

Red, 61 bytes
f: func[s][forall s[if odd? length? s[reverse s/1]print s/1]]

Try it online!

Jelly, 5 bytes
UJḤ$¦

Try it online!*
*Jelly outputs nested lists joined by spaces, and there is no native string type. Strings in Jelly are lists of characters, and that's why they're displayed that way. If you want them to be merged by spaces, Try this.

Charcoal, 9 bytes
ＥＮ⎇﹪ι²⮌ＳＳ

Try it online! Link is to verbose version of code. Note: Charcoal doesn't know the length of the list, so I've added it as an extra element. Explanation:
 Ｎ          First value as a number
Ｅ           Map over implicit range
    ι       Current index
     ²      Literal 2
   ﹪        Modulo
  ⎇         Ternary
       Ｓ    Next string value
      ⮌     Reverse
        Ｓ   Next string value
            Implicitly print array, one element per line.

Retina, 18 bytes
{O$^`\G.

*2G`
2A`

Try it online! Explanation: The first stage reverse the first line, then the second stage prints the first two lines, after which the third stage deletes them. The whole program then repeats until there is nothing left. One trailing newline could be removed at a cost of a leading ;.

CJam, 11 bytes
{2/Waf.%:~}

Try it online! (CJam array literals use spaces to separate elements)
Explanation:
{              Begin block, stack: ["Here are some lines" "of text for you" "to make a" "boustrophedon"]
 2/            Group by 2:         [["Here are some lines" "of text for you"] ["to make a" "boustrophedon"]]
   W           Push -1:            [["Here are some lines" "of text for you"] ["to make a" "boustrophedon"]] -1
    a          Wrap in array:      [["Here are some lines" "of text for you"] ["to make a" "boustrophedon"]] [-1]
     f.%       Vectorized zipped array reverse (black magic):
                                   [["senil emos era ereH" "of text for you"] ["a ekam ot" "boustrophedon"]]
        :~     Flatten:            ["senil emos era ereH" "of text for you" "a ekam ot" "boustrophedon"]
          }

Explanation for the Waf.% "black magic" part:

W is a variable preinitialized to -1. a wraps an element in an array, so Wa is [-1].
% pops a number n and an array a and takes every nth element of the array. When n is negative, it also reverses it, meaning that W% reverses an array.
. followed by a binary operation applies that operation to corresponding elements of an array, so [1 2 3] [4 5 6] .+ is [5 7 9]. If one array is longer than the other, the elements are kept without modification, meaning that Wa.% reverses the first element of an array.
f followed by a binary operation will take an element from the stack and then act like {<that element> <that operation>}%, that is, go through each element in the array, push its element, push the element first popped from the stack, run the operation, and then collect the results back into an array. This means that Wa.f% reverses the first element of every element in the array.

Wolfram Language (Mathematica), 33 bytes
Fold[StringReverse@*Append,{},#]&

Try it online!
How it works
StringReverse@*Append, when given a list of strings and another string as input, adds the string to the end of the list and then reverses all of the strings.
Folding the input with respect to the above means we:

Reverse the first line.
Add the second line to the end and reverse both of them.
Add the third line to the end and reverse all three.
Add the fourth line to the end and reverse all four.
And so on, until we run out of lines.

Each line gets reversed one time fewer than the previous line, so the lines alternate direction.

MATL, 7 bytes
"@gNo?P

Try it online!
Takes a cell array of strings, and leaves the result on the stack.
Explanation
"         % Loop over cell array
 @g     %   Push new string, and 'unwrap' it from its cell array.
     No?  %   Yes? Maybe so? (push stack size N, check if odd o, if so,...
        P %     Flip

As the implicit print function in MATL does not display an empty line for an empty item on the stack, we explicitly end the if-statement and loop and print the stack in the TIO footer:
]]X#

But this is not part of the program, as per the IO default

@LuisMendo Thanks (overlooked this comment for quite some time)

C,  118   103  101 bytes
Thanks to @gastropner for saving 15 bytes and thanks to @ceilingcat for saving a byte!
i;f(l,n)char**l;{for(;n--;++l,n&1&&puts(""))for(i=strlen(*l);(n&1||!puts(*l))*i;putchar((*l)[--i]));}

Try it online!
C, 147 bytes
i,j;f(char*s){char t[strlen(s)];for(i=0;;t[j++]=*s++)if(!*s|*s==10){t[j]=0;i=!i;for(i&&(j=!puts(t));j;j||puts(""))putchar(t[--j]);if(!*s++)break;}}

Try it online!

103 bytes if you go with clang or include string.h: f(l,n)char**l;{for(;n--;++l,puts(""))for(char*s=*l+strlen(*l);(n&1||printf(*l)*0)&s>*l;putchar(*--s));}

100 bytes and GCC is happy again: i;f(l,n)char**l;{for(;n--;++l,puts(""))for(i=strlen(*l);(n&1||!printf(*l))&i>0;putchar((*l)[--i]));}

@gastropner Thanks! I don't think using printf to print *l works, though, because the string might for example contain %d.

Swift, 90 85 82 72 bytes
-10 bytes thanks to @Mr.Xcoder
func f(a:[String]){print(a.reduce([]){$0.map{"\($0.reversed())"}+[$1]})}

You can use print and drop the return type declaration: func f(a:[String]){print(a.reduce([]){$0.map{"\($0.reversed())"}+[$1]})}

Ruby, 19 + 2 = 21 bytes
+2 bytes for -nl flags.
$.%2<1&&$_.reverse!

Try it online!
Explanation
Practically identical to the Perl 5 answer, though I hadn’t seen that one when I wrote this.
With whitespace, the code looks like this:
$. % 2 < 1 && $_.reverse!

The -p option makes Ruby effectively wrap your script in a loop like this:
while gets
  # ...
  puts $_
end

The special variable $_ contains the last line read by gets, and $. contains the line number.
The -l enables automatic line ending processing, which automatically calls chop! on each input line, which removes the the \n before we reverse it.

GNU sed, 31 + 1 = 32 bytes
+1 byte for -r flag.
G
:
s/(.)(.*\n)/\2\1/
t
s/.//
N

Try it online!
Explanation
G                   # Append a newline and contents of the (empty) hold space
:
  s/(.)(.*\n)/\2\1/   # Move the first character to after the newline
  t                   # If we made the above substitution, branch to :
s/.//               # Delete the first character (now the newline)
N                   # Append a newline and the next line of input

Röda, 33 bytes
{enum|[_[::-1]]if[_%2=0]else[_1]}

Try it online!
Explanation:
{
 enum|     /* Zip elements in the stream with [0,1,...] */
           /* For each string _1 and index _2: */
 [_[::-1]] /*  Push _1 reversed */\
 if[_%2=0] /*   if the index is even */
 else[_1]  /*  else push _1 */
}

SNOBOL4 (CSNOBOL4), 89 80 bytes
R	X =1 - X
	N =INPUT	:F(END)
	OUTPUT =EQ(X) N :S(R)
	OUTPUT =REVERSE(N) :(R)
END

Try it online!

Befunge-93, 48 bytes
 <~,#_|#*-+92:+1:
#^_@  >:#,_"#"40g!*40p91+,~:1+

Try It Online
Prints first line in reverse. Has a trailing newline.
Basically, it works by alternating between printing as it gets input and storing the input on the stack. When it reaches a newline or end of input, it prints out the stack, prints a newline, and modifies the character at 0,4 to be either a # or a no-op to change the mode. If it was the end of input, end the program

JavaScript (ES6), Firefox, 42 bytes, optimized from Arnauld's
a=>a.map(s=>[...s].sort(_=>a,a=!a).join``)

Clean, 59 bytes
import StdEnv
@t=[if(n rem 2<1)s(reverse s)\\s<-t&n<-[0..]]

Try it online!

Zsh+coreutils, 31 bytes
for s;((i^=1))&&<<<$s||rev<<<$s

Try it online!
Repeated xoring will switch i between 0 and 1, so we alternate our output.
Because the ternary chains our commands together, surrounding { } are unnecessary.
Zsh+coreutils, 23 bytes (almost correct)
for a b;<<<$a&&rev<<<$b

Try it online!
for sets b to the empty string if there are no more arguments. This unfortunately means that for an odd number of inputs, an extra empty line will be printed at the end.

Japt -m, 4 3 bytes
I/O as an array of lines.
zVÑ

Try it
zVÑ     :Implicit map of each string at 0-based index V in input array
z       :Rotate 90 degrees clockwise
 EÑ     :V*2 times

Pip, 16 bytes
Flg{Po?lRVlo!:o}

This loops over each line and reverses it based on the value of variable o(Predefined to 1), which is inverted each time the loop runs.
Try it online!
Fi,#gPi%2?RVg@ig@i

This one is based on the indices of each line instead.

Jelly, 3 bytes
UÐe

Try it online!
(or UÐo, reversing the other lines.)
U      (Vectorized) reverse
 Ðe    the even numbered lines.

Essentially Mr. Xcoder's 5-byter, but with what I assume is a newer addition to the language.

Vyxal, 3 bytes
yRY

Try it Online!
Look ma, no Unicode!
y   # Uninterleave
 R  # Vectorised reverse
  Y # Interleave

PHP, 54 bytes
function(&$a){foreach($a as&$s)$i++&1&&$s=strrev($s);}

function works on argument (call by reference)

Julia 0.6, 34 bytes
~x=x[2:2:end]=reverse.(x[2:2:end])

Try it online!
Function modifying the input in place.

Java 8, 53 bytes
a->{for(int i=1;i<a.length;i+=2)a[i]=a[i].reverse();}

Reverses every odd 0-indexed item.
Input as an array of StringBuffers. Modifies the input-array instead of returning a new one to save bytes.
Try it online.
Explanation:
a->{                       // Method with StringBuffer-array parameter and no return-type
  for(int i=1;i<a.length;  //  Loop `i` in the range `[1, input_length)
      i+=2)                //    And increase `i` by 2 after every iteration
    a[i]=a[i].reverse();}  //   Reverse the StringBuffer at index `i`

Python 3, 46 bytes
lambda l:[u[::(-1)**i]for i,u in enumerate(l)]

Try it online!

Thunno 2, 4 bytes
ıṅ{r

Attempt This Online!
Explanation
ıṅ{r  # Implicit input
ı     # Map over the input list:
 ṅ    #  Push the 0-based iteration index
  {   #  That many times repeat:
   r  #   Reverse the string
      # Implicit output


text:
Encode Factor Trees

I once saw on the xkcd fora a format for expressing numbers in an odd way. In this "factor tree" format:

The empty string is 1.
Concatenation represents multiplication.
A number n enclosed in parentheses (or any paired characters) represents the nth prime number, with 2 being the first prime number.

Note that this is done recursively: the nth prime is the factor tree for n in parentheses.

The factors of a number should be ordered from smallest to largest.

For example, here are the factor trees for 2 through 10:
()
(())
()()
((()))
()(())
(()())
()()()
(())(())
()((()))

Your task is to take in a positive integer, and output the factor tree for it.
Test Cases
In addition to the 9 above…
100 => ()()((()))((()))
101 => (()(()(())))
1001 => (()())(((())))(()(()))
5381 => (((((((())))))))
32767 => (()())((((()))))(()()(())(()))
32768 => ()()()()()()()()()()()()()()()

Rules

Characters other than ()[]{}<> are allowed in the output, but ignored.
You should be able to handle any input from 2 to 215 inclusive.
The winner is the shortest answer in bytes.

Similar to Brain-Flak: () nilad is 2 instead of 1, (...) monad is next prime instead of push, concatenation is multiply instead of add.

@user202729 you could probably get some irony points by writing a Brain-Flak answer—good luck though.

Definitely worth considering.

I would argue that this is a duplicate of Encode an integer. Here is my solution to that, with the front part removed and [1,0] replaced by "()". Also the Jelly solution there is remarkably similar to the one here

Why didn't that come up in the sandbox?

@StephenLeppik Personally, I saw it in the sandbox, but only noticed it was a duplicate after seeing solutions. Sorry :/

@H.PWiz it's okay, at least I got 60 rep and a bunch of flags out of it. Not to mention rolling out my new tag without it having to go through Suggested Edits.

@H.PWiz is there an existing challenge for decoding these?

I've been trying to find a method for determining if an integer is valid and decode-able. That might make a good challenge in and of itself. Not only do the 0s have to be balanced against the 1s so that the parentheses are balanced, but the primes they result in have to be sorted correctly.

Husk, 15 7 bytes
ṁös;₁ṗp

Try it online!
-8 bytes thanks to @Zgarb!
Explanation
Note that the header f€"[]"₁ just filters out all [ & ] characters, it's just so that the output is more readable, if you want to see the original output, here you go.
ṁ(s;₁ṗ)p  -- define function ₁; example input: 6
       p  -- prime factorization: [2,3]
ṁ(    )   -- map and flatten the following (example with 3): "[""]["[\"\"]"]"
     ṗ    --   get prime index: 2
    ₁     --   recurse: "[\"\"]"
   ;      --   create singleton: ["[\"\"]"]
  s       --   show: "[\"[\\\"\\\"]\"]"

The ternary if is unnecessary: since p1 is the empty list, the result is the empty string. Also, "()" can be sø if you switch to square brackets.

Hmm, actually since characters other than ()[]{}<> are ignored in the output by the rules, \J"()"could bes;` instead. It produces a ton of quotes and backspaces but the rules explicitly allow it.

Wolfram Language (Mathematica), 84 81 80 64 bytes
Byte count assumes Windows ANSI encoding.
Thanks to Misha Lavrov for saving 16 bytes.
±1=""
±x_:=Table[{"(",±PrimePi@#,")"},#2]&@@@FactorInteger@x<>""

Try it online!
Explanation
Quite a literal implementation of the spec. We're defining a unary operator ± via two separate definitions.
±1=""

This is just the base case, the empty string for 1.
±x_:=Table[±#,#2]&@@@FactorInteger@x<>""

For all other x, we factor the integer (this gives a list of prime-exponent pairs, {p, k}), generate a table of k copies of the representation of p.
For each p, we figure out the prime's index via PrimePi (i.e. the number of primes less than or equal to it), recursively pass it to ± and wrap the result in parentheses. Then flatten and join the result into a single string.

Jelly, 10 bytes
ÆfÆC$ÐLŒṘ€

Try it online!
-7 bytes thanks to user202729
Explanation
ÆfÆC$ÐLŒṘ€  Main Link
     ÐL     While the results have not yet repeated
ÆfÆC$       Prime factorize the number (vectorizes) and turn each prime to its prime index
       ŒṘ€  Since none of the lists actually contain anything, turn it to a Python string or else it won't print. Call on each because otherwise there will be an extra set of brackets around the output.

Since this is the way Jelly outputs, you can say your submission is a monadic link (like a function in other languages), and make it 7 bytes.

@Mr.Xcoder "The output is a string".

Python 2, 113 110 bytes
f=lambda n,d=2,p=1:n>2and(n%d and f(n,d+1,p+all(-~d%i for i in range(2,d)))or'(%s)'%f(p)+f(n/d,d,p))or'()'*~-n

Try it online!

ungolfed
def f(num, div=2, prime=1):
    if num > 2:
        if num % div:
            # if div does not divide num
            # try next divisor, add 1 to prime if the next divisor is prime
            return f(num, div + 1, prime + all((div + 1) % i for i in range(2, div)))
        else:
            # if div divides num add div as a factor, continue with num / div
            return '(%s)' % f(prime) + f(num / div, div, prime)
    else:
        # if num <= 1: return ''
        # if num == 2: return '()'
        return '()' * (num - 1)

Try it online!

JavaScript (ES6), 93 bytes
Uses the same approach as ovs' Python answer.
f=(n,d=2,k=1)=>n>2?n%d?f(n,++d,k+(P=n=>n%--d?P(n):d<2)(d)):`(${f(k)})`+f(n/d,d,k):n-2?'':'()'

Test cases

f=(n,d=2,k=1)=>n>2?n%d?f(n,++d,k+(P=n=>n%--d?P(n):d<2)(d)):`(${f(k)})`+f(n/d,d,k):n-2?'':'()'

;[2,3,4,5,6,7,8,9,10,100,101,1001,5381,32767,32768].forEach(
  n => console.log(n, '->', f(n))
)

R + numbers, 113 bytes
f=function(n)"if"(n<2,"",paste0("(",sapply(match(primeFactors(n),Primes(n)),f),")",collapse=""))
library(numbers)

Try it online!
Recursive function. Returns a string.
function(n)
if(n < 2)                                                # 1 is empty string
 ""                                                      #
else                                                     #
 paste0("(",                                             # wrap in parens
            sapply(                                      # for each
                   match(primeFactors(n),Primes(n))),    # prime index of factors of n
                                                     f), # apply f
           ")",                                          #
               collapse="")                              # collapse into a single string

Swift, 155 bytes
func f(_ n:Int)->String{var d=0;return n<2 ?"":(d=(2...n).first{n%$0<1}!,n==d).1 ?"(\(f((2...n).filter{m in(2...m).first{m%$0<1}==m}.count)))":f(d)+f(n/d)}

Explanation (Ungolfed)
func f(_ n:Int) -> String {                        // Declare recursive function f(n)
    var d = 0;                                     // Temporary variable d
    return n < 2 ?                                 // If n < 2:
        ""                                         //    Return empty string
    : (d = (2...n).first{n % $0 < 1}!, n == d).1 ? // If the lowest number divisible by n
                                                   // is equal to n (n is prime):
        "(\(f((2...n).filter{m in (2...m).first{   //    Return prime index of n (length of
        m % $0 < 1} == m}.count)))"                //    list of all primes ≤ n)
    :                                              // Else:
        f(d) + f(n / d)                            //    Return f(d) + f(n / d) where d is
}                                                  //    the smallest number divisible by n

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Advent Challenge 7: Balance the storage carts!
<< Prev Next >>
After some careful analysis, Santa was able to determine the dock size ranges and get the presents into the correct transportation dock.
Now, he needs you to help him balance out the transportation carts and place the presents in them in the most balanced fashion.
Challenge
You will be given the size of (the base of) the transportation cart as (width, height) and a list of all of the presents' sizes as integers.
An arrangement of presents on the transportation cart will have a certain center of mass, which should be as close to the center as possible (in other words, you want to minimize the Euclidean Distance between the center of mass and (width / 2, height / 2). The center of mass can be calculated by the following formula.
Formula
Let {(x_1, y_1), (x_2, y_2), ..., (x_i, y_i)} be the coordinates of the centers of the presents (these coordinates may be half-numbers (so #.5) if the
size is even). Let s = {s_1, s_2, ..., s_i} be the sizes of the presents.
Then, the center of mass is at ((x_1 × s_1 + x_2 × s_2 + ... + x_i × s_i) / sum(s), (y_1 × s_1 + y_2 × s_2 + ... + y_i × s_i) / sum(s)).
Task
Given the dimensions of the transportation cart m × n and the sizes of the presents, determine the positions of the presents in the most balanced arrangement. Note that presents may not intersect; each present with size s is an s × s × s cube.
Formatting Specifications
You may give the output in any reasonable format; for example, the positions of the top-left corners of the presents, the centers, an m × n matrix of integers indicating what present covers each space, etc. If there are multiple valid answers, you may return just one (does not have to be deterministic) or you can return them all.
Test Cases
Input
Output (given as the `m × n` matrix as ASCII-art)
----
5 × 5, 2, 2, 2, 2
11022    00220
11022    11220
00000 or 11033
33044    04433
33044    04400
----
5 × 7, 1, 1, 1, 2, 2
1000022
0000022
0003000 (or others)
4400000
4400005
----
3 × 4, 3
1110
1110
1110
---
3 × 4, 2, 1
0110
0110
0020

Please feel free to correct me if my test cases are not correct.
Rules

Standard Loopholes Apply
This is a code-golf, so the shortest answer in bytes wins
No answer will be accepted
There will always be at least one solution to all of the inputs

Note: I drew inspiration for this challenge series from Advent Of Code. I have no affiliation with this site
You can see a list of all challenges in the series by looking at the 'Linked' section of the first challenge here.
Happy Golfing!

Each present has the volume s³ but mass s? So the presents probably looks like this? Poor kids...

@user202729 whoops, I forgot to change the mass after I modified the formula :P future challenge idea though, the presents weren't properly loaded into the boxes

Note that the boxes with cardboard paper around and nothing inside has mass s², not s. Full box has mass s³. / Must presents be at integer coordinate?

@user202729 good point. close enough :P / yes, they do.

Would a solver working with a width of at most 32 be acceptable?

@Arnauld As long as the algorithm could theoretically work for input of any size, then yes.

Is it possible that the presents are not fit into the transportation dock?

@user202729 No. See rules section; there will always be at least one solution to the input. If they can't fit, then there's no solution.

Python 3, 533 494 476 bytes
from numpy import*
def o(a,v,t=[],n=1):
 if len(v)<1:return[[sum((d-e)**2for d,e in zip([sum(a)/sum(r)for a in zip(*[[a*k for k in b]for a,b in zip(r,t)])],[-~a/2 for a in a.shape]))**.5,a]]
 s,k=v[0],[[]]
 for p,i,j,l in[[copy(a),i,j,(i-~s/2,j-~s/2)]for i in range(a.shape[0]-s+1)for j in range(a.shape[1]-s+1)if all(a[i:i+s,j:j+s]<1)]:p[i:i+s,j:j+s]=n;k+=o(p,v[1:],t+[l],n+1)
 return k
w=input()
q,r=w[0],w[1:]
print(min([a for a in o(zeros(q),r)if a],key=lambda a:a[0])[1])

Try it online!
I used the numpy library in Python.  It is a very popular Python library and it specializes matrix/multi-dimensional array manipulation.
Mine finds a different, but equally valid, solution.  I did double check my work and, when I tried to find all solutions, it did find the one presented in the question as well.
Basic methodology is to bruteforce it.  So, every possible present location is checked, then the one with the least distance between it's center of gravity and the center of the slay is returned (or at least one of the possible solutions).

Pseudo-Ungolfed Version
I figured providing the ungolfed version would help people understand the algorithm.  I have made marginal improvements since this version, but this should give you a jump start in understanding it:
import numpy as np

with open("test.txt","w") as fo:
    input = lambda: [[3,4], 2, 1]

    def bruteForce(array, size, number):
        for i in range(array.shape[0]-size+1):
            for j in range(array.shape[1]-size+1):
                if np.all(array[i:i+size,j:j+size] == 0):
                    temp = np.copy(array)
                    temp[i:i+size,j:j+size] = number
                    yield temp, (i+(size+1)/2,j+(size+1)/2)

    #y, x because of how numpy works
    #euclid = https://codegolf.stackexchange.com/a/70536/67929
    def recursiveCheck(array,presents,presentLocations=[],number=1,currentMin=[10000,[]]):
        global rest, size
        if (len(presents) == 0):
            centerI = sum(a*b[0] for a,b in zip(rest,presentLocations)) / sum(rest)
            centerJ = sum(a*b[1] for a,b in zip(rest,presentLocations)) / sum(rest)
            euclid = lambda a,b:sum((d-e)**2for d,e in zip(a,b))**.5
            centerDelta = euclid([centerI,centerJ],[(a+1)/2 for a in array.shape])
            if centerDelta <= currentMin[0]:
                currentMin[0] = centerDelta
                currentMin[1] = array
                fo.write(repr(array) + "\n")
                fo.write(repr(presentLocations) + "\n")
                fo.write(repr([centerI,centerJ]) + "\n")
                fo.write(repr(centerDelta) + "\n")
            return
        for potentialPresentArray, newPresentLocation in bruteForce(array,presents[0],number):
            recursiveCheck(potentialPresentArray,presents[1:],presentLocations+[newPresentLocation],number+1,currentMin)

    suMatrix = input()
    size = suMatrix[0]
    rest = suMatrix[1:]
    recursiveCheck(np.zeros(size),rest)

Credits
I used a response by CarpetPython to aide me in creating a euclidean distance calculation in a minimal amount of bytes.
Mr. Xcoder reduced it by 28 bytes.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Reverse two sections of a string around a pivot
Background
I am currently in an AP Comp Sci A: Java class, and I want to start some of my friends on code golfing. I have a challenge from the course, and I would like to see how many bytes the community can do this challenge in.
Challenge details:
Given two input strings, the main string and the pivot string, do the following:
If the pivot string is exactly once as a substring of the main string, the part of the main string that comes before the pivot string shall be swapped with the part that comes after, while preserving the order within said subtrings being swapped.
For example:
If the pivot string is empty or the pivot string is not found within the main string, the program does not have to have defined behavior.
If there is more than one instance of the pivot string, the split should occur at the first and only the first instance of the pivot.
Examples:
Given the main string OneTwoThreeTwoOne and the pivot string Two, the output should be ThreeTwoOneTwoOne.
Given the main string 1Two2Two3Two4 and pivot Two, the output should be 2Two3Two4Two1.
Given the main string OneTwoThree and the pivot string "Two", the output should be ThreeTwoOne.
Given the main string the rabbit is faster than the turtle and the pivot string
 is faster than

(note the single space trailing and preceding), the output should be the turtle is faster than the rabbit.
Given the main string 1-2-3-4-5-6 and the pivot -, the output should be 2-3-4-5-6-1.
Afterword:
This is my first ever question on code golf, so if you have suggestions or constructive criticism, then feel free to say so.
Additionally, my code for this project (written in Java because the course focuses on that) can be found below. If you have any tips, I'd love to see them. Its currently 363 bytes, but I bet you guys can come up with much better and smaller solutions.
import java.util.Scanner;interface Main{static<T>void D(T f){System.out.println(f);}static void main(String[]A){Scanner s=new Scanner(System.in);D("Enter the first String:");String a=s.nextLine();D("Enter the pivot String:");String p=s.nextLine();if(p.isEmpty()|!a.contains(p)){D("Error: Pivot String not found.");return;}String w[]=a.split(p,2);D(w[1]+p+w[0]);}}

Note: The text for the inputs and for the case that the pivot string is not found is mandatory for the original assignment, but not for this challenge.

What is the expected output for pivot='-' and main='1-2-3-4-5-6'? Most submissions output 2-3-4-5-6-1 for this, but as I understand the challenge it should be 2-1-3-4-5-6.

It should only split the string on the first pivot. So intended output should be 2-3-4-5-6-1.

By the way, you can use the sandbox next time.

I think the emphasis "while preserving the order within said subtrings being swapped" just made it more confusing.  I already understand it that way, but the wording made it confusing if that's what you meant.

Mathematica, 42 bytes
Reverse@StringSplit[##,2]~StringRiffle~#2&

Try it online!

Jelly, 6 bytes
œṣṙ1j⁴

Try it online!
Explanation
œṣṙ1j⁴  Main Link
œṣ      Split around sublists equal to the pivot
  ṙ1    Rotate left by one
    j⁴  Rejoin on the pivot

Wow, any chance of an explanation? That's phenomenal!

@ThePlasmaRailgun It's not that phenomenal, in fact :P - Jelly has useful built-ins: œṣ is "split x around sublists equal to y", ṙ1 rotates the array one place to the left and j⁴ joins with the second input.

@ThePlasmaRailgun Adding explanation now. But for Jelly that's not even extremely impressive xD

Nice. I love it.

Python 2, 37 39 bytes
lambda a,b:b.join(a.split(b,1)[::-1])

Where a is the main string and b is the pivot string.
Try it online!

Change split(b) to split(b,1) to specify that you only want to split on the first occurance.

@ovs, edited to work on third test case

@mypetlion, I didn't know split accepted more arguments, thanks!

Wolfram Language (Mathematica), 34 bytes
p#2<>p<>#&@@StringSplit[#,p,2]&

Try it online!
An unnamed, curried function which should be called with the pivot first and the main string second. E.g., if you assigned the function to a name f:
f["-"]["1-2-3-4-5-6"]

Ohm v2, 4 bytes
ïλ⁴j

Try it online!

@ThePlasmaRailgun Same as Jelly, just shorter built-ins

SOGL V0.12, 9 5 bytes
ΘK+,∑

Try it Here!
Explanation:
Θ      split the 2nd input on the 1st one
 K     get the 1st element
  +    and add it to the end
   ,∑  join on the 1st input

Perl 5, 20 + 2 (-pl) = 22 bytes
<>=~/$_/;$_="$'$_$`"

Try it online!
Takes the pivot string on the first line, then the full string on the second.

playing with arguments i found this 20 bytes solution, otherwise the /s around $_ can be removed

also $_=~<>;$_="$'$&$"` is 20 bytes and reads arguments in the right order

Python 2, 53 44 bytes
thanks to ThePlasmaRailgun for some bytes
p,m=input()
k=m.split(p,1)
print k[1]+p+k[0]

Try it online!

Output on your test case with pivot "Two" and string "1Two2Two3Two4" should be "2Two3Two4Two1". It should only split on the first "Two", leaving you the array ["1", "2Two3Two4Two"]. Then you can just print k[1]+p+k[0]. This should have intended behavior.

Fixed. I'm also going to add an example test case to show people how it should be.

@ThePlasmaRailgun for the next time you want to improve an answer just leave a comment and let the op edit it in.

@ThePlasmaRailgun thanks for your clarification

Second and third lines become k,j=m.split(p,1);print j,p,k for 38 bytes.

Python 2, 37 bytes
lambda a,b:b.join(a.split(b,1)[::-1])

Try it online!

C# (Visual C# Compiler), 56 bytes
(m,p)=>(m+p+m).Substring(m.IndexOf(p)+p.Length,m.Length)

Try it online!

Alice, 18 bytes
/?.?.Qz
\IoI%!oo@/

Try it online!
Explanation
/...
\...@/

This is just a framework for linear Ordinal mode (string-processing) code. Unfolding the zigzag control flow, we get:
I.I.!zo?o?%Qo

I.  Read the first string, duplicate it.
I   Read the second string (the pivot).
.!  Store a copy of the pivot on the tape.
z   Drop. Removes everything up to and including the pivot from the first string,
    so we get only the stuff after the pivot.
o   Output that.
?o  Retrieve the pivot from the tape and output it.
?%  Retrieve the pivot again and split the input around (all occurrences of)
    the pivot.
Q   Reverse the stack.
o   Output the top of the stack (i.e. the chunk in front of the first pivot).

Retina, 24 23 bytes
tanks to Martin Ender for -1 byte
(.*)¶(.*?)\1(.*)
$3$1$2

Try it online!

R, 63 58 57 bytes
function(M,P)sub(sub("_",P,"(.+?)(_)(.+)"),"\\3\\2\\1",M)

Try it online!
M is the main string, P is the pivot.
ovs' Retina answer indicated that I could repair my earlier attempt at a regex approach
(.+)(Pivot string)(.+)

by adding ? to the first capture group.

Python 2, 48 bytes
lambda s,p:p.join(s.split(p)[1:]+s.split(p)[:1])

Try it online!

Pyth, 8 bytes
jQ.<cEQ1

Try it here!
Explanation
jQ.<cEQ1 - Full program.

    cEQ  - Split the second input by the first input.
  .<   1 - Cyclically rotate by 1 place to the left.
jQ       - Join on the first input.

Java 8, 47 bytes
x->y->x.replaceAll("(.*?)("+y+")(.*)","$3$2$1")

Try it online

changed replaceFirst by replaceAll because 2 bytes shorter and as the regex matches the whole string replace is done only once

Charcoal, 13 bytes
≔⪪θηθ⪫Ｅθ§θ⊕κη

Try it online! Link is to verbose version of code. Explanation:
  θ             First input
   η            Second input
 ⪪              Split
≔   θ           Assign result
      Ｅθ        Map over result
           κ    Current index
          ⊕     Incremented
        §θ      Circularly index into result
     ⪫      η   Join
                Implicitly print

JavaScript (ES6), 41 40 bytes
(s,p,[a,...r]=s.split(p))=>r.join(p)+p+a

Test cases

let f =

(s,p,[a,...r]=s.split(p))=>r.join(p)+p+a

console.log(f('the rabbit is faster than the turtle', ' is faster than '))
console.log(f('1-2-3-4-5-6', '-'))

C,  106  100 bytes
i,l;f(s,p)char*s,*p;{l=strlen(p);for(i=0;strncmp(s+i,p,l);++i);printf("%s%s",s+i+l,p);write(1,s,i);}

Try it online!

J, 14 bytes
#@[}.{.@ss|.,~

How it works:
The left argument is the pivot, the right one - the string to be reversed
            ,~   appends the pivot to the string
     {.@ss       finds the positions of the pivot in the string and takes the first one
          |.     rotates the appended string to the left, so that the pivot is at the start
#@[              finds the length of the pivot string (n)
   }.            drops n characters from the begining of the rotated string

Try it online!

SNOBOL4 (CSNOBOL4), 53 bytes
	P =INPUT
	INPUT ARB . R P REM . L
	OUTPUT =L P R
END

Try it online!
Takes input as Pivot, then Main, separated by a newline.
This is basically the SNOBOL equivalent of my R answer.

Japt, 8 7 bytes
£Zg°Y}V

Try it here

Perl 6, 31 bytes
->$_,$b {S/(.*?)$b(.*)/$1$b$0/}

Test it

PHP, 62 bytes
<?=![,$s,$p]=$argv,preg_filter("(^(.*)$p(.*)$)U","$2$p$1",$s);

requires PHP 7.1; may fail if the pivot contains regex special chars (\+*?[^]$(){}=!<>|:-).
no changes if Pivot is empty, empty output if Pivot is not in input.
Run with -n.
safe version, 77 bytes:
<?=preg_filter("(^(.*)".preg_quote($p=$argv[1])."(.*)$)U","$2$p$1",$argv[2]);

no changes if Pivot is empty, empty output if Pivot is not in input.
Run with -n.
non-regex version, 71 bytes:
$a=explode($p=$argv[2],$argv[1]);$a[]=array_shift($a);echo join($p,$a);

yields warnings if the Pivot is empty; no change if Pivot is not in input.
Run with -nr.
Try them online.

Red, 63 bytes
f: func[p s][rejoin[copy find/tail s p p copy/part s find s p]]

Try it online!

Swift, 131 bytes
import Foundation
func f(s:String,d:String){var c=s.components(separatedBy:d);print((c+[c[0]]).suffix(from:1).joined(separator:d))}

Explanation (ungolfed)
import Foundation                     // Import String.components
func f(s:String,d:String){
    var c=s.components(separatedBy:d) // Split the input string by the separator
    print((c+[c[0]])                  // Add the last element of c ([A,B,C] -> [A,B,C,A])
        .suffix(from:1)               // Remove the first element  ([A,B,C,A] -> [B,C,A])
        .joined(separator:d))         // Join with the separator
}

C (gcc), 76 bytes
f(s,t)char*s,*t;{char*p=strstr(s,t);printf("%s%s%.*s",p+strlen(t),t,p-s,s);}

Try it online!

C++11, 64 bytes
[s,p,&a]{int f=s.find(p);a=s.substr(f+p.size())+p+s.substr(0,f);}

A lambda, which captures the strings s, p and a, with a as a reference (in-out).
Test code
#include <iostream>
#include <string>

std::string Test(std::string s, std::string p) {
    std::string a;
[s,p,&a]{int f=s.find(p);a=s.substr(f+p.size())+p+s.substr(0,f);}();
    return a;
}

int main() {
    std::string
        s = "OneTwoThreeTwoOne",
        p = "Two",
        r = "ThreeTwoOneTwoOne";
    auto a = Test(s,p);
    std::cout << ((a==r)?"OK":"Failed") << ": " << a << std::endl;

    return 0;
}

Clean, 83 bytes
import StdEnv;f s c=(\p=p takeWhile++[hd s,c:p dropWhile])\g=reverse(tl(g((<>)c)s))

A String in Clean is normally {#Char} - an unboxed (#) Char array ({}). This function takes [Char] instead of String, which is a second, valid version of String.
The full function signature is f :: [.t] .t -> [.t] | [.t <= Char].
Try it online!


text:
Find a Fixed Point
Given an integer \$x_1\$ and some black box function \$f: ℤ → ℤ\$ find a fixed point of \$f\$ in the sequence defined by \$x_{k+1} := f(x_k)\$.
Details

A value \$x\$ is said to be a fixed point of \$f\$ if \$x = f(x)\$.

For instance if \$f(x) = \text{round}(\frac{x}{\pi})\$ and we have a starting point \$x_1 = 10\$ then we get \$x_2 = f(x_1) = f(10) = 3\$, then \$x_3 = f(x_2) = f(3) = 1\$, then \$x_4 = f(x_3) = f(1) = 0\$, and finally \$x_5 = f(x_4) = f(0) = 0\$ which means the submission should return \$0\$.

You can assume that the generated sequence actually contains a fixed point.
You can use the native type for integers in place of \$ℤ\$.
You can use any language for which there are defaults for black box functions input in the standard IO meta post. If there are no such default for your language feel free to add one in the sense of the definition of black box functions, and make sure to link your proposals in that definition. Also don't forget to vote on them.

Examples
f(x) = floor(sqrt(abs(x)))
0 -> 0,  all other numbers -> 1

f(x) = c(c(c(x))) where c(x) = x/2 if x is even; 3*x+1 otherwise
all positive numbers should result in 1,2 or 4 (Collatz conjecture)

f(x) = -42
all numbers -> -42

f(x) = 2 - x
1 -> 1

Note that while it's implied in the details that the black box function will converge on the fixed point, the last example says otherwise

@phflack The blackbox only has to converge for the given input.

Oh, originally I thought that the submission is not given x_0, which caused me some confusion. I thought a solution should be (Jelly) ~Nƭ⁻Ç$¿, which is something like, (pseudo code) for x in [0, -1, 1, -2, 2, -3, 3, -4, 4, ...]: if (x == f(x)): break; print(x); . That may worth another challenge.

Note for future visitors: Finding any fixed point doesn't work, you must find a fixed point reachable from x_0. It's guaranteed that there exists one.

And if not exist a fixed point, for a function f, and one initial value x0... What should be the value it have to return? And if x0=0 and f=int(9/(x-1)) with for x1=x0+1 f(x1)=f(1) is already one error... What should return the operator for that f , x0?

@RosLuP Your program just has to work if there is such a fixed point (see second bullet point in the details)

What if the program just repeatedly apply  times the function f on x_0? Is that abuse of native integer data type?

Yes, you can assume that the numbers required to compute the sequence are all in a reasonable range.

Actually, 1 byte
Y

Try it online!
Y is the fixed point function in Actually. In the TIO example, the function is shown being taken as a string, and £ is used to transform it to a function on the stack. It's also possible to just push the function to the stack like so. These are the only two ways to get a function input in Actually.

You just knew that some day this challenge was going to be posted, didn't you? :P

@EriktheOutgolfer I've actually used Y for several challenges. I'm apparently extremely precognizant :P

APL (Dyalog), 2 bytes
⍣=

Try it online!
NB: I define O←⍣= in the the input section due to a bug in that derived monadic operators can't be defined in the way that TIO likes to define things.
⍣ Is an operator that can be used like (function⍣condition) ⍵
It applies the function, f, to ⍵ until (f ⍵) condition ⍵ returns true.
⍣= is a derived monadic operator that takes a monadic function, f, as its left argument and applies it to its right argument, ⍵, until f ⍵ = ⍵

Maybe note that ⍣= is a derived monadic operator which takes a function as left operand and finds the fix point on the given initial value. I would use a different letter for ⍣= than f as it is an operator, not a function.

Yeah. I would. It is confusing that you call the "input" function f in your description, but then on TIO, f is your solution operator. You can also move the O←⍣= up in the Code field to let it be counted and to point out that that is the actual solution, and that the rest (Input) is just testing it.

Looks like a bug to me. I'll speak with relevant colleague tomorrow.

@Adám Updated. Let me know if the bug gets fixed

Haskell, 17 bytes
until=<<((==)=<<)

Try it online!

In case someone is interested: here is an explanation why until=<<((==)=<<)  finds a fix point of a given function.

MATLAB, 41 bytes
function x=g(f,x);while f(x)-x;x=f(x);end

There is also this beauty that does not need function files. Unfortunately it is a little bit longer:
i=@(p,c)c{2-p}();g=@(g,f,x)i(f(x)==x,{@()x,@()g(g,f,f(x))});q=@(f,x)g(g,f,x)

Try it online!

This answer was meant as an example and does not prevent anyone from answering.

Of course, if you called this Octave, you could remove two ;s. Try it online!.

And in your anonymous function, you can remove the @() before x for 50 bytes. Kudos too for the way you wrap your helper function (with the g(g) in the end), I only managed to do 51 bytes @(g,x)(f=@(r,z){@()r(r,m),z}{(m=g(z)==z)+1}())(f,x). I'm wondering if there's any combination of both approaches that's shorter still.

Mathematica, 11 bytes
#2//.x_:>#&

Try it online!
Mathematica, 10 bytes
FixedPoint

Try it online!

R, 36 35 bytes
thanks to JayCe for golfing down a byte
function(f,x){while(x-(x=f(x)))0;x}

Try it online!
Verify the example functions!
R port of flawr's solution.

For what it's worth... function(f,x){while(x-(x=f(x)))0;x} saves one byte.

Oh, 0, nice. Thanks much!

Standard ML (MLton), 30 bytes
fun& $g=if$ =g$then$else&(g$)g

Try it online! Use as & n blackbox.
The black box functions are defined as following:
fun blackbox1 x = floor(Math.sqrt(Real.fromInt(abs x)))

fun blackbox2 x = c(c(c(x)))
and c x = if x mod 2 = 0 then x div 2 else 3*x+1

fun blackbox3 _ = ~42

fun blackbox4 x = 2-x

Ungolfed version:
fun fixpoint n g = if n = g n then n else fixpoint (g n) g

Good to see SML in the wild! We use it for our functional programming class at our university.

Python 2, 39 37 33 bytes
thanks to @Mr.Xcoder for -2 bytes
s=lambda k:s(f(k))if k-f(k)else k

Try it online!
assumes the black-box function to be named f

Doesn't the function need to be passed as a parameter? I don't think pre-defined variables is an accepted input method.

I'm not sure you're allowed to assume the function is f, isn't that a form of assuming input is in a variable? (edit: ninja'd by mbomb)

@mbomb007 There is a consensus which allows it for black-box functions

JavaScript (Node.js), 25 22 21 bytes
thanks Herman Lauenstein for showing me this consensus
thanks to @l4m2 for -1 byte
Assumes the black-box function to be named f.
g=k=>f(k)-k?g(f(k)):k

Try it online!

This can be shortened if black-box functions to be taken as input can be assumed to be predefined under a given name

f(k)-k instead of

Jelly, 3 bytes
vÐL

Try it online!
Takes the left argument as a string representing a Jelly link (2_ for instance), and the right argument as an integer
How it works
 ÐL - While the output is unique...
v   -   Evaluate the function with the argument given

Brain-Flak, 24 bytes
(()){{}(({})<>[({})])}{}

Try it online!
(for the black box function x -> 2-x in the example below)
The provided black box function should be a program, that given x on the top of the stack, pop x and push f(x) - in other word, it should evaluate the function f on the value on the top of the stack.
Equivalent Mini-Flak is 26 bytes (thanks to Wheat Wizard for saving 2 bytes):
(()){{}(({})( )[{}({})])}{}
             ^ put the function f here

(not counting the comments and spaces)
Take the function (inside the <>) and a number x0 from input. (note that Brain-Flak is an esoteric language and can't take functional argument as input)

Example blackbox functions:
x -> 2-x: Try it online!

Explanation:

(()){{}(({})<f>[({})])}{}   Main program.
                            Implicit input from stdin to stack.
(  )                        Push
 ()                         literal number 1.
                            Now the content of the stack: [1, x0]
    {                 }     While stack top ≠ 0:
                            current stack content: [something ≠ 0, x]
     {}                       Pop stack top (something). stack = [x]
       (             )        Push
        ({})                    Stack top = x. Current stack = [x]
             f                  Evaluate f. Current stack = [f(x)]
            < >                   (suppress the value of f(x), avoid adding it)
               [    ]           plus the negative of
                ({})            the top of the stack ( = -f(x) )
                              In conclusion, this change (x) on the stack to
                              (f(x)), and then push (x + -f(x))
                            If it's 0, break loop, else continue.
                       {}   Pop the redundant 0 on the top.
                            Implicit output stack value to stdout.

Swift, 47 42 bytes
func h(_ n:Int){f(n)==n ?print(n):h(f(n))}

Naive approach, assumes that the black box function is named f

I am in doubt regarding your second attempt, because it is a complex closure and its type is ambiguous unless you explicitly cast it to {...}as(<parameter types>)-><return type>. If you don't specify its return type, it will throw build-time errors so I don't think it is valid as of now (note that the cast must be included in the byte count). Your first submission is fine, though.

APL (Dyalog Unicode), 14 bytes
{⍵=⍺⍺⍵:⍵⋄∇⍺⍺⍵}

Try it online!
The function at the header is equivalent to f(x) = floor(sqrt(abs(x)))
Thanks @Adám for pointing out that the original answer wasn't valid according to PPCG consensus.
How it works:
{⍵=⍺⍺⍵:⍵⋄∇⍺⍺⍵} ⍝ Main 'function' (this is actually an operator)
      :         ⍝ if
 ⍵=⍺⍺⍵          ⍝ the right argument (⍵) = the left function (⍺⍺, which is f) of ⍵
       ⍵        ⍝ return ⍵
        ⋄       ⍝ else
         ∇⍺⍺⍵   ⍝ return this function (∇) with argument f(⍵)

{⍵=f⍵:⍵⋄∇(f⍵)} would be ok for separate anonymous function from its name (n)

This assumes that f is preassigned, which I think is prohibited by PPCG consensus. {⍵=⍺⍺⍵:⍵⋄∇⍺⍺⍵} would be a valid operator solution.

C (gcc), 40 bytes
f(n,b)int(*b)(_);{n=n^b(n)?f(b(n),b):n;}

Try it online! Note that the flags are not necessary, they are there to aid with testing the fixpoint function defined above.
This is a function that takes an int n and a function pointer b : int → int. Abusing the fact that writing to the first variable argument sets the eax register, which is equivalent to returning†. Otherwise, this is pretty standard as far as C golf goes. n^b(n) checks for the inequality of n and the black box applied to n. When unequal, it calls the fixpoint function f again recursively with the application and black box as arguments. Otherwise, it returns the fixpoint.
†Citation needed, I vaguely remember reading this somewhere and google seems to confirm my suspicions
It declares input with K&R-style parameter typing:
f(n, b)
int(*b)(_);
{
    n=n^b(n)?f(b(n),b):n;
}

The arcane bit on the second line above declares b to be a function pointer that takes an integer parameter—the default type of _ is assumed to be an integer. Similarly, n is assumed to be an integer, and f is assumed to return an integer. Hooray for implicit typing?

Clean, 46 bytes
import StdEnv
p x=hd[n\\n<-iterate f x|f n==n]

Assumes the function is defined as f :: !Int -> Int
It takes the head of the infinite list of applications of f f f ... x filtered for those elements where f el  == el.
Try it online!
If you want to change the function in the TIO, Clean's lambda syntax is:
\argument = expression
(actually it's far more complicated, but thankfully we only need unary functions)

Octave, 37 bytes
function x=g(f,x);while x-(x=f(x))end

Try it online!
Octave has inline assignment but MATLAB doesn't, so this is a golfier Octave port of flawr's solution.
It also ports nicely to R.

Kotlin, 50 bytes
{f,k->var a=k;var b=a+1;while(b!=a){b=a;a=f(a)};a}

Try it online!

Forth (gforth), 36 bytes
This version just assumes f is predefined. It's not as cool as the solution below it. Both programs exit with a stack overflow if not found, or a stack underflow if found (after printing the result).
Try it online
: g dup f over = IF . THEN recurse ;

Forth (gforth), 52 bytes
This allows a function's execution token to be passed as a parameter, and is definitely the cooler solution.
: g 2dup execute rot over = IF . THEN swap recurse ;

Try it online
Explanation:
: g             \ x1 f          Define g. Params on the stack. f is on top
2dup execute    \ x1 f x2       duplicate both params, execute f(x1)
rot over        \ f x2 x1 x2    move x1 to top and copy x2 to top
= IF . THEN                     compare, if equal, print
swap recurse ;                  otherwise, recurse

Java 8, 42 bytes
This takes a Function<Integer, Integer> or IntFunction<Integer> and an int or Integer (curried) and returns the fixed point.
f->i->{while(i!=(i=f.apply(i)));return i;}

Try It Online
Takes advantage of the fact that Java evaluates subexpressions from left to right (so the old i is compared to the new), a property which I was unaware of while writing this!

Ruby, 31 28 bytes
->x,f{x=f[x]until x==f[x];x}

Try it online!

25 bytes - ->x,f{1while x!=x=f[x];x}

Clojure, 45 43 bytes
Well, this is the shortest and ugliest:
#(loop[a + b %2](if(= a b)a(recur b(% b))))

+ is there instead of a number so that it is not equal to any value of x0.
55 bytes and functional:
#(reduce(fn[a b](if(= a b)(reduced a)b))(iterate % %2))

Example:
(def f #(...))
(defn collaz [x] (if (even? x) (-> x (/ 2)) (-> x (* 3) (+ 1))))
(f (->> collaz (repeat 3) (apply comp)) 125)
; 1

tinylisp repl, 28 bytes
(d P(q((x)(i(e(f x)x)x(P(f x

Assumes that the function f is predefined.
Try it online! (The example function is f(x) = (x*2) mod 10.)
Ungolfed
(load library)
(def P
 (lambda (x)
  (if (equal? (f x) x)
   x
   (P (f x)))))

If f(x) equals x, then x is a fixed point; return it. Otherwise, recursively look for a fixed point starting from f(x) instead of x.

APL NARS 65 chars
r←(f v)n;c
   c←0⋄→B
E: r←∞⋄→0
A: n←r
B: r←f n⋄c+←1⋄→E×⍳c>1e3⋄→A×⍳r≠n

v operator would return ∞ (or possibly -oo or Nan) for error, else one value x with x=f(x).
In test f=floor(sqrt(abs(x))), f1=2-x, f2=c(c(c(x))) with c=x%2==0?x/2:3*x+1
  f←⌊∘√∘|
  f v 0
0
  f v 9
1
  f1←{2-⍵}
  f1 v 1
1
  f1 v ¯10
∞
  f1 v 2
∞
  c1←{0=2∣⍵:⍵÷2⋄1+3×⍵}
  f2←c1∘c1∘c1
  f2 v 1
1
  f2 v 2
2
  f2 v 7
2
  f2 v 82
4

x86 opcode, 8 bytes
fun:
        call    edx          ; 2B
        cmpxchg eax,    ecx  ; 3B, on 8086 use xchg and cmp instead
        jnz     fun          ; 2B
        ret                  ; 1B

Take input: ecx (value x0), edx (function address, take input from ecx, write result to eax without modifying the value of ecx and edx)
8086 opcode, 7 bytes (but slow)
    xor     cx,     cx
    call    dx
    loop    $-2
    ret

If there exists a fixed point, looping 65536 times always drive it there.
Take input: ax (initial value x0), dx (function address, take input from ax, write output to ax without modifying the value of cx and dx).
Output the fixed point in register ax.

It would certainly help if you make the answer more readable.

more edit to make it correct

dc, 30 bytes
[pq][Smrd3Rd3Rxd3R=mLmlmx]dsmx

Try it online!
Takes as input the function in the form of a macro and initial value on the stack(pushed in that order). Prints the fixed point.

J, 3 bytes
^:_

Try it online!
When a conjunction in J is missing an operand, it becomes an adjective. This program produces an adjective which takes as an argument a verb. ^: is the power or "repeat" verb, and the idiom f^:_, that is, f repeated infinitely, is J's limit application, which exactly solves this challenge:

An infinite power n produces the limit of the application of u .

Perl 5, 18 + 1 (-p)
$_=f$_ while$_^f$_

try it online

Vyxal, 1 byte
Ẋ

Try it Online!
Builtin lol

J-uby, 3 bytes
J-uby has a built-in operator for this:
:!~

Attempt This Online!

Japt, 14 bytes

gOvV
¥W?U:ßW

Try it
Japt doesn't have any built-in "repeat until the output is constant" functionality, or the ability to take functions directly as input. This program takes x as the first input, and a string defining a Japt function as the second input.
Explanation:
/n      # Store first input as U

/n      # Store second input as V

gOvV
 OvV    # Interpret V as Japt code
g       # Apply that function to U
        # Store the result as W

¥W      # Check whether U and W are the same
  ?U    # If they are, output U
    :ßW # Otherwise repeat the program with W and V as the inputs

A theoretical alternative would work if the function were assumed to already be stored in V, but there isn't really a good way to actually accomplish that in Japt so it's not really a reasonable input method.

Consensus allows for black box functions to be assigned to pre-defined variables, allowing you to get rid of the eval. Add in a couple of tweaks and you can get this down to 10 bytes

Japt, 10 bytes
Black-box function is preassigned to variable V
gU=gV)?ß:U

Try it
gU=gV)?ß:U     :Implicit input of integer U
g              :Sign of difference with
 U=            :  Reassign to U
   gV          :  Value of U after being passed through V
     )         :End sign
      ?        :If truthy (not 0)
       ß       :  Recursive call with new value of U
        :U     :Else return U

Go, 70 bytes
func f(O func(int)int,n int)int{x:=O(n)
for;x!=O(x);x=O(x){}
return x}

Attempt This Online!

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
The sequence of self-contained numbers
Let's define a self-contained number as a positive integer, whose digits appear in runs of length equal to themselves only. In other words, any decimal digit d (excluding 0) occurs only in runs of length exactly d.
Task
You can choose any of the three methods listed below:

Given an integer n, output the nth (either 0 or 1-indexed) self-contained number.
Given an integer n, output the first n self-contained numbers.
Print the sequence indefinitely.

Examples

133322 is a self-contained number because 3 appears in a run of three 3's, 1 is single and 2 occurs in a run of two 2's.

On the other hand, 35553355 isn't, because, although 5 and 3 occur five and three  times respectively, they do not form runs of adjacent digits.

44422 is not self-contained, because 4 only occurs three times.

12222333 isn’t either, because 2 appears in a run of four 2's, and it cannot be treated as two separate runs of two 2's.

Not surprisingly, this is OEIS A140057, and its first few terms are:
1, 22, 122, 221, 333, 1221, 1333, 3331, 4444, 13331, 14444, 22122, 22333, 33322, 44441, 55555, 122122, 122333, 133322, 144441, 155555

You can take input and provide output through any of the standard methods, in any programming language, while noting that these loopholes are forbidden by default. This is code golf, so the shortest code in bytes (in every language) wins.

Python 2, 104 94 83 bytes
-10 bytes thanks to Mr. Xcoder
-11 bytes thanks to Jonathan Allan
i=0
while 1:
 if`i`==''.join(d*int(d)for c,d in zip(`-i`,`i`)if d!=c):print i
 i+=1

Try it online!

...actually is this acceptable, since it will fall over once i becomes a long? It may be necessary to use str (I'm never really sure of these things though).

@JonathanAllan it's an interesting question. Normally we are allowed to assume that it's within the standard integer type, not long, but Python doesn't make this distinction very clear...

Mathematica, 66 bytes
Prints the sequence indefinitely
Do[##&&Print@t&@@(#==Tr[1^{##}]&@@@Split@IntegerDigits@t),{t,∞}]

Try it online!
In TIO you have to terminate the execution in order to see the result but in Mathematica works fine.
-12 bytes from Martin Ender

JavaScript (ES6), 76 71 68 bytes
Returns the n-th term of the sequence, 0-indexed.
f=(n,k)=>+(k+'').replace(/(.)\1*/g,s=>s.length^s[0])||n--?f(n,-~k):k

NB: As always with recursive functions, the input range depends on Tail Call Optimization support and the stack size of your engine.
Demo

f=(n,k)=>+(k+'').replace(/(.)\1*/g,s=>s.length^s[0])||n--?f(n,-~k):k

for(n = 0; n <= 10; n++) {
  console.log('a(' + n + ') = ' + f(n))
}

Alt. version, 65 bytes
Takes no input and prints the results with alert(), one at a time.
f=k=>f(-~k,+(k+'').replace(/(.)\1*/g,s=>s.length^s[0])||alert(k))

Try it online! (Stops as soon as the maximum stack size is exceeded.)

05AB1E, 9 bytes
Returns the nth term of the sequence, 1-indexed.
µNÔNγ€gJQ

Try it online!
Explanation
µ           # loop over increasing N until counter equals input
 NÔ         # push N with consecutive equal elements deduplicated
   Nγ       # push N grouped into runs of consecutive equal elements
     €g     # get the length of each run
       J    # join to a number
        Q   # check for equality
            # if true, implicitly increment counter

A possible source of inspiration from my 10-byte approach: µNγD€gs€ÙQ

Jelly, 7 bytes
DŒrZEµ#

Try it online!
-4 bytes thanks to Mr. Xcoder's early suggestion.
-1 thanks to Jonathan Allan.
Takes input from STDIN.

Haskell, 70 bytes
import Data.List
filter(all(\s->read[s!!0]==length s).group.show)[1..]

You can drop the leading x= as per our golfing rules.

CJam, 20 bytes
1{_Abe`::=:*{_p}&)}h

Try it online!
Explanation:
1                       push 1
 {                }h    while TOS is truthy (i.e. forever):            example iteration: 14444
  _                       duplicate                                                       14444 14444
   Ab                     convert to base 10 (get decimal digits)                         14444 [1 4 4 4 4]
     e`                   run-length encode (array of two-element arrays)                 14444 [[1 1] [4 4]]
       :                  map over the array:
        :                   fold between the two array elements with:
         =                    equality                                                    14444 [1 1]
          :               fold between the array elements with:
           *                multiplication (a.k.a. logical AND for 1 or 0)                14444 1
            {  }&         if this yields a result of 1:
             _              duplicate the number and                                      14444 14444
              p             print it                                                      14444 (output 14444)
                 )        increment the number                                            14445

Brachylog, 10 bytes
≜ℕẹḅ⟨l=h⟩ᵐ

Try it online!
Infinitely generates elements of the sequence through its input variable. (If it actually has to do the printing itself, append &ẉ⊥.) This is essentially code to solve the corresponding decision-problem with a ≜ prepended to brute-force the smallest solutions first:
        ᵐ    For every
  ḅ          run of
 ẹ           digits in
             the input variable
ℕ            (which is a non-negative integer),
   ⟨l  ⟩     its length
   ⟨  h⟩     and its first element
   ⟨ = ⟩     are equal.

I expected this to only take 9 bytes, but ḅ seems to require an explicit ẹ to separate the digits of a number into runs.

Stax, 10 bytes
Ç≡∟Öz≈¢αV¢

Run and debug it
This program filters all positive integers with a filter.  The digits are run-length encoded.  For each run, the digit must equal the run length.

8 bytes i think

@Razetime: Excellent!

JavaScript 4, 83 80 bytes
for(i=0;;)+(++i+'').replace(/(.)\1*/g,function(x,y){return y^x.length})||alert(i)

for(i=0;i<1000;)+(++i+'').replace(/(.)\1*/g,function(x,y){return y^x.length})||alert(i)

"Javascript 1"? Is there such a language name?

I mean it works since JavaScript appear, not sure if the name is correwct

sorry it seems not work in js1. I read and found no replace

Perl 6, 49 bytes
{(grep /^((\d)$0*:<?{$/.comb==$0}>)+$/,^Inf)[$_]}

Try it online!
Returns the n-th element of the sequence, zero-indexed.

The \d can just be .

R, 56 bytes
function(n)all((r=rle(el(strsplit(c(n,''),''))))$l==r$v)

Try it online!
Makes use of run length encoding on the split number.  Returns true if all the lengths equal the values.
Note: I have loaded the methods library in TIO to get el to work.

Husk, 10 bytes
fȯΛ§=L←gdN

Try it online!
Returns an infinite list. ↑ is used to show first n elements since it times out.

Pyth, 12
.f.AqMr8jZ10

Test online!

10 bytes: .fqFCr8jZT

Perl 5 -p, 48 bytes
++$\=~s|(.)\1*|$1-length$&&&redo|gre for 1..$_}{

Try it online!
Returns the n-th element, 1 indexed.

Java 10, 121 bytes
A lambda from int to int. The function takes an index n and returns the nth (1-indexed) sequence value.
n->{int x=0,m=1;for(;n>0;n-=m,m=1)for(var p:(++x+"").split("(?<=(.))(?!\\1)"))m=p.length()==p.charAt(0)-48?m:0;return x;}

Try It Online
Ungolfed
n -> {
    int x = 0, m = 1;
    for (; n > 0; n -= m, m = 1)
        for (var p : (++x + "").split("(?<=(.))(?!\\1)"))
            m = p.length() == p.charAt(0) - 48 ? m : 0;
    return x;
}

Japt, 15 bytes
Returns the nth term, 1-indexed.
Èì òÎeÈÎ¶XÊÃ}iU

Try it
Èì òÎeÈÎ¶XÊÃ}iU     :Implicit input of integer U
È                   :Function taking an integer X as argument
 ì                  :  To digit array
   ò                :  Partition between elements where
    Î               :    The sign of their difference is truthy (not 0)
     e              :  All true
      È             :  When passed through the following function as X
       Î            :    First element
        ¶           :    Is equal to
         XÊ         :    Length of X
           Ã        :  End function
            }       :End function
             iU     :Get the Uth integer that returns true

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
HSL to RGB values

The main purpose of the RGB (Red Green Blue) color model is for the sensing, representation and display of images in electronic systems, such as televisions and computers
HSL (Hue Saturation Lightness) is an alternative color model, designed in the 1970s by computer graphics researchers to more closely align with the way human vision perceives color-making attributes

Here are the wiki articles for RGB and HSL. It is common for graphics programs to do the calculations in HSL, and later convert to the preferred format for most screens: RGB.
The task is to write a function/program that takes HSL as an input and outputs RGB.
You can pick your preferred representation for I/O, as long as its consistent between them.
For example, they can be an array/tuple with 3 elements or an object with 3 properties named h, s, and l, but I'll accept other clever variations, like receiving the hsl as an integer (losing precision) and outputting an rgb integer.
The input can be assumed to be safe in range and format, both of which you can decide. I strongly suggest either the ranges 0-1 0-1 0-1 or 0-360 0-100 0-100 for hsl, and 0-1 0-1 0-1 or 0-255 0-255 0-255 for rgb.
Each answer is required to specify both of the above, and do put various variations in your answers if you're particularly proud of them, even if they don't have less characters than your other variations. Put the smallest on top.
Pseudo test cases for 0-360 0-100 0-100 → 0-255 0-255 0-255
h   s   l   → r   g   b

0   0   0   → 0   0   0
90  56  17  → 43  68  19
202 19  39  → 81  104 118
72  55  26  → 88  103 30

The formulae for the conversion can be found here:

This as a nice way to visualize the conversion:

Your suggested range for H of 0-360 is [0,360), would it be better written as 0-359?

@JonathanAllan I think it might look slightly more confusing, as to me, that suggests that 395.1 is not a possible input. If anything, using the a-b notation is wrong in itself when dealing with non-integer values, but I'd say it's ok to keep the question more readable. If anyone else complains, I'll rethink it, so thanks for pointing that out

Yeah, agreed on the 359.1 point - maybe just use the standard notation of [0,360) then :)

surprised to see no glsl answers ;)

JavaScript (ES6), 98 95 94 bytes
Takes H in [0,360) and S/L in [0,1). Outputs R, G and B as an array of 3 floats in [0,1).
(H,S,L)=>[5,3,1].map(i=>A(L*2)*S*([1,Y,0,0,Y,1][(i-~H)%6]-.5)+L,Y=(A=n=>n>1?2-n:n)((H/=60)%2))

Test cases
This snippet converts the results back into [0,255].

let f =

(H,S,L)=>[5,3,1].map(i=>A(L*2)*S*([1,Y,0,0,Y,1][(i-~H)%6]-.5)+L,Y=(A=n=>n>1?2-n:n)((H/=60)%2))

format = a => JSON.stringify(a.map(v => v * 255 + 0.5 | 0))

console.log(format(f(  0, 0.00, 0.00))) //  0   0    0
console.log(format(f( 90, 0.56, 0.17))) // 43  68   19
console.log(format(f(202, 0.19, 0.39))) // 81  104 118
console.log(format(f( 72, 0.55, 0.26))) // 88  103  30

How?
Initialization code
Y = (                  // we compute Y = 1 - |(H/60) mod 2 - 1| = X / C
  A = n =>             // A = function that returns 1 - |n - 1|
    n > 1 ?            //   first compare n with 1
      2 - n            //     which allows to simplify the formula to either 2 - n
    :                  //   or
      n                //     just n
)((H /= 60) % 2)       // divide H by 60 and compute Y = A(H % 2)

Main code
[5, 3, 1].map(i =>     // for each i in (5, 3, 1):
  A(L * 2) * S * (     //   compute (1 - |2L - 1|) * S (this is C), and multiply it by:
    [1, Y, 0, 0, Y, 1] //     either 0, 1 or Y (let's call this factor K), picked from
    [(i - ~H) % 6]     //     a cyclic sequence of period 6, using i and ~H (-6 ≤ ~H ≤ -1)
    - .5               //     minus 1/2
  )                    //   this gives: C(K - 1/2) = CK - C/2, where CK = 0, C or X
  + L                  //   we add L, leading to CK - C/2 + L = CK + m
)                      // end of map() --> returns [R, G, B]

Permutations of (0,C,X)
The slightly tricky part is to generate the correct permutation of (0,C,X) according to the angle of the hue component. As shown in the following figure, each column value is picked from the same cycling sequence of period 6, starting at different offsets. In the above code, we're using -~H instead of just +H because we need to coerce H to an integer. Hence the offsets (5,3,1) instead of (0,4,2).
                       C,X,0,0,X,C,C,X,0,0,X,C, ...
 +------> C,X,0,0,X,C  <--------->                  offset = 0, (0 - 1) mod 6 = 5
 | +----> X,C,C,X,0,0          <--------->          offset = 4, (4 - 1) mod 6 = 3
 | | +--> 0,0,X,C,C,X      <--------->              offset = 2, (2 - 1) mod 6 = 1
 | | |
(C,X,0) for   0 ≤ H <  60
(X,C,0) for  60 ≤ H < 120
(0,C,X) for 120 ≤ H < 180
(0,X,C) for 180 ≤ H < 240
(X,0,C) for 240 ≤ H < 300
(C,0,X) for 300 ≤ H < 360

Would taking H in [0,6) and outputting in [0,1] save some bytes?

@JonathanAllan Ah, I didn't notice the I/O format was loose. Thanks!

Python 2, 32 bytes
from colorsys import*;hls_to_rgb

Try it online!
This functionality is actually built into Python via the hls_to_rgb inside of the colorsys library.  The format mine inputs is a 0-1 range of HLS (instead of HSL, both are common acronyms for the same thing [albeit, HSL is more common]).  And mine outputs RGB values in a tuple with a range from 0 to 1.
Credits
Thanks to Jonathan Allan for pointing out that I just need to import it (and then further helping me reduce byte count).

I think this can just be 31 bytes as from colorsys import hls_to_rgb since than gives us a function that may be reused. Edit - make that 21 as from colorsys import*.

@JonathanAllan Thanks, updated.

Actually probably just import colorsys for 15!

@JonathanAllan Nice, updated again.

however true it might be, I think this affects the spirit of codegolfing a bit too much :/

@totallyhuman Hmm yes that actually makes sense, otherwise built-ins would always score zero. My bad. import colorsys;hls_to_rgb 26.

Updated the post.

I've never golfed in Python here and maybe this isn't how it's done, but wouldn't it make more sense for the byte count to be the sum of the import size and the function name size? I.e. from colorsys import* and hls_to_rgb, for 31 bytes? After all, this isn't a full program solution. That's essentially how I score my lambda-with-imports solutions in Java.

Mathematica, 155 bytes
(x~Clear~c;d=Piecewise@Table[{(P=Permutations)[P@{c,x,0}][[42,i]],(i-1)<=#_>

C++, 228 221 bytes
-7 bytes thanks to Zacharý
#define S(o,n)r[t[int(h[0])/60*3+o]+o-2]=(n+h[2]-c/2)*255;
void C(float*h,int*r){float g=2*h[2]-1,c=(g<0?1+g:1-g)*h[1],a=int(h[0])%120/60.f-1;int t[]={2,2,2,3,1,2,3,3,0,4,2,0,4,1,1,2,3,1};S(0,c)S(1,c*(a<0?1+a:1-a))S(2,0)}

The arguments are both arrays that have a minimum size of 3 elements ( i.e. float hsl[3] and int rgb[3]
Okay. Now, how does that work ? What is that long array ?
Well, it's not a long array, it's a int array. Joke aside, the array indicates by how many position we right shift C X and 0 when we want to select the correct permutation, + 2.
Remember how R', G' and B' are selected ?

Let's say we have a "normal" order that is {C, X, 0}
Now, when the first permutation (i.e. {C,X,0}) is selected, you need to not shift, which is exactly the same thing as right shifting by 0. So the first 3 elements of the array are 0,0 and 0
For the second permutation ( {X,C,0} ), we need to right shift C by 1, and left shift X by -1, so the fourth, fifth and sixth element of the array are 1,-1 and 0
And so on...
With the case of the 3rd and 4th permutation, i need to left shift the 0 by 2, so right shift by -2. Since there are more that 2 numbers that are negative, i rather add 2 to each elements in the array and substract 2 at the runtime ( for golfing reasons, to have only whole numbers in the array ).

221 bytes: https://pastebin.com/C8WaSSpb

Python 2, 119 112 bytes
def f(h,s,l):c=(1-abs(2*l-1))*s;m=l-c/2;x=c*(1-abs(h%2-1))+m;c+=m;return[c,m,x,c,m,x,m,c,x,m][7-int(h)*5%9:][:3]

Try it online!
Takes input as H=[0,6[, S=[0,1], L=[0,1]

HTML + JavaScript (ES6), 8 + 88 = 96 bytes

f=
(h,s,l)=>(p.style.color=`hsl(${h},${s}%,${l}%)`,getComputedStyle(p).color.match(/\d+/g))

H: <input type=number min=0 max=360 value=0 id=h>°
S: <input type=number min=0 max=100 value=0 id=s>%
L: <input type=number min=0 max=100 value=0 id=l>%
0,0,0

Takes input as an angle and two percentages. I'm scoring the HTML snippet
 and the JavaScript arrow function. I don't know what rounding browsers use, so my answers might differ slightly from yours.

GLSL (GL_ES) 160 144 134 131 bytes
Hue is in range 0-6 (saves 3 bytes)
Sat,light and rgb are 0-1
vec3 f(vec3 c){return mix(c.bbb,mix(clamp(vec3(-1,2,2)-abs(c.r-vec3(3,2,4))*vec3(-1,1,1),0.,1.),vec3(c.b>.5),abs(.5-c.b)*2.),c.g);}

Try it on book of shaders
Used colorpicker tool on a printscreen to test the output which was correct,
except a small error on 202 19  39  → 81  104 118 ,  which gave 80  104 118

Swift 4, 218 bytes
Accepts HSL values in the range [0,1] as arguments, and returns an array containing the RGB values in the same range:
import Cocoa;typealias F=CGFloat;func f(h:F,s:F,l:F)->[F]{var r=F(),g=F(),b=F(),x=s*min(1-l,l),n=2*x/max(l+x,1e-9);NSColor(hue:h,saturation:n,brightness:l+x,alpha:1).getRed(&r,green:&g,blue:&b,alpha:nil);return[r,g,b]}

The idea is to first convert the input from HSL to HSB, then using the HSB constructor of the built-in color object in Cocoa to retrieve the RGB values.
The UIKit version is the exact same length, as the only replacements are:

Cocoa → UIKit
NSColor → UIColor

Ungolfed:
#if os(iOS)
    import UIKit
    typealias Color = UIColor
#elseif os(OSX)
    import Cocoa
    typealias Color = NSColor
#endif

typealias F = CGFloat

func f(h: F,s: F,l: F) -> [F] {
    var r = F(), g = F(), b = F()

    let x = s * min(1 - l, l)
    let n = 2 * x / max(l + x, 1e-9)

    let color = Color(hue: h, saturation: n, brightness: l + x, alpha: 1)
    color.getRed(&r, green: &g,blue: &b, alpha: nil)

    return [r, g, b]
}

The following snippet can be used for testing, by just replacing the values of h, s, and l:
let h: CGFloat = 0
let s: CGFloat = 0
let l: CGFloat = 0

let result = f(h: h/360, s: s/100, l: l/100).map { Int(round($0*255)) }
print(result)

Unfortunately I can't provide a link to an online sandbox, since all of them run on Linux, which doesn't include Cocoa.

R, 88 bytes
function(h,s,l){v=(2*l+s*(1-abs(2*l-1)))/2;col2rgb(hsv(h,ifelse(v==0,v,(2*(v-l))/v),v))}

Try it online!
This function takes as input the H, S, and L values as 0-1 ranged values and outputs the RGB values as 0-255 ranged values. It converts the HSL representation to an HSV representation, then uses hsv() to convert the HSV representation to an R color (i.e. hex representation -- #rrggbb), then uses col2rgb() to convert the R color to RGB values.

Jelly,  39  32 bytes
-1 thanks to caird coinheringaahing (%2 is just Ḃ)
-1 and/or inspiration for -4 thanks to caird coinheringaahing too!
Ḥ;Ḃ’AC×©"⁵×\;0+³_®H¤⁴Ḟị336Œ?¤¤œ?

A full program taking three command line arguments:

L, H, S in the ranges [0,1), [0,6), and [0,1) respectively

which prints a list giving the RGB format as

[R, G, B] with each of the three values in the range [0,1]

Note: H may also wrap just like [0,360) would.
Try it online!
How?
Ḥ;Ḃ’AC×©"⁵×\;0+³_®H¤⁴Ḟị336Œ?¤¤œ? - Main link: number, L (in [0,1]); number, H (in [0,6))
Ḥ                                - double                 =     2L
  Ḃ                              - modulo by 2            =              H%2
 ;                               - concatenate            = [   2L   ,   H%2]

   ’                             - decrement              = [   2L-1 ,   H%2-1]
    A                            - absolute               = [  |2L-1|,  |H%2-1|]
     C                           - complement             = [1-|2L-1|,1-|H%2-1|]
                                 -                        = [C/S     ,C/X]
         ⁵                       - 3rd program argument   = S  (in [0,1])
        "                        - zip with:
      ×                          -   multiplication       = [C,C/X]
       ©                         -   (copy the result, C, to the register)
           \                     - cumulative reduce with:
          ×                      -   multiplication       = [C, C/X*C] = [C,X]
            ;0                   - concatenate zero       = [C,X,0]
               ³                 - 1st program argument   = L
              +                  - add (vectorises)       = [C+L,X+L,L]
                   ¤             - nilad followed by link(s) as a nilad:
                 ®               -   recall from register = C
                  H              -   halve                = C/2
                _                - subtract               = [C+L-C/2,X+L-C/2,L-C/2]
                             ¤   - nilad followed by link(s) as a nilad:
                    ⁴            -   2nd program argument = H
                     Ḟ           -   floor                = floor(H)
                            ¤    -   nilad followed by link(s) as a nilad:
                       336       -     literal 336
                          Œ?     -     Shortest permutation of natural numbers with a
                                 -     lexicographical index of 336 in all permutations
                                 -     thereof            = [3,5,6,4,2,1]
                      ị          -   index into (1-indexed & modular)
                              œ? - get that permutation of [C+L-C/2,X+L-C/2,L-C/2]
                                 - implicit print

Oops, of course. Thanks!


text:
It's a Slippery Slope
There has not been a challenge regarding slope fields, as a far as I can tell. So, I might as well make one.
The challenge
Given:

A black box function f which takes two arguments, x and y (both real numbers) , and returns the value of the slope at point (x,y) (also a real number)
A list of real numbers, X, representing the values along the x axis,
Another list of real numbers, Y, representing the values along the y axis.
A list of (x,y) pairs, U, which represents the inputs that f is undefined on. This argument can be removed if your language can detect errors.

Output:

A rectangle with a length of the length X, and a height of the length of Y. At each combination of row r and column c in the rectangle, (starting from the bottom left corner), the character that is placed at that position will depend on the sign value of f evaluated at x=c and y=r:

If the value is positive, the character is /.
If the value is zero, the character is -.
If the value is negative, the character is \.
If (x,y) is not in the domain of f (a.k.a. a member of U), then the character is . f is guaranteed to not error on every combination of x within X and y within Y if U is utilized.

Since I am horrible at explaining things, here's an example:
Input:
f(x,y) = x / y
X=[-1,0,1]
Y=[-1,0,1]
U=[[-1,0],[0,0],[1,0]]

Output:
\-/

/-\

At (0,0) (the bottom left corner), the corresponding X and Y values are -1 and -1 (since X[0] = -1 and Y[0] = -1). f(-1,-1)=(-1)/(-1)=1, thus / is used.
At (1,0) (the bottom row, middle column): X[1] = 0, Y[0] = -1, f(0,-1)=(0)/(-1)=0, and 0 is zero (duh), so the character is -.
At (1,1) (the center): X[1] = 0, Y[1] = 0. [0,0] is a member of U. Therefore, it corresponds to the  character. Or, if done without U: 0/0 is undefined, thus the character is .
At (2,2) (the top left): X[2] = 1, Y[2] = 1, f(1,1)=(1)/(1)=1, which is positive. Therefore, it corresponds to the / character.
Etc...

Floating Point
Any value of f within the range [-1e-9,1e-9] should be considered to have a sign of 0.
Winning condition
This is a code-golf, so lowest byte count wins!

Are the inputs sorted?

@Giuseppe No. And unsorted X and Y will actually change the answer.

Jelly, 23 bytes
Ṛ⁹,2⁶v$Ṡ$e⁵$?¥þị“/ \-”Y

Try it online!
Arguments: Y, X, U, f
f is a Python string containing Jelly code. Be sure to quote it appropriately, otherwise you may encounter errors.
Also, f takes a pair [x, y] as its argument, not two arguments x and y.

Can you please provide an explanation for those of us who have to constantly refer to the wiki?

@Zacharý sorry, no time to

Whenever you get the chance

Explanation (May not be 100% correct)

APL (Dyalog), 36 34 bytes
2 bytes saved thanks to @ngn
{o←⍺⍺⋄'\-/ '[⊖⍉⍺∘.{0::4⋄2+×⍺o⍵}⍵]}

Try it online! (with modified division, since basic APL 0÷0 is 1)
The black box function comes as left operand, X as left argument, and Y as right argument.

ideas: take x and y as ⍺ and ⍵, not just ⍵ (you can still have the ⍺⍺); in the inner dfn return 2+×⍺o⍵ on success and 4 on error and then do square bracket indexing on the whole matrix in order to save some quotes

@ngn Looks like it already does most of what you've mentioned?

@EriktheOutgolfer did you notice there's an inner { }?

@ngn problematic with complex results (2J1s)

@Uriel the problem says f "returns the value of the slope at point (x,y) (also a real number)"

@ngn, oh I see now. Thanks!

@Uriel You don't need ⍉ - just swap ⍺ and ⍵. And another improvement: you can use ⎕ for the inputs and claim it's not a "function" (i.e. operator) but a "complete program": o←⎕⋄'\-/ '[⊖⎕∘.{0::4⋄2+×⍺o⍵}⎕]

Haskell, 114 113 109 bytes
z x=last$0:[x|abs x>1e-9]
(x#y)(%)u=reverse[[last$"\\-/"!!floor(1+signum(z$c%r)):[' '|elem(c,r)u]|c<-x]|r<-y]

Try it online!
Fairly straightforward solution. Uses signum to index into a string for the right char if the point is defined.
EDIT: Thought of a way to shave off a byte
EDIT 2: Thanks @Laikoni for taking off another 4 bytes!

Taking f as third argument and as infix function saves another byte: Try it online!

Save some more bytes by using elem instead of notElem: Try it online!

Wolfram Language (Mathematica), 70 68 bytes
Table["-"["/","\\"][[Sign[x~#~y]]]~Check~" ",{y,Reverse@#3},{x,#2}]&

Try it online!
In the expression "-"["/","\\"], part 0 is the head ("-"), part 1 is "/", and part -1 (the last part) is "\\", so if we try to take the Sign[f]-th part of it, we get the appropriate character depending on if f is positive, negative, or zero. If none of the above apply, or if evaluating the function causes an error, the ~Check~ will catch the error and return the " " character instead.
(It still prints out a bunch of error messages, which should be ignored since we get the right answer at the end.)
We do this for all x and y values.

Python 2, 105 103 95 92 bytes
def f(F,X,Y,U):
 for y in Y[::-1]:print''.join('/ \-'[[x,y]in U or~cmp(0,F(x,y))]for x in X)

Try it online!

Error handling version:
Python 2, 135 132 125 bytes
def f(F,X,Y):
 def g(x,y):
	try:return'-\/'[cmp(0,F(x,y))]
	except:return' '
 for y in Y[::-1]:print''.join(g(x,y)for x in X)

Try it online!

You can save the same three bytes I saved for Erik by replacing ([x,y]in U)*' 'or'-\/'[cmp(0,F(x,y)) with '/ \-'[[x,y]in U or~cmp(0,f(x,y)) :)

@JonathanAllan Thanks :)

Python 2, 91 bytes
f,X,Y,U=input()
for y in Y[::-1]:print''.join('/ \-'[[x,y]in U or~cmp(0,f(x,y))]for x in X)

Try it online!
-3 thanks to Jonathan Allan.
Looks like I can't just assume f to be already assigned to a function.

Let us continue this discussion in chat.

Swift, 142 bytes
func f(X:[Float],Y:[Float]){print(Y.reversed().flatMap{y in X.flatMap{let s=try?b($0,y);return s==nil ?" ":s!>0 ?"/":s!<0 ?"\\":"-"}+["\n"]})}

Prints as an array of characters