Generate all halting Smallfuck programs of length n Your task is to write a program that, given a number n, returns a list of all valid, halting Smallfuck programs of length n, in any order.

Actually, we're using a variation of Smallfuck called F2, which is just Smallfuck with a right-unbounded tape. For the purposes of this challenge, a program that moves left from the start of the tape is considered invalid, as is one with unbalanced brackets.

Scoring

Since solving this for every n is impossible (as it would require you to solve the halting problem), your submission's score will be the lowest n for which it returns an incorrect answer.

Each submission must be, at most, 1000 bytes (though you are encouraged to provide an ungolfed version as well). In the event of a tie, the earlier answer wins.

Test Cases

n = 1:

+ &gt;


n = 2:

++ +&gt; &gt;+ &gt;&lt; &gt;&gt; []


n = 3:

+++ ++&gt; +&gt;+ +&gt;&lt; +&gt;&gt; &gt;++ &gt;+&lt; &gt;+&gt; &gt;&lt;+ &gt;&lt;&gt; &gt;&gt;+ &gt;&gt;&lt; &gt;&gt;&gt; &gt;[] [+] [&lt;] [&gt;] []+ []&gt;


n = 4:

++++ +++&gt; ++&gt;+ ++&gt;&lt; ++&gt;&gt; +&gt;++ +&gt;+&lt; +&gt;+&gt; +&gt;&lt;+ +&gt;&lt;&gt; +&gt;&gt;+ +&gt;&gt;&lt; +&gt;&gt;&gt; &gt;+++ &gt;++&lt; &gt;++&gt; &gt;+&lt;+ &gt;+&lt;&gt; &gt;+&gt;+ &gt;+&gt;&lt; &gt;+&gt;&gt; &gt;&lt;++ &gt;&lt;+&gt; &gt;&lt;&gt;+ &gt;&lt;&gt;&lt; &gt;&lt;&gt;&gt; &gt;&gt;++ &gt;&gt;+&lt; &gt;&gt;+&gt; &gt;&gt;&lt;+ &gt;&gt;&lt;&lt; &gt;&gt;&lt;&gt; &gt;&gt;&gt;+ &gt;&gt;&gt;&lt; &gt;&gt;&gt;&gt; [][] ++[] +&gt;[] &gt;&lt;[] &gt;&gt;[] [++] [+&lt;] [+&gt;] [&lt;+] [&lt;&lt;] [&lt;&gt;] [&gt;+] [&gt;&lt;] [&gt;&gt;] []++ []+&gt; []&gt;+ []&gt;&lt; []&gt;&gt; +[+] +[&gt;] &gt;[+] &gt;[&lt;] &gt;[&gt;] &gt;[]+ &gt;[]&lt; &gt;[]&gt; [+]+ [+]&gt; [&lt;]+ [&lt;]&gt; [&gt;]+ [&gt;]&gt; [[]]


Please inform me if there are any more that I have forgotten to add.
Java (OpenJDK 8), Score: ???

This clocks in at 980 bytes, since I had so much to work with I decided to make it a little more readable.  Basically I'm generating all the possible programs for length n and iterating them n^x times for some x.  x is currently 3 but it can be modified arbitrarily to any size, limited only by the limitation of the JVM's precission.  This will work for arbitrarily large input values if x is increased, but I have it set to 3 for tio.



import java.util.*;
public class Main{
    public static void main(String[] args){
        int i = new Scanner(System.in).nextInt();
        int x = 3;
        l:for(int j=0;j&lt;Math.pow(5, i);j++){
            try {
                String s="";
                for(int k=j;s.length()&lt;i;k/=5)
                    s="+&lt;&gt;][".charAt(k%5)+s;
                Stack&lt;Integer&gt;y=new Stack&lt;Integer&gt;();
                Map&lt;Integer,Integer&gt;f=new HashMap&lt;&gt;(),b=new HashMap&lt;&gt;();
                for(int m=0; m&lt;s.length();m++){
                    char c=s.charAt(m);
                    if(c=='[')y.push(m);
                    if(c==']'){int n=y.pop();f.put(n, m);b.put(m, n);}
                }
                if(y.size()&gt;0)
                    continue;
                boolean[] t= new boolean[s.length()];
                int l=0,n=0;
                for(long m=0;l&lt;s.length()&amp;m&lt;Math.pow(i,x);l++,m++){
                    switch(s.charAt(l)){
                    case'+':t[n]=!t[n];break;
                    case'&gt;':n++;break;
                    case'&lt;':n--; if(n &lt; 0)continue l;break;
                    case'[':if(!t[n])l=f.get(l);break;
                    case']':l=b.get(l)-1;break;
                    }
                }
                if(l&gt;=s.length()){
                    System.out.println(s);
                }
            } catch(Exception e){continue;}
        }
    }
}


Try it online!