You are given 100 arrays/sets of 5-8 numbers between 1-20. If you combine all the arrays you will always get at least one of each number (1-20), so don't worry about an "unsolvable" case. The goal is to find the combination of arrays that minimizes duplicate numbers while still getting one of eac...
@flawr If you're using is, everything in the right-hand side has to be bound to a value first, I think. That's why it works when you give it K and ask for F, but not the other way around.
In theory, clpfd mentioned by Unrelated String should help, but I don't understand it well enough to get it to work. I'm more familiar with Brachylog, which I think does some extra magic on top of clpfd.
Hmm. Also, it looks like it's backtracking over possibilities it shouldn't.
This is pretty clunky, but it seems to work. Dunno what the error message is about. :P
Actually, since the challenge in question guarantees that you'll be given an actual Fibonacci number, the J < F+2 check isn't necessary (removing it causes an infinite loop when F is not a Fibonacci number).
@flawr The problem there was that you'd said fib(0,0), but you hadn't said that fib(F,0) should fail for any nonzero F. So for example if the recursion tries fib(3,0), it should fail because 3 is not the 0th Fibonacci number, but instead it matches the fib(F,K) case and keeps recursing infinitely into negative values of K. (Assuming that the is problem is resolved first.)
@flawr Looks like a bottom-up approach to the recursion ends up slightly shorter than your original double-recursion approach (and much faster for big numbers). Here's what I came up with ungolfed.
(Still based on the idea that we need a predicate to generate the nth Fibonacci number and then another predicate to try all possible values of n until we find the right one, though. Therefore, still clunky.)
@flawr ! means "after this, don't backtrack on this predicate." In this case, it means "If the call to fib matches the fib(F,0,A,_) definition, don't ever try the fib(F,N,A,B) definition." That's necessary to prevent infinite recursion.
Another way of accomplishing the same thing in this specific case would be to test whether N>0 in the fib(F,N,A,B) definition: TIO
... Which, now that I think of it, saves bytes in the golfed version.
i lied im going to try and describe the challenge idea here so maybe someone will say "thats obviously stupid because <x>" or "that is known as <x> so you should google that for better terminology" before i write up a really badly worded sandbox
so you know how like, sometimes charts will be like xabc a b c and theyll have a specific order? like the pokemon type interactions where its like "here is how TOP interacts with LEFT"
rather than the usual, like, one has a great effect and the other has no effect
and i was wondering if you could make a meta chart, where the axes are "interaction 1 way" and "interaction the other way"
so if Rock covers Paper, and Paper is covered by Rock, you could input (covers, is covered by) and the output would be (Rock, Paper)
but maybe if you input like, (covers, covers), thered be no output
since theres no pair where X covers Y and Y covers X
so youd be given the list/table of interactions e.g [x verb y, x verb z, y verb x...] as input? and maybe be tasked with making the meta-table?
im having a rough time describing it apologies if im just rambling lol i just didnt want to have to sound this stupid in the sandbox
x A B C
A 1 1 2
B 2 1 1
C 2 1 2
=>
x | 1 | 2
--+-------------------+------------
1 | (A,A),(B,B),(B,C) | (A,B)
--+-------------------+------------
2 | (A,B) | (A,C),(C,C)
something like this but less ascii artish
and possibly less redundant across the diagonal in the output
CMQ: Opinions on what the 20 most useful pieces of punctuation (excluding periods and spaces) are, for my attempt at making a chat program on top of Radvylf's Chat on Chat program (currently I have ,!?'"();:/*-+=&%$@<>)
my great idea for a chat client was this: no names, no editing, no separation of different users, you get a line that no one else can write on and you write a message on it, once you post it youre kicked to the next available line
yeah i'm pretty sure 4chan doesn't permit arbitrary modification of everyone else's posts because the way people are on there that feature would get used a *lot*