Use threes to count the threes!

Write a program or function that takes two numbers - x>3 and n>0 - as input, and finds all possible bases b where the digit 3 appears at least n times in (x in base b).

Input and output may be through command line or function arguments, stdin/stdout, graphical input/output, error messages, function returns, etc.

The code must consist entirely of three-symbol "words", where each symbol is a letter or number (in printable ASCII) and the words are each separated by one non-alphanumeric printable ASCII character or newline (see example). Furthermore, adding a space into any of the words must ruin the program.

Shortest code wins.

Example

The following code meets the first part of the specs (but doesn't actually work):

abc 123 fwe[3gY]4fs-es3=13N
338 w3W|W2w

Test Cases

5 1 ->

8 1 -> 5

23 1 -> 4 5 6 7 10 20

15 2 -> 4

111 2 -> 4 6 9 36

819 3 -> 4 16

A test program written in Java 8 can be found at http://pastebin.com/E8GpHbfB.

• Just to prove a solution exists... esolangs.org/wiki/Lenguage (didn't expect Pietu's creation to be relevant so soon) – Sp3000 Dec 4 '14 at 18:33
• I'm not a fan of the restriction. It seems gimmicky and eliminates some languages. – xnor Dec 5 '14 at 9:00
• Should we consider adding a space in the middle only or at the edge too? – proud haskeller Dec 5 '14 at 16:08
• @proudhaskeller Only in the middle – Ypnypn Dec 5 '14 at 17:24
• This is impossible in J: I'd require a minimum of one =. to make it otherwise work under this restriction. Unrestricted, there is the 30 character n((=s+/@(3=#.inv)"0])#s=.]2+i.)x. – algorithmshark Dec 6 '14 at 5:34

BBC Basic, 207 bytes

BBC Basic allows you to abbreviate keywords by ending them with a period (e.g., PRINTPRI., REPEATREP.). I should really be using a named procedure here instead of a function declaration, but abbreviating DEF PROC_whatever to DEF PRO. just isn't going to work.

The rules make it impossible to use an IF statement, so instead I'm calculating the target line of a GOTO statement based on the result of a comparison. (In BBC Basic, true has a value of –1, so 101-ZIP is equal to 102 if ZIP is true, and 101 otherwise.)

The last line (103=000) ends the function definition and returns a value of zero.

Tested on BeebEm3. Lines 10–60 are excluded from the byte count.

10 READ X,N : IF X=0 THEN END
20 PRINT "x=";X;", n=";N
30 A = FNX(X,N)
40 GOTO 10
50 DATA 5,1,8,1,23,1,15,2,111,2,819,3,0,0
60 REM -------------------
100 DEF FNX(FOO,BAR)BAZ=004:REP.BAT=000:QUX=FOO:REP.XXD=QUX MOD BAZ:ZAP=XXD=003:BAT=BAT-ZAP:QUX=QUX-XXD:QUX=QUX/BAZ:UNT.QUX=000:ZIP=BAT<BAR:ZIP=101-ZIP:GOT.ZIP
101 PRI.BAZ
102 BAZ=BAZ+001:UNT.BAZ=FOO
103=000

CJam, 108 bytes

097{sLo,Lso=rii*rii:MLo;Lso_Lso,002>Lso{001$Lso\Lob{003=Lso}Lso,Lso,MLo(Lso>Lso}Lso,Lso\Lso;LoS*Lso}000$001*

It will not stop people using CJam...

003&bbb=001
nnn&bbb|bbb>nnn=000|000<111=mod nnn bbb&bbb+div nnn bbb&bbb
nnn%xxx=ggo nnn 004 xxx
ggo nnn bbb xxx|bbb>nnn=get[nnn]nnn|nnn&bbb>xxx-001=bbb:ggo nnn(bbb+001)xxx|000<111=ggo nnn(bbb+001)xxx
get(xxx:sss)bbb=sss

call like 8 % 1.

I mostly just used three-letter / operator names, but it was tricky to get an empty list ([]).

C - 252 characters

Will admit C is not the best language for this, and had to cheat a little bit...

To compile, save as fit.c then gcc -D___=/**/ -o fit fit.c

The function fit can be all concatenated on one line, but I thought it looked nicer and fit in with the threeness of the challenge by formatting in lines of 9 (=3×3) token/punctuation pairs. The hardest part was figuring out a way to check for == 3 without using ==!

// The function I'm counting...

fit(int not,int fin,int*rot)___{int
nor,fir,nit,ton,tin,ion;for(nor=004;
nor<not;nor=nor+001)___{for(nit=not,
fir=000;nit>000;nit=nit/nor)tin=nit%
nor,ion=tin<003|tin>003,ion=ion?000:
001,fir=fir+ion;ton=fir<fin,ton=ton?
000:001;rot[nor]___=ton;___}___ ___}

// This is the code to call the function...

#include <stdio.h>

main()
{
int a;
int X = {5, 8, 23, 15, 111, 819};
int N = {1, 1, 1, 2, 2, 3};

int i, j;

for (i = 0; i < 6; i++)
{
fit(X[i], N[i], a);

printf("%d %d ->", X[i], N[i]);

for (j = 4; j < X[i]; j++)
if (a[j]) printf(" %d", j);

printf("\n");
}

return 0;
}

Output is per specs:

5 1 ->
8 1 -> 5
23 1 -> 4 5 6 7 10 20
15 2 -> 4
111 2 -> 4 6 9 36
819 3 -> 4 16
• Fixed it, with only one minor cheat... – user15259 Dec 5 '14 at 18:35
• seems like if you can make your code only one statement using , you could get rid of the brackets – proud haskeller Dec 6 '14 at 7:35