text:
Bake me some moji
Given a string, character list, byte stream, sequence… which is both valid UTF-8 and valid Windows-1252 (most languages will probably want to take a normal UTF-8 string), convert it from (that is, pretend it is) Windows-1252 to UTF-8.
Walked-through example
The UTF-8 string
I        ♥        U  T  F  -  8
is represented as the bytes
49 20  E2 99 A5  20 55 54 46 2D 38
these byte values in the Windows-1252 table gives us the Unicode equivalents
49 20 E2 2122 A5 20 55 54 46 2D 38
which render as
I     â  ™  ¥     U  T  F  -  8
Examples
£ → Â£
Â£ → Ã‚Â£
Ã‚Â£ → Ãƒâ€šÃ‚Â£
I ♥ UTF-8 → I â™¥ UTF-8
árvíztűrő tükörfúrógép → Ã¡rvÃztÅ±rÅ‘ tÃ¼kÃ¶rfÃºrÃ³gÃ©p

What's the title about?

@user202729 See the "convert it" link. It's a pun.

So in summary, is it possible to take a list/array of integers?

@user202729 I'm pretty sure you can. It states "character list, byte stream, sequence...", which are integer lists/arrays by default in some languages.

@KevinCruijssen Is there any difference?

For convenience: The Windows 1252 character set is the same as Unicode, except in 0x80..0x9F, where the characters are € ‚ƒ„…†‡ˆ‰Š‹Œ Ž  ‘’“”•–—˜™š›œ žŸ. (space = unused)

Is a string valid as output rather than a list of bytes or code points? And if so, does it need to be encoded in UTF-8 internally?

@Jakob A string out is what's being asked for. I don't care about internal encoding, only what comes out in the end.

@user202729 https://en.wikipedia.org/wiki/Mojibake

@viraptor It is the first link in the OP.

@user202729 Uh, I'm not sure what you were trying to say, but that isn't remotely close to being true. Unicode has millions of characters, Windows-1252 only 256.

@DavidConrad "in the 0x00-0xFF range".

@Adám I missed it, because I expect "convert it" to point to some article about valid character conversion. It looks like the first commented missed it as well. It's not super clear :(

+1 for mentioning the árvíztűrő tükörfúrógép.

@DavidConrad, "Unicode has millions of characters" is exaggerated. Unicode defines 1,114,112 codepoints. Out of that 136,690 codepoints are currently used.

@Wernfried the point is comparing that to a 256-character charset.

bash, 14 bytes
iconv -fCP1252

Try it online!

upvoted, but if I'm not mistaken,that assumes, that system encoding is utf-8

Java 8, 72 66 36 25 bytes
s->new String(s,"cp1252")

Try it online.
s->  // Method with byte-array (UTF-8 by default) as parameter and String return-type
  new String(s,"cp1252")
     //  Pretend this UTF-8 input is (and convert it to) Windows-1252,
     //  and return it as UTF-8 String (by default) as well

cp1252 is an alias for Windows-1252. This alias cp1252 is the Canonical Name for the java.io and java.lang APIs, while the full name Windows-1252 is the Canonical Name for the java.nio API. See here for a full list of supported Java encodings, where we'd always want to use the shortest of the two for codegolfing.

Java winning code golf‽ That can't be right.

@Adám Hehe, I'm actually pleasantly surprised as well to see all these longer answers. ;) But I'm pretty sure Jelly, 05AB1E, etc. will beat me pretty soon.

I doubt that. They probably don't have built-in translate tables. Dyalog APL does though…

"Canonial Name for the java.nio API" :P

R 3.5.0 or higher, 32 20 bytes
scan(,"",e="latin1")

Try it online!
Oddly short for a string challenge in R... thanks to JayCe for golfing down 12 more bytes!
scan optionally takes an encoding argument to set the encoding of the input string. latin1 corresponds to, according to the documentation of Encoding

There is some ambiguity as to what is meant by a ‘Latin-1’ locale, since some OSes (notably Windows) make use of character positions used for control characters in the ISO 8859-1 character set. How such characters are interpreted is system-dependent but as from R 3.5.0 they are if possible interpreted as per Windows codepage 1252 (which Microsoft calls ‘Windows Latin 1 (ANSI)’) when converting to e.g. UTF-8.

I followed the link to the documentation of Encoding... and learned that scan also has an encoding argument O_O...
20 bytes

@JayCe whoda thunk it! Very nice!

Python 2, 40 38 bytes
-2 bytes thanks to Erik the Outgolfer.
lambda s:s.decode('1252').encode('u8')

Try it online!
u8 is an alias for utf-8.

Perhaps you could "cheat" a little with this: input().decode(...).encode(...) :) also I think you might be able to use some windows console encoding if in powershell (but I'm totally unsure about this).

See https://codegolf.stackexchange.com/a/167238/52609

@KeyWeeUsr the problem with your suggestion is that is doesn't actually output anything, as opposed to the answer you linked. R does output the value of bare expression while does not.

Ruby, 31 bytes
->s{s.encode("UTF-8","CP1252")}

Try it online!
Tests cases are included in the TIO

Python 3, 38 36 34 bytes
lambda s:s.encode().decode('1252')

Try it online!
note: After I had a working function I used ovs's python2 answer answer to learn about the header and footer fields for tio, so the header and footer are the same
edit: Trimmed it a little thanks to python3 defaulting to utf8 and a tip from ovs's submission :)

C#, 81 bytes
using e=System.Text.Encoding;s=>e.GetEncoding(1252).GetString(e.UTF8.GetBytes(s))

Try it online!
Thanks to Schmalls for 3 bytes

Can it be using e=System.Text.Encoding;s=>e.GetEncoding(1252).GetString(e.UTF8.GetBytes(s)) to get it down to 81?

@Schmalls Looks like yes, thanks!

180 bytes, machine code (16-bit x86)
I noticed most answers use builtin encode/decode (which I believe is perfectly fine), but I thought I'll continue my 16-bit quest.
As with previous ones, this was done without compiler using mostly HT hexeditor and ICY's hexplorer.
00000000: eb40 ac20 0000 1a20 9201 1e20 2620 2020  .@. ... ... &
00000010: 2120 c602 3020 6001 3920 5201 0000 7d01  ! ..0 `.9 R...}.
00000020: 0000 0000 1820 1920 1c20 1d20 2220 1320  ..... . . . " .
00000030: 1420 dc02 2221 6101 3a20 5301 0000 7e01  . .."!a.: S...~.
00000040: 7801 89f7 4646 89fa 89d9 4143 4bb4 3fcd  x...FF....ACK.?.
00000050: 2185 c074 288a 053c 8073 05e8 1700 ebec  !..t(..<.s......
00000060: 3ca0 721a d440 0d80 c050 86c4 e806 0058  <.r..@...P.....X
00000070: e802 00eb d7b4 4088 05b3 01cd 21c3 2c80  ......@.....!.,.
00000080: d0e0 89c3 8b00 89cb 85c0 74c0 3dff 0773  ..........t.=..s
00000090: 08c1 c002 c0e8 02eb cd50 c1e8 0c0c e0e8  .........P......
000000a0: d3ff 5825 ff0f c1c0 02c0 e802 0d80 8050  ..X%...........P
000000b0: 86c4 ebb8                                ....

Dissection
Implementation is pretty straight-forward, although I haven't given much thought to flow upfront so there is SOME spaghetti there.
I'll mix order a bit, to make it easier to follow...
0000 eb40               jmp         0x42

Skip over table that maps chars >= 0x80 < 0xa0, to unicode codes.
data db ACh,20h, 00h,00h, 1Ah,20h, ...

Invalid ones are encoded as 0, they are not mapped to anything
0075 b440               mov         ah, 0x40
0077 8805               mov         [di], al
0079 b301               mov         bl, 0x1
007b cd21               int         0x21
007d c3                 ret

Helper function used to print char in al, will be called few times.
0042 89f7               mov         di, si
0044 46                 inc         si
0045 46                 inc         si
0046 89fa               mov         dx, di
0048 89d9               mov         cx, bx
004a 41                 inc         cx
004b 43                 inc         bx

Prepare registers. Data will be read into 0x100, let si point into translation table above.
004c 4b                 dec         bx
004d b43f               mov         ah, 0x3f
004f cd21               int         0x21
0051 85c0               test        ax, ax
0053 7428               jz          0x7d

Read char from stdin, jump to 0x7d if EOF.
Sidenote: This actually is a small (but pretty well known) trick, 0x7d contains ret,
this will cause pop sp, sp at start points to end of a segment, there's 00 00 there, and cs:0 in DOS contains CD 20, which causes application to exit.
0055 8a05               mov         al, [di]
0057 3c80               cmp         al, 0x80
0059 7305               jnc         0x60
005b e81700             call        0x75
005e ebec               jmp         0x4c

If char is < 0x80, just print it out, and go to beginning of loop
(because helper function is setting BX to 1 - stdout, jumps will go to dec bx)
0060 3ca0               cmp         al, 0xa0
0062 721a               jc          0x7e
0064 d440               aam         0x40
0066 0d80c0             or          ax, c080
0069 50                 push        ax
006a 86c4               xchg        ah, al
006c e80600             call        0x75
006f 58                 pop         ax
0070 e80200             call        0x75
0073 ebd7               jmp         0x4c

This part deals with chars >= 0xa0, splits ascii code into "high" two bits and "low" 6 bits and applies utf-8 mask c080 for two bytes, then prints both of them
007e 2c80               sub         al, 0x80
0080 d0e0               shl         al, 0x1
0082 89c3               mov         bx, ax
0084 8b00               mov         ax, [bx+si]
0086 89cb               mov         bx, cx
0088 85c0               test        ax, ax
008a 74c0               jz          0x4c
008c 3dff07             cmp         ax, 07ff
008f 7308               jnc         0x99
0091 c1c002             rol         ax, 0x2
0094 c0e802             shr         al, 0x2
0097 ebcd               jmp         0x66

This part deals with chars >= 0x80 < 0xa0, it finds proper utf-8 code in the table at the top, if code equals 0, just skip to beginning, if it's below 0x7ff (ergo: fits on two UTF-8 bytes), just adjust the value and re-use previous code at 0x166.
0099 50                 push        ax
009a c1e80c             shr         ax, 0xc
009d 0ce0               or          al, e0
009f e8d3ff             call        0x75
00a2 58                 pop         ax
00a3 25ff0f             and         ax, 0fff
00a6 c1c002             rol         ax, 0x2
00a9 c0e802             shr         al, 0x2
00ac 0d8080             or          ax, 8080
00af 50                 push        ax
00b0 86c4               xchg        ah, al
00b2 ebb8               jmp         0x6c

Final part, deals with codes that are above 0x7FF, drop low 12 bits,
apply 0xE0 (see UTF-8 encoding description for reference) and print it out,
adjust lower 12 bits and apply 8080 mask and again reuse part that spits out two chars.

JavaScript, 64 bytes
x=>new TextDecoder('cp1252').decode(new TextEncoder().encode(x))

f =
x=>new TextDecoder('cp1252').decode(new TextEncoder().encode(x))

<input id=i oninput="o.value=f(i.value)" style="width:100%" />

<output id=o></output>

Even longer than Java answer. So sad. :(

PHP+mbstring, 63 49 bytes
<?=mb_convert_encoding($argv[1],'UTF8','CP1252');
It doesn't work on TIO due to the lack of mbstring.
The third parameter force mbstring to interpret the string as Windows-1252 encoded
-14 bytes thanks to Ismael Miguel

<?=mb_convert_encoding($argv[1],'UTF8','CP1252'); <-- even shorter!

C (gcc) + libiconv, 119 117 bytes
*f(s,t,u)void*s,*t,*u;{long i=strlen(s),j=i*4;u=t=malloc(j);iconv(iconv_open("UTF8","CP1252"),&s,&i,&u,&j);return t;}

Try it online!

You should change the language to "C (gcc) + libiconv" in this case

103 bytes

Scala 3, 18 bytes
Simply a port of Kevin Cruijssen's Java answer
String(_,"cp1252")

Try it in Scastie!
Ordinarily, I wouldn't post such a trivial answer, but this demonstrates Scala 3's universal apply methods, which let you omit new.


text:
Visualize a Nim board like an expert
Background
In the game of Nim, players alternate removing "stones" from "piles": on each turn, a player must remove between one and all stones from a single pile.  The object of Nim is to take the last stone or, in the misere variant, to force your opponent to do so -- however, it turns out the strategies are nearly identical.
Nim makes a fun bar game. You can use matchsticks or coins for the "stones," and the "piles" are typically arranged in a line.  Below is a classic setup with piles of 1, 3, 5, and 7:

If you've never played Nim before, you might try your hand at it before attempting this challenge.  Here's a version called "Pearls Before Swine".
Strategy
Optimal strategy in Nim is tricky enough that most lay people lose consistently to an expert, but simple to describe with binary arithmetic.
Doing mental binary XOR operations, however, is tough, so luckily there is an  equivalent way to visualize the correct strategy which is easier to implement in real time, even when drunk.
There are only three steps:

Mentally group the "stones" in each line into subgroups whose sizes are powers of 2, starting with the largest possible size: 8, 4, 2, and 1 are sufficient for most games.
Try to match each group with a twin in another line, so that every group has a pair.
If this isn't possible, remove unpaired "stones" from a single line (this will always be possible - see the Wikipedia link for why) so that step 2. becomes possible.

Or, said another way: "Remove some stone(s) from a single pile such that if you then group the piles into powers of 2 all groups may be paired with a group in some other pile."  With the caveat that you cannot break up larger powers of 2 into smaller ones -- eg, you cannot group a line with 8 stones into two groups of 4.
For example here's how you'd visualize the board above:

This board is perfectly balanced, so you'd want your opponent to move first.
The Challenge
Given a list of positive integers representing the size of Nim "piles", return a plain text visualization of the Nim board as seen by an expert.
What constitutes a valid visualization is best explained by example, but you must:

Assign a distinct character to each "power-of-2 subgroup" and its pair (unpaired subgroups do not qualify), and use that character to represent the "stones" in both subgroup and pair.
Represent any unpaired "stones" (ie, the ones an expert would remove when playing normal -- not misere -- Nim) using a hyphen: -.

There will be multiple ways to achieve a valid visualization, and all are valid.  Let's work through some test cases:
Test Cases
Input: 1, 3, 5, 7
Possible Output 1:
A
BBA
CCCCD
CCCCBBD

You may optionally include spaces between the characters, as well as blank lines between the rows:
Possible Output 2:
A

B B A

C C C C D

C C C C B B D

Input: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
The order and choice of characters can be whatever you like:
Possible Output 1:
G
E E
E E G
C C C C
C C C C F
B B B B D D
B B B B D D F
H H I - - - - -
A A A A A A A A I
A A A A A A A A H H

Unicode symbols are ok too:
Possible Output 2:
◎
◈  ◈
◈  ◈  ◎
△  △  △  △
△  △  △  △  ◉
◐  ◐  ◐  ◐  ◀  ◀
◐  ◐  ◐  ◐  ◀  ◀  ◉
▽  ▽  ◒  -  -  -  -  -
▥  ▥  ▥  ▥  ▥  ▥  ▥  ▥  ◒
▥  ▥  ▥  ▥  ▥  ▥  ▥  ▥  ▽  ▽

Input: 7
From the rules it follows that any "single pile" must be completely removed.
Possible Output 1:
-------

Possible Output 2:
- - - - - - -

Input: 5, 5
Possible Output:
A A A A B
A A A A B

Additional Rules

This is code golf with standard rules.  Shortest code wins.
Input is flexible, and may be taken in whatever list-ish form is convenient to you.
Output is flexible too, as the above examples illustrate.  Most reasonable variations will be allowed.  Ask if you're unsure about something.

Is there a limit to how many stones each pile may contain, or to how many distinct characters will be necessary for the visualization? (In the extreme case, what if, for example, more than the number of printable ASCII characters were needed, or more than 255 distinct characters?)

@Doorknob You can assume that won't happen.  You could even assume the letters of the alphabet will be sufficient for any input.

@Jonah would this be valid output for the second test case? ["H","EE","EEH","CCCC","CCCCI","DDDDFF","DDDDFFI","AAAAAAAA","AAAAAAAA-","----------"]

@ngn no bc you can only remove stones from 1 pile per turn

@Jonah I don't understand how you got H H I - - - - - in your eighth pile. 8 is a power of 2, so why not pair it up with a block from 9 (=8+1)?

@ngn you could, you have 3 piles with 8+, so you could make 3 possible pairs, with a different leftover row in each case.  valid solutions aren’t always unique

Is the input guaranteed to be non-decreasing?

@Οurous no the input could come in any order

The sizes of groups in the lines must be decreasing, so any output containing a line like AAAABBBB or ABB would be invalid, correct? And there should only be one row with unpaired stones?

@Οurous I think the simple answer yes.  Technically AAAABBBB is actually invalid, and ABB is not -- but it makes the output less readable so I think just making decreasing within a line an explicit rule is best.

Do we need to minimise the number of stones marked for removal?

@Οurous no, the only requirement is to leave a balanced board

Should the strategy actually be something like, "remove some stone(s) from a single pile such that if you then group the piles into powers of two all groups may be paired with a group in some other pile"? As it's written it seems that for the 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 input a valid output would be '0', '11', '110', '2222', '22223', '444455', '4444553', '66666666', '66666666-', '7777777788' (or is this valid?)

@JonathanAllan Your description is correct, and arguably clearer than mine.  That said, the 88 in your example would be prohibited by the "unpaired subgroups do not qualify" clause, forcing your 8s to become dashes, creating dashes in two piles, violating the single pile rule.  So it is invalid according to the existing description.

The point was more about the "strategy" section, since it implies grouping each pile starting with the highest possible power of two - note that the 7s are unpaired too. Also "unpaired subgroups do not qualify" does not really mean much to me as I read it :/

@JonathanAllan, Even there, your example does not conform to step 3: 'Remove unpaired "stones" so that all groups are paired off when it's your opponent's turn.'.  That said, if the description isn't clear to you it may be unclear to others, so I'll add your sentence to the description.

Step one seems to imply grouping the piles like I have above (effectively using the set bits in the binary representations), which may then lead to steps two and/or three not being possible - it's only when one then studies the example that it becomes clear that the piles are not formed like that (or that they need to be adjusted in some way to meet two and three). (...it's also a shame because I implemented a terse solution that relies on it)

@JonathanAllan Yes, I am relying on the logic that all 3 steps must occur simultaneously.  So if you perform steps 1 and 2 but cannot perform step 3, you must adjust your solution to steps 1 and 2.  Which I can see being confusing.  I've added your description below.

Ruby, 169 164 148 bytes
->a{s=eval a*?^
c=?@
m={}
a.map{|x|z=x-(x^s);[$><<?-*z,x-=z,s=0]if z>0
n=1
eval'x&1>0?[$><<(m[n]||c.next!)*n,m[n]=!m[n]&&c*1]:0;n*=2;x/=2;'*x
puts}}

Try it online!
First, we initialize

the nim-sum with s=eval a*?^ (which is shorter than a.reduce:^)
the variable c, which stores the first unused unique character
a map m that maps power-of-two lengths to characters used to represent them

Then, looping over each pile, we run the following:
z=x-(x^s);[$><<?-*z,x-=z,s=0]if z>0

Per Wikipedia's strategy, if nim-sum XOR pile is less than pile, we should remove stones from that pile such that its length becomes nim-sum XOR pile. By storing the difference in the variable z, we can test to see whether this difference is positive, and if so 1.) print that many dashes, 2.) subtract it from the pile, and 3.) set the nim-sum variable to zero to prevent further stone removal.
n=1
eval'[...];n*=2;x/=2;'*x

Now we "loop" over each bit and keep track of their values by repeatedly dividing x by 2 and multiplying the accumulator n by 2. The loop is actually a string evaluated x times, which is far greater than the log2(x) times it's necessary, but no harm is done (aside from inefficiency). For each bit, we run the following if the bit is 1 (x&1>0):
$><<(m[n]||c.next!)*n

Print a character n times. If we already printed an unpaired group of this many stones, use that character; otherwise, use the next unused character (advancing c in-place due to the !).
m[n]=!m[n]&&c*1

If m[n] existed (i.e. we just completed a pair), then m[n] is reset. Otherwise, we just started a new pair, so set m[n] to the character we used (*1 is a short way to make a copy of c).

Python 2, 150 196 206 bytes
def f(p):
 c=48;s=[l*'.'for l in p];m=2**len(bin(l))
 while m:
  if sum(m*'.'in l for l in s)>1:
   for i,l in enumerate(s):s[i]=l.replace('.'*m,chr(c)*m,`s`.count(chr(c)*m)<2)
   c+=1
  else:m/=2
 return s

Try it online!

I don't think this works for 4, 9, 10.

@Neil Nice catch, should be fixed now

Sorry, I managed to fool it again, this time with 14, 21, 35.

It also fails for [1, 3, 4, 5], where it should remove the entire second pile.

@Doorknob, Is that required? The rules say There will be multiple ways to achieve a valid visualization, and all are valid

@Neil, Fixed for larger numbers now :)

@TFeld I think so, because currently (after removing one stone from the second row) it tries to pair one stone in the second row with the top row and one with the last stone in the bottom row. It should take the entire second row as a group, because it has a power-of-two number of stones.

@TFeld Doorknob is correct, in 1 3 4 5 you must remove the entire 2nd pile.  If you can make a pile of 2, you can't choose to split it up.  The strategy won't work if you do.  Note that there are still multiple correct visualizations, in that you can still select different sets of characters, spacing, etc.

Some golfs for 189 bytes.

And then a full program is 181 bytes

You may also set c=m=2**len(bin(l)), since the characters don't matter as long as they are distinct, but you'll get some really gnarly outputs! (EDIT: oh, actually you want to stay in range(256) of course. But I guess there's no reason c=1 wouldn't be allowed, say.)

JavaScript (ES6), 215 bytes

f=
(a,c=0,x=eval(a.join`^`),i=a.findIndex(e=>(e^x)<e),b=a.map(_=>``),g=e=>(d=e&-e)&&a.map((e,i)=>e&d&&(a[i]-=d,b[i]=(c++>>1).toString(36).repeat(d)+b[i]))&&g(e-d))=>g(eval(a.join`|`),b[i]='-'.repeat(a[i]-(a[i]^=x)))||b
<textarea oninput=o.textContent=/\d/.test(this.value)?f(this.value.match(/\d+/g)).join`\n`:``></textarea><pre id=o>

Only visualises up to 36 different characters. I'm relieved this works for 1, 3, 4, 5.

Really nice.  It's fun to play with it in real time.

Clean, 454 bytes
still golfing
import StdEnv,Text,Data.List
$p=join"\n"[{#toChar c+'-'\\c<-e}\\e<-[take i(e++[0,0..])\\e<-r[[~c\\c<-reverse e,_<-[1..c]]\\e<-hd[q\\q<-foldr(\h t=[[a:b]\\a<-h,b<-t])[[]][[c\\c<-subsequences(takeWhile((>=)k)(iterate((*)2)1))|sum c<=k]\\k<-p]|sum[1\\a<-q&b<-p|sum a<>b]<2&&foldr(bitxor)0(flatten q)==0]]1&i<-p]]
r[]_=[]
r[h:t]n|all((<)0)h=[h:r t n]
#[m:_]=removeDup[e\\e<-h|e<0]
#(a,[x:b])=span(all((<>)m))t
=r([[if(e==m)n e\\e<-k]\\k<-[h:a]++[x]]++b)(n+1)

Try it online!
Defines the function $ :: [Int] -> String, taking the pile sizes and returning a string where - denote stones to be removed, and groups are represented by ASCII characters ascending from -.
If enough groups are needed the characters will wrap back around eventually, and due to the foldr it requires more than a gigabyte of memory to run the second test-case.
Indented version of the giant comprehension:
$p=join"\n"[
    {#
        toChar c+'-'
        \\c<-j
    }
    \\j<-[
        take i(e++[0,0..])
        \\e<-r[
            [
                ~c
                \\c<-reverse e
                ,_<-[1..c]
            ]
            \\e<-hd[
                q
                \\q<-foldr(\h t=[
                    [a:b]
                    \\a<-h
                    ,b<-t
                ])[[]][
                    [
                        c
                        \\c<-subsequences(takeWhile((>=)k)(iterate((*)2)1))
                        |sum c<=k
                    ]
                    \\k<-p
                ]
                |sum[
                    1
                    \\a<-q
                    &b<-p
                    |sum a<>b
                ]<2&&foldr(bitxor)0(flatten q)==0
            ]
        ]1
        &i<-p
    ]
]

Just curious, Clean seems similar to haskell... what are its advantages over Haskell?

@Jonah It is quite similar, yes. Off the top of my head, it has lower-level type manipulation, inline IL / Assembly, and interop with C all achieved easier than with Haskell. However, for actual use, due to the obscurity and experimental/academic nature of Clean, I would recommend Haskell (which also has more support in terms of libraries, and reference information). I just happen to like Clean is all.

source: Stack Exchange

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

sort: votes


text:
Indexing Cha-Cha Slide
Introduction:
Although I originally had a Dutch song in my head, where the lyrics are: "Doe 'n stapje naar voren, en 'n stapje terug" (which translated to "Take a little step forward, and a little step back"), when I searched for the full lyrics, I realized they only got back and forth, and never sideways.
So, instead I now use the lyrics of Mr C The Slide Man a.k.a. DJ Casper - Cha-Cha Slide for this challenge.
If we ignore everything else and only look at the words "left", "right", "back", and "hop" (I counted "hop" as forward) including the mentioned amounts, the full song will have the following list (I'm using the abbreviations LRBH here):
LBHRLLBHRLBHHRRLLLRLBHHHHRRLLLBHHHHHRLRLRLHRLLBHHLRLBHH

Here the full song lyrics in a hideable JavaScript code-snippet (to save space), where the moves and amounts are surrounded with blocked brackets:

To the [left], take it [back] now y'all
One [hop] this time, [right] foot let's stomp
[Left] foot let's stomp, cha cha real smooth

Turn it out, to the [left]
Take it [back] now y'all
One [hop] this time, [right] foot let's stomp
[Left] foot let's stomp, cha cha now y'all

Now it's time to get funky
To the [right] now, to the [left]
Take it [back] now y'all
One [hop] this time, one [hop] this time
[Right] foot [two] stomps, [left] foot [two] stomps
Slide to the [left], slide to the [right]
Criscross, criscross
Cha cha real smooth

Let's go to work
To the [left], take it [back] now y'all
[Two] [hops] this time, [two] [hops] this time
[Right] foot [two] stomps, [left] foot [two] stomps
Hands on your knees, hands on your knees
Get funky with it, aahhhhhhhhhh yaaaa
Come on, cha cha now y'all

Turn it out, to the [left]
Take it [back] now y'all
[Five] [hops] this time
[Right] foot let's stomp, [left] foot let's stomp
[Right] foot again, [left] foot again
[Right] foot let's stomp, [left] foot let's stomp

Freeze, everybody clap yo hands
Come on y'all, check it out
How low can you go?
Can you go down low?
All the way to da floor?
How low can you go?
Can you bring it to the top?
Like it never never stop?
Can you bring it to the top?
One [hop], [right] foot now
[Left] foot now y'all
Cha cha real smooth

Turn it down, to the [left]
Take it [back] now y'all
One [hop] this time, one [hop] this time
Reverse, reverse
Slide to the [left], slide to the [right]
Reverse reverse, reverse reverse
Cha cha now y'all
Cha cha again
Cha cha now y'all
Cha cha again
Turn it down

To the [left], take it [back] now y'all
[Two] [hops] two hops, two hops two hops    EDIT: Made a mistake here, but bit to late to change it now..

Challenge:
Now onto the challenge itself. We take one, two, or three inputs †. One of them is a list of index-integers (so either non-negative for 0-indexed; or positive for 1-indexed). (The other inputs are optional and explained in the challenge rules.)
Every test case will start at a position {x=0, y=0}.
Now use the lyrics-list of moves and remove all moves at the given indices of the input-list. Then 'walk' over the moves (up to the largest index of the input-array) and output the position you'll end up at.
The moves will change the coordinates as follows:
- R: x+1
- L: x-1
- H: y+1
- B: y-1
Challenge rules:

The moves-list can be accessed any way you'd like. †: Can be an additional input; can be in a separated file on disk you'll read from; can be in a class-level variable you access. It will have to be in the form of L, R, B and H though (can be a string or character-list/array), so you cannot save the moves-list as 1s and -1s or integers.
The moves-list given above is hard-coded and will always be the same. (Which is also why it's fine to put it as class-level field instead of taking it as an input if this helps the byte-count of your answer.)
Input-list can be both 0-indexed or 1-indexed (up to you)
We only 'walk' the moves up to and excluding the largest index of the list.

†: You are also allowed to take this last item as separated integer input, instead of the last item of the input-array.

Output of the x and y coordinates we end up at can be in any reasonable format (integer-array containing two items, delimited string, printed to STDOUT on two separated lines, etc.)
You can assume the input-list is sorted from lowest to highest (or highest to lowest if that's what you prefer, in which case the first item is the initial size of the moves-list - if not taken as separated input). And it also won't contain any duplicated indices.
If the largest index of the input-list is larger than the list of moves above (55 moves are in the moves-list above), we wrap around to the beginning of the list again (as many times as necessary depending on the largest index of the input).
You are allowed to output y,x instead of x,y, but please specify this in your answer if you do.

Example:
Input: [0,4,8,10,13,14,27,34,42,43,44,50,53,56,59,60,64]
Here the moves and (0-indexed) indices above one-another:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64
L, B, H, R, L, L, B, H, R, L, B, H, H, R, R, L, L, L, R, L, B, H, H, H, H, R, R, L, L, L, B, H, H, H, H, H, R, L, R, L, R, L, H, R, L, L, B, H, H, L, R, L, B, H, H, L, B, H, R, L, L, B, H, R, L

Removing the indices of the input-list, we'll have the following moves-list remaining:
1, 2, 3, 5, 6, 7, 9,11,12,15,16,17,18,19,20,21,22,23,24,25,26,28,29,30,31,32,33,35,36,37,38,39,40,41,45,46,47,48,49,51,52,54,55,57,58,61,62,63
B, H, R, L, B, H, L, H, H, L, L, L, R, L, B, H, H, H, H, R, R, L, L, B, H, H, H, H, R, L, R, L, R, L, L, B, H, H, L, L, B, H, L, H, R, B, H, R

Now if we walk from position {0, 0} over the remaining moves, we'll have the following new coordinates after every move:
{0,0};B,{0,-1};H,{0,0};R,{1,0};L,{0,0};B,{0,-1};H,{0,0};L,{-1,0};H,{-1,1};H,{-1,2};L,{-2,2};L,{-3,2};L,{-4,2};R,{-3,2};L,{-4,2};B,{-4,1};H,{-4,2};H,{-4,3};H,{-4,3};H,{-4,5};R,{-3,5};R,{-2,5};L,{-3,5};L,{-4,5};B,{-4,4};H,{-4,5};H,{-4,6};H,{-4,7};H,{-4,8};R,{-3,8};L,{-4,8};R,{-3,8};L,{-4,8};R,{-3,8};L,{-4,8};L,{-5,8};B,{-5,7};H,{-5,8};H,{-5,9};L,{-6,9};L,{-7,9};B,{-7,8};H,{-7,9};L,{-8,9};H,{-8,10};R,{-7,10};B,{-7,9};H,{-7,10};R,{-6,10}

So the final output will be: {-6, 10}
General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code.
Also, adding an explanation for your answer is highly recommended.

Test cases:
0-indexed input: [0,4,8,10,13,14,27,34,42,43,44,50,53,56,59,60,64]
1-indexed input: [1,5,9,11,14,15,28,35,43,44,45,51,54,57,60,61,65]
Output: {-6, 10}

0-indexed input: [55]    (Note: There are 55 moves in the unmodified list)
1-indexed input: [56]    (Note: There are 55 moves in the unmodified list)
Output: {-6, 11}

0-indexed input: [0,1,4,5,6,9,10,15,16,17,19,20,27,29,30,37,38,39,41,44,45,46,49,51,52]
1-indexed input: [1,2,5,6,7,10,11,16,17,18,20,21,28,30,31,38,39,40,42,45,46,47,50,52,53]
Output: {10, 16}

0-indexed input: [2,3,7,8,11,12,13,14,18,21,22,23,24,25,26,31,32,33,34,35,36,38,40,42,43,47,48,50,53]
1-indexed input: [3,4,8,9,12,13,14,15,19,22,23,24,25,26,27,32,33,34,35,36,37,39,41,43,44,48,49,51,54]
Output: {-18, -7}

0-indexed input: [0]
1-indexed input: [1]
Output: {0, 0}

0-indexed input: [4,6,7,11,12,13,15,17,20,28,31,36,40,51,59,66,73,74,80,89,92,112,113,114,116,120,122,125,129,134,136,140,145,156,161,162,165,169,171,175,176,178,187,191,200]
1-indexed input: [5,7,8,12,13,14,16,18,21,29,32,37,41,52,60,67,74,75,81,90,93,113,114,115,117,121,123,126,130,135,137,141,146,157,162,163,166,170,172,176,177,179,188,192,201]
Output: {-17, 37}

0-indexed input: [25,50,75,100,125,150,175,200,225,250]
1-indexed input: [26,51,76,101,126,151,176,201,226,251]
Output: {-28, 49}

Can we output the coordinates in reverse order?

@Shaggy Umm, sure, why not. As long as you clearly specify it in your answer.

@Arnauld Yes, the moves are those displayed and will never change. I will perhaps clarify this more clearly if it wasn't clear yet. (Which is also why you can have it as a hardcoded class-level field if it would benefit your byte-count.)

Can the output be a pair of floats?

@Jakob Sure. If they don't have anything else besides decimal 0s it's fine (floating point precision neglected of course).

Very late to the challenge, but two of your test cases seem to have wrong input for the 1-indexed case: an extra 82 in the sixth one, and 29 instead of 39 in the third testcase (the sorting indicates you might have intended that to actually be 28/29, but the expected output shown is from using 38/39 there).

05AB1E, 15 12 bytes
Saved 3 bytes thanks to Erik the Outgolfer
ÝsKèIêRS¢2ôÆ

Try it online!
or as a Test suite
Explanation
Ý                 # push range [0 ... input_int]
 sK               # remove all elements in input_list from this range
   è              # cyclically index into the moves-list with the remaining elements
    Iê            # push the unique chars of the move-list, sorted
      R           # reverse
       S¢         # count the occurrences of each char in "RLHB"
         2ô       # split into 2 parts
           Æ      # reduce each part by subtraction

Nice answer! Didn't even knew about Æ. Smart way to just count all moves and use Æ to calculate the difference for the RL and BH pairs.

Æ has existed forever, hasn't it? I'd assume so, seeing as I didn't know about it. Seems like the commands I think are "new" have existed since inception, but I never knew how to use them lol. Oh, +1

@MagicOctopusUrn: It has indeed existed forever ;)

Ruby, 98 ... 58 55 bytes
->a{([*0..a[-1]]-a).sum{|c|-1i**(m[c%55].ord%19)}.rect}

Try it online!
Explanation:
The main trick is using complex numbers to represent moves: 'B' is -i, 'H' is +i, 'L' is -1 and 'R' is +1. If we convert all the moves into complex numbers, then with a single sum we get the right result.
I tried different ways, but then I found the magic number 19: we don't need to fiddle with regex matching because:
B  is ASCII 66; 66%19=9  and i^9  = i
H  is ASCII 72; 72%19=15 and i^15 =-i
L  is ASCII 76; 72%19=0  and i^0  = 1
R  is ASCII 82; 82%19=6  and i^6  =-1

So, put that all together, sum, invert the sign, and we're done.
Thanks Jakob for -3 bytes

Clever use of complex numbers! Since the move string is fixed, you can replace (m*c+m)[c] with m[c%55].

JavaScript (ES6), 85 bytes
As per the challenge rules, this code expects the global-scope string m to hold the list of moves. (Saving 3 bytes, as suggested by @KevinCruijssen.)
Takes input as a list of 0-based indices, ordered from lowest to highest.
a=>a.map(g=i=>j++<i&&g(i,p=m.search(m[~-j%55])*3%5,x+=--p%2,y-=--p%2),j=x=y=0)&&[x,y]

Try it online!
How?
Each move character is converted to its position in the move string "LBHR...". We multiply the result by 3 and apply a modulo 5, which gives p. We then have:

dx = ((p-1) mod 2)
dy = -((p-2) mod 2)

Where the sign of a mod b is that of a.
 character | position | * 3 | mod 5 | dx | dy
-----------+----------+-----+-------+----+----
    'L'    |     0    |  0  |   0   | -1 |  0
    'B'    |     1    |  3  |   3   |  0 | -1
    'H'    |     2    |  6  |   1   |  0 | +1
    'R'    |     3    |  9  |   4   | +1 |  0

Jelly, 14 bytes
Rḟị⁵ċⱮ⁵QṢṚ¤_2/

Try it online!
Argument 1/Left argument: Maximum 1-based index.
Argument 2/Right argument: 1-based indices.
Argument 3: Moves-list as a string. Function is still reusable if the third command-line argument is used for this purpose.

Java 10, 129 119 112 107 100 86 bytes
a->m->{var r=new int[2];for(;m-->0;)r[s[m%55]/73]-=a.add(m)?s[m%55]*3%5-2:0;return r;}

Takes the maximum as additional input; moves-list is a character-array on class-level.
Inspired by @Emigna's 05AB1E answer.
-7 bytes thanks to @Jakob.
-14 bytes thanks to @Geobits.
Try it online.
Explanation:
a->m->{              // Method with Integer-Set & int parameters and int-array return
  var c=new int[2];  //  [x,y] result-array, starting at {0,0}
  for(;m-->0;)       //  Use the `m` input as index, and loop in the range (`m`, 0]
    r[s[m%55]/73]-=  //   Subtract from either x or y based on the character:
     a.add(m)?       //    If the input-set doesn't contain the current index `m`:
      s[m%55]*3%5-2  //     Modify the x or y coordinate based on the character
     :               //    Else:
      0;             //     Leave the x or y coordinate unchanged
  return r;}         //  Return count(R)-count(L) and count(H)-count(B) as result

s[m%55]/73 maps to either the x or y coordinate depending on the character (Try it online):
Letter    Unicode value    /73

B         66               0
H         72               0
L         76               1
R         82               1

s[m%55]*3%5-2 maps to the correct +1 or -1 depending the character (Try it online):
Letter    Unicode value    *3     %5    -2

B         66               198    3     1
H         72               216    1     -1
L         76               228    3     1
R         82               246    1     -1

If you take the index list as a mutable set you can use a.add(m) as the if condition.

And int c[] can be int[]c.

@Jakob Ah, int c[] was from a previous version where I still used an index i instead of using m. And smart of using a Set's add instead of !contains, thanks!

You can avoid the byte-hogging subtraction at the end by using c[2] for axis (with s[m%55]/73) and walking it with something like 3*s[m%55]%5-2 (I wish I could see a way to shorten that, but...). Along with a ternary, it's a->m->{var c=new int[2];for(;m-->0;)c[s[m%55]/73]-=a.add(m)?3*s[m%55]%5-2:0;return c[1]+","+c[0];} for 98.

@Geobits Thanks! And -12 bytes more by just returning the int[] instead of a String. :)

Python 3, 85 bytes
b is the index list (a set) and l is the end index. The move list (a string or character list) appears free as s. This is a port of G B's Ruby answer, and an explanation of the approach can be found there.
def f(b,l):r=sum(-1j**(ord(s[i%55])%19)for i in set(range(l))-b);print(r.real,r.imag)

Try It Online
Ungolfed
def f(b, l):
    r = sum(
        -1j ** (ord(s[i % 55]) % 19)
        for i in set(range(l)) - b
    );
    print(r.real, r.imag)

MATL, 16 bytes
:wX-)Jw19\^s_&Zj

Try it online!
Takes 3 inputs like the Jelly answer, the largest index, the list of indices to skip, and the 55 character array.

Clean, 148 ... 130 bytes
import StdEnv
$i=foldr(\a(x,y)|any((==)a)i=(x,y)=case m.[a rem 55]of'H'=(x,y+1);'B'=(x,y-1);'L'=(x-1,y);_=(x+1,y))(0,0)[0..last i]

Try it online!
Defines the function $ :: [Int] -> (Int, Int), taking a list of (sorted from smallest to largest) indices to be removed from the moves before foldr-ing the applicable operations over (0,0).

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


text:
Camel Up Cup: An AI board game tournament
Camel Up Cup 2k18
In this challenge, we will be playing the semi-popular board game Camel Up.
Camel Up! is a board game that has players betting on camels to win rounds, win the game or lose the game, set traps to influence movement or move a camel. Each of these decisions rewards you with the chance of getting some money, which is what determines the winner. Players should use probability, game-state considerations and opponent tenancy to make their decisions. Here is a short video showing players how to play.
How to play
Here is a rough idea of how to play. Watching one of the videos may be more helpful because they have visuals :)
On your turn you have 4 options.

Move a camel. This picks a camel from those who haven't moved and moves it between 1-3 spaces. You get 1 coin. Rounds end when all five camels have moved, they can then all move
Place a trap. This goes on the board until the end of round. You choose +1/-1 trap. If a camel or camel stack lands on it they move +1/-1 and you get a coin. You cannot place a trap on square 0. You can place a trap where camels are, although it will only affect camels that land on it after.
Round winner bet. You take a bet on a round winner. They win you get 5/3/2/1 depending on if you were the 1st/2nd/3rd to bet on that camel.
Game winner/loser. You take a bet on who will be in first or last at the end of the game. you get 8/5/3/1/1 (I think) based on if you were 1st/2nd/3rd/etc to bet on that camel

Notes:

There are 5 camels. They start on a position randomly from 0-2.
When a camel is moved (see above for what triggers this) they move 1-3 squares. If they would be placed on a square with another camel they are put "on top" of the other, creating a camel stack. If a camel is to move it moves all camels above it on the camel stack. The camel at the top of the stack is considered in the lead
If you land on a +1 trap (see above for what triggers this) you move one square further forward. Standard stacking rules apply.
However if you hit a -1 trap you move one square backwards. You go under the stack of camels that are on that square, if any.
The game ends when a camel hits square 16. This immediately invokes round end and game end triggers
Game winner/loser bets can be done only once per camel. I.e. you cannot bet on a camel to win and lose the game

Challenge
In this challenge, you will write a Python 3 program to play a four player, winner takes all glory game of Camel Up
Your program will receive the gamestate, which contains:

camel_track: with the locations of the camels
trap_track: with the location of the traps (entry of the form [trap_type (-1,1), player])
player_has_placed_trap: an array telling you if players have placed a trap this round
round_bets: an array of the bets placed this round. Of the form [camel,player]
game_winner_bets / game_loser_bets: arrays of the bets players made for camels to win or lose the game. You will only be able to see the value of players who made the bets, not who they bet on. You can know who you bet on. #of the form [camel,player]
player_game_bets: another representation of the game_winner_bets / game_loser_bets. Again, only look at the bets that your bot made.
player_money_values: an array showing the amount of money each player has.
camel_yet_to_move: An array showing if a camel has moved this round.

On top of the gamestate you also get:

player: an integer telling you what player number you are (0-3).

Syntax for what players should return is:

[0] : Move Camel
[1,trap_type,trap_location] : Place Trap
[2,projected_round_winner] : Make Round Winner Bet
[3,projected_game_winner] : Make Game Winner Bet
[4,projected_game_loser] : Make Game Loser Bet

This should be wrapped in a move(player,gamestate) method
For instance, here's a player that will make a round winner bet if they are in last place. If they aren't then they will place a trap on a random square.
class Player1(PlayerInterface):
     def move(player,g):
         if min(g.player_money_values) == g.player_money_values[player]:
            return [2,random.randint(0,len(g.camels)-1)]
        return [1,math.floor(2*random.random())*2-1,random.randint(1,10)]

The game was chosen for several reasons: it has a relatively small pool of options to select from (roughly 20 choices per turn, easily narrowed down to usually about 3-4), games are short and there is an element of luck (makes it so even the "bad" bots can win).
Gameplay
The tournament runner can be found here: camel-up-cup. Run camelup.py to run a tournament or the function PlayGame to run games. I'll keep that repository updated with new submissions. Example programs can be found in players.py.
A tournament consists of 100 games per 10 players (rounded up, so 14 players means 200 games). Each game will be four random players selected from the pool of players to fill the four positions. Players will not be able to be in the game twice.
Scoring
The winner of each game is the player with the most money at the end of the game. In the case of a tie at the end of a game all players with the maximum money amount are awarded a point. The player with the most points at the end of the tournament wins. I will post scores as I run the games.
The players submitted will be added to the pool. I added three really dumb bots and one that I made to start.
Caveats
Do not modify the inputs. Do not attempt to affect the execution of any other program, except via cooperating or defecting. Do not make a sacrificial submission that attempts to recognize another submission and benefit that opponent at its own expense. Standard loopholes are banned.
Limit the time taken by your bot to be ~10s per turn.
Submissions may not duplicate earlier submissions.
Please don't view game_winner or game_loser bets from other players. Its pretty easy to do but still cheating.
If you have any questions, feel free to ask.
Winning
The competition will stay open indefinitely, as new submissions are posted. However, I will declare a winner (accept an answer) based on the results one month after this question was posted (July 20th).
Results
Player0: 12
Player1: 0
Player2: 1
Sir_Humpfree_Bogart: 87

Maybe I read past it, but how many Camels are there in play? Also, how many squares do they have to travel to get to the other side? Based on your GitHub code I'm pretty sure it's 5 camels and 25 squares, but I didn't see this mentioned in the challenge description. As for placing bets, can we bet any amount, or it will bet 1 by default? Do we have a spending limit, or can we bet every round indefinitely? As for players moving a camel, which camel is moved? The camel with your matching player-nr? If yes, why are there 4 players but 5 camels?

Would have been perfect to have Perl answers

Welcome to PPCG!

100 games per 10 players seems pretty low IMO, especially with a game with so much randomness

To make it clear to future readers:  second place is worth as much as last place, so bet it all for the win.

" I added three really dumb bots and one that I made to start.":  You should post them below if they are going to compete

@AdmBorkBork Thank you! I'm new to this so welcome all pointers. This worked well in real life -- amped to see how it plays out here

@NathanMerrill Thank you for the clarification / suggestion! I'll add the bots below soon. I'm torn on the # of games... obviously you want more to be deterministic... I felt like the 100 per 10 was a decent way to get 20 games / person. I'd be down to double or triple it but not much more than that

@KevinCruijssen I added a quick "How To Play" section. The game is nearly no differences from the board game which may be easier since you can see the concepts visually

Sir_Humpfree_Bogart.py
This is a bot I made for the Camel Up Cup Tournament.
First, they look at all the possible configurations that the camels could end up at the end of the round. Then they determine the expected value of betting on a camel winning the round using
EV_roundwin = (chance_1st)*(payout) + (chance_2nd)*(payout) - (chance_3rd_or_worse)*(cost)

Then they move camels randomly until a camel wins. After doing this a few thousand times you can estimate the chance each camel will win and lose. Again, we get the expected value of these using
EV_gamewin = (chance_1st)*(payout) - (chance_2nd_or_worse)*(cost)

The only other options are moving a camel (which always yields one coin, so its expected value is one) and placing a trap. Both teams felt placing a trap was a weak enough option to ignore it entirely. With this information the bots chose the option with the highest expected value.
Since the tournament viewed a second place finish the same as a last place finish it makes sense if you are behind to take chances to get into first place. SBH used distance_from_first_place and nearness_to_end to determine how risky the bot should be, where if you are far from first and close to the end then riskiness would be high and if you are in first or far from the end of the game the riskiness would be low. With a low riskiness the bot would decide on an action with a high expected value option and a high riskiness yielding the option with a high upshot. The exact equation was
Functional_EV = EV + (upshot-EV) * riskiness

where upshot is the highest payout you can get from a decision and riskiness ranges from 0 to 1.

players.py
These are incredibly dumb bots to get the tournament going. They have nearly no logic but act as frameworks for people to use
import random
import math
from playerinterface import PlayerInterface

class Player0(PlayerInterface):
    def move(player,g):
        #This dumb player always moves a camel
        return [0]

class Player1(PlayerInterface):
    def move(player,g):
        #This player is less dumb. If they have the least amount of money they'll make a round winner bet
        #If they aren't in last then they'll place a trap on a random square. Still p dumb though
        if min(g.player_money_values) == g.player_money_values[player]:
            return [2,random.randint(0,len(g.camels)-1)]
        return [1,math.floor(2*random.random())*2-1,random.randint(1,10)]

class Player2(PlayerInterface):
    def move(player,g):
        #This dumb player always makes a round winner bet
        return [2,random.randint(0,len(g.camels)-1)]


text:
Recover the prime from the prime power
Definition: a prime power is a natural number that can be expressed in the form pn where p is a prime and n is a natural number.
Task: Given a prime power pn > 1, return the prime p.
Testcases:
input output
9     3
16    2
343   7
2687  2687
59049 3

Scoring: This is code-golf. Shortest answer in bytes wins.

Can n be 1?

@user202729: In the 4th test-case n = 1.

Maybe it would have been more challenging to get the power part instead of the prime part. As it is, this is just "Get the lowest factor that isn't 1"

05AB1E, 1 byte
f

Try it online!

Are you sure that a list (or [] around the number) is a valid output?

@EriktheOutgolfer: Relevant meta

Huh, didn't know about that, thanks.

For those wondering, f = push list of prime factors (no duplicates)

Shakespeare Programming Language, 209 207 bytes
T.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page]Ajax:Listen tothy!Page:You cat!Scene V:.Page:You be the sum ofyou a cat!Be the product ofthe quotient betweenI you you worse I?If soLet usScene V.Open heart

Try it online!
(I/you)*you<I is shorter than I%you>0 in SPL.

The right tool for the job.

Java 8, 46 39 37 bytes
n->{int r=1;for(;n%++r>0;);return r;}

-7 bytes indirectly thanks to @Tsathoggua.
-2 bytes thanks to JoKing
Try it online.
Explanation:
n->{               // Method with integer as both parameter and return-type
  int r=1;         //  Start the result-integer `r` at 1
  for(;n%++r>0;);  //  Increase `r` by 1 before every iteration with `++r`
                   //  and loop until `n` is divisible by `r`
  return r;}       //  After the loop, return `r` as result

Following Luis Mendo's answer in python3, would it be possible to write n->{for(int i=1;++i<=n;)if(n%i<1)return i;} to get 43 characters? (I don't speak Java.)

@Tsathoggua As you have it right now not, since Java methods must always have a return. n->{for(int i=1;++i<=n;)if(n%i<1)return i;return n;} would work, but is unfortunately longer. Java can have a single return in infinite loops however, which does indeed save bytes, so thanks! n->{for(int i=1;;)if(n%++i<1)return i;}. Since i will become n eventually (like with the test case 2687) and n%n==0, the i<=n isn't required in this case.

How about 37 bytes. I'm not familiar enough with Java to see if any more can be golfed

@JoKing I don't see anything to golf further, so thanks for the -2.

Python 3, 36 35 bytes
-1 byte thanks to mathmandan
f=lambda n,x=2:n%x and f(n,x+1)or x

Try it online!
Recursive function that finds the first factor larger than 1

Nice. You can (usually) save a byte if you replace if/else with and/or. Like, f=lambda n,x=2:n%x and f(n,x+1)or x.

MATL, 4 3 bytes
Yfu

Try it online!
Explanation:
       % Implicit input:      [59049]
Yf     % Prime factorization: [3 3 3 3 3 3 3 3 3 3]
  u    % Unique elements:     [3]
       % Implicit output

Very nice improvement! I would upvote again :-)

Octave, 16 bytes
@(x)factor(x)(1)

Try it online!
Explanation:
@(x)              % Anonymous function taking x as input
    factor(x)     % Prime factorization
             (1)  % Get the first element

Or:
@(x)max(factor(x))  % the makeup of makeup artists

Whitespace, 80 61 60 bytes
[S S T  T   N
_Push_-1][S S S N
_Push_0][T  N
T   T   _Read_STDIN_as_number][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][S S S N
_Push_0][T  T   T   _Retrieve][S N
T   _Swap][T    S T T   _Modulo][N
T   T   N
_If_0_Jump_to_Label_LOOP][S S T T   N
_Push_-1][T S S N
_Multiply][T    N
S T _Print_as_number]

-20 bytes thanks to @JoKing.
Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
Explanation in pseudo-code:
Integer n = STDIN as integer
Integer i = -1
Start LOOP:
  i = i - 1
  if(n modulo-i is negative)
    Go to next iteration of LOOP
  else
    i = i * -1
    Print i
    Exit with error: No exit defined

Example run: input = 9
Command   Explanation                    Stack        Heap     STDIN    STDOUT    STDERR

SSTTN     Push -1                        [-1]
SSSN      Push 0                         [-1,0]
TNTT      Read STDIN as integer          [-1]         {0:9}    9
NSSN      Create Label_LOOP              [-1]         {0:9}
 SSSTN    Push 1                         [-1,1]       {0:9}
 TSST     Subtract top two (-1-1)        [-2]         {0:9}
 SNS      Duplicate top (-2)             [-2,-2]      {0:9}
 SSSN     Push 0                         [-2,-2,0]    {0:9}
 TTT      Retrieve                       [-2,-2,9]    {0:9}
 SNT      Swap top two                   [-2,9,-2]    {0:9}
 TSTT     Modulo top two (9%-2)          [-2,-1]      {0:9}
 NTSN     If neg.: Jump to Label_LOOP    [-2]         {0:9}

 SSTTN    Push -1                        [-2,-1]      {0:9}
 TSST     Subtract top two (-2-1)        [-3]         {0:9}
 SNS      Duplicate top (-2)             [-3,-3]      {0:9}
 SSSN     Push 0                         [-3,-3,0]    {0:9}
 TTT      Retrieve                       [-3,-3,9]    {0:9}
 SNT      Swap top two                   [-3,9,-3]    {0:9}
 TSTT     Modulo top two (9%-3)          [-3,0]       {0:9}
 NTSN     If neg.: Jump to Label_LOOP    [-3]         {0:9}
 SSTTN    Push -1                        [-3,-1]      {0:9}
 TSSN     Multiply top two (-3*-1)       [3]          {0:9}
 TNST     Print as integer               []           {0:9}             3
                                                                                error

Program stops with an error: No exit found.

Do you need the i == n check? n%n would be 0 anyway

@JoKing Ah, of course. Thanks, 19 bytes saved right there. :)

Could you only loop if not n%i and call the print afterwards?

@JoKing I'm pretty sure not. Whitespace doesn't really have loops, it just has jumps to labels. The only three options I have is to: 1. jump to a certain label unconditionally; 2. jump to a certain label if the top of the stack is 0; 3. jump to a certain label if the top of the stack is negative. Unfortunately there isn't a "jump to label if positive" to continue the loop. I could accomplish this by multiplying by -1 before checking for negative, but I doubt that will be shorter.

Tried to do it with a negative modulus and ended up at 6260 bytes (yay). Turns out you can't store at negative heap addresses (though 0 saved a couple of bytes)

@JoKing Thanks again! Yes, I tried saving an input in a negative heap address before, but unfortunately that doesn't work. Also, TIO works as intended with negative modulo, but apparently vii5ard which I usually use to develop in (easier to debug and see all commands) will give 9%-2 = 1 instead of -1. But I use TIO as lead in my Whitespace answers, which works completely fine. Well done!

JavaScript (ES6), 25 bytes
f=(n,k=2)=>n%k?f(n,k+1):k

Try it online!

Funky, 30 bytes
n=>fori=2n>i i++if1>n%i breaki

Try it online!

0== can be 1> I think.

Pyth, 2 bytes
hP

Try it here!

Jelly, 3 bytes
ÆfḢ

Try it online!
ÆfṪ, ÆfX could also be seriously competing functions.
ÆfQ could be a seriously competing full program.

C (gcc), 28 bytes
f(k,p){for(p=1;k%++p;);k=p;}

Try it online!

Forth (gforth), 34 bytes
: f 1 begin 1+ 2dup mod 0= until ;

Try it online!
Explanation

Iterate integers starting from 2
Stop and return when you find one that divides n with no remainder

Code Explanation
: f               \ Define a new word
  1               \ place a 1 on the stack (to use as a counter/index)
  begin           \ start indefinite loop
    1+ 2dup       \ increment counter and duplicate counter and prime power
    mod           \ calculate power % index
  0= until        \ end the loop if modulus is 0 (no remainder)
;                 \ end word definition

R, 32 26 bytes
@Giuseppe with different logic and a shorter solution:
(x=2:(n=scan()))[!n%%x][1]

Try it online!
Original:
numbers::primeFactors(scan())[1]

Try it online!
This is obviously a much superior port of the 05AB1E solution.

APL (Dyalog Extended), 7 2 bytes
⊃⍭

Try it online!
⍭ gives a list of factors, ⊃ gets the first of them.

Vyxal 1, 1 byte
′

There was a builtin just for this.

Try it Online!

@Lyxal Is that because of Vyxal 2? If so, I can label mine Vyxal 1 and you can post a separate answer.

no, it's the exact same program. turns out you don't need the h at the end.

it just looks different

@Lyxal I don't understand. Just the first command also gives the exponents instead of just the primes, right?

The ′ gives all prime factors. The question only wants one (hence why I made it ′h). However, other answers seem to get away with printing all factors, so it's just ′ (or Ǐ)

Regex (ECMAScript), 10 bytes
(xx+?)\1*$

Try it online!
Works by finding the smallest prime factor. Takes its input in bijective unary, as a sequence of x characters in which the length represents the number. The output is returned in capture group 1.
         # No anchor needed, since every input N>=2 returns an output
(xx+?)   # \1 = the smallest number >=2 for which:
\1*$     # N-\1 is divisible by \1

Wow. The things regex can do...

Brachylog, 2 bytes
ḋh

Try it online!
Explanation
ḋ       Prime decomposition
 h      Head

J, 4 bytes
0{q:

Select { the first 0 of the prime factors q:
Try it online!

Neim, 1 byte

Try it online!

U+1D414 is one character, but in UTF-8 and UTF-16 this is represented by 4 bytes.

@RuudHelderman Correct, but this isn't in UTF-8 nor UTF-16.

@RuudHelderman You may want to see Neim codepage.

@JungHwanMin Thanks; browsing Okx's earlier Neim submissions, I noticed my slightly ignorant reaction wasn't the first. Clever feature, but far from obvious; warrants explanation (as done here). Quoting code-golf tag info: "Unless the question is specified to be scored by characters, it is scored by bytes. If it doesn't specify a character encoding to use for scoring, answers which use Unicode code points outside 0 to 255 should state the encoding used."

@RuudHelderman per meta consensus, if an answer does not specify an encoding, it defaults to the language's default encoding. If that doesn't exist, then it is UTF-8. In this case, Neim has a defined default encoding, so it is assumed to be the encoding of the answer, without the answerer having to explain as such.

Haskell, 26 bytes
f n=until((<1).mod n)(+1)2

Try it online!

Mathematica, 17 bytes
Divisors[#][[2]]&

The second smallest divisor.

Husk, 2 bytes
←p

Try it online!

ARBLE, 19 bytes
index(factors(a),1)

Try it online!

Japt -g, 1 byte
k

Try it here

Python 3, 47 45 44 bytes
Inspired by Kevin Cruijssen's answer in Java.
2 3 bytes removed thanks to Jo King.
lambda n:[i+1for i in range(n)if n%-~i<1][1]

Try it online!

You have an extra space before the if, and the condition can be <1

You can save one byte by doing range(n) and incrementing i in place

PowerShell, 31 bytes
param($a)(2..$a|?{!($a%$_)})[0]

Try it online!
Constructs a range from 2 to input $a, pulls out those elements where (?) the modulo operation % results in a zero !(...) (i.e., those that are divisors of $a), and then takes the smallest [0] one thereof. That's left on the pipeline, output is implicit.

Visual Basic .NET (.NET Framework v4.5), 123 71 bytes
-52 bytes thanks to @Jo King
Function A(n)
For i=n To 2 Step-1
A=If(n Mod i=0,i,A)
Next
End Function

Try it online!
Ungolfed:
Function A(input As Long) As Long
    For i = input To 2 Step -1
        A = If (input Mod i = 0, i, A)
    Next
End Function

Explanation:
The i loop searches backwards from the first number, and finds all numbers that divide it evenly. Because we are going backwards, the smallest is stored in the vairable A.
VB gives you a free variable that matches your function name (in my case, A). At the end of the function execution, the value in that variable is returned (barring an explicit Return statement.

You don't need the prime check at all. The smallest factor of a number (other than 1) is guaranteed to be a prime, otherwise there would be a smaller factor

@JoKing D'oh! Of course, can't believe I missed that. Thanks!

Perl 6, 22 bytes
{grep($_%%*,2..$_)[0]}

Try it online!
Anonymous code block that filters the factors of the range of 2 to the input and returns the first one. I tried using ^$ to save 2 bytes, but that didn't work in the case that the input was prime.

Haskell, 29 bytes
f y=[x|x<-[2..],mod y x<1]!!0

Try it online!

Pari/GP, 17 bytes
n->factor(n)[1,1]

Try it online!

Pari/GP, 17 bytes
n->divisors(n)[2]

Try it online!

Ruby, 100 bytes
require"prime"
i=gets.to_i
Prime.each(i){|p|(1..i).each{|n|c=p**n==i
    puts p if c
    exit if c}}

Try it online!

Stax, 3 bytes
|fh

Run and debug it
First element of prime factorization.

Julia 0.6, 25 bytes
n->[2:n;][n.%(2:n).<1][1]

Try it online!

-4 bytes

Ruby, 26 bytes
->n,i=1{(1>n%i+=1)?i:redo}

Try it online!

QBasic, 39 bytes
INPUT x
p=2
WHILE x\p<x/p
p=p+1
WEND
?p

Trial division; finds the first factor greater than 1, which is guaranteed to be the prime factor.
The only trick here is the condition x\p<x/p, which uses integer vs. floating point division to test whether "x is not divisible by p." See this tip for details.

Thunno 2, 1 byte
Ƒ

Try it online!
Unique prime factors built-in.

Desmos, 32 bytes
-17 bytes thanks to @Aiden Chow!
d=[2...n]
f(n)=d[mod(n,d)=0].min

Try it on Desmos!
Find the smallest factor (>1) of \$n\$.
Desmos, 49 bytes
p=[\sqrt[i]n\for i=[n...1]]
f(n)=p[\ceil(p)=p][1]

Explaination
Finds the smallest integer value of \$\sqrt[i]n\$ (\$i\in\mathbb Z\$)
In other words, make \$\sqrt[i]n\$ an integer with the greatest value of \$i\$
Try it on Desmos!

32 bytes

@AidenChow darn, i'm surprised i didn't think of that

It's always helpful to check other peoples' answers :P

ARBLE, 17 bytes
primefactors(n)/z

Try it online!


text:
Prime Time Travel
Don't tell anyone, but I've nicked my uncle's time travel machine! My uncle is obsessed with prime numbers, though, and that shows in the machine — he has programmed it so that it can only go to dates that sum up to a prime number.
So it can't go to 1947-08-15 because 1947+8+15 = 1970, which is not a prime number. It can go to 1947-07-25, because 1947+7+25 = 1979, which is prime. So if I want to go back to watch India's independence celebrations, it looks like I'll have to go a few weeks earlier and wait out those 20 days.
I have some other dates that I want to go to, and I'll similarly have to go to a date before (or if I'm lucky, equal to) my target date, that sums up to a prime number. I'm impatient, though, and don't want to wait too much — so I want to find the date I can use that is closest to my target date.
Can you write me a program that takes my target date and gives me the date I should input into the time machine — the closest date before or equal to the given date whose parts add up to a prime number?
(For this challenge, we're using the proleptic Gregorian calendar — which simply means we use the current Gregorian calendar even for periods when people then were using the older Julian calendar.)
Input

A date

ideally, any date in the Current Era (AD); practically, whatever subset of that your language can naturally handle
in any single human-readable format⁺ you like

Output

The date closest to the input date, which is less than or equal to the input and whose date+month+year sums up to a prime number.

in any single human-readable format⁺ you like

⁺: "human readable" as in the day, month and year all separately spelt out, in whatever order
Test cases
1947-08-15
=> 1947-07-25
1957-10-04
=> 1957-09-27
1776-07-04
=> 1776-07-04
999-12-12
=> 0999-12-10
2018-06-20
=> 2018-06-15
1999-01-02
=> 1998-12-29
1319-12-29
=> 1319-07-01

(Thanks to @Shaggy, @PeterTaylor, and @Arnauld for help with the question.)

Is it OK to have a nonsense time in the output? (e.g. Fri Jul 25 02:46:39 CEST 1947)

@wastl Yes, as long as the date info is a contiguous fixed length substring of the output (so no for that particular example).

JavaScript (Node.js), 94 bytes
Takes input as 3 integers in currying syntax (year)(month)(day). Returns a hyphen-separated string with a leading hyphen.
y=>m=>g=d=>(P=k=>n%++k?P(k):~k)(n=eval(s='-'+new Date(y,m-1,d).toJSON().split`T`[0]))?g(d-1):s

Try it online!
How?
We first convert the date to JSON format yyyy-mm-ddT00:00:00.000Z (ISO 8601), split it on the 'T', keep only the left part and add a leading hyphen, which gives -yyyy-mm-dd.
s = '-' + new Date(y, m - 1, d).toJSON().split`T`[0]

This expression s can now be eval()'uated to get the opposite n of the sum of year + month + day.
n = eval(s)

We use the helper function P() to test whether -n is prime (in which case it returns 0). If it is, we return s. Otherwise, we try again with the previous day.
(P = k => n % ++k ? P(k) : ~k)(n) ? g(d - 1) : s

I feel like I need a day off just from understanding how that prime check works and terminates. Good golfing!

Red, 87 bytes
func[d][d: d + 1 until[d: d - 1 n: d/2 + d/3 + d/4 i: 1 until[n %(i: i + 1)= 0]i = n]d]

Try it online!
More readable:
f: func [ d ] [
    d: d + 1
    until [
        d: d - 1
        n: d/day + d/month + d/year
        i: 1
        until [
            i: i + 1
            n % i = 0
        ]
        i = n
    ]
    d
]

Python 2, 130 127 bytes
Input is year, month, day.
-3 bytes thanks to Kevin Cruijssen.
from datetime import*
def f(a):
  while(lambda n:any(n%m<1for m in range(2,n)))(a.year+a.month+a.day):a-=timedelta(1)
  print a

Try it online!

You are allowed to take a date-object as input, so you can save 3 bytes.

@KevinCruijssen thank you. Do you think this is a valid input format?

I don't see why it wouldn't be, so that's another -4. Hadn't thought about that.

Ruby, 94 bytes
Try it online!
Takes a single Date input, and returns a string in the ISO 8601 format (YYYY-MM-DD).
require'date'
require'prime'
->d{d.downto(0){|i|break i.to_s if (i.day+i.month+i.year).prime?}}

It uses Ruby's prime module. If that's not allowed, or frowned upon, then for two bytes more I present this abomination:

Ruby, 97 bytes
Try it online!
It uses a check for a number being prime from this stackoverflow answer. I have no idea how this works, it looks a bit like witchcraft.
Same input as above, and same output.
require'date'
->d{d.downto(0){|i|break i.to_s if ?1*(i.day+i.month+i.year)!~ /^1?$|^(11+?)\1+$/}}

Using modules is perfectly fine as long as the import lines are included in the byte count (which you've done here). It seems like you don't need the parantheses around the initial d and the space after the if though, so you can shave off 3 bytes from your first answer removing those. TIO link

I do like the witchcrafty abomination though. It's pretty neat and simple once you look into it: ?x*n !~ /^x?$|^(xx+?)\1+$/ = to check  if n is prime, make a string of n 'x's, check that it's not 0 or 1 x's (which are not prime), and that it doesn't match any 2 or more x's repeating itself (matching ^(xxxxx)\1+$ would mean n is divisible by 5). It abuses the regex engine's backtracking to do our looping for us - it's brilliant, it's monstrous, and animal sacrifice was probably involved in its discovery.

Good spot about the parentheses and the space! Thanks.

The "witchcraft" version can be done in 92 bytes, see here. Because the sum we want to check for primality is at least 3 (since minimum date 0001-01-01 sums to 1+1+1=3), we can remove the part of the regex that is specifically to handle input being 0 or 1. Removing that and simplifying gives a 91 byte version.

An interesting approach. Save 2 bytes by using 'mon' instead of 'month'

R, 117 bytes
function(d){while(!numbers::isPrime(y(d))){d=d-1};d}
`<`=format
y=function(d)sum(as.integer(c(d<"%Y",d<"%m",d<"%d")))

Try it online!

Java 8, 144 128 bytes
d->{for(;;d=d.minusDays(1)){int n=d.getYear()+d.getMonthValue()+d.getDayOfMonth(),i=2;for(;i<n;n=n%i++<1?0:n);if(n>1)return d;}}

Try it online.
java.time.LocalDate class has been an improvement in comparison to the old java.util.Date, but why did they had to make those names longer (getMonthValue and getDayOfMonth instead of getMonth and getDay).. >.>
Explanation:
d->{                      //  Method with LocalDate as both parameter and return-type
  for(;;                  //  Loop indefinitely
      d=d.minusDays(1)){  //    Going one day back after every iteration
    int n=d.getYear()+d.getMonthValue()+d.getDayOfMonth(),
                          //   Set `n` to the sum of year+month+day
    i=2;for(;i<n;n=n%i++<1?0:n);if(n>1)
                          //   If `n` is a prime:
      return d;}}         //    Return the now modified input-LocalDate `d`

Ruby, 57 53 bytes
->d{d-=9until/^(11+)\1+$/!~?1*(d.day+d.year+d.mon);d}

Try it online!
Not my idea - stolen from the "abomination" by IMP1

Original idea:
Ruby, 59 bytes
->d{d-=9until((2...w=d.day+d.year+d.mon).all?{|x|w%x>0});d}

Try it online!

Would using 8e4 instead work?

Yes, of course it works. It also works using 9 or any other smaller number. It only takes a lot longer to run. Thanks.

F#, 134 133 bytes
let rec s(d:System.DateTime)=
 let x=d.Year+d.Month+d.Day
 if(Seq.tryFind(fun i->x%i=0){2..x-1}).IsNone then d else d.AddDays(-1.)|>s

-1 byte thanks to from sundar.
Try it online!
Total the day, month and year and see if it's prime. If it is, return that date. If not, decrement the date by 1 day and try again.

You can save a byte by writing -1.0 as -1., in the AddDays call.

You're right... that's really weird. But useful. Thanks.

PowerShell, 105 90 bytes
for($a=$args[0];'1'*((Date $a -f yyyy+MM+dd)|iex)-match'^(..+)\1+$';$a=$a.AddDays(-1)){}$a

Try it online!
Thanks to sundar for -13 bytes.
Takes input as a DateTime 2018-06-20 and saves it into $a. Then we're in a for loop. Each iteration, we're taking $a -formatted like yyyy+MM+dd (i.e., the current date we're on separated by + signs) added together with |iex (similar to eval), string-multiplying that with 1s to form a unary number, and using a prime-checking regex to determine if the current date is prime or not. If it is not prime, we .AddDays(-1) to go backwards a day and continue the loop. If it is prime, we break out of the loop and place $a onto the pipeline with implicit output.
The resulting output is culture-dependent. On TIO, which uses en-us, the output is long-date format, which looks like Saturday, July 1, 1319 12:00:00 AM.

You can save a few bytes by sending the argument as a datetime object. Also, the regex can be simplified to match composites above 2 (since minimum date is 0001-01-01 whose sum is 3). I took a crack at these changes here.

(note though that I'm a powershell newbie and that linked code is only minimally tested, haven't even tried all the test cases from here.)

@sundar I thought about that input, but it seemed a little "cheaty" to me, so I went with string input instead. Thanks for the tip on the regex -- I don't fully understand how it works, so I just smile and nod when it comes up. Hehe.

Bash, 114 108 bytes
a=`date +%s -d$1`
while [ "`date +%d+%m+%Y -d@$a|bc|factor|awk NF!=2`" ]
do a=$[a-86400]
done
date +%F -d@$a

Try it online!
My first ever bash golf. Honestly, my first real bash program ever ... primality test taken from here.
This might sometimes fail if there is a timezone change, but TIO uses UTC, so there it should work.

Is the " 9" in the first line a typo? Removing that and the quotes around it (since we can require that the input must not contain spaces), and adding an a at the end after @$, gives working code at 110 bytes.

@sundar I thought that there might be problems with daylight saving time, but I will check that tomorrow again

C (gcc), 167 164 bytes
-3 bytes thanks to ceilingcat.
r;P(n,i){for(r=0;++i<n;)r|=n%i<1;}f(y,m,d){for(;P(y+m+d,1),r;)d=--d?d:" >8><><>><><>"[!--m?y--,m=12:m]/2+(m==2&y%4<1&y%100|y%400<1);printf("%04d-%02d-%02d",y,m,d);}

Try it online!
Rundown
r;P(n,i){for(r=0;++i<n;)r|=n%i<1;}

The anti-prime-checking function. Since the earliest valid year we need to deal with is 0001-01-01, the lowest number we ever need to worry about is 3, so the special-case checks for n==2 or n < 2 are stripped out. r is set to a truthy value if n is not a prime. r is kept global, since not having to return it saves two bytes (i=n; to return vs ,r to check the global). i is set to 1 by the function caller, to save another 2 bytes.
f(y,m,d){for(;P(y+m+d,1),r;)

We take the date as three separate integers and start the main loop, which goes on until y+m+d is prime. Then we come to the meat of the function:
!--d?                           Decrement day and check if zero, which means we go back to last day of previous month.
d=" >8><><>><><>"               The string contains the number of days of each month times 2, to bring them into printable ASCII range.
                                We begin the string with a space, to avoid having to substract from index later.
[!--m?y--,m=12:m]/2+            Decrement month and check if zero. If so, go back a year and set m to 12. Use m as index in string.
(m==2&!(y%4)&y%100|!(y%400))    If the new month is February, add 1 to day if it's a leap year.
:0;                             Do nothing if day did not become zero.

It might seem iffy to use m and y both in the leap year check and as the index of the string, when the evaluation order is unspecified. Luckily, we only check for leap year if m == 2, which can't happen at the same time as we change m and y, since that only happens going from January to December, so the leap year check is never bothered by the order of evaluation.
Finally, the result is printed to STDOUT:
printf("%04d-%02d-%02d",y,m,d);}

C# - 281 239 232 Char
using System;class P{static void Main(){var d=DateTime.Parse(Console.ReadLine());do{int c=d.Year+d.Month+d.Day;if(c%2!=0){int i=3;for(;i<=c;i+=2)if(c%i==0)break;if(i>=c)break;}d=d.AddDays(-1);}while(d>DateTime.MinValue);Console.WriteLine(d);}}

ungolfed:
using System;
class P
{
    static void Main()
    {
        var d = DateTime.Parse(Console.ReadLine());
        do
        {
            int c = d.Year + d.Month + d.Day;
            // minimum datetime in c# is 0001-01-01
            // therefore do not need to check for the first two primes
            int i = 3;
            for (; i < c; i += 2) if (c % i == 0) break;
            // check to break the date decrement loop if counter passed the input value
            // ie, no factor could be found
            if (i >= c) break;

            d = d.AddDays(-1);
        } while (d > DateTime.MinValue);
        Console.WriteLine(d);
    }
}

Made the code less efficient but smaller.  Prime loop will now go up to the integer rather than the square root.  It will also process all even numbers.

You can probably remove public. Also, since it doesn't seem to be disallowed to get the date input as a calling parameter, you could have Main(string[]a) and then DateTime.Parse(a[0])

MATL, 14 bytes
`tsZp?.}YOqZOT

Try it online!
Alternately:
15 bytes
`tsZp~tbYOw-ZOw

Try it online!

Scala, 116 bytes
d=>LazyList.iterate(d)(_ minusDays 1)find{d=>val s=d.getYear+d.getMonthValue+d.getDayOfMonth
2 to s/2 forall(s%_>0)}

Uses java.time.LocalDate as input and output.
Try it in Scastie


text:
Find the Number With the Highest Sum of Neighbors
The Challenge
Given a grid of numbers (10 <= N <= 99)
Return number with the highest sum of the four numbers adjacent to it; that is the numbers above, below, right, and left of the number, but not itself.

The number itself does not count, only its four neighbors.
A number on the edge should be treated as though the missing number is a 0.
I will design the test to avoid ties.
Numbers will not repeat.
This is code-golf.

Example
Given
56 98 32 96
12 64 45 31
94 18 83 71

Return
18

A Real Test
Given
98 95 67 66 57 16 40 94 84 37
87 14 19 34 83 99 97 78 50 36
18 44 29 47 21 86 24 15 91 61
60 41 51 26 10 58 11 62 55 71
42 85 56 12 46 81 93 65 49 77
89 13 74 39 54 76 92 33 82 90
96 88 70 79 80 28 25 20 75 68
38 63 17 72 53 48 73 30 45 69
64 35 32 31 23 43 22 52 27 59

Return
13

Given
82 43 79 81 94 36 17 64 58
24 52 13 87 70 18 28 61 69
16 99 75 21 50 44 89 90 51
49 80 63 31 54 65 41 55 38
67 91 76 78 23 86 83 14 73
46 68 62 77 34 48 20 74 10
33 35 26 97 59 66 25 37 32
12 92 84 27 85 56 22 40 45
96 15 98 53 39 30 88 71 29
60 42 11 57 95 19 93 72 47

Return
15

"A number on the edge can be treated as though the missing number is a 0." - That implies we have a choice as to how to handle numbers on an edge of the grid. Can we therefore choose to wrap around to the other side of the grid?

@Shaggy No.  That might change the expected result.  Let's all do it the same way.  Text updated s/can/should/

waiting for the inevitable MATL answer

I notice most of the solutions mutate the input in some way.  Is that conventional here?  My (yet to be posted) solution includes the bytes required to mutate the input and I'm wondering why many others do not.

@Umbrella We generally don't care if the input gets modified. We're interested in short code, not clean code. So long as the output is right, we tend to be pretty permissive.

MATL, 20 15 13 12 bytes
t1Y6Z+tuX>=)

Saved 5 bytes thanks to Emigna, 2 thanks to Giuseppe, and another thanks to Luis Mendo.
Try it online!
Explanation
t1Y6Z+tuX>=)
t                  Duplicate the (implicit) input.
 1Y6               Push the array [0 1 0; 1 0 1; 0 1 0].
    Z+             Convolve with the input.
       uX>         Get the maximum unique element...
      t   =        ... and compare elementwise.
           )       Index into the input.

APL (Dyalog Unicode), 31 27 26 24 23 bytesSBCS
-2 thanks to Cows quack. -1 thanks to ngn.
Anonymous tacit prefix function. Takes a matrix as argument. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems.
{⊃⍒,(+/--/)⊢∘,⌺3 3⊢⍵}⊃,

Try it online!
, ravel (flatten) the input
{…}⊃ pick an element from that according to the result of the following function:
 ⊢⍵ yield the argument (separates 3 3 from ⍵)
 …⌺3 3 apply the following function to each 3-by-3 neighbourhood:
  ⊢∘, ignore the edge-information in favour of the ravelled (flattened) neighbourhood
  (…) apply the following tacit function to those
   -/ the alternating sum (lit. right-associative minus reduction)
   +/- subtract that from the sum (this gives the sum of every other element)
 , ravel (flatten) that (the neighbourhood sums)
 ⍒ produce the indices which would sort that
 ⊃ pick the first (i.e. the index of the highest sum)

That was fast.  Did you come prepared? ;)

@Umbrella No, I just use a programming language which is quick to program in.

How's this {⊃⍒,{+/1↓⍉4 2⍴⍵}⌺3 3⊢⍵}⊃,? Edit: or even {⊃⍒,{⊢/+⌿4 2⍴⍵}⌺3 3⊢⍵}⊃,

@Cowsquack I always forget that trick.

-1 byte: {⊃⍒,(+/--/)⊢∘,⌺3 3⊢⍵}⊃,

Jelly, 22 bytes
;€0ZṙØ+SṖ
,ZÇ€Z+$/ŒMœị

Try it online!
Not having convolution built-ins like MATL and Dyalog Forgetting your language has convolution built-ins (thank you @dylnan) hurts, but we can do sort of okay without them, partially thanks to ŒM and œị. First, a helper function to compute neighbors in just one direction, which incidentally transposes the input:
;€0Z         Append a zero to each row, then transpose.
    ṙØ+S     Rotate by +1 and −1 (Ø+ = [1,-1]) and sum these.
        Ṗ    Pop the last row.

Visually, the computation is:
1 2 3   ;€0   1 2 3 0   Z   1 4 7   ṙØ+     2 5 8   0 0 0     S   2  5  8   Ṗ   2  5  8
4 5 6  ————→  4 5 6 0  ——→  2 5 8  ————→  [ 3 6 9 , 1 4 7 ]  ——→  4 10 16  ——→  4 10 16
7 8 9         7 8 9 0       3 6 9           0 0 0   2 5 8         2  5  8       2  5  8
                            0 0 0           1 4 7   3 6 9         4 10 16

Interpretation: cell (x, y) of this result is the sum of cell (y, x)'s horizontal neighbors. (For example, here we see that f(A)[2,3] = 16 = 7 + 9 = A[3,1] + A[3,3].)
Then, the main function:
,ZÇ€            Pair the input with its transpose and apply helper to both.
    Z+$/        Fold by Z+, i.e., turn [X,Y] into transpose(X)+Y.
                Now we've summed the horizontal and vertical neighbors for each cell.
        ŒM      Find the 2D index of the maximal value.
          œị    2D-index (into the original input).

What about æc?

oh, I didn't know about it :) I'm too busy to golf more so feel free to write an answer using it.

Jelly, 18 bytes
5BæcµḊṖ)
ZÇZ+ÇŒMœị

Try it online!
The helper function finds the neighbors of each element in each row. The main function does this to the rows and the columns then finds the element that has the maximum neighborhood sum.
5BæcµḊṖ)
5B           bin(5): 1,0,1
  æc         Convolve with [[1,2,9],[other rows]] (for example): [[1,2,10,2,9],...]
    µ        New chain.
       )     Apply this to each element:
     Ḋ       Remove the first element.
      Ṗ      Remove the last element.
             Gives [[2,10,2],...]

ZÇZ+ÇŒMœị
Z            Zip the matrix
 Ç           Apply helper function
  Z          Zip again. Yields the sum of the vertical neighbors of each element.
   +         Add:
    Ç        The sum of each element's horizontal neighbors.
     ŒM      Find the multidimensional index of the maximal element.
       œị    Index back into the original matrix.

Wolfram Language (Mathematica), 58 bytes
Im@Last[Union@@ListConvolve[{a={0,1,0},{1,I,1},a},#,2,0]]&

Convolve the matrix with \$ \left( \begin{smallmatrix} 0 & 1 & 0 \\ 1 & i & 1 \\ 0 & 1 & 0 \end{smallmatrix} \right) \$, take the element with the largest real part, and take its imaginary part.
Try it online!

Python 2, 127 bytes
def f(a):n=len(a[0]);b=sum(a,[])+[0]*n;print b[max(range(len(b)-n),key=lambda i:b[i-1]*(i%n>0)+b[i+1]*(i%n<n-1)+b[i-n]+b[i+n])]

Try it online!

Stencil, 1 + 10 = 11 bytes
Command-line option: 1 compute 1 generation
y⊃⍨⊃⍒,
+/N

Try it online!
y from the flattened original input
⊃⍨ pick
⊃ the first
⍒ in descending order
, of the flattened
+/ sums of
N the von neumanN neighbourhoods without selves

Of course there's a language with a one character built-in for the neighbors.

To be fair, its sole purpose is to solve these kinds of problems.

Why is it non-competing?

@KevinCruijssen I added y to the language when I saw that it needed easier access to the original input. Before that, you had to write (,⍎'input') instead of y.

@Adám Ah ok, yeah, then it indeed is non-competing. Hadn't noticed the challenge was posted yesterday. If it was an old challenge, non-competing because the language (or language version) is newer doesn't make it non-competing anymore in the current meta.

JavaScript (ES6), 94 bytes
a=>a.map(p=m=(r,y)=>p=r.map((v,x)=>(s=~r[x-1]+~p[x]+~(a[y+1]||0)[x]+~r[x+1])>m?v:(m=s,o=v)))|o

Try it online!
How?
Instead of looking for the maximum of the sum of the 4 neighbors, we look for the minimum m of the sum s of their one-complements. This allows us to process undefined values just like zeros, because:
~undefined === -1
~0 === -1

The inner map() is written in such a way that it does not alter the content of the row r. Therefore, we can save its result in p in order to test top neighbors in the next iteration.
We use:

~r[x-1] for the left cell
~r[x+1] for the right cell
~p[x] for the top cell
~(a[y+1]||0)[x] for the bottom cell

K (ngn/k), 43 40 bytes
{(,/x)@*>,/(+g@+x)+(g:{(+':x)-|-':|x})x}

Try it online!

Javascript ES6, 170 bytes
c=g=>{s=0;n=0;f=m=>m||[];for(i=0;i<g.length;i++)for(j=0;j<g[i].length;j++){s=~~f(g[i-1])[j]+~~f(g[i+1])[j]+~~f(g[i])[j-1]+~~f(g[i])[j+1];b=s>n?g[i][j]+!(n=s):b;}return b}

Welcome to PPCG! Your code seems to assume that the input is stored in a variable named g, which is not allowed. You should write either a full program that reads the input or a function (which is usually and by far the preferred way in JS).

@Arnauld Thank you ! I fixed the code

You may consider adding a TIO link to make it easier to test. (I removed the 2nd test case to have the link fit in a comment.)

Java 8, 187 bytes
m->{int r=0,l=m.length,i=l,L,j,S=0,s;for(;i-->0;)for(L=j=m[i].length;j-->0;)if((s=(i<1?0:m[i-1][j])+(i<l-1?m[i+1][j]:0)+(j<1?0:m[i][j-1])+(j<L-1?m[i][j+1]:0))>S){S=s;r=m[i][j];}return r;}

Try it online.
Explanation:
m->{                           // Method with integer-matrix parameter and integer return
  int r=0,                     //  Result-integer, starting at 0
      l=m.length,              //  Amount of rows
      i=l,                     //  Rows index integer
      L,                       //  Amount of columns
      j,                       //  Column index integer
      S=0,                     //  Largest sum of four cells
      s;                       //  Current sum of four cells
  for(;i-->0;)                 //  Loop over the rows
    for(L=j=m[i].length;j-->0;)//   Inner loop over the columns
      if((s=                   //    Set the current sum to: the sum of:
           (i<1?0:m[i-1][j])   //     Value of the cell to the left, or 0 if out of bounds
          +(i<l-1?m[i+1][j]:0) //     Value of the cell to the right, or 0 if out of bounds
          +(j<1?0:m[i][j-1])   //     Value of the cell down, or 0 if out of bounds
          +(j<L-1?m[i][j+1]:0))//     Value of the cell up, or 0 if out of bounds
         >S){                  //    If this current sum is larger than the largest sum:
        S=s;                   //     Replace the largest sum with this current sum
        r=m[i][j];}            //     And set the result to the current cell
  return r;}                   //  Return the result


text:
Zigzag this string by collapsing duplicates
Given a string, your task is to collapse it into a zigzag-like structure as described below.
Folding into a Zigzag
We'll take the string "Mississippi" as an example:

First, output the longest prefix consisting of unique characters only:
Mis

When you reach the first duplicate character C, ignore it, and output the longest prefix consisting of unique characters of the remaining string (issippi) vertically, below the first occurrence of C:
Mis
  i
  s

Repeat the process, alternating between horizontal and vertical continuation. But now be careful (at step 1) to continue outputting horizontally from latest occurrence of the duplicate character, which is not necessarily the last one, as in this case:
Mis
  i
  sip
-----
Mis
  i
  sip
    i

Rules

The string will only contain printable ASCII characters, but won't contain any kind of whitespace.
You can compete in any programming language and can take input and provide output through any standard method and in any reasonable format1, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.
1 Input: String / List of characters / whatever else your language uses to represent strings. Output: Multiline string, list of strings representing lines or list of lists of characters/length-1 strings, but please include a pretty-print version of your code in your answer, if possible.
Regarding additional spaces, the output may contain:

Leading / trailing newlines
Trailing spaces on each line / at the end
A consistent number of leading spaces on each line

You must begin to output horizontally, you may not start vertically.

Test cases
Inputs:

"Perfect"
"Mississippi"
"Oddities"
"Trivialities"
"Cthulhu"
"PPCG"
"pOpOpOpOpOpOp"
"ABCCCE"
"ABCCCECCEEEEC"
"abcdcebffg"
"abca"
"AAAAAAAA"

Corresponding outputs:

Perf
 c
 t

Mis
  i
  sip
    i

Od
 ies
 t

Triv
  a
  l
  ies
  t

Cthul
  u

P
C
G

pO
OpO
pOp
 p

ABC
  C
  E

ABC
  CCE
  E EC

abcd
  e
  b
  fg

abc

A
AA
 A

@JungHwanMin Because you should't jump back to the first b, as you should only consider duplicates in the remaining string, that is, after "branching". Once you reach the second c, you output the longest prefix of unique chars of the remaining string, which is ebffg (thus outputting ebf vertically and continuing horizontally after that), so you don't have to worry about the characters from the part of the string that was already outputted before switching orientation. If it still feels unclear to you, I'll make another step-by-step example with this test case.

How should we handle lower/upper case? For example ABCcde

You should treat them as different characters. E.g "A" ≠ "a". The output for ABCcde would just be ABCcde

Test case suggestion: AAAAAAAA

@JungHwanMin AAAAAAAAdded that one too.

Wolfram Language (Mathematica), 143 bytes
{#}//.{q___,a_,r___,a_,Longest@s___}:>{q}~f@{a,r}~{{s}}//.{q_~f@a_~s_}/;s~FreeQ~f:>(PadLeft@{q~Join~#,##2}&)@@PadRight@Join[{a},s]/. 0->" "&

Try it online!
Contains 0xF8FF, which corresponds to the \[Transpose] operator.
Phew, it was tough making the result into a string. Getting each branch isn't so tough: #//.{q___,a_,r___,a_,Longest@s___}:>{q,a,{r},{s}}&

Python 2, 131 bytes
X=Y=y=0
s=input()
o=()
l={}
for i in s:o+=[' ']*len(s),;exec('l[i]=X,Y','y^=1;X,Y=l[i];l={}')[i in l];o[Y][X]=i;X+=y<1;Y+=y
print o

Try it online!
-1 thanks to Lynn.
Prints as a tuple of lists of length-1 strings. Pretty-printed output.

Python 2, 184 176 175 168 bytes
-5 bytes thanks to Mr. Xcoder

def f(x):i,k=[p for p in enumerate(map(x.find,x+"z"))if cmp(*p)][0];return[x[:i]+' '*len(x)]+[' '*k+''.join(d)+i*' 'for d in zip(*f(x[i+1:]))]if x[len(set(x)):]else[x,]

Try it online!

I don't think the latest save is valid; what if the input contains \? Also, you can output as a list of lists of length-1 strings, as I do in my solution, per the OP.

@EriktheOutgolfer same byte count :c

CJam, 81 bytes
{_,_S*a*a\+{__L#){V!:V;L#)LM:L;=~:U;:T}{[TU]a+L+:L}?;U@_U=T4$tt\;TV!+:T;UV+:U;}*}

Try it online!