| Bytes | Lang | Time | Link |
|---|---|---|---|
| 232 | Perl 5 | 241113T234345Z | Kjetil S |
| 498 | Python3 | 241111T160054Z | Ajax1234 |
| 036 | 05AB1E | 241111T151913Z | Kevin Cr |
| 150 | JavaScript V8 | 241109T143238Z | Arnauld |
| 085 | Charcoal | 241109T112953Z | Neil |
Perl 5, 232 bytes
@S=0..($m=20*($N=pop));sub f{@S[@_]=();!$s{"@$_"}++&&(grep$_&&$m>$_,@$_)&&f(@$_)for[0,@_[2..$#_]],[@_[0..@_-3],0],[0,@_[2..@_-3],0],[0,(map$_[$_+1]?$_[$_]+$_[$_+1]+$_[$_+2]:0,0..@_-3),0]}f(0,(1)x(8+$N/20),0);$_&&$N&&$N--&&say for@S;
Python3, 498 bytes
lambda:sorted({*range(1,max(k:={j for k in range(1,20)for j in F(k,700)})+1)}-k)
def F(b,C):
q,S=[([1]*b,[])],[]
for b,t in q:
if any(k>C for k in b):continue
if len(b)==1:yield b[0];continue
Q=[(0,[0]*len(b),b)]*(b!=[])
for I,r,B in Q:
if I==len(r):q+=[T:=([k for k in r if k],t+[b])]*(T not in S);S+=[T];continue
if I==0 or I==len(r)-1:Q+=[(I+1,r,B)]
for m in[[I-1,I,I+1],[I,I+1],[I-1,I]]:
if all(len(r)>i>=0 for i in m):R=[*r];R[I]=sum(B[u]for u in m);Q+=[(I+1,R,B)];break
05AB1E, 36 bytes
∞ʒÐUÅ1"DXª1èX‹iŒε0.øü3OD®.V)"©.V˜Xå≠
Outputs the infinite sequence. Unfortunately, it's extremely slow, so barely even outputs \$a(1)=11\$ within 60 seconds on TIO..
Explanation:
∞ # Push the infinite positive list: [1,2,3,...]
ʒ # Filter it by:
DU # Store a copy of the current value in variable `X`
Å1 # Push a list of that many 1s
"..." # Push the recursive string explained below
© # Store this string in variable `®`
.V # Pop and evaluate it as 05AB1E code
˜ # Flatten it
Xå # Check whether `X` is in this flattened list
≠ # Invert the check, since we only want unstackable numbers
# (after which the filtered infinite list is lazily output
# implicitly)
D # Create a copy of the current list
Xª # Append `X` in case the list is of length 1
1è # Pop and get the second item (0-based 1st)
X‹i # If it's still smaller than `X`, continue:
Œ # Get all substrings of this list
ε # Map over each substring:
0.ø # Surround it with a leading and trailing 0
ü3 # Pop and get all overlapping triplets
O # Sum each overlapping triplet
D # Duplicate this list of sums
®.V # Do a recursive call on the copy
) # Wrap everything currently on the stack into a list
JavaScript (V8), 150 bytes
Prints the sequence forever (slowly).
for(n=9;a=[];o<n&&print(n))for(++n;a.push(1)<n;g(a))g=(a,p)=>a[i=1]<n&&g([p,...a]=a.map(v=>(v+=~-p-~a[p=v,i++])-n?v:o=n))&a.pop(g(a))&g(a)&g([p,...a])
Commented
for( // outer loop:
n = 9; // start with n = 9 (*)
a = []; // start each iteration with a = []
o < n && print(n) // if o < n, n is unstackable -> print it
) //
for( // inner loop:
++n; // increment n
a.push(1) < n; // push 1 in a[], stop if a[] has n elements
g(a) // invoke g with a[]
) //
g = ( // g is a recursive function taking:
a, // a[] = current row
p // p = variable required in the scope of g,
) => // initially undefined
a[i = 1] < n && // stop if a[1] >= n or a[1] is undefined
g( // otherwise, do a 1st recursive call:
[p, ...a] = // save the result of map() in p and a[]
a.map(v => // for each value v in a[]:
( v += // compute the sum of the boxes
~-p - ~a[ // below the current box: v + p + a[i]
p = v, // update p to v
i++ // increment i
] //
) - n ? // if the result is not n:
v // just yield v
: // else:
o = n // n is stackable -> update o to n
) // end of map()
) // end of recursive call()
& a.pop(g(a)) // 2nd call without the 1st term
& g(a) // 3rd call without the 1st and last terms
& g([p, ...a]) // 4th call without the last term
(*) We can safely ignore \$n=1\$ to \$n=9\$ which are all stackable. Besides, our code would not work for \$n\in[1\dots3]\$. But we do need to process a stackable number (\$n=10\$) before processing the first unstackable one (\$n=11\$) to make sure that the variable \$o\$ is defined before it's tested.
Charcoal, 85 bytes
NθW‹Lυθ«→≔…¹X³ⅈυ≔E⊕⊗ⅈE⊕κ¹ηFη«≔⁻υκυ≔EκΣ✂κ∧μ⊖μ⁺²μ¹κFE²✂κλFE²✂⮌λμ¿∧μ∧‹⌊μX³ⅈ¬№ημ⊞ημ»»I…υθ
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input n.
W‹Lυθ«
Repeat until at least n unstackable numbers have been found.
→
Start considering wider and taller stacks.
≔…¹X³ⅈυ
Consider unstackable numbers up to a value of 3ˣ.
≔E⊕⊗ⅈE⊕κ¹η
Consider stacks with bases of widths 1 to 2x+1.
Fη«
Loop over each stack.
≔⁻υκυ
Remove any stackable numbers.
≔EκΣ✂κ∧μ⊖μ⁺²μ¹κ
Calculate the next layer.
FE²✂κλFE²✂⮌λμ
Consider the layer with the first and/or last element(s) removed.
¿∧μ∧‹⌊μX³ⅈ¬№ημ⊞ημ
If this is a new stack and not too tall then add this stack for further consideration.
»»I…υθ
Output the first n unstackable numbers.