Use threes to count the threes!

1

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.

Ypnypn

Posted 2014-12-04T17:53:13.580

Reputation: 10 485

This is impossible in GP: The parser ignores spaces outside strings, and so adding a space into a word won't alter its meaning. – Charles – 2015-02-05T01:36:02.927

6

Just to prove a solution exists... http://esolangs.org/wiki/Lenguage (didn't expect Pietu's creation to be relevant so soon)

– Sp3000 – 2014-12-04T18:33:59.440

7I'm not a fan of the restriction. It seems gimmicky and eliminates some languages. – xnor – 2014-12-05T09:00:54.613

Should we consider adding a space in the middle only or at the edge too? – proud haskeller – 2014-12-05T16:08:41.247

@proudhaskeller Only in the middle – Ypnypn – 2014-12-05T17:24:58.190

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 – 2014-12-06T05:34:25.427

Answers

8

BBC Basic, 207 bytes

BBC Basic allows you to abbreviate keywords by ending them with a period (e.g., PRINT ↠ PRI., REPEAT ↠ REP.). 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

r3mainer

Posted 2014-12-04T17:53:13.580

Reputation: 19 135

4

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...

jimmy23013

Posted 2014-12-04T17:53:13.580

Reputation: 34 042

3

Haskell, 219

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 ([]).

proud haskeller

Posted 2014-12-04T17:53:13.580

Reputation: 5 866

2

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[999];
    int X[6] = {5, 8, 23, 15, 111, 819};
    int N[6] = {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

user15259

Posted 2014-12-04T17:53:13.580

Reputation:

Fixed it, with only one minor cheat... – None – 2014-12-05T18:35:01.303

seems like if you can make your code only one statement using , you could get rid of the brackets – proud haskeller – 2014-12-06T07:35:37.513