Skip to main content
added 6 characters in body
Source Link

Applesoft, 29 oops, 32 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated as the "input" need not be byte-counted itself. As stated in the OP, the input would be given as "ABCD". (I didn't initially realize that I needed to specify input being obtained, which added 4 bytes, while I golfed the rest down a byte.)

INPUTI$:X=RND(1)*4:PRINTMID$(I$,(X<.5)+X+1,1)

The terms INPUT, RND, PRINT and MID$ are each encoded internally as single-byte tokens.

First, X is assigned a random value in the range 0 < X < 4. This is used to choose one of the characters from I$, according to (X < .5) + X + 1. Character-position value is taken as truncated evaluation of the expression. X < .5 adds 1 if X was less than .5, otherwise add 0. Results from X break down as follows:

A from .5 ≤ X < 1           = 12.5%
B from X < .5 or 1 ≤ X < 2  = 37.5%
C from 2 ≤ X < 3            = 25%
D from 3 ≤ X < 4            = 25%

Applesoft, 29 32 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated as the "input" need not be byte-counted itself. As stated in the OP, the input would be given as "ABCD". (I didn't initially realize that I needed to specify input being obtained, which added 4 bytes, while I golfed the rest down a byte.)

INPUTI$:X=RND(1)*4:PRINTMID$(I$,(X<.5)+X+1,1)

The terms INPUT, RND, PRINT and MID$ are each encoded internally as single-byte tokens.

First, X is assigned a random value in the range 0 < X < 4. This is used to choose one of the characters from I$, according to (X < .5) + X + 1. Character-position value is taken as truncated evaluation of the expression. X < .5 adds 1 if X was less than .5, otherwise add 0. Results from X break down as follows:

A from .5 ≤ X < 1           = 12.5%
B from X < .5 or 1 ≤ X < 2  = 37.5%
C from 2 ≤ X < 3            = 25%
D from 3 ≤ X < 4            = 25%

Applesoft, 29 oops, 32 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated as the "input" need not be byte-counted itself. As stated in the OP, the input would be given as "ABCD". (I didn't initially realize that I needed to specify input being obtained, which added 4 bytes, while I golfed the rest down a byte.)

INPUTI$:X=RND(1)*4:PRINTMID$(I$,(X<.5)+X+1,1)

The terms INPUT, RND, PRINT and MID$ are each encoded internally as single-byte tokens.

First, X is assigned a random value in the range 0 < X < 4. This is used to choose one of the characters from I$, according to (X < .5) + X + 1. Character-position value is taken as truncated evaluation of the expression. X < .5 adds 1 if X was less than .5, otherwise add 0. Results from X break down as follows:

A from .5 ≤ X < 1           = 12.5%
B from X < .5 or 1 ≤ X < 2  = 37.5%
C from 2 ≤ X < 3            = 25%
D from 3 ≤ X < 4            = 25%
Inproving according to comment received
Source Link

Applesoft, 2929 32 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated as the "input" may be treated as "given", and need not be byte-counted itself. In this caseAs stated in the OP, I'm saying that the input is the value of the variable I$would be given as "ABCD". (I didn't initially realize that I needed to specify input being obtained, which has been assigned "ABCD"added 4 bytes, while I golfed the rest down a byte.)

X = INT ( RND INPUTI$:X=RND(1) * 8)*4: PRINT MID$ PRINTMID$(I$,X / 2 + 1 + NOT X(X<.5)+X+1,1)

The terms INTINPUT, RND, PRINT, MID$ and NOTMID$ are each encoded internally as single-byte tokens.

First, X is assigned a random integervalue in the range 0 to 7< X < 4. This is used to choose one of the characters from I$, according to (X < .5) + X/2 + 1 + NOT X. Character-position value is taken as truncated divisionevaluation of X/2the expression. NOT X < .5 adds 1 if X was zeroless than .5, otherwise add 0. Results from X break down thusas follows:

A from .5 ≤ X < 1           = 12.5%
B from 0,X 2,< 3.5 or 1 ≤ X < 2  = 37.5%
C from 4,2 5 X < 3            = 25%
D from 6,3 7≤ X < 4            = 25%

Applesoft, 29 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated "input" may be treated as "given", and need not be byte-counted itself. In this case, I'm saying that the input is the value of the variable I$, which has been assigned "ABCD".

X = INT ( RND (1) * 8): PRINT MID$ (I$,X / 2 + 1 + NOT X,1)

The terms INT, RND, PRINT, MID$ and NOT are each encoded as single-byte tokens.

First, X is assigned a random integer in the range 0 to 7. This is used to choose one of the characters from I$, according to X/2 + 1 + NOT X. Character-position value is taken as truncated division of X/2. NOT X adds 1 if X was zero, otherwise add 0. Results from X break down thus:

A from 1        = 12.5%
B from 0, 2, 3  = 37.5%
C from 4, 5     = 25%
D from 6, 7     = 25%

Applesoft, 29 32 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated as the "input" need not be byte-counted itself. As stated in the OP, the input would be given as "ABCD". (I didn't initially realize that I needed to specify input being obtained, which added 4 bytes, while I golfed the rest down a byte.)

INPUTI$:X=RND(1)*4:PRINTMID$(I$,(X<.5)+X+1,1)

The terms INPUT, RND, PRINT and MID$ are each encoded internally as single-byte tokens.

First, X is assigned a random value in the range 0 < X < 4. This is used to choose one of the characters from I$, according to (X < .5) + X + 1. Character-position value is taken as truncated evaluation of the expression. X < .5 adds 1 if X was less than .5, otherwise add 0. Results from X break down as follows:

A from .5 ≤ X < 1           = 12.5%
B from X < .5 or 1 ≤ X < 2  = 37.5%
C from 2  X < 3            = 25%
D from 3 ≤ X < 4            = 25%
Source Link

Applesoft, 29 bytes

A little "retrocomputing" example. Bear with me, I'm brand new at this. I gather that what is designated "input" may be treated as "given", and need not be byte-counted itself. In this case, I'm saying that the input is the value of the variable I$, which has been assigned "ABCD".

X = INT ( RND (1) * 8): PRINT MID$ (I$,X / 2 + 1 + NOT X,1)

The terms INT, RND, PRINT, MID$ and NOT are each encoded as single-byte tokens.

First, X is assigned a random integer in the range 0 to 7. This is used to choose one of the characters from I$, according to X/2 + 1 + NOT X. Character-position value is taken as truncated division of X/2. NOT X adds 1 if X was zero, otherwise add 0. Results from X break down thus:

A from 1        = 12.5%
B from 0, 2, 3  = 37.5%
C from 4, 5     = 25%
D from 6, 7     = 25%