text:
Double-time is not double time
Based on this challenge.
In the rhythm game osu!, the difficulty modifier "Double-time" actually only increases the speed by 50%.
Your task, is to write a program that outputs a positive even integer (higher than 0), and when each byte/character (your choice which) in your source code is duplicated, it should output the number multiplied by 1.5.
For example if your source code is ABC and that outputs 6, then AABBCC should output 9.
Following the original challenge's rules:
Rules

You must build a full program.
The initial source must be at least 1 byte long.
Both the integers must be in base 10 (outputting them in any other base or with scientific notation is forbidden).
Your program must not take input (or have an unused, empty input) and must not throw any error (compiler warnings are not considered errors).
Outputting the integers with trailing / leading spaces is allowed.
You may not assume a newline between copies of your source.
This is code-golf, so the fewest bytes in each language wins!
Default Loopholes apply.

I imagine this will be far less trivial than the original challenge, but hopefully we'll see some creative and unique answers!

@Fatalize write a program that outputs a positive even integer Yes it will. Every even number can be multiplied by 1.5 to result in a whole integer

It seems like a dupe to me.

@EriktheOutgolfer Very similar but I'm sure this one is going to be a lot harder (unless I'm missing something obvious).

@EriktheOutgolfer and it's duplicating each character, not the entire source. So ABC becomes AABBCC rather than ABCABC

@Mayube Oh I get it.

Duplicating characters may make trivial languages unrunnable. I wonder if there is a solution in a not single-character-command-styled or expression-based language.

@KeyuGan More than likely not unless you can do something clever with comments.

@TheLethalCoder Maybe the biggest obstacle is full program. It is hard to imagine a duplicated program still have a valid entry point / function.

So it only has to be able to do so once? that's not much of a challenge, is it?

Would you consider linking to the new homepage?

@FrenzyLi done. I don't use the osu site enough to even realise there was a new homepage :P

@KeyuGan There is a full-program solution in at least one non-golfing language. Here.

Pylons, 7 5 4 bytes
Picked a random language on TIO used it
46vt

Explanation:
Try it Online!
46    # Stack is [4, 6]

v     # Reverse the stack [6, 4]

t     # take top of stack 4

Doubled:
4466   # Stack is [4, 4, 6, 6]

vv     # Reverse the stack twice so it's the same [4, 4, 6, 6]

tt     # take top of stack 6 and again which is 6 again

Saved 2 bytes thanks to  officialaimm
Saved 1 bytes thanks to  Veedrac

Hey, 4/6vt works as well...

I wholeheartedly approve of the strategy of picking a random TIO language and learning it for a challenge

@officialaimm you are right, thanks.

4/6 <- 4 divided by nothing -> 4 ; and then 6. 44//66 <- 4 divided by 4 -> 1 ; nothing divided by nothing -> nothing ; and then 6 and 6. Maybe. Well done though.

Wouldn't 46vt do the same?

Jelly, 2 bytes
!‘

Try it online!
Explanation:
!‘ Implicit 0
!  Factorial
 ‘ Increment

Doubled version:
!!‘‘

Try it online!
Explanation:
!!‘‘ Implicit 0
!    Factorial
 !   Factorial
  ‘  Increment
   ‘ Increment

If you do it a third  time it goes from 3 -> 4, not 3->4.5??

@tuskiomi No because it's not expected to do so.

LibreOffice Calc, 8 bytes
=A2+3
19

Save it as *.csv and open it in LibreOffice Calc. You will get 22 in A1.

Double them:
==AA22++33

1199

You will get 33 in A1

clever language choice!

vim, 5
i1<esc>X<C-a>

Without doubling:
i1<esc>  insert the literal text "1"
X        delete backwards - a no-op, since there's only one character
<C-a>    increment, giving 2

With doubling:
ii11<esc>   insert the literal text "i11"
<esc>       escape in normal mode does nothing
XX          since the cursor is on the last character, delete "i1"
<C-a><C-a>  increment twice, giving 3

MATL, 3 bytes
TnQ

Try it online! Or doubled version.
Explanation
In MATL a scalar value (number, char, logical value) is the same as a 1×1 array containing that value.
Normal version:
T    % Push true
n    % Number of elements of true: gives 1
Q    % Add 1: gives 2

Doubled version:
TT   % Push [true, true]
n    % Number of elements of [true, true]: gives 2
n    % Number of elements of 2: gives 1
Q    % Add 1: gives 2
Q    % Add 1: gives 3

TnQ for the answer... :D [We sometimes use tnq as a short-form for thank-you]

@officialaimm :) [we sometimes use that to get the first n elements from an array...]

Python 2 REPL, 11 bytes
(3/1)*(2/1)

This simply evaluates to 3*2=6. Duplicated, it is
((33//11))**((22//11))

which evaluates to 3**2, which is 3 to the power of 2, or 9.

Welcome to the site.  This python does not produce any output and thus is not a valid answer.  However if you change your answer to be a Python REPL, this does produce output and thus is a valid answer.  You will either have to delete this answer or change the language from python 2 to python 2 repl.

@WheatWizard Thanks, and thanks for helping! Did I do this properly?

Not sure if this answer is valid. Just post here in case some one may got ideas from here.
Node.js with -p flag, 7 bytes
By Alex Varga:
3/3*22

33//33**2222

Node.js with -p flag, 11 bytes
Old one:
3*2*0/1+22

33**22**00//11++2222

Output 22 and 33.

How is it supposed to do 33? TIO doesn't seem able to do it. It locks on 00.

How about: 3/3*22

@AlexVarga so sweet.

@V.Courtois you are using strict mode

@tsh how do I prevent using strict mode?? I thought it used strict only if the code began with use strict;

Is there a reason Node.js is specified as opposed to just JavaScript?

@EdmundReed need -p flag to output expression value

APL, 7 bytes
⊃⍕⌊3×⍟2

Prints 2.
⊃⊃⍕⍕⌊⌊33××⍟⍟22

Prints 3.
Try it online!
Waaat?
Single:
3×⍟2         → 2.079441542  ⍝  3 * ln 2
⌊2.079441542 → 2            ⍝  floor
⊃⍕           → '2'          ⍝  format and take first character

Double:
⍟⍟22          → 1.128508398  ⍝  ln ln 22
×1.128508398  → 1            ⍝ signum
33×1          → 33           ⍝  33 * 1
⌊⌊33          → 33           ⍝  floor
⊃⊃⍕⍕          → '3'          ⍝  format and take first character

Could you please align the comments vertically? Or do we have different settings or something causing it on my end to loop like this?

@KevinCruijssen I think that's your browser font, but browsers doesn't render APL as monospaced anyways. that mine http://prntscr.com/fwp0l0

Ah well, it's still readable and a great answer regardless. :)

It renders as monospace for me. Probably just depends on the font (https://prnt.sc/fwrnz1). The comments are definitely not aligned though :P

@therealfarfetchd thanks, I've updated the last 3 rows

CJam, 4 bytes
],))

Try it normally!
Try it doubled!
Explanation
Normal:
]     e# Wrap the stack in an array: []
 ,    e# Get its length: 0
  ))  e# Increment twice: 2

Double:
]         e# Wrap the stack in an array: []
 ]        e# Wrap the stack in an array: [[]]
  ,       e# Get its length: 1
   ,      e# Get the range from 0 to n-1: [0]
    )     e# Pull out its last element: 0
     )))  e# Increment 3 times: 3

The overloads are tricky...;)

AB], also works.

Actually, 3 bytes
1u*

Try it online!
Explanation:
1u* Errors are ignored
1   Push 1
 u  Increment
  * Multiply

Doubled version:
11uu**

Try it online!
Explanation:
11uu** Errors are ignored
1      Push 1
 1     Push 1
  u    Increment
   u   Increment
    *  Multiply
     * Multiply

05AB1E, 2 bytes
X>

Try it online!
Explanation:
X> Only top of stack is printed
X  Push X (default 1)
 > Increment

Doubled version:
XX>>

Try it online!
Explanation:
XX>> Only top of stack is printed
X    Push X (default 1)
 X   Push X (default 1)
  >  Increment
   > Increment

Neim, 2 bytes
>

Try it online!
Explanation:
> Implicit 0
  Factorial
 > Increment

Doubled version:
>>

Try it online!
>> Implicit 0
    Factorial
    Factorial
  >  Increment
   > Increment

4 out of the 5 answers... you're really going for it on this one!

@TheLethalCoder At least it's not 15 yet. ;)

Pyth, 3 bytes
he1

Try it here.
Explanation:
he1
h   Increment
 e   Last digit
  1   1

Doubled version:
hhee11

Try it here.
Explanation:
hhee11
h      Increment
 h      Increment
  e      Last digit
   e      Last digit
    11     11

one he11 of an answer

Ruby REPL, 8 bytes
";3#";22

The REPL only prints the last value evaluated: 22.
Doubled:
"";;33##"";;22

This time 33 is the last value evaluated. The string is discarded once again, and a # starts a comment.

Zsh, 14 bytes
<:|echo 22
3
:

Try it online!
Getting a full program in a non-golfing language to print anything with source code duplicated like this is a challenge. Zsh is very useful for this, because files and heredocs are implicitly passed to cat. Let's take a look at the first line in both cases:
<:|echo 22            # Give the file : on stdin to cat. cat pipes to 'echo 22', which ignores stdin
<<::||eecchhoo  2222  # Start heredoc on following lines with EOF string '::', pass to cat.
                      # Since cat exits 0, 'eecchhoo 2222' is not executed

So long as 3 is not a program, the first program will only print 22.
The second program will print 33 surrounded by extra newlines (due to the duplication).

If 3 is a function/program/alias, then this 18 byte solution will still work!
<:|echo 22\\c\
3
:

Try it online!
The last \ is line continuation, so the newline is discarded, effectively making the echo statement
echo '22\c3'. The \c causes echo to stop printing after 22 (which also happens to suppress the newline).

R, 11 6 bytes
1+7*!0

Try it online!
! is negation, and ** is exponentiation (an alias for ^). Numerics get converted to booleans: 0 to FALSE, all others to TRUE. Booleans get converted to integers: FALSE to 0, TRUE to 1, so !0==1, !1==0, !!00==0 and !!11==1.
The single version thus computes \$1+7\times 1=8\$, and the double version computes \$11+77^0=12\$.

I was just trying to come up with a solution relying on * and **, but you beat me to it!

@Giuseppe I'm not convinced my solution is optimal (the need for brackets around !0 is annoying). There might be something shorter with - and *, but I haven't found such a solution yet...

><>, 19 8 Bytes
32b*!{n;

Prints 22
Try it online!
Explanation:
32b   push literals onto the stack: [3,2,11]
*     multiply the top two values: [3,22]
!     skip the next instruction
{     (skipped)
n     pop and print the top value from the stack (22)
;     end execution

Doubled:
3322bb**!!{{nn;;

Prints 33
Try it online!
Explanation:
3322bb push literals onto the stack: [3,3,2,2,11,11]
**     multiply top values (twice): [3,3,2,242]
!      skip next instruction
!      (skipped)
{{     rotate the stack to the left (twice): [2,242,3,3]
nn     pop and print the top two values from the stack (33)
;      end execution

Old Version:
Normal:
11+!vn;
    n
    ;

Prints 2
Try it online!
Explanation:
1    push 1 on the stack: [1]
 1    push 1 on the stack: [1,1]
  +    add top two values of the stack: [2]
   !    skip the next instruction
    v    (skipped)
     n    print the top value of the stack (2)
      ;    end execution

Doubled:
1111++!!vvnn;;
        nn
        ;;

Prints 3
Try it online!
Explanation:
1111    push four 1's on the stack: [1,1,1,1]
    +    add top two values of the stack: [1,1,2]
     +    add top two values of the stack: [1,3]
      !    skip the next instruction
       !    (skipped)
        v    change direction of execution (down)
         n    print the top value of the stack (3)
          ;    end execution

I think you're supposed to duplicate the newlines too.

@EriktheOutgolfer There aren't newlines anymore.

Cubix, 6 bytes
O.1)W@

Prints 2.
  O
. 1 ) W
  @

Pushes 1, ) increments, W jumps left to O which outputs 2, and @ finishes the program.
Doubled up, it's obviously OO..11))WW@@, which on a cube is:
    O O
    . .
1 1 ) ) W W @ @
. . . . . . . .
    . .
    . .

It pushes 1 twice, ) increments twice, W jumps left again, which puts it at the right-hand O heading north, which outputs 3, and then the next command is @ which terminates the program.
Try it online!
Doubled online!

Klein, 8 6 bytes
/3+@4\

Single, Double
Explanation
For the single the program follows a pretty straightforward path.  The first mirror deflects it into the second which deflects it through the 4 to the end of the program.
The double is a little more complex.  Here it is:
//33++@@44\\

The first two mirrors work the same, however there is a new mirror due to the doubling which deflects the ip back to the beginning, it is caught by the duplicate of the first mirror  and deflected towards the end.  All that is run is the 33++ which evaluates to 6.

TI-Basic, 3 bytes
Single:
int(√(8

The last expression is implicitly returned/printed in TI-Basic, so this prints 2
Doubled:
int(int(√(√(88

Returns/prints 3
TI-Basic is a tokenized language; int(, √(, and 8 are each one byte in memory.

Technically the challenge spec explicitly states when each character is doubled, but I'll allow this and update the spec

Perl 6, 14 bytes
'|d 3#';say 22

Try it online! Try it doubled!
This uses the conveniently named debug function dd to output the doubled program to STDERR. To separate the logic we encase the doubled program in quotes, which then cancel each other out when doubled, along with a comment character # to comment out the now invalid normal program.

This works as-is in 5 too (with some imports)!

Vyxal, 2 bytes
¡›

Try it Online!
Port of the Jelly answer.
   # (implicit zero)
¡  # Factorial
 › # Incremented

Doubled (Try it Online!):
¡    # 0 factorial = 1
 ¡   # 1 factorial = 1
  ›› # Incremented twice = 3

Vyxal, 3 bytes
ðL›

Try it Online!
ð   # Space character
 L  # Length
  › # Incremented

Doubled (Try it Online!)
ðð     # Space character (one's a nop)
  LL   # Length twice (one's a nop)
    ›› # Incremented twice

why is the second space/length symbol a nop?

@Mayube It's not really a nop, just is in the context of this program. If we push two spaces and only use one, the other's useless. ðL gets a 1, and the length of 1 is 1 so the second does nothing.

Ah that makes sense!

Hexagony, 6 bytes
))$$!@

Try it online! (Try it doubled!)
Explanation
  ) )
 $ $ !
  @ .

This program does nothing too weird; it just executes each line in order:

)): Increment twice (memory cell = 2).
$$: Jump the jump; basically a no-op.
!: Print memory cell (2)
@: Stop.

   ) ) )
  ) $ $ $
 $ ! ! @ @
  . . . .
   . . .

Only the first and third lines are executed, due to Hexagony's control flow:

))): Increment 3 times (memory cell = 3).
)$$$: This line is skipped.
$!: Jump over the first !, so the memory cell isn't printed twice.
!: Print 3.
@: Stop.

Stax, 3 bytes
UJ^

Run and debug it
Run and debug the doubled one
U pushes -1.  J squares.  ^ increments.

MathGolf, 2 bytes
▬)

Try it online! Try it doubled
Similar to other answers in that the first instruction produces a 1 even when doubled and the second increments it. In this case, I've used reverse exponentiation (0**0 = 0**0**0 = 1) but it also could have been any of the !£≤° instruction and perhaps even more that I missed.

Deadfish~, 12 bytes
iis(ooh)iiio

Try it online!
Try it doubled!
Explanation
iis(ooh)iiio

Set the accumulator to 2, square it, print twice to get 44, stop.
iiiiss((oooohh))iiiiiioo

Set the accumulator to 4 and square it twice to get 256.
Since Deadfish~ doesn't like the number 256, it sets the accumulator to 0 instead.
The (...) part of the code is ignored if the accumulator is 0, and then the rest of the code prints 66.

Perl 5 + -M5.10.0 -MData::Dump+(dd), 17 bytes
q{\};d 3#};say 22

Try it online!
Doubled
qq{{\\}};;dd  33##}};;ssaayy  2222

Try it online!
Explanation
I was hopeful to find a way to trigger a print without using an external, but I couldn't come up with anything so I settled on dd.
The trick here was to leverage Perl's flexibly delimited strings to encase the doubled code without causing a syntax error. Using {...} (or any other pairs like(), [], <>) means in the original code the end char can be escaped with a single \ which when doubled is just a backslash. Using q is easiest as qq is just as valid.
q{\};d 3#};say 22

Here we have a short string containing };d 3#, then we just say 22 which outputs 22.
qq{{\\}};;dd  33##}};;ssaayy  2222

Here we have a string containing a single \ and then we ddump out 33 and the rest of the program is commented out.

Now that I look through the other answers I see that @JoKing's answer would work as-is with my command line arguments too...

Japt, 2 bytes
Another "factorial+1" solution.
ÊÄ

Test it
ÊÊÄÄ

Test it

Octave, 1 byte
I think we all know this is a worthless answer. Gotta show Octave some love.
0

Try it online!


text:
Three triangular numbers
Description
There have been quite a few other challenges concerning these numbers before, and I hope this one is not among them.
The n th triangular number equals the sum of all natural numbers up to n, simple stuff. There are a wikipedia page and an entry at OEIS, for those who wish to inform themselves further.
Now, Gauss found out that every natural number may be expressed as a sum of three triangular numbers (these include 0), and it is fine to have one number more than once, e.g. 0 + 1 + 1 = 2.
Challenge
Your task is to write a program or function, given a natural number (including 0), prints three triangular numbers that sum up to the argument. You may print the numbers separeted by spaces, as an array, or by another method you like. However, it is forbidden to use any builtin functions to directly get an array, a range or any other form of collection containing a list of triangular numbers (for instance a single atom that yields the range).
Test cases
9 -> 6 + 3 + 0 or 3 + 3 + 3
12 -> 6 + 6 + 0 or 6 + 3 + 3 or 10 + 1 + 1
13 -> 6 + 6 + 1
1 -> 1 + 0 + 0
0 -> 0 + 0 + 0

Note: If there is more than one possible combination, you may print any or all, but you must print any combination only once, eliminating all combinations that are a result of rearranging other combinations.
I'd really appreciate a try-it link and an explanation, I really love to see how you solve the problem ;)
This is code-golf, so standard loopholes apply. May the shortest answer in bytes win!

You're welcome to! ;)

For 12 you can also do 1 + 1 + 10.

I guess INPUT a: PRINT 0,0,a would be a loophole?

@steenbergh a won't always be a triangular number

I can parse "builtin functions to directly get an array, a range or any other form of collection containing a list of triangular numbers" in two ways, but neither of them makes sense. The first prohibits all builtins which directly get an array, but that seems to prohibit all use of arrays in every language I know; the other prohibits builtins to "directly get ... a range ... containing a list of triangular numbers", but I don't know what that would mean.

@PeterTaylor that means that no builtin functions returning a collection of triangular numbers and taking no arguments are banned - you must generate the required collection by using a formula or the sum of the necessary natural numbers instead.

So built-in functions which take an argument n and return a list of the first n triangle numbers are permitted? That feels rather targetted against some specific language, although I don't know which.

I urge you to lift this restriction. I promise you it won't improve the inter-language answer quality or fairness in the way you think.

For 13 you can do 10+3+0, right?

@PeterTaylor I'm not, I just want to avoid that one can just use a collection of triangular numbers that is directly provided by the language they use. I'm not familiar with any golfing language, so I can't know if there is a builtin in some language. I want them to solve the generation of the numbers on their own, because there are a different ways, and it gives the challenge a bit of a twist, in my opinion.

@KevinCruijssen Yep.

@racer290 He's asking because for the other test cases you listed all possible answers.

05AB1E, 10 bytes
Code:
ÝηO3ãʒOQ}¬

Explanation:
Ý             # Compute the range [0 .. input]
 η            # Get the prefixes
  O           # Sum each prefix to get the triangle numbers
   3ã         # Cartesian repeat 3 times
     ʒ  }     # Keep elements that
      OQ      #   have the same sum as the input
         ¬    # Retrieve the first element

Uses the 05AB1E encoding. Try it online!

Ahhh... Yep; that'd do it.

Python 2, 99 bytes
from random import*
n=input()
while 1:b=sample([a*-~a/2for a in range(n+1)]*3,3);n-sum(b)or exit(b)

Try it online!
I'm pretty amazed this is shorter than itertools or a triple list comprehension! It (eventually) spits out a random answer every time you run it.
Two 102s:
n=input();r=[a*-~a/2for a in range(n+1)];print[(a,b,c)for a in r for b in r for c in r if a+b+c==n][0]
def f(n):r=[a*-~a/2for a in range(n+1)];return[(a,b,c)for a in r for b in r for c in r if a+b+c==n][0]

itertools looks to be 106:
from itertools import*;lambda n:[x for x in product([a*-~a/2for a in range(n+1)],repeat=3)if sum(x)==n][0]

+1 for random output. :) I'm also surprised that gives the shortest solution (thus far).

Thank you very much for the method. The corresponding Ruby code has 57 bytes.

Jelly, 12 bytes
0r+\œċ3S=¥Ðf

Try it online!
How it works
0r+\œċ3S=¥Ðf   input: n
0r             [0 1 ... n]
  +\           cumsum
    œċ3        combinations of 3 elements, with repetition
          Ðf   filter on
       S          sum
        =         equals n

Please consider adding an explanation.. =)

@racer290 done.

Brachylog, 13 bytes
⟦⟦ᵐ+ᵐj₃⊇Ṫ.+?∧

Try it online!
How it works
⟦⟦ᵐ+ᵐj₃⊇Ṫ.+?∧  input: n
⟦              [0 1 ... n]
 ⟦ᵐ            [[0] [0 1] [0 1 2] ... [0 1 ... n]]
   +ᵐ          [0 1 3 ... n(n+1)/2]
     j₃        [0 1 3 ... n(n+1)/2 0 1 3 ... n(n+1)/2 0 1 3 ... n(n+1)/2]
       ⊇       is a superset of
        Ṫ      a list of three elements
         .     which is the output
          +?   which sums up to be the input

Retina, 63 59 bytes
.+
$*
^((^1|1\2)*)((1(?(4)\4))*)((1(?(6)\6))*)$
$.1 $.3 $.5

Try it online! Link includes test cases. (1(?(1)\1))* is a generalised triangular number matcher, but for the first triangular number we can save a few bytes by using ^ for the initial match.

Haskell, 66 59 bytes
Thanks for allowing to output all solutions, that was fascinating distraction!
I was so happy to not need to extract one solution and be able to just give them all that I didn't notice the cost that comes from avoiding permuted solutions. @Lynn's remark explained that to me and let me save 7 bytes.
f n|l<-scanl(+)0[1..n]=[(a,b,c)|c<-l,b<-l,a<-l,a+b+c==n]!!0

This binds more than enough triangular numbers to l and checks all combinations.

Isn’t dropping the a>=b,b>=c conditions and just suffixing !!0 to your code also a valid answer? Outputting all solutions doesn’t really help you here.

@Lynn You're right of course, I got distracted. Thanks!

MATL, 18 bytes
Q:qYs3Z^t!sG=fX<Y)

This outputs the first result in lexicographical order.
Try it at MATL Online!
Explanation
Q     % Implicitly input n. Add 1
:     % Range (inclusive, 1-based): gives [1 2 ... n+1]
q     % Subtract 1 (element-wise): gives [0 1 ... n]
Ys    % Cumulative sum
3Z^   % Cartesian power with exponent 3. Gives a matrix where each row is a
      % Cartesian tuple
t     % Duplicate
!s    % Sum of each row
G=    % Does each entry equal the input?
f     % Find indices that satisfy that condition
X<    % Minimum
Y)    % Use as row index into the Cartesian power matrix. Implicitly display

Python 3, 119 bytes
lambda n:[l for l in combinations_with_replacement([(t**2+t)/2for t in range(n)],3)if sum(l)==n]
from itertools import*

Try it online!
Thanks to @WheatWizard for saving 12 bytes!

Your map (and perhaps your filter) can be written shorter as a list comprehension.

Here's a TIO of the changes implemented.

@WheatWizard thanks for the idea, I can't believe I didn't think of a list comprehension for the map

Filter objects are perfectly valid output, but if you want to output a list you can use a splat like so [*filter(...)]

What I had tried was (x,y,z) for x,y,z in... which is longer than your l for l in... which likely accounts for that difference.

PHP, 351 bytes
$r=[];function f($a=[],$c=0){global$argn,$t,$r;if($c<3){$n=$argn-array_sum($a);$z=array_filter($t,$f=function($v)use($n,$c){return$v>=$n/(3-$c)&&$v<=$n;});foreach($z as$v){$u=array_merge($a,[$v]);if(($w=$n-$v)<1){if(!$w){$u=array_pad($u,3,0);sort($u);if(!in_array($u,$r)){$r[]=$u;}}}else f($u,$c+1);}}}for($t=[0];$argn>$t[]=$e+=++$i;);f();print_r($r);

Try it online!

Mathematica, 63 bytes
(t=#;#&@@Select[Table[i(i+1)/2,{i,0,t}]~Tuples~{3},Tr@#==t&])&

With infix syntax and that whack way of getting First that saves a whopping 2 bytes, (t=#;#&@@Select[Table[i(i+1)/2,{i,0,t}]~Tuples~{3},Tr@#==t&])& for 62 bytes.

Great, I'll edit

C/C++ - 197 bytes
#include<stdio.h>
#define f(i,l,u) for(int i=l;i<=u;i++)
int t(int n){return n>1?n+t(n-1):n;}
int c(int n){f(a,0,n)f(b,a,n)f(c,b,n)if(t(a)+t(b)+t(c)==n)return printf("%d %d %d\n",t(a),t(b),t(c));}

Blow by blow:
#include<stdio.h>

Needed for printf.  Could be elided for certain versions of C
#define f(i,l,u) for(int i=l;i<=u;i++)

Space saving for loop.
int t(int n){return n>1?n+t(n-1):n;}

Recursive triangle evaluator.
int c(int n){f(a,0,n)f(b,a,n)f(c,b,n)if(t(a)+t(b)+t(c)==n)return printf("%d %d %d\n",t(a),t(b),t(c));}

This guy does the heavy lifting.  Three nested for loops iterate a, b, c from 0 to n, note that b and c each iterate from the previous value up to n.  It's not strictly necessary to trim iteration like that since the return coming in a minute solves the "duplicate" problem.
At the inner level, if the sum of the three triangle numbers == the desired value, print the triangles and return.
You can legally remove the return keyword and convert the return type of c to void to save a few more bytes and print all possible solutions.  It is for this reason that iterations are limited, if all loops ran from 0 to n it would cause duplicates.

CJam, 26 bytes
{_),[{\_@+}*]3m*_{:+}%@#=}

Port of my MATL answer. This is an anonymous block that expects the input on the stack and replaces it by the output array.
Try it online!

R, 66 bytes
n=scan();b=expand.grid(rep(list(cumsum(0:n)),3));b[rowSums(b)==n,]

Brute force algorithm; reads n from stdin and returns a dataframe where each row is a combination of 3 triangular numbers that add up to n. If necessary, I can return only the first row for +4 bytes.
Try it online!

Java 8, 164 bytes
n->{int t[]=new int[n+1],i=0,j=0;for(;i<=n;)if(Math.sqrt(8*i+++1)%1==0)t[j++]=i-1;for(int a:t)for(int b:t)for(int c:t)if(a+b+c==n)return new int[]{c,b,a};return t;}

Explanation:
Try it here.
n->{                     // Method with int parameter and int-array return-type
  int t[]=new int[n+1],  //  Create an int-array to store triangular numbers
      i=0,j=0;           //  Two index-integers
  for(;i<=n;)            //  Loop (1) from 0 to `n` (inclusive)
    if(Math.sqrt(8*i+++1)%1==0)
                         //   If `i` is a triangular number
      t[j++]=i-1;        //    Add it to array `t`
                         //  End of for-loop (1) (implicit / single-line body)
  for(int a:t)           //  Loop (2) over the triangular numbers
    for(int b:t)         //   Inner loop (3) over the triangular numbers
      for(int c:t)       //    Inner loop (4) over the triangular numbers
        if(a+b+c==n)     //     If the three triangular numbers sum equal the input
          return new int[]{c,b,a};
                         //      Return these three triangular numbers as int-array
                         //    End of loop (4) (implicit / single-line body)
                         //   End of loop (3) (implicit / single-line body)
                         //  End of loop (2) (implicit / single-line body)
  return t;              //  Return `t` if no sum is found (Java methods always need a
                         //  return-type, and `t` is shorter than `null`;
                         //  since we can assume the test cases will always have an answer,
                         //  this part can be interpret as dead code)
}                        // End of method

JavaScript, 108 bytes
r=[],i=a=b=0
while(a<=x)r.push(a=i++*i/2)
for(a=0;a<3;){
b=r[i]
if(b<=x){
x-=b
a++
console.log(b)}
else i--}

Explanation
x represents the input
while(a<=x)r.push(a=i++*i/2) Creates an array of all triangular numbers up to x
The for loop prints the highest triangular number less than x, then subtracts that number from x, for three iterations. (basically a greedy algorithm)

You've got the same problem I do: by taking the biggest triangle number <= x at each step, you aren't guaranteed to have a triangle number for your 3rd place. Check your output for x = 103: 91 + 10 + 1 = 102

Pyth, 19 bytes
I am so out of practise with Pyth, it's untrue :/
hfqQsT.C*3+0msSdSQ3

Try it out here.
hfqQsT.C*3+0msSdSQ3  Implicit: Q=input()

                SQ   Range 1-n
            m        Map the above over d:
              Sd       Range 1-d
             s         Sum the above
                     Yields [1,3,6,10,...]
          +0         Prepend 0 to the above
        *3           Triplicate the above
      .C          3  All combinations of 3 of the above
 f                   Filter the above over T:
    sT                 Where sum of T
  qQ                   Is equal to input
h                    Take the first element of that list

You could possibly save a byte by leaving out the selector for the first list element because you are allowed to print all possible solutions too.

@racer290 Even better, though the results will be in the form [[a,b,c],[d,e,f]] - would that be ok?

@racer290 Actually, no, filtering the duplicates would not be free by the looks of things, so it wouldn't be any shorter :c

Ruby 61 57 55 bytes
Inspired by Lynn's Python answer. It generates random triplets until the desired sum is achieved:
->n{x=Array.new 3{(0..rand(n+1)).sum}until x&.sum==n;x}

It requires Ruby 2.4. In Ruby 2.3 and older, it's a syntax error, and Range#sum isn't defined. This longer version (64 bytes) is needed for Ruby 2.3:
->n{x=Array.new(3){(a=rand(n+1))*-~a/2}until x&.inject(:+)==n;x}

Here's a small test:
f=->n{x=Array.new 3{(0..rand(n+1)).sum}until x&.sum==n;x}
# => #<Proc:0x000000018aa5d8@(pry):6 (lambda)>
f[0]
# => [0, 0, 0]
f[13]
# => [0, 3, 10]
f[5]
# => [3, 1, 1]
f[27]
# => [21, 3, 3]
f[27]
# => [0, 21, 6]
f[300]
# => [3, 21, 276]

Try it online with Ruby 2.3!

Javascript (ES6), 108 bytes - fixed
Takes an integer as an input, outputs an array [a, b, c] containing a sorted list of triangle numbers a + b + c = x, where a is the largest triangle number less than or equal to the input, and b is the largest triangle number less than or equal to the input minus a.
x=>{t=[0],t.f=t.forEach,i=j=k=0;for(;j<x;t[i]=j+=i++);t.f(a=>t.f(b=>t.f(c=>a+b+c==x?k=[a,b,c]:0)));return k}

Explanation
x=>{
    t=[0],                               // initialize an array of triangle numbers
    t.f=t.forEach,                       // copy forEach method into t.f,
                                         // saves a net of 4 bytes
    i=j=k=0;
    for(;j<x;t[i]=j+=i++);               // populate t with all triangle numbers that
                                         // we could possibly need
    t.f(                                 // loop over all t
        a=>t.f(                          // loop over all t
            b=>t.f(                      // loop over all t
                c=>a+b+c==x?k=[a,b,c]:0  // if a+b+c = x, set k = [a,b,c], else noop
                                         // using a ternary here saves 1 byte vs
                                         // if statement
                                         // iterating over t like this will find all
                                         // permutations of [a,b,c] that match, but
                                         // we will only return the last one found,
                                         // which happens to be sorted in descending order
            )
        )
    );
    return k
}

const F = x=>{t=[0],t.f=t.forEach,i=j=k=0;for(;j<x;t[i]=j+=i++);t.f(a=>t.f(b=>t.f(c=>a+b+c==x?k=[a,b,c]:0)));return k};

$('#output').hide();
$('#run').click(() => {
  const x = parseInt($('#input').val(), 10);
  if (x >= 0) {
    $('#input').val(x);
    const values = F(x);
    $('#values').text(values.join(', '));
    $('#output').show();
  }
  else {
    $('#output').hide();
    alert('You must enter a positive integer');
  }
});

Enter a value: <input type="text" id="input" />

<button id="run">Get triangle numbers</button>

Triangle numbers are:

You're not explaining the most interesting part: why is x-m-n a triangular number, i.e. why does this work?

Well dangit, turns out it isn't guaranteed. All of the test cases I used just happened to produce a valid triplet of triangle numbers. Back to the drawing board.

Fixed now, less happy with this solution <;o( but at least it works.

J, 36 bytes
((2!1+$@]#:0({I.@,)=)]+/+/~)2!1+i.,]

Try it online!

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Help! I forgot my password!
Help! I just logged into Stack Exchange, but I forgot what my password is! I need a way to work it out before I log off.
Luckily, I'm an excellent hacker. Not only was I able to find my password's hash, but I also found Stack Exchange's hashing algorithm! It takes the ASCII value of each digit multiplied by that digit's place, then sums all those values together. For example:
"135" -> 1*49 + 2*51 + 3*53 = 310

I remember that my password is 3 digits long, and that each character is a number between 0 and 5 inclusive (such that it will match the regex: ^[0-5]{3}$), but that's still too many possibilities to guess. I need a program that can convert a hash back into potential passwords, but despite being an expert hacker, I can't code to save my life! I was able to write these tests out by hand though:
input -> output
288   -> 000                      // lowest possible hash
290   -> 200, 010
298   -> 022, 050, 103, 131, 212, 240, 321, 402, 430, 511
318   -> 555                      // highest possible hash

Can one of you write a program for me that will take in a hash and print all the possible passwords I could have used?
The input will always be able to produce at least one valid password. Any output format is allowed, as long as the strings can be clearly identified. I'm also not concerned about leading zeroes, so if a potential password is 001, I'll also accept 01 or 1.
Please help me from being locked out of Stack Exchange!
Scoring
This is code-golf, so the shortest answer in each language wins!

Isn't 1's Ascii value 49 instead of 48?

And 3 is 51 as well.

Whoops, thanks I fixed that. I think my test cases are still ok though.

@LordFarquaad test cases look fine but example should be "135" -> 1*49 + 2*51 + 3*53 = 310

must be delimited by a comma (a comma followed by one or more spaces is ok too) Why the restrictive output format? We usualy allow flexible formats

@LuisMendo honestly, because this is my first code golf question. I don't really know the standard for specifying how a list should be outputted. How would you normally say it? Would you just not address it and it's understood? I can make an edit, but I don't want to mess up the existing answers.

The usual here is to say something like "any ouput format is allowed, as long as the strings can be clearly identified". Or maybe allow any non-numeric separator. If you change it, notify current answerers with a comment in their answer

outputing 54 instead of 054 is acceptable?

@FelipeNardiBatista Yep, leading zeroes are optional. I remember I used 3 digits, so if I just see 54 I can work out the zeroes in front.

05AB1E, 9 bytes
5Ý3ãʒÇƶOQ

Try it online!
Returns list of lists of digits.

That makes for a pretty decent password.

C, 113 108 bytes
f(int h){int i=47,j,k;while(++i<54)for(j=47;++j<54)for(k=47;++k<54;)if(h==i+j+j+k*3)printf("%c%c%c",i,j,k);}

It is unique to see what is meant for output, the output is of the format: 200010
All passwords are written as 3-digits without delimiter.

Hey, code I can read!  Nice contrast to Jelly and such.  +1 for using a classic language.  :)

Jelly, 16 bytes
Ṿ€Oæ.J
6Ḷṗ3Ç⁼¥Ðf

A monadic link returning a list of lists of digits.
Try it online!
How?
Ṿ€Oæ.J - Link 1, hash: list of integers (the digits of a password)
Ṿ€     - unevaluate €ach (giving a list of characters)
  O    - cast to ordinals (Ṿ€O could actually be replaced with +48 too)
     J - range of length (i.e. [1,2,3] in all use-cases)
   æ.  - dot product

6Ḷṗ3Ç⁼¥Ðf - Main link: number, n
6Ḷ        - lowered range of 6 = [0,1,2,3,4,5]
  ṗ3      - Cartesian power with 3 = [[0,0,0],[0,0,1],...,[5,5,5]] (all passwords)
       Ðf - filter keep if:
      ¥   -   last two links as a dyad (right implicitly n):
    Ç     -     call last link (1) as a monad
     ⁼    -     equals right?

Python 2, 126 75 bytes
-2 thanks to @ArnoldPalmer
lambda h:[(P/36,P%36/6,P%6)for P in range(216)if P/36+P%36/6*2+P%6*3==h&31]

Try it online!

If you replace both P/6/6's with P/36, you save 2 bytes

This is exactly what I was about to write, +1

@Felipe Nardi Batista, I don't know why that would be the case

MATL, 20 bytes
'0':'5'3Z^t3:*!si=Y)

Try it online!
Explanation
'0':'5'   % Push inclusive range from '0' to '5', that is, '012345'
3Z^       % Cartesian power with exponent 3. Each Cartesian tuple is a row
t         % Duplicate
3:        % Push [1 2 3]
*         % Multiply element-wise with broadcast
!s        % Sum of each row
i         % Input number
=         % Logical mask of values that equal the input
Y)        % Use as logical index into the rows of the matrix. Implicit display

Python 2, 81 bytes
lambda h:[(a,b,c)for a in r for b in r for c in r if a+2*b+3*c+288==h]
r=range(6)

Try it online!

Haskell, 71 70 64 61 bytes
l=[0..5]
f p=[show=<<[a,b,c]|a<-l,b<-l,c<-l,p-288==a+2*b+3*c]

Try it online!

CJam, 26 25 bytes
-1 byte thanks to Challenger5
{:H;6Zm*{s:i3,:).*:+H=},}

Anonymous block expecting the hash on the stack (as an integer) and leaves the result on the stack (as a list of strings).
Try it online!
Explanation
:H;    e# Store the hash in H.
6Zm*   e# 3rd Cartesian power of [0 1 2 3 4 5].
{      e# For each tuple in the power:
 s     e#  Stringify the tuple.
 :i    e#  Get the code point of each digit.
 3,:)  e#  Push [1 2 3].
 .*    e#  Element-wise multiplication of the two lists.
 :+    e#  Sum the result.
 H=    e#  Check if it's equal to the hash.
},     e# Filter the tuples to only ones for which this block gave a truthy result.

@LordFarquaad Oh, uh... I didn't even see that in the first place so I guess that's fortunate

{:H;6Zm*{s:i3,:).*:+H=},} is 1 byte shorter. It uses digit strings in the filter rather than numbers as to use m*'s automatic range.

@Challenger5 Nice, thanks!

C# (.NET Core),133 131 125 123 bytes
n=>{int i,j,k;for(i=48;i<54;++i)for(j=48;j<54;++j)for(k=48;k<54;++k)if(i+j*2+k*3==n)Console.Write($"{i%48}{j%48}{k%48},");}

Try it online!

I gave more thorough advice previously, but I didn't get it to work right. For now my simple optimization is to use Console.Write($"{i%48}{j%48}{k%48},"); for output rather than building a return value, and removing the unnecessary brackets around the if statement to save 8 bytes.

I tried that option previously, but the Lambda requires a return value. Removing the brackets will work though. Thanks :)

The lambda requires a return value if you define it as Func<int,string>, but if you define it as Action<int> then it doesn't expect a return value.

Did not realize that! I am new to both c# and golfing, but decided to try it out when I have nothing else to do at work. Thanks again for the tips. I greatly appreaciate them.

You can get rid of the parentheses around n

You can save 2 bytes by declaring the variables inside the first loop: for(int i=48,j,k;i<54;++i)

Also by incrementing the counters in the condition you can save another 3 bytes. Eg: for(j=47;++j<54;)

In C# answers you must include every using statement, so you must either modify the answer to use System.Console... or add using System; to the byte count. Welcome to PPCG and glad to see you have chosen C# as your language!

If you play with the ambiguity between char and int in C#, you can declare your iteration variables as char in the first loop and still do the hash calculation exactly as you do while simplifying the Console.Write() sentence. Thus you can get a proper 119-byte solution. Try it online!

JavaScript (Firefox 30-57), 72 bytes
n=>[for(i of s="012345")for(j of s)for(k of s)if(n-i-j*2-k*3==288)i+j+k]

Charcoal, 33 bytes
Ｆ⁶Ｆ⁶Ｆ⁶¿⁼⁺℅Ｉι⁺×℅Ｉκ²×℅Ｉλ³Ｉθ«ＩιＩκＩλ⸿

Try it online!
A similar approach to other answers: loop thrice from 0 to 5, calculate the hash and print the state of the iteration variables if it coincides with the input hash.
Link to the verbose version.

Java, 162 Bytes
static void f(int n){for(int i=48;i<54;i++){for(int j=48;j<54;j++){for(int k=48;k<54;k++){if(i+j*2+k*3==n)System.out.println((char)i+""+(char)j+""+(char)k);}}}}

R, 67 62 61 bytes
-5 bytes thanks to Jarko Dubbeldam
b=t(t(expand.grid(rep(list(0:5),3))));b[b%*%1:3==scan()-288,]

Try it online!
reads the number from stdin; returns a matrix where the rows are the characters.
It generates all possible trios of digits in a matrix format (b), computes the matrix product b * [1,2,3], takes the rows of b which match (subtracting 288 from the input which is 1*48+2*28+3*48) and returns them.

t(t(m)) is a shorthand for as.matrix(m)

Pyth, 18 bytes
fqQs*VS3CMT^jkU6 3

QBIC, 40 bytes
[0,5|[0,5|[0,5|~a+b+b+c+c+c+288=:\?a,b,c

Explanation
[0,5|                Make a FOR loop run through the possible digits for pos 1, called a
[0,5|                Loop for #2, b
[0,5|                Loop for #3, c
                     Calculate the hash by taking a once, b twice and c thrice,
                     and raising all to their ASCII codepoints
 a+b+b+c+c+c+288
~               =:   IF thta is euqal to the given hash (read from cmd line)
\?a,b,c              THEN print the digits
                     (the IF and the FOR loops are auto-closed by QBIC)

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Check If my String is Prime
We define a prime character as a character that has a prime ASCII value. We define a prime string as a String that only contains prime characters.
Given a String that only contains printable ASCII, determine whether that String is prime.
Input / Output
You can take input either as a String or as a list of individual characters. You have to output two different and consistent values depending on whether the String is prime, following the standard rules for a decision-problem. You are guaranteed that the input will be non-empty.
Test Cases
Truthy cases (Prime Strings):

"aeg"
"aIS5"
"aaaaaaaaaaaaaa"
"/S/S"
"=;+"

Falsy cases (not Prime Strings):

"maTHS"
"Physics"
"\\\\"
"PPCG"
"Code Golf"
"Prime"

This is code-golf, so the shortest code in bytes wins! Standard rules for this tag apply.

It's not very unique, though I +1'd it.

@Mr.Xcoder I downvoted (and I personally would say dupe) of generic prime checking with some boilerplate (.unicodePoints.every(isPrime)) the thing is none of these boilerplate functions would even likely have the capability to be golfed as they are isPrime surrounded by language built ins. I don't want to smash as I would hammer it and would also like to get consensus

The definition of a prime string as simply not containing any non-prime characters seems less interesting than it could be, and a poor analogy with digits of numbers.  For example, in regular decimal numbers, 33 is non-prime even though all its digits are prime.

Jelly, 4 bytes
OÆPẠ

Try it online!
Explanation
Remember that a string is an array of characters, so operations like O will apply to each individual character.
OÆPẠ
O        Ord; cast each character to a number
 ÆP      Is it ÆPrime? gives 1 for truthy and 0 for falsey
   Ạ     Ạll; returns 1 if the array contains no falsey values

05AB1E, 3 bytes
ÇpW

Try it online!

Ç   # To ASCII array.
 p  # Is prime?
  W # Min value from.

ÇpP also works.

You beat me by a few seconds. I had ÇpP.

@Riley I'm surprised I was beaten by a Jelly answer, I answered hella quick, all I had to do was grab the ASCII command heh.

Python 3, 56 bytes
lambda s:all(x%i for x in map(ord,s)for i in range(2,x))

Try it online!

MATL, 3 bytes
ZpA

Outputs 1 for prime string, 0 otherwise.
Try it online!
Explanation
     % Implicit input
Zp   % Isprime. Applies element-wise to the code point of each entry
A    % All. Gives 1 iff all results are non-zero.
     % Implicit display

Brachylog, 3 bytes
ạṗᵐ

Try it online!

Haskell, 32 bytes
all(`elem`"%)+/5;=CGIOSYaegkmq")

Try it online!

CJam, 8 bytes
q:i:mp:&

Try it online!
Explanation
q         e# Read input
 :i       e# Convert to code points
   :mp    e# Check if each is prime
      :&  e# Reduce by AND

C, 113 bytes
p(int c){for(int i=1;++i<c;)if(!(c%i))return 1;return 0;}c(char*s){char*a="p";while(*s++)if(p(*s))++a;printf(a);}

You can do for(int i=1;++i<c;) for your first for-loop to save 1 byte.

You can always omit int return type and argument type (if there's no other types) in C

I reduced the size from 137 to 113 bytes

APL (Dyalog), 21 bytes
⎕CY'dfns'
∧/1pco⎕UCS⎕

Try it online!
Explanation
⎕CY'dfns' This allows us to use pco
⎕UCS⎕     Convert the characters in the input to its respective code points
1pco      pco with 1 as the left argument gives 1 iff the right argument is prime
          This is applied across the array of code points
∧/        Reduce by AND; return 1 if all elements are truthy, otherwise give false

Perl, 46 bytes
45 bytes code + 1 for -p.
$_=y///c==grep!/^(11+?)\1+$/,map"1"x ord,/./g

Try it online! (-l added to run all tests at once)

R, 42 bytes
all(pracma::isprime(utf8ToInt(scan(,''))))

Reads from stdin, requires the pracma (practical math) package to be installed. Checks if all the UTF-8 encoding of the characters are prime. Unfortunately, this won't work on TIO...
Try it online!

Mathematica, 30 bytes
And@@PrimeQ@ToCharacterCode@#&

Quite self-explanatory.

QBIC, 28 bytes
[_l;||q=q*µasc(_sA,a,1)]?q=0

This prints -1 for non-prime strings, and 0 for prime ones. That is opposite to QBasic's usual approach to true/false, but this is the shortest way t comply with the 'consistent values' criterium. Output would otherwise be 0 or 1/-1.
Explanation
[    |          FOR a = 1 to
 _l |             the length of
   ;              A$ (read from the cmd line)
q=q*            Multiply q (which starts as 1) by
µ                -1 if the following is prime, 0 otherwise:
 asc(       )   take the ASCII value of
     _sA,a,1      a substring of A$, starting at pos a, for 1 char
]               NEXT
?q=0            If we've tested all chas in the string, print -1 if q=0
                and we've found a non-prime, or a 0 for prime strings

Mathematica, 36 bytes
FreeQ[PrimeQ@ToCharacterCode@#,1<0]&

Try it online!
-2 bytes from @JungHwanMin

-2 bytes: FreeQ[PrimeQ@ToCharacterCode@#,1<0]&

C# (.NET Core), 60 bytes
s=>s.All(i=>Enumerable.Range(2,(int)i-2).All(j=>((int)i)%j))

You need to include using System.Linq; into your byte count here.


text:
Randomly select a character, plinko-style
Let's see how good your language of choice is at selective randomness.
Given 4 characters, A, B, C, and D, or a string of 4 characters ABCD as input, output one of the characters with the following probabilities:

A should have a 1/8 (12.5%) chance to be chosen
B should have a 3/8 (37.5%) chance to be chosen
C should have a 2/8 (25%) chance to be chosen
D should have a 2/8 (25%) chance to be chosen

This is in-line with the following Plinko machine layout:
   ^
  ^ ^
 ^ ^ ^
A B \ /
     ^
    C D

Your answer must make a genuine attempt at respecting the probabilities described. A proper explanation of how probabilities are computed in your answer (and why they respect the specs, disregarding pseudo-randomness and big numbers problems) is sufficient.
Scoring
This is code-golf so fewest bytes in each language wins!

Can we assume the built-in random function in our language of choice is random?

@Mr.Xcoder within reason, yes.

So, for clarity, the input is always exactly 4 characters, and it should assign probabilities to each in accordance with exactly the provided Plinko layout? Generating Plinko layouts or simulating them is entirely unnecessary as long as the probabilities are correct within the accuracy provided by your random source?

@KamilDrakari correct.

Not very useful due to its length, but I found out that the expression ceil(abs(i - 6)/ 2.0) will map an index from 0-7 to an index from 0-3 with the appropriate distribution (0 111 22 33) for this challenge...

Can I do a spin-off of this, potentially accepting a well-formed plinko machine to do the output?

@MagicOctopusUrn Provided it's different enough to not be dupe hammered, go for it!

Lean Mean Bean Machine, 55 43 42 bytes
-13 bytes thanks to Alex Varga
  O
  i
  ^
 ^ ^
\ ^ ^
 i / U
 ii
 ^
i U
U

Hope you guys don't mind me answering my own question after only 2 hours, but I highly doubt anybody else was planning on posting an answer in LMBM.
This literally just reflects the Plinko layout shown in the OP, flipped horizontally to cut down on unnecessary whitespace.

I don't know how to test this, but this might work: https://gist.github.com/anonymous/e537edc8c89a72f3631ef765b352b98d

@AlexVarga ooh that works

-1 byte: https://gist.github.com/anonymous/5ae3b2529f1d981ac3b320eb330f32e3

Jelly, 6 bytes
Ḋṁ7;ḢX

A monadic link taking a list of four characters and returning one with the probability distribution described.
Try it online!
How?
Ḋṁ7;ḢX - Link: list of characters, s  e.g. ABCD
Ḋ      - dequeue s                         BCD
 ṁ7    - mould like 7 (implicit range)     BCDBCDB
    Ḣ  - head s                            A
   ;   - concatenate                       BCDBCDBA
     X - random choice                     Note that the above has 1*A, 3*B, 2*C, and 2*D

Clever trick with the ṁ!

Cubix, 39 24 22 21 19 bytes
.<.^iD>D|@oioi.\i;U

View in the online interpreter!
This maps out to the following cube net:
    . <
    . ^
i D > D | @ o i
o i . \ i ; U .
    . .
    . .

Random Distribution Implementation Explanation
Cubix is a language in which an instruction pointer travels around the faces of a cube, executing the commands it encounters. The only form of randomness is the command D, which sends the IP in a random direction: an equal chance of 1/4 each way.
However, we can use this to generate the correct weighted probabilites: by using D twice. The first D has a 1/4 of heading to a second D. This second D, however, has two directions blocked off with arrows (> D <) which send the instruction pointer back to the D to choose another direction. This means there are only two possible directions from there, each with a 1/8 overall chance of happening. This can be used to generate the correct character, as shown in the diagram below:

(Note that, in the actual code, the arrow on the right is replaced with a mirror, |)
Code Explanation
        . <
        . ^
IP> i D > D | @ o i
    o i . \ i ; U .
        . .
        . .

The instruction pointer starts on the right, at the character i, facing right. It executes this i, taking the first character as input, and then moves onto the D, beginning the random process shown above.

Char A: In the case that the first D sends us east, and the second south, we need to print character A. This is already on stack from the first i. The following is executed:

\ - Reflect the IP so it heads east
i; - Take an input, then pop it again (no-op)
U - Perform a U-turn, turning the IP left twice
o - Output the TOS, character A
@ - Terminate the program

Char B: If either the first or second D head north, we need to generate character B, which will be the next input. Both paths execute the following commands:

^ - Head north
< - Head west, wrapping round to...
i - Take another input, character B
o - Output the TOS, character B
; - Pop the TOS
@ - Terminate the program

Char C: If the first D sends us west, the following is executed:

i - Take another input, character B
i - Take another input, character C
o - Output TOS, character C
@ - Terminate the program

Char D: If the first D sends us south, the following is executed:

i - Take another input, character B
.. - Two no-ops
i - Take another input, character C
| - This mirror reflects east-west, but the IP is heading north, so we pass through it.
^ - This joins up with the path taken for character B. However, because we have taken two inputs already, the fourth character (character D) will end up being printed.

This is spectacular! I can't believe you managed to fit the proper probabilities and all four paths on a size-2 cube. I wonder if I can subscribe to a feed of Cubix answers so I don't miss them...

@ETHproductions Thank you, I'm sure there's a way to cut off a byte or two, but I'm also quite proud of this answer :)

Python, 50 bytes
lambda x:choice(x[:2]+x[1:]*2)
from random import*

An unnamed function taking and returning strings (or lists of characters).
Try it online!
How?
random.choice chooses a random element from a list, so the function forms a string with the correct distribution, that is, given "ABCD", "ABCD"[:2] = "AB" plus "ABCD"[1:]*2 = "BCD"*2 = "BCDBCD" which is "ABBCDBCD".

I found a way to golf my solution and then realised it's identical to yours, just in reverse order :/

R, 31 bytes
sample(scan(,''),1,,c(1,3,2,2))

Reads the characters from stdin separated by spaces. sample draws random samples from its first input in quantity of the second input (so 1), (optional replacement argument), with weights given by the last argument.
Try it online!
Try it n times!
For the latter code, I sample n times (set n in the header) with replacement set to True (it's false by default), tabulate the results, and divide by n to see the relative probabilities of the inputs.

PHP, 28 bytes
<?=$argn[5551>>2*rand(0,7)];

Run as pipe with -nR.
01112233 in base-4 is 5551 in decimal ...

108 possible values with the same length ... 7030 is among my personal favorites.

APL, 14 bytes
(?8)⊃1 3 2 2\⊢

Input as a string.
How?
1 3 2 2\⊢ - repeat each letter x times ('ABCD' → 'ABBBCCDD')
⊃ - take the element at index ..
(?8) - random 1-8

Would you mind reviewing my J answer and letting me know if it can be improved?

17 bytes

@Uriel Try it online!

@Uriel There is no such encoding. Either you go full UTF-8, or you count every character as two bytes (UTF-16), or you add 5 bytes for ⎕U2378.

@Adám oh, I see. then get Dyalog to replace some of these unneeded European accented letters for the new symbols, to save bytes! ;)

@Uriel Actually, Geoff suggested building me such a golfing version. But then it wouldn't be a publicly available language, and thus it would disqualify. However, we could make a thin cover which just substitutes ö§Öçî for ⍤⌸⍠⊆⍸…

Java 8, 53 44 bytes
s->s[-~Math.abs((int)(Math.random()*8)-6)/2]

This is a Function<char[], Character>.
Try it online! (this test program runs the above function 1,000,000 times and outputs the experimental probabilities of choosing A, B, C, and D).
The general idea here is to find some way to map 0-7 to 0-3, such that 0 appears 1/8 times, 1 appears 3/8 times, 2 appears 2/8 times, and 3 appears 2/8 times. round(abs(k - 6) / 2.0)) works for this, where k is a random integer in the range [0,8). This results in the following mapping:
k -> k - 6 -> abs(k-6) -> abs(k-6)/2 -> round(abs(k-6)/2)

0 -> -6 -> 6 -> 3   -> 3
1 -> -5 -> 5 -> 2.5 -> 3
2 -> -4 -> 4 -> 2   -> 2
3 -> -3 -> 3 -> 1.5 -> 2
4 -> -2 -> 2 -> 1   -> 1
5 -> -1 -> 1 -> 0.5 -> 1
6 -> 0  -> 0 -> 0   -> 0
7 -> 1  -> 1 -> 0.5 -> 1

Which, as you can see, results in the indices 0 111 22 33, which produces the desired probabilities of 1/8, 3/8, 2/8 and 2/8.
But wait! How in the world does -~Math.abs(k-6)/2 achieve the same result (again, where k is a random integer in the range [0,8])? It's pretty simple actually... (x+1)/2 (integer division) is the same thing as round(x/2), and x + 1 is the same thing as -~x. Although x+1 and -~x are the same length, in the above function it is better to use -~x since it -~ takes precedence and thus does not require parenthesis.

I know it's been a while, but you can golf two bytes by changing the placement of the integer-cast (since Math.abs also accepts doubles as parameter): s->s[-~(int)Math.abs(Math.random()*8-6)/2] (42 bytes).

Pyth, 8 7 bytes
O+@Q1t+

Uses the exact same algorithm as in my Python answer.
Try it here!
Pyth, 10 8 bytes
O+<Q2*2t

Uses the exact same algorithm as is Jonathan Allan's Python answer.
Try it here!

Explanation

O - Takes a random element of the String made by appending (with +):

<Q2 - The first two characters of the String.
*2t Double the full String (*2) except for the first character (t).

Applying this algorithm for ABCD:

<Q2 takes AB.
*2t takes BCD and doubles it: BCDBCD.
+ joins the two Strings: ABBCDBCD.
O takes a random character.

-2 thanks to Leaky Nun (second solution)
-1 thanks to mnemonic (first solution)

>Q1 becomes tQ, which becomes t.

You can save a byte on the second solution by replacing *2 with + and using the implicit input twice.

@Mnemonic Thanks, I think I have’t used it because I thought of y instead, which doesn’t work for strings...

Charcoal, 11 bytes
‽⟦εεζζηηηθ⟧

Try it online! Link is to verbose version of code, although you hardly need it; ‽ picks a random element, ⟦⟧ creates a list, and the variables are those that get the appropriate input letters (in reverse order because I felt like it).

Jelly, 8 bytes
122b4⁸xX

Try it online!
Remove the X to see "ABBBCCDD". The X chooses a random element.

C# (.NET Core), 76 55 bytes
s=>(s+s[1]+s[1]+s[2]+s[3])[new System.Random().Next(8)]

Try it online!
My first answer written directly on TIO using my mobile phone. Level up!
Explanation: if the original string is "ABCD", the function creates the string "ABCDBBCD" and takes a random element from it.

Your program should take the characters as input from STDIN

@Mayube fixed, though it may still be golfed...

Javascript 35 bytes
Takes a string ABCD as input, outputs A 1/8th of the time, B 3/8ths of the time, C 1/4th of the time, and D 1/4th of the time.
x=>x[5551>>2*~~(Math.random()*8)&3]

Explanation
x=>x[                     // return character at index
    5551                  // 5551 is 0001010110101111 in binary
                          // each pair of digits is a binary number 0-3
                          // represented x times
                          // where x/8 is the probability of selecting
                          // the character at the index
    >>                    // bitshift right by
    2 *                   // two times
    ~~(                   // double-bitwise negate (convert to int, then
                          // bitwise negate twice to get the floor for
                          // positive numbers)
        Math.random() * 8 // select a random number from [0, 8)
    )                     // total bitshift is a multiple of 2 from [0, 14]
    &3                    // bitwise and with 3 (111 in binary)
                          // to select a number from [0, 3]
]

><>, 25 22 19 bytes
i_ixio;o
ox</;
;\$o

Try it online!, or watch it at the fish playground!
A brief overview of ><>: it's a 2D language with a fish that swims through the code, executing instructions as it goes. If it reaches the edge of the code, it wraps to the other side. The fish starts in the top left corner, moving right. Randomness is tricky in ><>: the only random instruction is x, which sets the fish's direction randomly out of up, down, left and right (with equal probability).
At the start of the program, the fish reads in two characters of input with i_i (each i reads a character from STDIN to the stack, and _ is a horizontal mirror, which the fish ignores now). It then reaches an x.
If the x sends the fish rightwards, it reads in one more character (the third), prints it with o and halts with ;. The left direction is similar: the fish reads two more characters (so we're up to the fourth), wraps around to the right, prints the fourth character and halts. If the fish swims up, it wraps and prints the second character, before being reflected right by / and halting. If it swims down, it gets reflected left by the / and hits another x.
This time, two directions just send the fish back to the x (right with an arrow, <, and up with a mirror, _). The fish therefore has 1/2 chance of escaping this x in each of the other two directions. Leftwards prints the top character on the stack, which is the second one, but downwards first swaps the two elements on the stack with $, so this direction prints the first character.
In summary, the third and fourth characters are printed with probability 1/4 each; the first character has probability 1/2 x 1/4 = 1/8; and the second character has probability 1/4 + 1/2 x 1/4 = 3/8.

05AB1E, 5 bytes
¦Ćì.R

Try it online!
Explanation
¦Ćì.R   Argument s                      "ABCD"
¦       Push s[1:]                      "BCD"
 Ć      Enclose: Pop a, Push a + a[0]   "BCDB"
  ì     Pop a, Concatenate a and s      "ABCDBCDB"
   .R   Random pick

05AB1E, 8 bytes
ìD1è0ǝ.R

Try it online!
         # Implicit input                            | [A,B,C,D]
ì        # Prepend the input to itself               | [A,B,C,D,A,B,C,D]
 D1è     # Get the second character                  | [A,B,C,D,A,B,C,D], B
    0ǝ   # Replace the first character with this one | [B,B,C,D,A,B,C,D]
      .R # Pick a random character from this array   | D

MATL, 12 10 bytes
l3HHvY"1Zr

Try it online! Or run it 1000 times (slightly modified code) and check the number of times each char appears.
Explanation
l3HH   % Push 1, 3, 2, 2
v      % Concatenate all stack contents into a column vector: [1; 3; 2; 2]
Y"     % Implicit input. Run-length decode (repeat chars specified number of times)
1Zr    % Pick an entry with uniform probability. Implicit display

Changes in modified code: 1000:"Gl3HH4$vY"1Zr]vSY'

1000:"...] is a loop to repeat 1000 times.
G makes sure the input is pushed at he beginning of each iteration.
Results are accumulated on the stack across iterations. So v needs to be replaced by 4$v to concatenate only the top 4 numbers.
At the end of the loop, v concatenates the 1000 results into a vector, S sorts it, and Y' run-length encodes it. This gives the four letters and the number of times they have appeared.

Yep, looks to be fixed now

@Mayube Thanks for noticing!

C (gcc), 50 49 bytes
i[8]={1,1,1,2,2,3,3};f(char*m){m=m[i[rand()%8]];}

Try it online!

ABCD is example input, your code should take 4 characters (or a string of length 4) as input

34 bytes

05AB1E, 6 bytes
«À¨Ć.R

Try it online!
Explanation
Works for both lists and strings.
«       # concatenate input with itself
 À      # rotate left
  ¨     # remove the last character/element
   Ć    # enclose, append the head
    .R  # pick a character/element at random

Ruby, 34 33 29 27 bytes
Saved 2 bytes thanks to @Value Inc
Input as four characters
a=$**2
a[0]=a[1]
p a.sample

construct an array [B,B,C,D,A,B,C,D] and sample it.
try it online!
try it n times! (I converted it to a function to repeat it more easily, but the algorithm is the same)

$* is an alias for ARGV.

Javascript, 31 30 bytes / 23 bytes
Seeing asgallant's earlier Javascript answer got me to thinking about JS. As he said:

Takes a string ABCD as input, outputs A 1/8th of the time, B
  3/8ths of the time, C 1/4th of the time, and D 1/4th of the time.

Mine is:
x=>(x+x)[Math.random()*8&7||1]

Explanation:
x=>(x+x)[                 // return character at index of doubled string ('ABCDABCD')
         Math.random()*8  // select a random number from [0, 8]
         &7               // bitwise-and to force to integer (0 to 7)
         ||1              // use it except if 0, then use 1 instead
        ]

From Math.random()*8&7 it breaks down as follows:
A from 4      = 12.5% (1/8)
B from 0,1,5  = 37.5% (3/8)
C from 2,6    = 25%   (1/4)
D from 3,7    = 25%   (1/4)

Version 2, 23 bytes
But then thanks to Arnauld, who posted after me, when he said:

If a time-dependent formula is allowed, we can just do:

which, if it is indeed allowed, led me to:
x=>(x+x)[new Date%8||1]

in which new Date%8 uses the same break-down table as above.
And %8 could also be &7; take your pick. Thanks again, Arnauld.

Pyth, 7 bytes
@z|O8 1

Test suite
O8 generates a random number from 0 to 7. | ... 1 applies a logical or with 1, converting the 0 to a 1 and leaving everything else the same. The number at this stage is 1 2/8th of the time, and 2, 3, 4, 5, 6, 7 or 8 1/8 of the time.
@z indexes into the input string at that position. The indexing is performed modulo the length of the string, so 4 indexes at position 0, 5 at position 1, and so on.
The probabilities are:

Position 0: Random number 4. 1/8 of the time.
Position 1: Random number 0, 1 or 5. 3/8 of the time.
Position 2: Random number 2 or 6. 2/8 of the time.
Position 3: Random number 3 or 7. 2/8 of the time.

ngn/apl, 10 bytes
⎕a[⌈/?2 4]
?2 4 chooses randomly a pair of numbers - the first among 0 1 and the second among 0 1 2 3
⌈/ is "max reduce" - find the larger number
⎕a is the uppercase alphabet
[ ] indexing

note the chart for max(a,b) when a∊{0,1} and b∊{0,1,2,3}:
    ┏━━━┯━━━┯━━━┯━━━┓
    ┃b=0│b=1│b=2│b=3┃
┏━━━╋━━━┿━━━┿━━━┿━━━┫
┃a=0┃ 0 │ 1 │ 2 │ 3 ┃
┠───╂───┼───┼───┼───┨
┃a=1┃ 1 │ 1 │ 2 │ 3 ┃
┗━━━┻━━━┷━━━┷━━━┷━━━┛

if a and b are chosen randomly and independently, we can substitute 0123=ABCD to get the desired probability distribution

Python 3, 64 55 51 bytes
-9 bytes thanks to @ovs
lambda s:choice((s*2)[1:]+s[1])
from random import*

Try it online!

Explanation
random.choice() gets a random character of the String, while (s*2)[1:]+s[1] creates BCDABCDB for an input of ABCD, which has 1/8 As, 2/8 Cs, 2/8 Ds and 3/8 Bs.

Use random.choice for 55 bytes: lambda s:choice((s[0]+s[1:]*3)[:8])

@ovs Found a shorter way ^. Thanks for the choice() though.

Mathematica, 25 bytes
RandomChoice@{##,##2,#2}&

input

["A", "B", "C", "D"]

-23 bytes from @MarkS!

The argument idea is very nice, but you don't need to introduce a random integer or use the byte-heavy StringTake. RandomChoice[{##,##2,#2}]&  works in 26 bytes.

Whoops, I should have used @ to save a byte: RandomChoice@{##...

QBIC, 27 bytes
?_s;+;+B+B+;+C+;+D,_r1,8|,1

Explanation
?           PRINT
 _s         A substring of
   ;+       A plus
   ;+B+B+   3 instances of B plus
   ;+C+     2 instances of C plus
   ;+D      2 instances of D plus
   ,_r1,8|  from position x randomly chosen between 1 and 8
   ,1       running for 1 character

><>, 56 bytes
v
!

"
D
C
B
A ;
" o
! @
! ^<
x!^xv!
@  v<
@  o
o  ;
;
o

Try it online!

Chip, 60 bytes
)//Z
)/\Z
)\/^.
)\x/Z
)\\\+t
|???`~S
|z*
`{'AabBCcdDEefFGghH

Try it online!
The three ?'s each produce a random bit. On the first cycle, these bits are run through the switches above (/'s and \'s) to determine which value we are going to output from this table:
000 a
01_ b
0_1 b
10_ c
11_ d

(where _ can be either 0 or 1). We then walk along the input as necessary, printing and terminating when the correct value is reached.
The big alphabetic blob at the end is copied wholesale from the cat program, this solution simply suppresses output and terminates to get the intended effect.

Java (OpenJDK 8), 40 38 bytes
s->s[5551>>2*(int)(Math.random()*8)&3]

Try it online!
5551 in base 10 is 01112233 in base 4. So let's randomly pick one of those base-4 digits using bit shift and selection, then pick the n-th character from the originating char[].

I've been outgolfed! I figured there was a way to do it with bitwise operators, but I don't really know much about them... Nice job!

@SocraticPhoenix Thank you! I figured the algorithms were different enough that I should make another answer. However, while I came up with this myself, I had not seen until this morning that the same idea had already been posted.

Ruby, 32 bytes
Pretty straightforward..?
->s{s[[0,1,1,1,2,2,3,3].sample]}

Try it online!

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%

Welcome to Programming Puzzles and Code Golf! We require submissions here to be golfed as much as possible at least trivially, so that includes removing unnecessary whitespace (I apologize if the whitespace here is necessary). Additionally, I'm not sure of the standards about Applesoft, but I don't believe you are allowed to assume that those operators are single-byte tokens unless the internal representation is a single byte. Also, you may not assume that the input is stored in a variable; rather, you must actually take it as input, a command line argument, or a function parameter. Thanks!

@HyperNeutrino None of the whitespace was necessary, although space after "INPUT" and "PRINT" would've improved readability. It did happen that in this antique cybertongue spaces were traditionally displayed in the places I had them. For the tokens I mentioned it is indeed true that "internal representation is a single byte". Meanwhile, I golfed the code I had down a byte.

Common Lisp, 198 bytes
(setf *random-state*(make-random-state t))(defun f(L)(setf n(random 8))(cond((< n 1)(char L 0))((and(>= n 1)(< n 4))(char L 1))((and(>= n 4)(< n 6))(char L 2))((>= n 6)(char L 3))))(princ(f "ABCD"))

Try it online!
Readable:
(setf *random-state* (make-random-state t))
(defun f(L)
    (setf n (random 8))
    (cond
            ((< n 1)
                (char L 0))
            ((and (>= n 1)(< n 4))
                (char L 1))
            ((and (>= n 4)(< n 6))
                (char L 2))
            ((>= n 6)
                (char L 3))
    )
)
(princ (f "abcd"))

braingasm, 17 bytes
4[,>]<4r<#z[2r>].

Works like this:
4[,>]<             Input 4 bytes from stdin and stay in cell 3 (0-indexed).
        <          Move left ...
      4r           ... randomly between 0 (inclusive) and 4 (exclusive) times.
         #z[   ]   If we're at cell 0,
              >      move right ...
            2r       ... with 50% probability.
                .  Print the byte value of the cell.

Given the input ABCD, each character has 1/4 = 2/8 chance of being printed because of  4r, but if we selected A, we have 1/2 chance of printing B instead, giving A (1/4)/2 = 1/8 chance and B 1/4 + 1/8 = 3/8 chance.

J, 16 bytes
(1?8:){1 3 2 2&#

how?

1 3 2 2&# - copy the input elementwise, ie, 1 copy of A, 3 copies of B, etc, yielding the list ABBBCCDD
1?8: - choose 1 element at random from the list 0 1 2 3 4 5 6 7
{ - "From", ie, choose from ABBBCCDD the random index generated by 1?8:

Try it online!

looks pretty golfy to me. though I don't know much about J..

@Uriel thanks.  sorry i assumed you knew J since you know APL well....

just the basics, I mostly transpile from APL...

-1 byte: 1 3 2 2&#{~1?8:.

C, 106 bytes
int f(){int r=(int)random()%8;if(!r--)return 'A';if(--r-->0)if(r<2)return 'C';else return 'B';return 'D';}

Could you use the ternary operator ...?...:... to have only one return and drastically reduce your number of bytes?

q/kdb+, 15 13 bytes
Solution:
1?a[0],7#1_a:

Example:
q)1?a[0],7#1_a:"ABCD"
,"B"

Explanation:
This is pretty much a q version of the jelly solution. Create the list "ABCDBCDB" and then pick one item from it at random
Bonus:
Another q solution in 15 bytes, same style as the APL one:
1?(,/)1 3 2 2#'

A k version of this solution is 13 bytes:
1?,/1 3 2 2#'

CJam, 11 bytes
XZYY]q.*smR

Try it Online
XZYY]    e# add [1,3,2,2] to stack
q        e# add input string to stack
.*       e# element-wise multiply the two arrays. char * int in CJam = repeat character x times
s        e# flatten result to string
mR       e# pick random char from string

05AB1E, 9 bytes
•20åÝ•.Rè

Try it online!
•20åÝ•   # Push 33221110.
     .R  # Randomly selected index.
       è # Character at that index.

Octave, 30 28 bytes
@(S)S([1:4 2 2:4])(randi(8))

Try it online!
Previous answer:
@(S)S('ABBBCCDD'(randi(8))-64)

Try it online!
Input is taken as a string of 4 characters.
Explanation:
Instead of [1 2 2 2 3 3 4 4 ] we can write 'ABBBCCDD'-64 and randomly select one of indexes and use the index to extract the desired character from the string.

JavaScript (ES6), 25 bytes / 30 bytes
In both following versions, we're looking for two positive integers m and n such that n MOD (m + i) MOD 4 gives us results in [0...3] at the expected frequencies for i in [0...7].

Version 1, 25 bytes
If a time-dependent formula is allowed, we can just do:
s=>s[11%(new Date%8+2)%4]

This one is using n = 11 (smallest possible value of n) and m = 2.
i | 2 + i | 11 % (2 + i) | 11 % (2 + i) % 4
--+-------+--------------+-----------------
0 |     2 |            1 |                1
1 |     3 |            2 |                2
2 |     4 |            3 |                3
3 |     5 |            1 |                1
4 |     6 |            5 |                1
5 |     7 |            4 |                0
6 |     8 |            3 |                3
7 |     9 |            2 |                2

Demo

let f =

s=>s[11%(new Date%8+2)%4]

for(stat = {A:0, B:0, C:0, D:0}, i = 0; i < 80000; i++) {
  stat[f("ABCD")]++;
}
console.log(stat);

Version 2, 30 bytes
With the native JavaScript PRNG -- which generates a floating-point number in [0...1) -- we'd rather do:
s=>s[21%(Math.random()*8|8)%4]

Here, we use n = 21 and m = 8 because it allows us to do the addition and isolate the integer part at the same time with Math.random()*8|8.
i | 8 + i | 21 % (8 + i) | 21 % (8 + i) % 4
--+-------+--------------+-----------------
0 |     8 |            5 |                1
1 |     9 |            3 |                3
2 |    10 |            1 |                1
3 |    11 |           10 |                2
4 |    12 |            9 |                1
5 |    13 |            8 |                0
6 |    14 |            7 |                3
7 |    15 |            6 |                2

Demo

let f =

s=>s[21%(Math.random()*8|8)%4]

for(stat = {A:0, B:0, C:0, D:0}, i = 0; i < 80000; i++) {
  stat[f("ABCD")]++;
}
console.log(stat);

Bash, 52 bytes
f(){ c=$1$2$2$2$3$3$4$4;echo ${c:$(($RANDOM%8)):1};}

Usage exemple:
$ f a b c d
b
$ f a b c d
d
$ f a b c d
b
$ f a b c d
a

the space after { is mandatory.

on 100000 iterations : a:12.41% , b 37.65%, c 24.93%,  d 24,99% . with for i in $(seq 1 100000); do f a b c d ; done | awk '{ t[$1]++ } END { for(i in t){ print i " : " t[i];} }'

PowerShell, 64 bytes
$args|%{($_-replace '(^.)(.)',"`$1`$2`$2`$2$'")[(Get-Random)%8]}

Try it online!
It replaces the string abcd with abbbcdcd using regex witchcraft and then randomizes which of the eight characters it chooses.  The regex is expensive; it requires a backtick per grouping, so there may be a better method using recursive lookups.
Here's a quick explanation of the regex:
For input abcd the full match is ab, grouping $1 is 'a', grouping $2 is 'b', and $' (note quote, not backtick) returns everything after the full match.  Then, the pattern $1$2$2$2$' is substituted for the full match:  abcd goes to  $1$2$2$2$' + cd = abbbcdcd

TI-Basic, 25 bytes
sub(Ans,randInt(1,8),1
If int(2rand(Ans="A
"B

The characters should be taken as input.

Ok, fixed that.

Perl 5, 26 bytes
say((A..D,B..D,B)[rand 8])

Try it online!

SmileBASIC, 31 bytes
LINPUT S$N=RND(8)?S$[N+!N*2>>1]

Pick a number from 0 to 7, add 2 if it's 0, then divide by 2.

Thunno 2, 7 bytes
«¦/d×Jɼ

Try it online!
Explanation
«¦/d×Jɼ  # Implicit input
«¦/      # Push 1322
   d     # Cast to digits
    ×    # Multiply elementwise
     J   # Join into a string
      ɼ  # Choose a random character
         # Implicit output


text:
Find the Second Zero
Challenge
Given an integer in 32-bit two's complement format, return the index of the second least-significant zero digit in the binary representation, where an index of 0 represents the least significant bit, and an index of 31 represents the most significant bit.
If there is no second zero, you may return 0, any negative number, any falsy value, or report an error in a way that makes sense in your language.
You may use 1-indexing if you prefer, but the test cases below will use 0-indexing.
You may use unsigned integers if you prefer; if you do, then you must handle integers in the range [0, 2^32). If you use signed integers, you must handle integers in the range [-2^31, 2^31). The test cases here will use signed integers, but note that -x (signed) is 2^32 - x (unsigned).
Test Cases

0  (0b00)        -> 1
1  (0b001)       -> 2
10 (0b1010)      -> 2
11 (0b01011)     -> 4
12 (0b1100)      -> 1
23 (0b010111)    -> 5
-1 (0b11..11)    -> None
-2 (0b11..10)    -> None
-4 (0b11..00)    -> 1
-5 (0b11..1011)  -> None
-9 (0b11..10111) -> None
2^31-2 (0b0111..1110) -> 31

Scoring
This is code-golf, so the shortest answer in each language wins!

Can we use an unsigned integer instead?

Yes you may, as long as you then handle integers in the range [0, 2^32).

Sandbox for those who can see deleted posts

Are we taking the integer or the string 0b... as input?

You should take the integer as input. You may take the decimal representation as a string if you wish, but not the binary representation

If we take unsigned is there always a second zero, since they are not 32-bit, or are we to assume a 32-place limit?

@JonathanAllan I guess not, since I was corrected on my Jelly answer with 2^32-1 because I wasn't supposed to return 33.

@JonathanAllan Erik's answer is correct. I've updated the challenge spec to reflect that you should handle 32-bit integers whether you choose to take them as signed or unsigned

What should be the behavior of the code for 2^32-1=2147483647 as input?

@mdahmoune If you are taking signed integers, that number is outside the input range. If you are taking unsigned numbers, then that number is 0b1111...1111 (the signed equivalent being -1). Having no second zero, you should report an error. This is one of the given test cases.

May we return any of those results if the input has no second zero bit, or does it need to be a well-defined result?

You should stay consistent. I'll say you can return any non-positive integer as one of the options though

Python 2, 45 bytes
lambda n:[i for i in range(32)if n|1<<i>n][1]

Try it online!
Uses 0-indexing, unsigned numbers, and throws an error on no second zero.
Simply creates a list of indices of non-set bits, from lowest to highest, and returns the second entry.

Welcome to PPCG! Nice first post!

Thanks! I'm still really new to golfing trickery in Python, so I'm glad this code didn't get golfed down immediately.

Great :) what about n=2147483647?

@mdahmoune 2**31-1 should error out since its binary representation in 32 bits is 0b01111111111111111111111111111111, which doesn't have a second 0.  Unless I'm missing something...

JavaScript (ES6), 34 bytes
Returns a 0-based index, or -1 if no second zero is found.
n=>31-Math.clz32((n=~n^~n&-~n)&-n)

Test cases

let f =

n=>31-Math.clz32((n=~n^~n&-~n)&-n)

console.log(f(0))       // -> 1
console.log(f(1))       // -> 2
console.log(f(10))      // -> 2
console.log(f(11))      // -> 4
console.log(f(12))      // -> 1
console.log(f(23))      // -> 5
console.log(f(-1))      // -> None
console.log(f(-2))      // -> None
console.log(f(-4))      // -> 1
console.log(f(-5))      // -> None
console.log(f(-9))      // -> None
console.log(f(2**31-2)) // -> 31

Alternate expression
n=>31-Math.clz32((n=~n^++n&-n)&-n)

Recursive version, 42 bytes
Returns a 0-based index, or false if no second zero is found.
f=(n,p=k=0)=>n&1||!k++?p<32&&f(n>>1,p+1):p

How?
f=(n,p=k=0)=>                               // given n, p, k
             n&1||                          // if the least significant bit of n is set
                  !k++?                     // or this is the 1st zero (k was not set):
                       p<31&&               //   return false if p is >= 31
                             f(n>>1,p+1)    //   or do a recursive call with n>>1 / p+1
                                        :p  // else: return p

Test cases

f=(n,p=k=0)=>n&1||!k++?p<32&&f(n>>1,p+1):p

console.log(f(0))       // -> 1
console.log(f(1))       // -> 2
console.log(f(10))      // -> 2
console.log(f(11))      // -> 4
console.log(f(12))      // -> 1
console.log(f(23))      // -> 5
console.log(f(-1))      // -> None
console.log(f(-2))      // -> None
console.log(f(-4))      // -> 1
console.log(f(-5))      // -> None
console.log(f(-9))      // -> None
console.log(f(2**31-2)) // -> 31

Alternate version suggested by Neil, 41 bytes
Returns a 0-based index, or throws a too much recursion error if no second zero is found.
f=(n,c=1)=>n%2?1+f(~-n/2,c):c&&1+f(n/2,0)

41-byte recursive version: f=(n,c=1)=>n%2?1+f(~-n/2,c):c&&1+f(n/2,0)

Jelly, 7 bytes
|‘‘&~l2

Try it online!
It outputs something not in the range [1,31] if there isn't the second zero. This includes 32 33 and (-inf+nanj). I guess that makes some sense.
It calculates log(((x|(x+1))+1)&~x)/log(2).

-inf+nanj I didn't think that could even exist

It does not output (-inf+nanj) for an input of 2147483647 which has a binary representation of 31 1s, hence no second zero in 32-bit signed notation (this is why it's so much shorter than mine and Erik's answers).

Actually, when does it produce (-inf+nanj)?

...ah I think worked it out, you're using the signed option?

IA-32 machine code, 14 13 bytes
Hexdump:
F7 D1 0F BC C1 0F B3 C1 0F BC C9 91 C3

Disassembly listing:
0:  f7 d1                   not    ecx
2:  0f bc c1                bsf    eax,ecx
5:  0f b3 c1                btr    ecx,eax
8:  0f bc c1                bsf    ecx,ecx
b:  91                      xchg   eax, ecx
c:  c3                      ret

Receives input in ecx; output is in al. Returns 0 on error.
First of all, it inverts the input, so it can use the bit scan instructions to look for set bits. It looks for the least significant set bit, resets it, looks for least significant set bit again, and returns the result.
If the bit-scan instruction doesn't find any set bit, the Intel documentation says the output is undefined. However, in practice all processors leave the destination register unchanged in this case (as noted by Cody Gray, AMD documentation describes this behavior as mandatory).
So, there are the following cases:

No zero bits (binary 111...1): ecx is set to 0 by not and remains 0
One zero bit: ecx is set to 0 by btr and remains 0 after bsf
Two zero bits: ecx is set to the proper value by bsf

It is only Intel's documentation that says bit scans on 0 are undefined. AMD's documentation explicitly documents that the destination is unchanged. If you want to avoid this behavior, you would normally add the REP prefix to get either LZCNT or TZCNT, but that increases the byte count, which is naturally undesirable for code golf.

You're actually doing too much work here. The challenge doesn't require you to discriminate between the case where there are no zero bits and the case where there's only 1 zero bit. It allows you to return 0 (or any negative value) in both cases. So, although the 1-byte SALC+DEC is extremely clever, you can shave off a byte by just using whatever is in ECX as of the second BSF instruction. The only thing that requires is a 1-byte XCHG to get the result in EAX so it can be returned. In other words, not ecx; bsf eax, ecx; btr ecx, eax; bsf ecx, ecx; xchg eax, ecx; ret

Here's a "try it online" link for the above. Since you're using ECX as the input register, we need to tell GCC to use the fastcall calling convention.

Java (OpenJDK 8), 44 38 bytes
i->i.numberOfTrailingZeros(~i&-i-2)&31

Try it online!
Returns 0 if no second zero bit exists.

Java, ...  194 191     186 Bytes
static int f(int n){char[] c=Integer.toBinaryString(n).toCharArray();int j=0,o=2^32-2,i=c.length,l=i-1;if(n<0|n>o)return 0;for(;j<2&i>0;j+=c[--i]==48?1:0);if(j==2)return l-i;return 0;}

-159 Bytes for using smaller variable names and removing whitespace
-25 Bytes, after taking even shorter variables and thanks to @KevinCruijssen tips
-18 Bytes, more whitespaces, function name
-3 Bytes, thanks to @KevinCruijssen, shortening if condition
-5 Bytes, Thanks to @Arnold Palmer, @KevinCruijssen, shortening loop
Ungolfed
public static int getPosSecondZero2(int number){
    int overflow = 2^32-2;
    if(number < 0 || number > overflow){
        return 0;
    }
    String binaryString = Integer.toBinaryString(number);
    char[] binaryCharArray = binaryString.toCharArray();
    int count = 0;
    int idx = binaryCharArray.length;
    int length = binaryCharArray.length -1;
    while(count < 2 && idx>0){
        idx--;
        if(binaryCharArray[idx] == '0'){
            count++;
        }
    }
    if(count == 2)
        return length-idx;
    return 0;
}

Welcome to PPCG! There are quite a few things you can golf: static  can be removed; if(n<0||n>o){return 0;}can be if(n<0|n>o)return 0; (| instead of || and no brackets); bs, bsa, etc. can all be single characters (never use multi-byte variable/method names in code-golf); You can combine ints, like this: int o=2^32-2,c=0,i=x.length,l=i-1;. And there are some more things to golf. Tips for golfing in Java and Tips for golfing in all languages might be interesting to read. Again welcome, and enjoy your stay! :)

I think there are still a couple spaces you can remove in your variable declarations. Welcome! :)

@musicman523 Thanks, yeah fixed it. 194 for now :)

if(c[i]=='0'){j++;} can still be golfed to if(c[i]==48)j++; for -3 bytes :) EDIT: Or better yet: while(j<2&&i>0){i--;if(c[i]=='0'){j++;}} can be for(;j<2&i>0;j+=c[i--]==48?1:0); for -8 bytes.

Your 8 Byte suggestion will throw an ArrayOutOfBoundException, or I'm just too dense to implement it correctly :)

@0x45 I believe if you change @KevinCruijssen's code to for(;j<2&i>0;j+=c[--i]==48?1:0); it should work.  The error is coming from i being the length of the string, so initially you're trying to index past the bounds of the array.  If you do a pre-decrement (as shown in the updated snippet), then the first time you use it it will access c[c.length-1] like in your original code.

@ArnoldPalmer Ah, you're indeed right. I placed the -- incorrectly.. My bad, sorry 0x45.

Currently should fail most test cases:
The complete int range has to be supported -> the <0 and overflow? check has to be removed. 2^32-2 is the same as 2^30 which is 28 (^ is xor, not pow).
Integer#toBinaryString does not pad the string with leading zeros -> will fail iff the result would be any of the leading zeros.
Besides that the code can be further golfed: The whitespace in char[] c is not required.
One return statement with a ternary operator is shorter.
j+=c[--i]==48?1:0 can be replaced with j+=1-c[--i]/49. l=i-1 ... l-i could be replaced with l=i ... l+~i.

Example in Java8

Actually, j+=1-c[--i]/49 should be j+=~c[--i]&1.

Dyalog APL, 20 bytes
{2⊃(⍳32)/⍨~⌽⍵⊤⍨32⍴2}

Uses 1-indexing, throws INDEX ERROR in case of no second zero.
How?
⍵⊤⍨ - encode ⍵ as a
32⍴2 - binary string of length 32
⌽ - reverse
~ - negate (0→1, 1→0)
(⍳32)/⍨ - compress with the range 1-32 (leaving indexes of zeros)
2⊃ - pick the second element

You could save a lot of bytes using Where (⍸)

@TwiNight I use dyalog 14

TIO has Dyalog 16 if you need

Jelly, 13 bytes
B¬Ṛ;1,1ḣ32TḊḢ

Try it online!
Uses 1-indexing, gets unsigned integer as input. Returns 0 for not found.

This outputs 33 for the input 4294967295 (2^32-1, the 32-bit unsigned equivalent of -1)

@musicman523 Hmm, something smells fishy...

Jelly, 12 bytes
,4BUFḣ32¬TḊḢ

A monadic link, taking an integer, using the unsigned option and returning the 1-indexed result (returns 0 when none exists).
Try it online!
or
32Ḷ2*|€n⁸TḊḢ

Try that
How?
1.
,4BUFḣ32¬TḊḢ - Link: number, n   e.g. 14
,4           - pair with 4            [14,4]
  B          - to binary              [[1,1,1,0],[1,0,0]]
   U         - upend                  [[0,1,1,1],[0,0,1]]
    F        - flatten                [0,1,1,1,0,0,1]
     ḣ32     - head to 32             [0,1,1,1,0,0,1] (truncates the right if need be)
        ¬    - not (vectorises)       [1,0,0,0,1,1,0]
         T   - truthy indexes         [1,5,6]
          Ḋ  - dequeue                [5,6]
           Ḣ - head                   5
             -   if the dequeued list is empty the head yields 0

2.
32Ḷ2*|€n⁸TḊḢ - Link: number, n   e.g. 14
32Ḷ          - lowered range of 32    [ 0, 1, 2, 3, 4, 5, ...,31]
   2*        - 2 exponentiated        [ 1, 2, 4, 8,16,32, ...,2147483648]
     |€      - bitwise or for €ach    [15,14,14,14,30,46, ...,2147483662]
        ⁸    - chain's right argument 14
       n     - not equal?             [ 1, 0, 0, 0, 1, 1, ..., 1]
         T   - truthy indexes         [ 1, 5, 6, ..., 32]
          Ḋ  - dequeue                [ 5, 6, ..., 32]
           Ḣ - head                   5
             -   if the dequeued list is empty the head yields 0

x86_64 machine code, 34 32 bytes
Not sure if this is the right approach, quite a lot of bytes (turns out it is not):
31 c0 83 c9 ff 89 fa 83 e2 01 83 f2 01 01 d1 7f 09 ff c0 d1 ef eb ee 83 c8 ff 83 f8 1f 7f f8 c3

Try it online!
second_zero:
  # Set eax = 0
  xor  %eax, %eax
  # Set ecx = -1
  xor %ecx,%ecx
  not %ecx

  # Loop over all bits
Loop:
  # Get current bit
  mov %edi, %edx
  and $0x1, %edx
  # Check if it's zero and possibly increment ecx
  xor $0x1, %edx
  add %edx, %ecx
  # If ecx > 0: we found the position & return
  jg Return
  # Increment the position
  inc %eax
  # Shift the input and loop
  shr %edi
  jmp Loop

Fix:
  # If there's not two 0, set value to -1
  xor %eax,%eax
  not %eax

Return:
  # Nasty fix: if position > 31 (e.g for -1 == 0b11..11)
  cmp $31, %eax
  jg  Fix

  ret

Thanks @CodyGray for -2 bytes.

Looping through all of the bits is probably not the right approach, either for code golfing or for real world. The real breakthrough will be using one of the instructions that allow you to manipulate all 32 (or 64) bits at once, like BSF, BSR, POPCNT, BT, etc. Anatolyg has submitted a solution along these lines. I haven't yet determined if it can be beat. :-p

By the way, a potentially useful code-golfing trick to set a register to -1 is to OR it with -1. For example, or ecx, -1. That's 3 bytes, 1 byte shorter than XOR+NEG. This isn't a good trick when not golfing because it introduces a false read dependency on the destination register, but there you'd just use mov ecx, -1 and spend the 5 bytes.

8th, 149 bytes
2 base swap >s nip decimal s:len 32 swap n:- ( "0" s:<+ ) swap times s:rev null s:/ a:new swap ( "0" s:= if a:push else drop then ) a:each swap 1 a:@

Commented code
: f \ n -- a1 a2 n

  \ decimal to binary conversion
  2 base swap >s nip decimal

  \ 32bit formatting (padding with 0)
  s:len 32 swap n:- ( "0" s:<+ ) swap times

  \ put reversed binary number into an array
  s:rev null s:/

  \ build a new array with position of each zero
  a:new swap ( "0" s:= if a:push else drop then ) a:each

  \ put on TOS the position of the 2nd least least-significant zero digit
  swap 1 a:@
;

Usage and output
ok> : f 2 base swap >s nip decimal s:len 32 swap n:- ( "0" s:<+ ) swap times s:rev null s:/ a:new swap ( "0" s:= if a:push else drop then ) a:each swap 1 a:@ ;

ok> [0, 1, 10, 11, 12, 23, -1, -2, -4, -5, -9, 2147483646]

ok> ( dup . " -> " .  f . 2drop cr ) a:each
0 -> 1
1 -> 2
10 -> 2
11 -> 4
12 -> 1
23 -> 5
-1 -> null
-2 -> null
-4 -> 1
-5 -> null
-9 -> null
2147483646 -> 31

R, 66 bytes
w=which.min
x=strtoi(intToBits(scan()));w(x[-w(x)])*any(!x[-w(x)])

reads from stdin; returns 0 for no second zero and the place otherwise.
Try it online!

MMIX, 20 bytes (5 instrs)
xxd --jelly
00000000: 23ff0001 c00000ff 23ff0001 da00ff00  #”¡¢Ċ¡¡”#”¡¢ḷ¡”¡
00000010: fe010000                             “¢¡¡

Disassembly
sndz    ADDU $255,$0,1
        OR   $0,$0,$255     // x |= x + 1
        ADDU $255,$0,1
        SADD $0,$255,$0     // x = popcnt((x + 1) & ~x)
        POP  1,0

The algorithm is essentially the obvious "remove rightmost 0; figure out position of rightmost 0". The neat trick here is that I managed to do it without flipping all the bits first.