Code Golf
counting add tag
DJMcMayhem

Given two lists, A and B, return the first element of A that appears the fewest times in B.

For example,

The elements ‘2’ and ‘6’ both appear 0 times in B. Because ‘2’ occurs first, your program/function should return 2. (note that ‘9’ appears in B but not in A.)

B may be empty, but A will always have at least 1 element.

More examples:

Top Answer Python 2
xnor

29 bytes

Try it online!

Conveniently, Python chooses the earliest element in case of a tie.

Answer #2 SQL (Postgres)
Jack Douglas

148 bytes

<>https://dbfiddle.uk/?rdbms=postgres_12&fiddle=6c90524b802f73aacb2f6d372a310e18&hide=15

Explanations etc.

The order of elements in B is immaterial so it is represented as a regular table but A is an array as the order matters in that input.

Answer #3 APL (Dyalog Extended)
Adám

6 bytes

Anonymous tacit infix function taking A as left argument and B as right argument.

Try it online!

 the first of

 the Count-A-In-B

 ascending ordered

 then

 used to reorder

A

Answer #4 Kotlin
ajc2

29 bytes

-6 by changing sortedBy to minBy.

minBy always appears to take the earlier item in the event of a tie.

Try it online!

Answer #5 05AB1E
liek

5 bytes

Input should be taken in the order B, A instead.

Try it online!

Explanation

5 years
Jack Douglas — Sunday, 8th Mar 2020 13:26

obviously we don’t want to be adding burdens but it sounds like he may prefer not to be doing it on his own

Jack Douglas — Sunday, 8th Mar 2020 13:25

I’m not sure how heavy his hosting needs are compared to db<>fiddle, but that’s something we could consider offering

Jack Douglas — Sunday, 8th Mar 2020 13:24

i wonder if he would appreciate the offer of teaming up

Jack Douglas — Sunday, 8th Mar 2020 13:24
Jack Douglas replying to Adám — Sunday, 8th Mar 2020 13:22

that’s helpful to know, thanks

2 hours
Adám replying to Jack Douglas — Sunday, 8th Mar 2020 11:46

We pay pretty much all of his expenses.

Adám replying to Jack Douglas — Sunday, 8th Mar 2020 11:46
2 hours
Jack Douglas — Sunday, 8th Mar 2020 09:37

From the TIO home page: “TIO is getting more and more traffic, so additional arenas will be required. Also, server-side permalinks will eventually require a separate storage. With your help, I hope to ensure a smooth operation of all TIO services.”, so I imagine it’d be safer to run our own instances

Jack Douglas replying to Adám — Sunday, 8th Mar 2020 09:36

I’ve tried to get in touch with Dennis on the TIO forum, but no reply so far and it seems quiet in there. I think putting the effort in to get TIO working here will be well worth it as it’ll help other communities too, so we will definitely give it a go. Can you point me at a good place to start of the unofficial api?

3 days
Adám replying to Jack Douglas — Thursday, 5th Mar 2020 19:41

It has an (unofficial) API, which several people have written code for in various languages (Dyalog uses two separate interfaces, one in APL and one in JS).

3 hours
Jack Douglas — Thursday, 5th Mar 2020 16:19

I haven’t looked at the code at all

Jack Douglas replying to Adám — Thursday, 5th Mar 2020 16:18

does TIO have an api we could use for that or are you suggesting some sort of scraping?

a day
Adám — Wednesday, 4th Mar 2020 17:59

We’re also working on a replacement for the existing https:/tryapl.org which offloads computations to TIO as backend. You can see the WIP prototype here.

Adám replying to Jack Douglas — Wednesday, 4th Mar 2020 17:58

Yes, but I actually meant using the existing TIO. Dyalog host a competition where phase I includes instant checking of the submissions, but the actual execution is offloaded to TIO. My idea was simply that you could recognise <>https://tio.run/…, decode and display the fields, and insert a [run] button which would update the Output and Debug fields.

17 minutes
Jack Douglas — Wednesday, 4th Mar 2020 17:41

to you happen to know the creator of TIO?

Jack Douglas — Wednesday, 4th Mar 2020 17:41

I imagine it would be possible to separate the TIO bits that are inherently vulnerable onto one or more stateless VMs like the db<>fiddle backends

Jack Douglas replying to Adám — Wednesday, 4th Mar 2020 17:40

yes I think so — I looked into it briefly before. It’s (obviously?) asking to get hacked running a server like that but the same is true for the db<>fiddle backends, so we already run them on dedicated hardware quarantined from all other VMs and could simply add any TIO server onto that platform.

2 hours
DJMcMayhem replying to Jack Douglas — Wednesday, 4th Mar 2020 15:14

Correct

an hour
Adám — Wednesday, 4th Mar 2020 14:10

@Jack The dbfiddle is neat. Any chance of getting TIO support?

30 minutes
Adám replying to Jack Douglas — Wednesday, 4th Mar 2020 13:40

I think it is clear that B’s order doesn’t matter.

2 hours
Jack Douglas — Wednesday, 4th Mar 2020 12:00

@DJMcMayhem Am I right that the order of elements in input B doesn’t matter?

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.