oeis

First appearance in Stern's Diatomic Sequence

房东的猫 提交于 2019-12-20 14:16:50
问题 You get an integer n and you need to find the index of its first appearance in Stern's Diatomic Sequence. The sequence is defined like this: a[0] = 0 a[1] = 1 a[2*i] = a[i] a[2*i+1] = a[i] + a[i+1] See MathWorld. Because n can be up to 400000, it's not a good idea to brute-force it, especially since the time limit is 4000 ms. The sequence is pretty odd: first occurrence of 8 is 21, but first occurrence of 6 is 33. Any ideas how to solve this? Maybe this might help: OEIS 回答1: We can easily

Finding certain arrangements of all 2-combinatons for a given list

為{幸葍}努か 提交于 2019-12-10 18:12:43
问题 Given a list L of an even number (2k) of elements, I'm looking for an algorithm to produce a list of 2k-1 sublists with the following properties: each sublist includes exactly k 2-combinations (pairs where the order does not matter) of elements from L, each sublist includes every elements from L exactly once, and the union of all elements from all sublists is exactly the set of all possible 2-combinations of the elements from L. For example, if the input list is L = [a, b, c, d], we have k =

Algorithm improvement for enumerating binary trees

我与影子孤独终老i 提交于 2019-11-27 07:53:30
问题 Currently I can enumerate rooted planar unlabeled binary trees using the following brute-force Prolog code. e --> u | b | t. u --> ['[op(u),['], e, [']]']. b --> ['[op(b),['], e, [','], e, [']]']. t --> ['number(n)']. Note: See output listings below. and output them in increasing size using es(S) :- length(Ls, _), phrase(e, Ls), % or e(Ls,[]), atomic_list_concat(Ls,S). However this is inefficient brute-force algorithm. Is there a more efficient algorithm for enumerating rooted planar