text:
Numbers divisible by the sum and product of their digits
Take a positive integer X. This number is part of the sequence we are interested in if the sum of all digits of X is a divisor of X, and if the product of all digits of X is a divisor of X.
For example, 135 is such a number because 1 + 3 + 5 = 9 which divides 135 = 9 * 15 and 1 * 3 * 5 = 15 which also divides 135.
This is sequence A038186 in the OEIS.
Your task: given an integer N, output the Nth positive integer with such properties.
Inputs and outputs

Numbers may be 0-indexed or 1-indexed; please indicate which one your answer use.

The input may be taken through STDIN, as a function argument, or anything similar.

The output may be printed to STDOUT, returned from a function, or anything similar.

Test cases
The test cases below are 1-indexed.
Input        Output

1            1
5            5
10           12
20           312
42           6912
50           11313

Scoring
This is code-golf, so the shortest answer in bytes wins.

would it be ok to print out each number as you calculate it up towards n=infinity?

@BlueEyedBeast No, you have to take an input and return the corresponding number.

When checking 10, is the product of its digits 0 or 1?

@george its product is 0.

Can I arbitrarily limit the range of the input if the upper limit of the range wouldn't be computed before the heat death of the universe anyways?

That is, my program could take 60 hours, or 60 millenia, to generate the output for input 20000, so can I limit the size of the list to like, 5000?

@cat There is no requirement in speed or memory. Your program can take ten years for input 1 on a supercomputer, as long as you can show that it would be correct on an infinitely quick machine with infinite memory.

05AB1E, 13 12 bytes
Thanks to Emigna for saving a byte!
µNNSONSP‚ÖP½

Explanation:
µ          ½   # Get the nth number for which the following holds:
  NSO          #   The sum of digits of the current number
     NSP       #   And the products of digits of the current number
 N      ‚ÖP    #   Divides the current number
               # If the nth number has been reached, quit and implicitly print N

Uses the CP-1252 encoding. Try it online!

µNNSONSP‚ÖP½ works as well doesn't it?

@Emigna Nice one! Thanks :)

Pyke, 14 bytes (non-competitive) (1-indexed)
~1IY'sB]im%X)@

Try it here!
My god what a lot of new features.
~1             -   infinite list of natural numbers
  IY'sB]im%X)  -  filter(^, V) - remove if any truthiness
   Y           -      digits(i)
    'sB]       -     [sum(^), product(^)]
        im%    -    map(^, %i)
           X   -   splat(^)
             @ - ^[input]

Of which are non-competitive

a bugfix in I where it would only check if the first item on the stack was truthy
digits - return a list of digits in the number
@ used to get the nth item of an infinite list

Of which were being used for the first time:

all of the above
infinite lists

Remove the last 2 bytes to get all of these numbers.

Jelly, 13 bytes
DµP;SðḍȦ
1Ç#Ṫ

1-based.
TryItOnline!
How?
DµP;SðḍȦ - Link 1, test a number
D        - convert to a decimal list
 µ       - monadic chain separation
   ;     - concatenate the
  P      -     product, and the
    S    -     sum
     ð   - dyadic chain separation
      ḍ  - divides n?
       Ȧ - all (i.e. both)

1Ç#Ṫ - Main link, get nth entry, 1-based: n
1 #  - find the first n matches starting at 1 of
 Ç   - the last link (1) as a monad
   Ṫ - tail (the ultimate result)

C#, 118 bytes
n=>{int x=0,c=0;for(;;){int s=0,p=1,i=++x;while(i>0){s+=i%10;p*=i%10;i/=10;}if((c+=p>0&&x%s+x%p<1?1:0)==n)return x;}};

Full program with ungolfed function and test cases:
using System;

public class Program
{
    public static void Main()
    {
        // x - output number
        // c - counter
        // s - sum
        // p - product
        // i - iterator
        Func<int,int>f= n=>
        {
            int x=0, c=0;
            for ( ; ; )
            {
                int s=0, p=1, i=++x;
                while (i > 0)
                {
                    s += i%10;
                    p *= i%10;
                    i /= 10;
                }
                if ( (c += p> 0&& x%s+x%p<1 ? 1 : 0) == n)
                    return x;
            }
        };

        // tests:
        Console.WriteLine(f(1));  //1
        Console.WriteLine(f(5));  //5
        Console.WriteLine(f(10)); //12
        Console.WriteLine(f(20)); //312
        Console.WriteLine(f(42)); //6912
        Console.WriteLine(f(50)); //11313
    }
}

for(int x=0,c=0;;) saves you 1 byte.

Perl 6, 44 bytes (0-indexed)
{grep({$_%%(.comb.sum&[*] .comb)},1..*)[$_]}

Explanation:
{                                          }  # A function, with an argument n (`$_`)
 grep(                           ,1..*)       # Filter the infinite list
      {$_                       }             # Check that the function's argument
         %%(                   )              # is divisible by
                     &                        # both:
            .comb.sum                         # - the sum of the digits
                      [*] .comb               # - the product of the digits
                                       [$_]   # Get the n-th value

Infinite lists ftw!

@joshua thanks, but those parens are necessary for the precedence. Also, using a weird symbol instead of * would mean more bytes.

Dangit I forgot to check if it had a Perl 6 answer before posting. Also I would (did) handle Failures by using //0 in the grep block.

@BradGilbertb2gills Don't hesitate to post a better version! I didn't use //0 because it's usually accepted in codegolf to print to stderr.

It was literally exactly the same except for //0

Jellyfish, 45 bytes
p
\Ai
\&
>(&]&|0
  <*&d
 &~bN
  10
 ( )/+
 /*

Try it online!
Explanation
This is by far the most elaborate (and also the longest) program I've written in Jellyfish so far. I have no idea whether I'll be able to break this down in an understandable manner, but I guess I'll have to try.
Jellyfish provides a fairly general iteration operator, \, which helps a lot with "finding the Nth something". One of its semantics is "iterate a function on a value until a separate test function gives something truthy" (in fact, the test function receives both the current and the last element, but we'll only make it look at the current element). We can use this to implement a "next valid number" function. Another overload of \ is "iterate a function on a starting value N times". We can use our previous function and iterate it on 0 N times, where N is the input. All of that is set up fairly concisely with this part of the code:
p
\Ai
\&
>     0

(The reasons why 0, the actual input to the resulting function, is over there are a bit complicated and I won't go into them here.)
The issue with all of this is, that we won't be passing the current value to the test function manually. The \ operator will do this for us. So we now have construct a single unary function (via compositions, hooks, forks and currying) which takes a number and tells us whether it's a valid number (i.e. one which is divided by its digit sum and digit product). This is fairly non-trivial when you can't refer to the argument. Ever. It's this beauty:
 (&]&|
  <*&d
 &~bN
  10
 ( )/+
 /*

The ( is a unary hook, which means that it calls the function below (f) on its input (the current value x), and then passes both of them to the test function to the right (g), that is it computes g(f(x), x).
In our case, f(x) is another composite function which obtains a pair with the digit product and digit sum of x. That means g will be a function that has all three values to check if x is valid.
We'll start by looking at how f computes the digit sum and digit product. This is f:
 &~b
  10
 ( )/*
 /+

& is also composition (but the other way round). ~ is currying so 10~b gives function that computes the decimal digits of a number, and since we're passing that to & from the right, that's the first thing that will happen to the input x. The remainder uses this list of digits to compute their sum and product.
To compute a sum, we can fold addition over it, which is /+. Likewise, to compute the product we fold multiplication over it with /*. To combine both of these results into a pair, we use a pair of hooks, ( and ). The structure of this is:
()g
f

(Where f and g are product and sum, respectively.) Let's try to figure out why this gives us a pair of f(x) and g(x). Note that the right hook ) only has one argument. In this case, the other argument is implied to be ; which wraps its arguments in a pair. Furthermore, hooks can also be used as binary functions (which will be the case here) in which case they simply apply the inner function only to one argument. So really ) on a single function g gives a function that computes [x, g(y)]. Using this in a left hook, together with f, we obtain [f(x), g(y)]. This, in turn is used in a unary context, which mean that it's actually called with x == y and so we end up with [f(x), g(x)] as required. Phew.
That leaves only one thing, which was our earlier test function g. Recall that it will be called as g([p, s], x) where x is still the current input value, p is its digit product and s is its digit sum. This is g:
  &]&|
  <*&d
    N

To test divisibility, we'll obviously use modulo, which is | in Jellyfish. Somewhat unusually, it take its right-hand operand modulo its left-hand operand, which means that the arguments to g are already in the right order (arithmetic functions like this automatically thread over lists, so this will compute the two separate moduli for free). Our number is divisible by both the product and sum, if the result is a pair of zeros. To check whether that's the case, we treat the pair as a list of base-2 digits (d). The result of this is zero, only when both elements of the pair are zero, so we can negate the result of this (N) to obtain a truthy value for whether both values divide the input. Note that |, d and N are simply all composed together with a pair of &s.
Unfortunately, that's not the full story. What if the digit product is zero? Division and modulo by zero both return zero in Jellyfish. While this may seem like a somewhat odd convention, it actually turns out to be somewhat useful (because we don't need to check for zero before doing the modulo). However it also means we can get a false positive, if the digit sum does divide the input, but the digit product is zero (e.g. input 10).
We can fix this by multiplying our divisibility result by the digit product (so if the digit product is zero it will turn our truthy value into a zero as well). It turns out to be simpler to multiply the divisibility result with the pair of product and sum, and extract the result from the product afterwards.
To multiply the result with the pair, we kinda need to get back at an earlier value (the pair). This is done with a fork (]). Forks are kinda like hooks on steroids. If you give them two functions f and g, they represent a binary function which computes f(a, g(a, b)). In our case, a is the product/sum pair, b is the current input value, g is our divisibility test, and f is the multiplication. So all of this computes [p, s] * ([p, s] % x == [0, 0]).
All that's left now is to extract the first value of this, which is the final value of the test function used in the iterator. This is as simple as composing (&) the fork with the head function <, which returns the first value of a list.

As the creator of Jellyfish, I approve this message. (Really, I would lose patience halfway through solving this challenge in Jellyfish.)

Actually, 20 bytes
Naive implementation of the sequence definition. Golfing suggestions welcome! Try it online!
u`;;$♂≈;Σ(%@π(%|Y`╓N

Ungolfing
         Implicit input n.
u        Increment n, so that we don't accidentally include 0 in the sequence.
`...`╓   Starting with x=0, return the first n+1 values of x where f(x) is truthy.
  ;;       Duplicate x twice.
  $♂≈      str(x) and convert each char (each digit) into an int. Call this digit_list.
  ;        Duplicate digit_list.
  Σ        Get sum(digit_list).
  (%       Get x % sum(digit_list), which returns 0 if sum is a divisor of x.
  @        Swap the other duplicate of digit_list to TOS.
  π        Get prod(digit_list).
  (%       Get x % prod(digit_list), which returns 0 if prod is a divisor of x.
  |        Get x % sum(digit_list) OR x % prod(digit_list).
  Y        Logical negate, which only returns 1 if both are divisors, else 0.
N        Return the last value in the list of x where f(x) is truthy,
          that is, the nth value of the sequence.

R, 132 115 bytes
New version thanks to @Billywob nice comments !
n=scan();b=i=0;while(i<n){b=b+1;d=strtoi(el(strsplit(c(b,""),"")));if(na.omit(c(!b%%sum(d)&!b%%prod(d),0)))i=i+1};b

Ungolfed :
n=scan()
b=i=0

while(i<n)
    b=b+1;
    d=strtoi(el(strsplit(c(b,""),""))) #Splitting the number into its digits

    if(na.omit(c(!b%%sum(d)&!b%%prod(d),0)))
        i=i+1
b

Since R behave strangley with NAs, I had to add the whole ifelse(is.na(...)) part!
Or use na.omit(...)

n=scan();b=i=0;while(i<n){b=b+1;d=strtoi(el(strsplit(c(b,""),"")));if(!b%%sum(d)&ifelse(is.na((p=!b%%prod(d))),F,p))i=i+1};b saves a few bytes by: el(...) instead of [[1]], using c(b,"") instead of paste(b),negating the logical expressions by ! instead of ==0 and skipping the curly brackets on the if statement. My guess is that there should be an easier way of handling the NA issue but couldn't figure out something clever.

Turns out we can circumvent it by appending a 0 to the expression evaluated in the if statement. However, this returns a warning when the product isn't equal to 0. n=scan();b=i=0;while(i<n){b=b+1;d=strtoi(el(strsplit(c(b,""),"")));if(na.omit(c(!b%%sum(d)&!b%%prod(d),0)))i=i+1};b

@Billywob Thanks a lot ! i didn't know about el(...) !

JavaScript (ES6), 72 bytes
k=>eval("for(n=0;(E=o=>n%eval([...n+''].join(o))!=0)`+`|E`*`||--k;)++n")

Demo
It tends to be slow for higher values, so I'm limiting it to 20 here.

let f =

k=>eval("for(n=0;(E=o=>n%eval([...n+''].join(o))!=0)`+`|E`*`||--k;)++n")

console.log(f(1));  // 1
console.log(f(5));  // 5
console.log(f(10)); // 12
console.log(f(20)); // 312

Brachylog, 22 bytes
:1yt
#>=.@e+:I*.@e*:J*

Try it online!
Explanation
:1y                    Evaluate the first N valid outputs to the predicate below given the
                         main input as input
   t                   The output is the last one

#>=.                  Output is a strictly positive integer
    @e+               The sum of its digits…
       :I*.           …multiplied by an integer I results in the Output
           @e*        The product of its digits…
              :J*     …multiplied by an integer J results in the Output

JavaScript (ES6), 78
n=>eval("for(i=0;n;!p|i%s|i%p||n--)[...++i+''].map(d=>(s-=d,p*=d),s=0,p=1);i")

Less golfed
n=>{
  for(i=0; n; !p|i%s|i%p || n--)
    s=0,
    p=1,
    [...++i+''].map(d=>(s-=d, p*=d));
  return i
}

Pyth, 18 bytes
e.f!.xs%LZsM*FBsM`

Try it online: Demonstration
Explanation:
e.f!.xs%LZsM*FBsM`ZZQ1   implicit variables at the end
e                        print the last number of the
 .f                 Q1   first Q (input) numbers Z >= 1, which satisfy:
                 `Z         convert Z to a string, e.g. "124"
               sM           convert each digits back to a number, e.g. [1, 2, 4]
            *FB             bifurcate with product, e.g. [[1, 2, 4], 8]
          sM                take the sum of each, e.g. [7, 8]
       %LZ                  compute the modulo of Z with each number, e.g. [5, 4]
      s                     and add both numbers, e.g. 9
    .x             Z        if an exception occurs (mod 0), use number Z instead
   !                        test, if this number is zero

Haskell, 94 85 72 71 bytes
([n|n<-[0..],(==)=<<map(gcd n)$[product,sum]<*>[read.pure<$>show n]]!!)

1-indexed.
Thanks to @Zgarb for saving 13 bytes!
Thanks to @nimi for saving a byte!

(==)=<<map(gcd n)$[sum k,product k] should save some bytes.

And while we're doing that, [sum k,product k] can be map($read.pure<$>show n)[sum,product].

One more byte: ([n|n<-[0..],(==)=<<map(gcd n)$[product,sum]<*>[read.pure<$>show n]]!!)

APL (Dyalog Unicode), 33 bytes
I followed an idea of @ngn when it comes to wrapping the function in some sort of a ⍣-based operation.
{1+⍣{0=+/((1∘⊥,×/)⍎¨⍕⍺)|⍺ ⍺}⍣⍵⊢0}

Explanation:
{1+⍣{0=+/((1∘⊥,×/)⍎¨⍕⍺)|⍺ ⍺}⍣⍵⊢0}
{1+⍣                        ⍣⍵⊢0}  ⍝ Execute the inner dfn until it returns one ⍵ times
                                   ⍝ and yield the last number it processed.
    {0=+/((1∘⊥,×/)⍎¨⍕⍺)|⍺ ⍺}       ⍝ 1 if ⍺ is divisible by sum and product of its digits.
                  ⍎¨⍕⍺             ⍝ digits of ⍺
              ,                    ⍝ a vector of...
               ×/                  ⍝ product of digits
           1∘⊥                     ⍝ sum of digits
                       |⍺ ⍺        ⍝ each modulo ⍺
     0=+/                          ⍝ both divisible?

Try it online!

27

I'm fairly certain this 25er works.

Could have saved 2 bites({}) by using ⎕ to get input instead of making it a dfn

Vyxal, 9 bytes
λ₍∑ΠḊA;ȯt

Try it Online!
Apparently there's a 10 byte 0-indexed version.
-3 bytes from Lyxal.

9 bytes. 10 bytes

MATL, 21 bytes
`@tFYAtswph\~?@]NG<]&

Long and inefficient...
Try it online!
How it works
`        % Do...while
  @      %   Push current iteration index (1-based)
  tFYA   %   Duplicate. Convert number to its digits
  ts     %   Duplicate. Sum of digits
  wp     %   Swap. Product of digits
  h\     %   Concatenate. Modulo. This gives a length-2 array
  ~?     %   If the two values are zero: we found a number in the sequence
    @    %     Push that number
  ]      %   End if
  NG<    %   True if number of elements in stack is less than input
]        % End do...while. If top of the stack is true: next iteration. Else: exit
&        % Specify only one input (top of stack) for implicit display

Python3, 134 80 Bytes
New version thanks to Flp.Tkc

t=input();h=k=0;p=int
def g(x,q=0,w=1):
    for i in x:X=p(x);I=p(i);q+=I;w*=I
    return w!=0and X%q+X%w<1
while h<p(t):k+=1;h+=g(str(k))

New code, I remembered a golfing way to do the factorial
f,t=lambda x:0**x or x*f(x-1),0
for i in str(f(int(input()))):t+=int(i)
print(t)

The code itself isn't very golf-like, more like brute force golf
def g(x):
    q=0;w=1;X=int(x)
    for i in x:I=int(i);q+=I;w*=I
    return (w!=0+ X%q==0and X%w==0)
t=input();h=k=0
while h<int(t):
    k+=1
    if g(str(k))is True:h+=1

g(x) is a function that returns True if x fits the criteria.

In the future, use <1 instead of ==0. You don't need the is True, the point of an if statement is to check whether the condition is true anyway. You can use Python 2's backtick shortcut for str/repr to shave some bytes. There's also a lot of unneeded whitespace here.

Also, you can use booleans as integer values: h+=g(str(k)) adds 1 if True, 0 if False.

@Flp.Tkc can you explain the backtick trick. I've tried to use it and it threw a syntax error

Doing (backtick)x(backtick) in Python 2 is the same is repr(x) or str(x) in Python 3 :)

@Flp.Tkc that only works in pre Python 3. It was removed in 3.0

Yep, I did say that both times I mentioned it.

@Flp.Tkc yes, but my solution is in Python3, not Python 2, so it wouldn't work

Let us continue this discussion in chat.

Python 2, 122 110 Bytes
def a(m,i=1,k=1):n=map(int,`i`);p=reduce(lambda x,y:x*y,n);k+=p and 1>i%sum(n)+i%p;return(k>m)*i or a(m,i+1,k)

1 indexed, you need to use a Python interpreter with a quite high recursion limit.

x86-16 machine code, 52 bytes
00000000: 33db 4351 8bc3 bf0a 0033 f6b1 0133 d2f7  3.CQ.....3...3..
00000010: f703 f291 f7e2 9142 e314 85c0 75ef 8bc3  .......B....u...
00000020: 33d2 f7f6 8bc3 85d2 7504 f7f1 85d2 5975  3.......u.....Yu
00000030: d1e2 cfc3                                ....

Listing:
33 DB       XOR  BX, BX         ; X = 0
        NUM_LOOP:
43          INC  BX             ; increment X
51          PUSH CX             ; save loop counter (N)
8B C3       MOV  AX, BX         ; AX = current X
        START_N:
BF 000A     MOV  DI, 10         ; DI = decimal divisor of 10
33 F6       XOR  SI, SI         ; SI = sum of digits
B1 01       MOV  CL, 1          ; CX = product of digits
        SPLIT_DIGITS:
33 D2       XOR  DX, DX         ; clear high word of dividend
F7 F7       DIV  DI             ; AX = quotient, DX = remainder
03 F2       ADD  SI, DX         ; SI = SI + digit
91          XCHG AX, CX         ; AX = running product, CX = quotient
F7 E2       MUL  DX             ; AX = AX * digit
91          XCHG AX, CX         ; CX = running product, AX = quotient
42          INC  DX             ; ZF = NZ (hacky)
E3 14       JCXZ END_N          ; if digit is a 0, end with Falsey
85 C0       TEST AX, AX         ; is quotient 0?
75 EF       JNZ  SPLIT_DIGITS   ; loop until it is
8B C3       MOV  AX, BX         ; AX = current X
33 D2       XOR  DX, DX         ; clear high word of dividend
F7 F6       DIV  SI             ; divide X by sum
8B C3       MOV  AX, BX         ; AX = current X
85 D2       TEST DX, DX         ; if sum remainder is 0 then Truthy (ZF = ZR)
75 04       JNZ  END_N          ; if not, end with Falsey (ZF = NZ)
F7 F1       DIV  CX             ; divide X by product
85 D2       TEST DX, DX         ; if product remainder is 0 then Truthy (ZF = ZR)
        END_N:
59          POP  CX             ; restore loop counter
75 D1       JNZ  NUM_LOOP       ; if falsey, keep looping and don't decrement counter
E2 CF       LOOP NUM_LOOP       ; otherwise decrement counter and loop
C3          RET                 ; return to caller

Callable function. Input N in CX, Output Nth positive integer in BX.
N of 50 is about 4 seconds on an IBM PC 5150:

Wonder, 33 bytes
@:^#0(!>@!(| %#0sum#0)%#0prod#0)N

Zero-indexed. Usage:
(@:^#0(!>@!(| %#0sum#0)%#0prod#0)N)9

Explanation
More readable:
@
  iget #0
    (fltr@
      not (or % #0 sum #0) % #0 prod #0
    ) N

Basically gets an infinite list of numbers divisible by its digital sum and product by filtering an infinite list of whole numbers through a predicate. Then the nth item is simply picked out of the list.

JavaScript (ES6), 70 bytes
k=(b,n=1,f=c=>n%eval([...n+''].join(c))!=0)=>f`+`|f`*`||--b?k(b,n+1):n

This turned out quite a bit like @Arnauld's answer, but recursion is apparently 2 bytes shorter. Works in Chrome, though it's very slow on inputs greater than 30 or so (50 takes 6 seconds).

C89, 381 226 195 170 169 bytes
1-indexed (same exact answers as in the challenge).
Assumes 4-byte (32 bit) int (most modern architectures).
I genuinely believe this can't go any shorter.
x,c,*b,m,t,i,a;g(n){for(b=malloc(0);c<n;b[c-1]=x++,t=1){char s[9];for(i=m=0;i<sprintf(s,"%d",x);m+=a,t*=a)a=s[i++]-48;b=m*t?x%m+x%t?b:realloc(b,4*++c):b;}return b[c-1];}

Function int g (int) leaks memory and accesses uninitialised memory once per call but doesn't segfault and returns the right number.
Full program that takes input in unary (./prog $(seq 1 10) for 10) with ungolfed (kinda):
x, c, * b, m, t, i, a;

g(n) {
 for (b = malloc(0); c < n; b[c - 1] = x++, t = 1) {
  char s[9];
  i = m = 0;
  for (; i < sprintf(s, "%d", x); m += a, t *= a) a = s[i++] - 48;
  b = m * t ? x % m + x % t ? b : realloc(b, 4 * ++c) : b;
 }
 return b[c - 1];
}

main (j) {
  printf("%d\n", g(--j));
}

Old answer:
C99, 381 bytes
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <stdlib.h>
#define U uint64_t
#define S size_t
S f(S n){U x=0;S c=1,l;U*b=malloc(sizeof(U));while(c<=n){char s[21];snprintf(s,20,"%"PRIu64,x);U m=0,t=1;l=strnlen(s,21);for(S i=0;i<l;i++){U a=(U)s[i]-48;m+=a,t*=a;}if(m*t?(!(x%m))&&(!(x%t)):0){b=realloc(b,sizeof(U)*++c);b[c-1]=x;}++x;}U o=b[n];free(b);return o;}

This can probably be golfed more.
Full program:
#include <stdio.h>
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>

bool qualifies (const uint64_t);
size_t       f (const size_t);

int main(const int argc, const char* const * const argv) {
  (void) argc;
  size_t arg = strtoull(argv[1], NULL, 10);
  uint64_t a = f(arg);
  printf("a: %" PRIu64 "\n", a);
  return 0;
}

bool qualifies (const uint64_t num) {
  char s[21];
  snprintf(s, 20, "%" PRIu64 "", num);

  uint64_t sum  = 0,
           mult = 1;
  size_t    len = strnlen(s, 400);

  for (size_t i = 0; i < len; i++) {
    uint64_t a = (uint64_t) s[i] - 48;
    sum += a, mult *= a;
  }

  //printf("sum: %" PRIu64 "\nmult: %" PRIu64 "\n", sum, mult);
  return sum * mult ? (! (num % sum)) && (! (num % mult)) : false;
}

size_t f (const size_t n) {
  uint64_t x = 0;
  size_t s_len = 1;
  uint64_t* nums = malloc(sizeof (uint64_t) * s_len);

  while (s_len <= n) {
    if (qualifies(x)) {
      ++s_len;
      //printf("len: %zu\n", s_len);
      nums = realloc(nums, sizeof (uint64_t) * s_len);
      nums[s_len - 1] = x;
    }
    ++x;
  }

  uint64_t o = nums[n];
  free(nums);
  return o;
}

https://tio.run/nexus/c-gcc-99-64#VVDRaoMwFH33KzJHS6LpUHFl7Dbb897GxCcnQ22kgRhLkjK34rd3UbfCLuHccO6Bc@693Iru2Gu7E8raryM3d4cn748zdi9FPTN73grFUY5OTrhNP@yVypAR39wRGWpxhhQ552hgEWSoYTGVkAc16yop@wZPwr7FOSHweRCS42bHnL45VBqZIolLMOqonUGLDU0i6q/817eX0zalA4EcdSyilsUgmbFaSa4mVUyg7bUzFs5T7CSIMJwiVMz5mEKUm/QBupBV1AasglG0uAvsM77Bw6ojZL2ef5aQx4ica6b5ErWm17BBGDYE6qLZxCUbYAxDBznqWV2oElrNOa4JaG5PWqEexotbAHWVUJh4Zw@5@t3JX@3R//eufOquFpMJ72eMo7klS0uTZRS5k3nj5Qc generates a few warnings, but it's equivalent. However, I think it's fine to use int for everything, since it's the default integer type.

@Dennis I'm not used to omitting headers and ignoring warnings outside of  C89, so I golf with all warnings enabled and as errors :P I'll rewrite in C89 though.

@Dennis Fixed :D

Julia, 81 bytes
n->(i=c=1;while c<n d=digits(i+=1);all(d.>0)&&i%sum(d)==i%prod(d)<1&&(c+=1)end;i)

This is an anonymous function that accepts an integer and returns an integer. To call it, give it a name. The approach is the obvious one: check every number until we've encountered n terms of the sequence. The all check is necessary to ensure we don't get a DivisionError from % when the product of the digits is 0.
Ungolfed:
function f(n)
    i = c = 1
    while c < n
        d = digits(i += 1)
        all(d .> 0) && i % sum(d) == i % prod(d) < 1 && (c += 1)
    end
    return i
end

Try it online! (includes all test cases)

You can save two bytes by assigning prod(d) to p or something and then replacing the all(d.>0) with p>0. And you can save another by moving the i%sum(d) onto the other side of the 1 i.e. p<1>i%sum(d).

C, 110 bytes
p;s;i;j;f(n){j=0;while(n){i=++j;p=1;s=0;do p*=i%10,s+=i%10;while((i/=10)>0);if(p>0&&j%p+j%s==0)--n;}return j;}

Ungolfed and usage:
p;s;i;j;
f(n){
 j=0;
 while(n){
  i=++j;
  p=1;
  s=0;
  do
   p*=i%10,   //product
   s+=i%10;   //sum
  while((i/=10)>0);
  //check if product is not zero since floating point exception
  if(p>0 && j%p + j%s == 0)--n;
 }
 return j;
}

int main(){
 int n;
 scanf("%d",&n);
 printf("\n%d\n", f(n));
}

Scala, 80 68 bytes
Stream from 1 filter{n=>val x=n+""map(_-48.0);n%x.sum+n%x.product<1}

Try it online!
0-indexed. Streams are not only infinite collections but also functions taking an Int and giving the element at that index.
Stream from 1             //Infinite stream starting at 1
  filter { n =>           //Filter each n according to this predicate:
    val x =               //List of digits
      n + ""              //Convert to string
        map(_ - 48.0);    //Turn each character into its corresponding number (as a double, so n%0 works later)
    n % x.sum +           //n modulo the sum of its digits
      n%x.product         //plus n modulo the product of its digits
      < 1                 //Make sure that's less than 1, i.e. both are 0
  }

Husk, 13 bytes
!f§Λ`¦o§eΠΣdN

Try it online!
Combinators good but combinators long :(
-1 byte from Leo in SE Chat.

APL (Dyalog Unicode), 2527 bytes
This even better answer curtesy of Adam
1+⍣{0=⍺|⍨(+/∧×/)⍎¨⍕⍺}⍣⎕⊢0

This is essentially the same just hcf is taken of the sum and product saving 2 bytes
1+⍣{0=∨/⍺|⍨(+/,×/)⍎¨⍕⍺}⍣⎕⊢0

Try it online!
⎕ ⍝ takes user input

{...}⍣n ⍵ ⍝ repeats the function n times

1∘+⍣{0=∨/⍺|⍨(+/,×/)⍎¨⍕⍺} ⍝ given a number repeatetly adds 1(1∘+) untill the condition is satisfied

{⍵|⍨(+/,×/)⍎¨⍕⍵} ⍝ converts numbers to a list of numbers and then take there sum and product and then take there reminder after dividing with the given number

∨/ ⍝ takes HCF of the list escecially checking if both the numbers are not zero

0= ⍝returs true if the hcf is zero

Golfs down the the same as this.

TIO link for you: Try it online!

Thunno 2 ct, 6 bytes
ƘçSpḊp

Try it online!
Explanation
ƘçSpḊp  # Implicit input, n
Ƙ       # nth positive integer, k, where:
 ç      #  Parallelly apply:
  S     #   Sum of digits of k
   p    #   Product of digits of k
    Ḋ   #  Is k divisible by them
     p  #  Both return true?
        # Implicit output

PHP, 96 bytes
Takes n as a command line argument.
Golfed
for(;$i<$argv[1];)!($p=array_product($d=str_split(++$j)))|$j%array_sum($d)||$j%$p?:$i++;echo $j;

Ungolfed
for (; $i < $argv[1];)                             // Loop until we've found the nth number as pass by command line
    !($p = array_product($d = str_split(++$j))) || // Split our current number into its digits and assign that to a variable, then assign the product of that array to another variable.
                                                   // As well, we're checking if the product equals 0, to prevent an error from trying to mod by 0 later. The condition short circuits before it happens.
    $j % array_sum($d) ||                          // Check if the sum of the array is a divisor
    $j % $p                                        // Check if the product is a divisor
    ?: $i++;                                       // Increment the number of found instances only if all conditions are met.
echo $j;                                           // Output to screen.

PowerShell v2+, 84 bytes
param($n)for(;$n){$n-=!(++$a%(($b=[char[]]"$a")-join'+'|iex)+$a%($b-join'*'|iex))}$a

Iterative solution. Takes input $n and enters a for loop so long as $n is not zero. Each iteration, we subtract from $n the result of a Boolean statement, broken out below:
!(++$a%(($b=[char[]]"$a")-join'+'|iex)+$a%($b-join'*'|iex))
!(                                                        ) # Encapsulate in a NOT
  ++$a%                                                     # Increment $a and take mod ...
        ($b=[char[]]"$a")                                   # Turn $a into char-array, store in $b
                         -join'+'                           # Join the char-array together with +
                                 |iex                       # and eval it
                                      $a%($b-join'*'|iex)   # Similar for *
                                     +                      # Addition

Thus, only if $a%(sum) and $a%(product) are both equal to zero will the addition also be zero, and thus the Boolean-not will be True and therefore $n is decremented.
Once we exit the loop (i.e., we hit the nth term), we simply place $a on the pipeline, and output is implicit.
Examples
Note: This tosses a bunch of "Attempted divide by zero" errors to STDERR, which is ignored by default. I've explicitly added a 2>$null to the example below to cleanup the output. It's also pretty slow once it gets to about 30 or so, and 50 takes about 45 seconds on my machine.
PS C:\Tools\Scripts\golfing> 1,5,10,20,30,42,50|%{"$_ --> "+(.\numbers-divisible-by-sum-and-product.ps1 $_ 2>$null)}
1 --> 1
5 --> 5
10 --> 12
20 --> 312
30 --> 1344
42 --> 6912
50 --> 11313

BASH, 125 bytes
while ((n<$1));do
((i++))
p(){ fold -1<<<$i|paste -sd$1|bc;}
z=`p \*`
((z))&&[ $[i%`p +`]$[i%z] -eq 0 ]&&((n++))
done
echo $i

Perl 5 -MList::Util=sum,product -p, 63 bytes
($\%sum(@a=++$\=~/./g)+$\=~/0/||$\%product@a)&&redo for 1..$_}{

Try it online!
1-indexed

Jelly, 11 bytes
DS,PƊḍ¹Ạµ#Ṫ

Try it online!
0-indexed
          Ṫ  get the last element after
        µ#   counting the first (input) elements where
       Ạ     all (both) are true:
     ḍ¹      the element is divisible by
 S,P         the sum, and the products of
D            the digits

Julia, 72 bytes
n->(i=c=1;while c<n d=digits(i+=1);c+=i%sum(d)<all(d.>0)>i%prod(d)end;i)

Try it online!
improvement over Alex A's answer (explanation there)


text:
Grid ASCII art code golf
Challenge
Create the shortest program that meets the requirements
Requirements

The code must generate a 5x5 grid of 0s, like so:
00000
00000
00000
00000
00000

The code must accept an input (column, row, character). The grid must change accordingly:
Start:
00000
00000
00000
00000
00000

Input:
(2,5,*)

Output:
0*000
00000
00000
00000
00000

(Note: the bottom-left corner is position 1,1.)
The program must return an error message other than the grid if the row/column input is not 1,2,3,4, or 5. This can be any message of your choice (as long as it's not the grid), so 0 is an acceptable error-output.
The program must work with all printable ASCII characters (of a US keyboard).

THE WINNER
The winner will be the person who has the shortest code and fulfills all requirements. If more than one answer works and has the same (shortest) length, the person who answered first will be the winner.

The program must return an error message. What error message? Can the program return 0 for error and the grid for success?

That is a great idea. By an error message I meant something that tells the user that their input was invalid, but your idea would work just fine.

Where is the origin on the matrix? does it need to be zero or one indexed?

The bottom most left corner is (1,1).

Welcome to PPCG, by the way.

he program must work with all characters on the US keyboard Why not just ASCII? I do not even know the characters of a US keyboard, and that doesn't add anything to the challenge

@LuisMendo I think the US keyboard is ASCII, or is at least a subset.

I will disregard the US keyboard requirement.

The program must return an error message if the row/column input is greater than 5 I suppose we must also throw an error for values lower than 1. But could you please edit your question to clarify this point?

@DaveJones Wouldn't if the row/column input is not 1, 2, 3, 4, or 5 be better?

yes. Sorry for the confusion.

Does it matter how we output the grid as long is it is correct and errors on bad input?

no, the method of output is arbitrary as long as it fulfills the specifications of the challenge

@ConorO'Brien  My keyboard has F1-F12 and arrow keys (whick generates multi character escape sequences) and Print Screen (which generates something that is NOT an ASCII character) - so it is a superset of ASCII.  I think we have to disregard the US keyboard requirement - otherwise my program actually needs to detect that the Print Screen or Pause key has been pressed and then which character should it stick in the grid?

@JerryJeremiah but those aren't characters on the US keyboard.

Wow, Turtlèd is going to have a good time here...

As I said above, if you need to, you can disregard the US keyboard requirement as long as it works for all ascii characters

Question says 'the code must generate a 5x5 grid of 0s', does that mean we need to output both the starting grid and the altered grid, or only the final grid?

You only need to output the final grid.

-1 Because of the cumbersome I/O format.

Dyalog APL, 17 13 10 bytes
Prompts for an enclosed array containing (row, column) and then for a character. Gives INDEX ERROR on faulty input.
⊖⍞@⎕⊢5 5⍴0

Try it online!
⊖ flip upside-down the result of
⍞ inputted-character
@ replacing the content at position
⎕ evaluated-input (enclosed row, column)
⊢ of
5 5⍴ 5×5 array of
0 zeros

Is ⊢ necessary? I think in this case it's redundant.

@ConorO'Brien @ConorO'Brien if it isn't there, the parser sees (⊂⎕)5 5 as a single 3-element array – the argument to ⍴.

That is 13 Unicode characters, not 13 bytes, isn't it?

@wilx Click on the word bytes!

This answer is the winner.

Ruby, 157 149 bytes
g=(1..5).map{[0]*5}
loop{puts g.map(&:join).join ?\n
x=gets.match /\((.),(.),(.)\)/
a,b=x[1].hex,x[2].hex
1/0 if a<1||a>5||b<1||b>5
g[5-b][a-1]=x[3]}

Error on malformed input or out of bound position
Thanks to ConorO'Brien (8 bytes) and afuous (2 bytes) for helping saving bytes

loop do...end -> loop{...}; I think Array.new(5,[0]*5) works, too, or even [*[0]*5]*5.

@ConorO'Brien Nope, Array.new(5,[0]*5) make an array of reference and [*[0]*5]*5 make a flat array

Oh, right. Omit the first *. Then that still creates an array of references.

Array.new(5){[0]*5} can be replaced with (1..5).map{[0]*5} to save 2 bytes.

Batch, 199 bytes
@echo off
if %1 gtr 0 if %1 lss 6 if %2 gtr 0 if %2 lss 6 goto g
if
:g
for /l %%j in (5,1,-1)do call:l %* %%j
exit/b
:l
set s=000000
if %2==%2 call set s=%%s:~0,%1%%%3%%s:~%1%%
echo %s:~1,5%

Errors out if the position is out of range.

I think you can use symbols for <, like ^<. not sure tho.

PHP, 111 100 97 bytes
$s=str_repeat("00000\n",5);$s[($x=($a=$argv)[1])+29-6*$y=$a[2]]=$a[3];echo$x&&$y&&$x<6&$y<6?$s:E;

prints E if row/column out of range.
Run with php -r <code> <row> <column> <character>

Python, 66 bytes
lambda a,b,n,l='00000\n':6>b>0<a<6and(5-b)*l+l[:a-1]+n+l[a:]+~-b*l

Won´t this fail for a=4,b=3?

@Titus not anymore ;D

Solution also works for Python3

Dyalog APL, 24 20 18 bytes
Saved 4 bytes thanks to Zgarb! Saved 2 bytes thanks to Adam!
a←5 5⍴0⋄a[⊂⎕]←⍞⋄⊖a

Prompts for input. See below for an explanation.

20 bytes
{a←5 5⍴0⋄a[⊂⍺]←⍵⋄⊖a}

Assign to a function and call it y x f 'c'. E.g.:
      f←{a←5 5⍴0⋄a[⊂⍺]←⍵⋄⊖a}

      5 2 f '*'
0 * 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

      6 6 f '*'
INDEX ERROR
     ←{a←5 5⍴0 ⋄ a[⊂⍺]←⍵ ⋄ ⊖a}
               ∧

      0 0 f '*'
INDEX ERROR
     ←{a←5 5⍴0 ⋄ a[⊂⍺]←⍵ ⋄ ⊖a}
               ∧

Explanation
{a←5 5⍴0⋄a[⊂⍺]←⍵⋄⊖a}

{...} is a function with left argument ⍺ and right argument ⍵. ⋄ separates statements, so there are three statements:
a←5 5⍴0⋄a[⊂⍺]←⍵⋄⊖a

The first statement a←5 5⍴0 sets a to a 5 by 5 grid of 0s.
The second statement sets the member at coordinates dictated by ⍺ to ⍵ (that is, the character).
Finally, we perform ⊖ on a and return that, yielding the firsts of a reversed.

{a←5 5⍴0⋄a[⊂⌽⍺]←⍵⋄⊖a} saves a few bytes.

@Zgarb Oh, fantastic! I didn't know indexing worked like that.

You can save two bytes by converting to a tradfn body: a←5 5⍴0⋄a[⊂⎕]←⍞⋄⊖a

@Adám how does that work? It doesn't seem to work on TryAPL.

@ConorO'Brien Right. TryAPL prohibits prompting for input, but you can get the full version for free.

JavaScript (ES6), 73 76 bytes
Throws a TypeError if the column or the row is out of range.
(c,r,C,a=[...`00000
`.repeat(5)])=>(a[29+c-r*6]=C,c<1|r<1|c>5|r>5||a).join``

Demo

let f =

(c,r,C,a=[...`00000
`.repeat(5)])=>(a[29+c-r*6]=C,c<1|r<1|c>5|r>5||a).join``

console.log(f(2,5,'*'));

Sweet, but does it throw an error if either c or r is less than 1?

@ETHproductions It's only testing c == 0 || r == 0. But I guess you're right: I will update it to prevent negative values.

C#, 199 Bytes
Based on Pete Arden's answer
string g(int c, int r, char a){if(c<1|c>5|r<1|r>5)return "Index Error";var b="00000";var d=new[]{b,b,b,b,b};c--;d[r-1]=new string('0',c)+a+new string('0',4-c);return string.Join("\r\n",d.Reverse());}

Ungolfed:
public static string G(int c, int r, char a)
    {
        if (c < 1 || c > 5 || r < 1 || r > 5) return "Index Error"; // Check it's not out of range
        var b = "00000";
        var d = new [] { b, b, b, b, b };                           // Generate display box, and fill with the default character
        c--;                                                        // Convert the X to a 0 based index
        d[r - 1] = new string('0',c) + a + new string('0',4-c);     // Replace the array's entry in y coordinate with a new string containing the new character
        return string.Join("\r\n", d.Reverse());                    // Reverse the array (so it's the right way up), then convert to a single string
    }

Welcome to the site! I'm not an expert in C#, but it looks like there's some whitespace you could remove.

(Sorry, don't know submission etiquette) Shorter G(): public static string G(int c,int r,char a){return(0<c&&c<6&&0<r&&r<6)?string.Concat(Enumerable.Range(1,29).Select(i=>i%6>0?i/6==5-r&&i%6==c?a:'0':'\n')):"Index Error";}

Brain-Flak 415 Bytes
Includes +3 for -c
([][()()()]){{}}{}({}<(({}<(({})<>)<>>)<>)<>([((((()()()){}){}){}){}]{}<([((((()()()){}){}){}){}]{})>)(()()()()()){({}[()]<(({})){{}(<({}[()])>)}{}({}<(({})){{}(<({}[()])>)}{}>)>)}{}({}{}){<>{{}}<>{}}<>>)<>(()()()()()){({}[()]<(((((((((()()()){}){}){}){})))))((()()()()()){})>)}{}{}<>({}<()((((((()()()){}){}()){}){}()[{}])({})({})({})({}){}{}[((((()()()){}){}){}){}()]){({}[()]<<>({}<>)>)}{}<>{}>)<>{({}<>)<>}<>

Try it Online!
Takes the character to insert first, then the row then column without spaces.
Most of this is just error handling. Brain-Flak doesn't have a good way to check if values are in a range. For errors, it either outputs nothing, or just the character that was supposed to be inserted. Solving the actual problem only takes 211 bytes:
<>(()()()()()){({}[()]<(((((((((()()()){}){}){}){})))))((()()()()()){})>)}{}{}<>({}<()((((((()()()){}){}()){}){}()[{}])({})({})({})({}){}{}[((((()()()){}){}){}){}()]){({}[()]<<>({}<>)>)}{}<>{}>)<>{({}<>)<>}<>

Jelly, 28 bytes
This feels way too long...
Ṫ0ẋ24¤;ṙÑs5UY
’ḅ5
Ṗḟ5R¤
-ÑÇ?

TryItOnline!
How?
Ṫ0ẋ24¤;ṙÑs5UY - Link 1, make grid: [row, column, character] e.g. [5,2,'*']
Ṫ             - tail: character                                  '*'
     ¤        - nilad followed by link(s) as a nilad
 0            -     zero
  ẋ           -     repeated
   24         -     24 times                                     [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
      ;       - concatenate:                                     "000000000000000000000000*"
        Ñ     - call next link (2) as a monad                    21
       ṙ      - rotate left by                                   "000*000000000000000000000"
         s5   - split into chunks of length 5                    ["000*0","00000","00000","00000","00000"]
           U  - upend (reveres each)                             ["0*000","00000","00000","00000","00000"]
            Y - join with line feeds                              0*000
              - implicit print                                    00000
                                                                  00000
’ḅ5 - Link 2, position: [row, column]                             00000
’   - decrement                                                   00000
 ḅ5 - convert from base 5

Ṗḟ5R¤ - Link 3, input error checking: [row, column, character]
Ṗ     - pop: [row, column]
 ḟ    - filter out values in
  5R¤ - range(5): [1,2,3,4,5] - any values not in this remain giving a truthy result

-ÑÇ? - Main link: [row, column, character]
   ? - ternary if:
  Ç  -    last link (3) as a monad
-    -    -1 (if truthy - the error identification)
 Ñ   - next link (1) as a monad (if falsey - the grid)

05AB1E, 27 22 bytes
Returns no grid when row/column > 5.
‚6‹Pi25L²<5*¹+Q5äR»1³‡

Try it online!
Previous version
‚6‹Pi26G¾5²<*¹+NQi\³}})5äR»

JavaScript (ES6), 89 bytes
f=(X,Y,Z,x=5,y=5)=>x+y>1?(x?X+x-6|Y-y?0:Z:`
`)+f(X,Y,Z,x?x-1:5,y-!x):X<1|X>5|Y<1|Y>5?e:""

Because I love recursion. Throws a ReferenceError on invalid coordinates.

Excel VBA, 67 Bytes
Outputs to the range A1:E5 on the activesheet of the vba project, exits with

Run-time error '1004':
Application-defined or object-defined error

when an invalid input is provided.
Code:
Sub a(c,r,x)
c=IIf(r<1Or c>5,-1,c)
[A1:E5]=0
Cells(6-r,c)=x
End Sub

Usage:
a 4,5,"#"

Output (from example above):
    A   B   C   D   E
1   0   0   0   #   0
2   0   0   0   0   0
3   0   0   0   0   0
4   0   0   0   0   0
5   0   0   0   0   0

Mathematica, 38 bytes
(x=Table[0,5,5];x[[-#2,#]]=#3;Grid@x)&

Octave 49 bytes
@(c,r,s)char(accumarray([6-r c],s+0,[5 5],[],48))

C#, 208 Bytes
Golfed:
string G(int c,int r,char a){if(c<1||c>5||r<1||r>5)return"Index Error";var b="00000";var d=new string[]{b,b,b,b,b};d[r-1]=d[r-1].Substring(0,c-1)+a+d[r-1].Substring(c);return string.Join("\r\n",d.Reverse());}

Ungolfed:
public string G(int c, int r, char a)
{
  if (c < 1 || c > 5 || r < 1 || r > 5) return "Index Error";
  var b = "00000";
  var d = new string[] { b, b, b, b, b };
  d[r - 1] = d[r - 1].Substring(0, c - 1) + a + d[r - 1].Substring(c);
  return string.Join("\r\n", d.Reverse());
}

Testing:
Console.Write(G(6, 6, '*')); //Index Error

Console.Write(G(1, 4, '#'));

00000
#0000
00000
00000
00000

Console.Write(G(5, 5, '@'));

0000@
00000
00000
00000
00000

Console.Write(G(1, 1, '}'));

00000
00000
00000
00000
}0000

If c and/or r are out of bounds it will throw an IndexOutOfRangeException so you might be able to remove the first if statement though I haven't checked the specs properly for that. You can compile to a Func<int, int, char, string> to save bytes, I believe you need to add using System.Linq; in because of the Reverse call though I can't remember off the top of my head

Change d[r - 1] = d[r - 1].Substring(0, c - 1) + a + d[r - 1].Substring(c); to d[--r] = d[r].Substring(0, c - 1) + a + d[r].Substring(c); to save 4 bytes

QBIC, 53 50 bytes
EDIT: Now that I know that I don't have to show the starting grid, I've swapped out the user inputs _!_!_? for command line parameters ::;, saving 3 bytes.
[5|?@00000|]::;~(b>5)+(c>5)>1|_Xd\$LOCATE 6-c,b|?B

Original version: This halts between printing the 0-grid and taking the coordinates for the substitution, showing the 0-grid.
[5|?@00000|]_!_!_?~(b>5)+(c>5)>1|_Xd\$LOCATE 6-c,b|?B

Prints 5 strings of 5 0's, asks user for 2 numerical inputs and 1 string input, checks if the numbers are < 5 and uses QBasic's LOCATE function to substitute the right character.

WinDbg, 95 bytes
j(0<(@$t0|@$t1))&(6>@$t0)&(6>@$t1)'f8<<16 L19 30;eb2000018+@$t0-@$t1*5 @$t2;da/c5 8<<16 L19';?0

Almost half of it just verifying the indexes are in range... Input is done by setting the psuedo-registers $t0, $t1, and $t2 (where $t2 holds the ascii value of the char to replace). For example, (2,5,*) like the example would be:
0:000> r$t0=2
0:000> r$t1=5
0:000> r$t2=2a

Prints 0 on error.
How it works:
j (0<(@$t0|@$t1)) & (6>@$t0) & (6>@$t1)  * If $t0 and $t1 are both positive and less than 6
'
    f 8<<16 L19 30;                      * Put 19 (0n25) '0's (ascii 30) at 2000000 (8<<16)
    eb 2000018+@$t0-@$t1*5 @$t2;         * Replace the specified cell with the new char
    da /c5 8<<16 L19                     * Print 19 (0n25) chars in rows of length 5
';
    ?0                                   * ...Else print 0

Sample Output:
0:000> r$t0=2
0:000> r$t1=5
0:000> r$t2=2a
0:000> j(0<(@$t0|@$t1))&(6>@$t0)&(6>@$t1)'f8<<16 L19 30;eb2000018+@$t0-@$t1*5 @$t2;da/c5 8<<16 L19';?0
Filled 0x19 bytes
02000000  "0*000"
02000005  "00000"
0200000a  "00000"
0200000f  "00000"
02000014  "00000"

0:000> r$t0=-2
0:000> j(0<(@$t0|@$t1))&(6>@$t0)&(6>@$t1)'f8<<16 L19 30;eb2000018+@$t0-@$t1*5 @$t2;da/c5 8<<16 L19';?0
Evaluate expression: 0 = 00000000

0:000> r$t0=4
0:000> r$t1=2
0:000> r$t2=23
0:000> j(0<(@$t0|@$t1))&(6>@$t0)&(6>@$t1)'f8<<16 L19 30;eb2000018+@$t0-@$t1*5 @$t2;da/c5 8<<16 L19';?0
Filled 0x19 bytes
02000000  "00000"
02000005  "00000"
0200000a  "00000"
0200000f  "000#0"
02000014  "00000"

0:000> r$t1=f
0:000> j(0<(@$t0|@$t1))&(6>@$t0)&(6>@$t1)'f8<<16 L19 30;eb2000018+@$t0-@$t1*5 @$t2;da/c5 8<<16 L19';?0
Evaluate expression: 0 = 00000000

Haskell, 77 bytes
r=[1..5]
(x#y)c|x>0,x<6,y>0,y<6=unlines[[last$'0':[c|i==x,j==6-y]|i<-r]|j<-r]

Usage example:
*Main> putStr $ (2#5) '*'
0*000
00000
00000
00000
00000

If x and y are within range, outer and inner loop through [1..5] and take the char c if it hits the given x and y and a 0 otherwise. If x or y is not in range, a Non-exhaustive patterns exception is raised.

Java, 99 bytes
(i,j,k)->{int[]b=new int[]{60,60,60,60,60};int[][]a=new int[][]{b,b,b,b,b};a[i-1][5-j]=k;return a;}

Vim, 60 47 42 76 keystrokes
Input is in the format (on the first line):
25*

With the cursor starting at the beginning
"ax"bxx:if<C-r>a<1||<C-r>a>5||<C-r>b<1||<C-r>b>5
^
endif
6i0<ESC>Y5pG:norm <C-r>al<C-r>bkr<C-r>-
Hqqxjq5@qdd

If the input is invalid, then throws: E492: Not an editor command: ^
The cide that produces the output is only 42 bytes, but in order to create an error, my bytecount is drastically increased.

BTW I don't know how to create the error in Vim

Bash, 59 bytes
Golfed
printf '00000%0.s\n' {1..5}|sed "$1 s/./$3/$2"|grep -z "$3"

$1, $2 - row, column, $3 - replacement char, error is reported via exit code
Test
>./box 2 2 "*"
00000
0*000
00000
00000
00000
>echo $?
0

>./box 6 2 '*'
>echo $?
1

Java 8, 194 192 bytes
interface M{static void main(String[]a){String r="";int i=0,j,z=new Byte(a[0]),y=new Byte(a[1]);for(;++i<6;r+="\n")for(j=0;++j<6;r+=6-i==y&j==z?a[2]:0);System.out.print(z>0&z<7&y>0&y<7?r:0);}}

Try it here with correct input.
Try it here with incorrect input.
This would be 116 114 bytes instead as function instead of full program:
(a,b,c)->{String r="";for(int i=0,j;++i<6;r+="\n")for(j=0;++j<6;r+=b==6-i&a==j?c:0);return a>0&a<7&b>0&b<7?r:"0";}

Try it here.
Explanation:
interface M{                  // Class
  static void main(String[]a){//  Mandatory main-method
    String r="";              //   Result-String, starting empty
    int i=0,j,                //   Index-integers
        z=new Byte(a[0]),     //   First input converted to integer
        y=new Byte(a[1]);     //   Second input converted to integer
    for(;++i<6;               //   Loop (1) from 1 to 6 (inclusive)
        r+="\n")              //     After every iteration: Append a new-line to the result
      for(j=0;++j<6;          //    Inner loop (2) from 1 to 6 (inclusive)
        r+=6-i==y             //     If the second input equals `6-1`,
           &j==z?             //     and the first input equals `j`:
            a[2]              //      Append the third input to the result-String
           :                  //     Else:
            0                 //      Append a zero to the result-String
      );                      //    End of inner loop (2)
                              //   End of inner loop (1) (implicit / single-line body)
    System.out.print(         //   Print:
     z>0&z<7&y>0&y<7?         //    If the coordinates are valid (1-6):
      r                       //     Print the result `r`
     :                        //    Else:
      0);                     //     Print 0 as error instead
  }                           //  End of main-method
}                             // End of class

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:
Generate all brace-strings of length n
A brace string is defined as a string consisting of the characters *()[] in which braces match correctly:
[brace-string] ::= [unit] || [unit] [brace-string]
[unit]         ::= "" || "*" || "(" [brace-string] ")" || "[" [brace-string] "]"

This is a valid brace-string:
((())***[]**)****[(())*]*

But these are not:
)(
**(**[*](**)
**([*)]**

Your task is to write a program (or function) that, given a positive integer n, takes a number as input and outputs (or returns) all valid brace strings of length n.
Specifications

You may output the strings in any order.
You may output as a list or a string separated by a different character.
Your program must handle 0 correctly. There is 1 possible brace-string of length 0, which is the empty string "".
This is code-golf, so the shortest valid answer – measured in bytes – wins.

Test Cases
0.
1. *
2. ** () []
3. *** ()* []* (*) [*] *() *[]
4. **** ()** []** (*)* [*]* (**) **() **[] *(*) *[*] (()) ()() ()[] ([]) [**] [()] [[]] []() [][] *()* *[]*

The number of entries in the output is A025235

@GabrielBenamy Ah. I was wondering whether that had been looked at before. Interesting.

What is the winning condition? I assume shortest program (code golf).

Related.

Since everyone is assuming this is code golf, I will tag the challenge accordingly (as it would otherwise make all existing answers somewhat pointless). If you intended a different winning criterion, you could consider posting a new challenge.

A longer test case?

@edc65 5, 6, and 7 have lengths 61, 191, and 603 respectively. Are more test cases really needed?

I can find all the lengths at A02535. What I need is the string list. Luckily there are many valid answers now that give the correct list.

The point is mainly that I'm too lazy to write them out :-)

Jelly, 29 bytes
-3 bytes thanks to @JonathanAllan
Please, alert me if there are any problems/bugs/errors or bytes I can knock off!
“[(*)]”ṗµḟ”*œṣ⁾()Fœṣ⁾[]FµÐLÐḟ

Try it online!
The previous solution(s) I had:
“[(*)]”ṗµḟ”*œṣ⁾()Fœṣ⁾[]FµÐL€Ṇ€Tị
“[(*)]”ṗµ¹ḟ”*œṣ⁾()Fœṣ⁾[]FµÐL€Ṇ€Tị
“[(*)]”ṗµ¹ḟ”*œṣ⁾()Fœṣ⁾[]FµÐL€Ṇ€×Jḟ0ị
“[(*)]”x⁸ṗ⁸Qµ¹ḟ”*œṣ⁾()Fœṣ⁾[]FµÐL€Ṇ€×Jḟ0ị
“[(*)]”x⁸ṗ⁸Qµ¹µḟ”*œṣ⁾()Fœṣ⁾[]FµÐL€Ṇ€×Jḟ0ị
“[(*)]”x⁸ṗ⁸Qµ¹µḟ”*œṣ⁾()Fœṣ⁾[]FµÐLµ€Ṇ€×Jḟ0ị

Explanation (My best attempt at a description):
Input n
“[(*)]”ṗ-All strings composed of "[(*)]" of length n
µḟ”*    -Filter out all occurences of "*"
œṣ⁾()   -Split at all occurences of "()"
F       -Flatten
œṣ⁾[]   -Split at all occurences of "[]"
F       -Flatten
µÐL     -Repeat that operation until it gives a duplicate result
Ðḟ      -Filter

You can save three bytes using filtering (“[(*)]”ṗµḟ”*œṣ⁾()Fœṣ⁾[]FµÐLÐḟ)

Prolog, 69 bytes
s-->[];e,s.
e-->"*";"(",s,")";"[",s,"]".
b(N,A):-length(A,N),s(A,[]).

One of the most interesting properties of Prolog is that in many cases it's capable of running a program backwards; for example, instead of testing to see if something's true, you can generate all solutions for which it's true, and instead of checking the length of a string, you can generate all strings with a given length. (Another nice property of Prolog is that it requires whitespace after the end of each predicate definition, and a newline can be inserted as cheaply as a space; thus even golfed programs are often fairly readable.)
The above defines a predicate (the equivalent of a function) b which tests to see if a string has a given length and is a "brace string" as defined in the question. Specifically, it does this via Prolog's grammar/regex/pattern-match support that gives some nice, short sugar for defining this sort of expression (apparently this is standard/portable, but I was unaware of this while originally writing the answer, and thus assumed the answer would work on only one Prolog implementation; it seems it works on every implementation that complies with the standards, though). The program can be translated into English fairly directly; the first two lines say "an s is an empty string, or an e followed by an s; an e is an asterisk, or an s in parentheses, or an s in square brackets". The third line can be interpreted as "The b of N can be A if A is a list with length N and A is an s followed by a null string."
I took some care to write s (and thus b) so that they match each "brace string" in exactly one way (which is the reason that both s and e have to exist, rather than grouping them into one predicate). This makes them both entirely reversible; thus b can be used to generate all "brace strings" of a given length, in addition to testing if a string is a brace string of a given length (it can also be used a third way round, to figure out the length of a brace string, but that is almost certainly its least useful mode of operation). The implementation is recursive, e.g. to generate an s, the code will generate all possible es that are no longer than the required length of the output, and append all possible ss that fit in the remaining space to them; because I specified the length of the argument in advance (within b), the Prolog engine knows that it can't generate output that's longer than the given length, which allows the recursion to terminate.
Here's an example of the program in operation:
| ?- b(4,A),format("~s ",[A]),fail.
**** **() **[] *()* *(*) *[]* *[*] ()** ()() ()[] (*)* (**) (()) ([]) []** []() [][] [*]* [**] [()] [[]]

it feels like there should be some cost to the syntax required to specify whether you want to run the program "forwards" or "backwards". perl pays 1 byte for every bit of that sort of thing

Well, you could make a rule that arguments at the end are always the return value, then reverse the order of the arguments to specify which way round you're running the program. It's fairly common for golfing languages to figure out what they should be doing partly by looking at whether they were given any input, and this is a comparable principle. In general, though, it's hard to make rules that apply to every possible language; running builtins like length and append either way round is a fundamental part of the language, and user functions often do the same.

Oh, hmm. I assumed there was some indication in your example that triggered the behavior in question.

Nah, it's entirely due to which arguments are given. In the program above, I write length(A,N); if N is given and A isn't (which will happen if the predicate's used in the way requested in the program), length will generate a list A consisting of N unknown elements. Using length to measure the length of a list is probably more commonly used (although using it "backwards" is fairly common in Prolog programming). Most predicates end up working much the same way (the only reason they don't is if attempting to reverse them would construct an infinite loop, which is fairly common).

I'm pretty sure this works in all popular Prolog distributions. I think it maches ISO Prolog's specifications so you can label that answer as just "Prolog".

@Fatalize: I thought --> was nonstandard; maybe not though?

@ais523 --> and DCGs in general are standard ISO Prolog.

At first sight this seems to do what most solutions do: generate strings of the given length and test them. But I think it is more efficient and if that is the case, you should mention that. - Also, I think the third use mode is more like test if a string of any length is a brace-string, and if it is, also "return" its length.

@ChristianSievers: a Prolog implementation will use the obvious implementation for this, recursively generating es in terms of ss and ss in terms of es, whilst using the (known) length of the output to determine when to stop. (You can see this in the order in which the strings were returned.) I've edited this into the post. (And yes, the third mode would test if the string is a brace-string, and return its length if it is.)

Haskell, 101 94 bytes
7 bytes saved by Zgarb!
b 0=[""]
b n=[x++y|k<-[1..n],x<-u k,y<-b$n-k]
u 1=["*"]
u n=[a:s++b|s<-b$n-2,a:b<-["()","[]"]]

Almost straightforward, following the definition, but with the "" case moved.
Use:
*Main> map b [0..3]
[[""],["*"],["**","()","[]"],["***","*()","*[]","()*","[]*","(*)","[*]"]]
*Main> length $ b 10
21595

(The second computation takes less than a second on a slow machine.)
I'd also like to share the result of another approach I came up with while thinking about generating functions. It defines a list b of lists of strings such that b!!n contains all brace-strings of length n. Similarly, u!!n contains all atoms of size n-1. One nice thing is that the code is not using any numbers. It is not completely golfed: u and i could be inlined, and it certainly misses a few other golfing opportunities. Unfortunately, it doesn't look like it can be made shorter than the first version, but it computes length $ b !! 10 even faster.
b=[""]:b%u
u=["*"]:map i b
i=concatMap(\s->['(':s++")",'[':s++"]"])
(b:c)%f=zipWith(++)[[x++y|x<-b,y<-e]|e<-f]([]:c%f)

Save two bytes with b$n-k and b$n-2. Also, on the final line you can do a:b<-["()","[]"] and return a:s++b.

Oh I wanted to use ["()","[]"] but couldn't see how to improve code size with it. Thanks!

Python 2, 128 bytes
n=input()
for i in range(5**n):
 try:s=','.join('  "00([*])00"  '[i/5**j%5::5]for j in range(n));eval(s);print s[1::4]
 except:1

Screw recursive regexes – we’re using Python’s parser! In order to verify that, for example, *(**[])* is a brace-string, we do the following:

Make a string like "*", (0,"*","*", [0,0] ,0) ,"*", where every second character of four is a character from the brace-strings, and the remaining characters are glue to make this a potential Python expression.
eval it.
If that doesn’t throw an error, print s[1::4] (the brace-string characters).

The glue characters are picked so that the string I make is a valid Python expression if and only if taking every second character out of four yields a valid brace-string.

Mathematica, 116 bytes
#<>""&/@Select[Characters@"*([)]"~Tuples~#,(#/."*"->Nothing//.{a___,"(",")",b___}|{a___,"[","]",b___}:>{a,b})=={}&]&

Explanation
Characters@"*([)]"

Find the characters of the string "*([)]", giving the List {"*", "(", "[", ")", "]"}.
... ~Tuples~#

Find the tuples of the above list with length n.
(#/."*"->Nothing//.{a___,"(",")",b___}|{a___,"[","]",b___}:>{a,b})=={}&

Unnamed Boolean function to find whether the tuple is balanced:
#/."*"->Nothing

Delete all "*" in the input.
... //.{a___,"(",")",b___}|{a___,"[","]",b___}:>{a,b}

Repeatedly delete all consecutive occurrences of "(" and ")" or "[" and "]" until the input does not change.
... =={}

Check whether the result is an empty List.
Select[ ... , ... ]

Find the tuples that give True when the Boolean function is applied.
#<>""&/@

Convert each List of characters into Strings.

Somewhat unexpectedly, {x=a___,"(",")",y=b___}|{x,"[","]",y} seems to work.

PHP, 149 bytes
for(;$argv[1]--;$l=$c,$c=[])foreach($l?:['']as$s)for($n=5;$n--;)$c[]=$s.'*()[]'[$n];echo join(' ',preg_grep('/^((\*|\[(?1)]|\((?1)\))(?1)?|)$/',$l));

Uses the good old generate all possible and then filter method. Use like:
php -r "for(;$argv[1]--;$l=$c,$c=[])foreach($l?:['']as$s)for($n=5;$n--;)$c[]=$s.'*()[]'[$n];echo join(' ',preg_grep('/^((\*|\[(?1)]|\((?1)\))(?1)?|)$/',$l));" 4

Retina, 78 bytes
Byte count assumes ISO 8859-1 encoding.
.+
$*
+%1`1
*$'¶$`($'¶$`)$'¶$`[$'¶$`]
%(`^
$';
)+`(\[]|\(\)|\*)(?=.*;)|^;

A`;

Try it online!
Explanation
I'm generating all possible strings of length 5 and then I filter out the invalid ones.
.+
$*

This converts the input to unary, using 1 as the digit.
+%1`1
*$'¶$`($'¶$`)$'¶$`[$'¶$`]

This repeatedly (+) replaces the first (1) one in each line (%) in such a way that it makes five copies of the line, one for each possible character. This is done by using the prefix and suffix substitutions,  $` and $' to construct the remainder of each line.
This loop stops when there are no more 1s to replace. At this point we've got all possible strings of length N, one on each line.
%(`^
$';
)+`(\[]|\(\)|\*)(?=.*;)|^;

These two stages are executed for each line separately (%). The first stage simply duplicates the line, with a ; to separate the two copies.
The second stage is another loop (+), which repeatedly removes [], () or * from the first copy of the string, or removes a semicolon at the beginning of the line (which is only possible after the string has vanished completely).
A`;

Valid strings are those that no longer have a semicolon in front of them, so we simply discard all lines (A) which contain a semicolon.

I tried onliny with input 5: ok. With input 6 I got an error page

@edc65 Works for me, but of course this approach is not exactly efficient, so it takes a few seconds. What sort of error page do you mean?

Input 5: answer in 3 sec. Input 6: after 7 seconds, Inside the Output box, I get the html source of what is probably an error page from my proxy. If it's a timeout then it's a very short timeout ... I was trying to get a right test case for input 6, as I my answer seems ok up to input 5, but wrong for 6 or more

@edc65 It definitely takes longer than 7 seconds, and TIO's timeout is a minute. I've never seen the error you describe, might be worth bringing this up in the TIO chat (or if you prefer on gitter or GitHub). As for reference output, here is what I get for input 6: http://pastebin.com/WmmPPmrc (Input 7 takes more than a minute.)

Python 3.5, 146 bytes
import re;from itertools import*;lambda f:{i for i in map(''.join,permutations("[()]*"*f,f))if re.fullmatch("(\**\[\**\]\**|\**\(\**\)\**)*|\**",i)}

Very long compared to other answers, but the shortest one I could currently find. It is in the form of an anonymous lambda function and therefore must be called in the format
print(<Function Name>(<Integer>))
Outputs a Python set of unordered strings representing all possible brace-strings of the input length.
For example, assuming the above function is named G, invoking G(3) would result in the following output:
{'[*]', '*()', '*[]', '(*)', '***', '[]*', '()*'}

Try It Online! (Ideone)

However, if, like me, you aren't really a fan of simplifying things using built-ins, then here is my own original answer not using any external libraries to find permutations, and currently standing at a whopping 288 237 bytes:
import re;D=lambda f:f and"for %s in range(%d)"%(chr(64+f),5)+D(f-1)or'';lambda g:[i for i in eval('["".join(('+''.join('"[()]*"['+chr(o)+'],'for o in range(65,65+g))+'))'+D(g)+']')if re.fullmatch("(\**\[\**\]\**|\**\(\**\)\**)*|\**",i)]

Again, like the competing answer, this one is in the form of a lambda function and therefore must also be called in the format
print(<Function Name>(<Integer>))
And outputs a Python list of unsorted strings representing all brace-strings of the input length. For example, if the lambda were to be invoked as G(3), this time the output would be the following:
['*()', '(*)', '*[]', '[*]', '()*', '[]*', '***']

Also, this one is also a lot faster than my other answer, being able to find all brace-strings of length 11 in about 115 seconds, those of length 10 in about 19 seconds, those of length 9 in about 4 seconds, and those of length 8 in about 0.73 seconds on my machine, whereas my competing answer takes much longer than 115 seconds for an input of 6.
Try It Online! (Ideone)

Python, 134 bytes
from itertools import*
lambda n:[x for x in map(''.join,product('*()[]',repeat=n))if''==eval("x"+".replace('%s','')"*3%('*',(),[])*n)]

repl.it
Unnamed function that returns a list of valid strings of length n.
Forms all length n tuples of the characters *()[], joins them into strings using map(''.join,...) and filters for those that have balanced brackets by removing the "pairs" "*", "()", and "[]" in turn n times and checking that the result is an empty string (n times is overkill, especially for "*" but is golfier).

05AB1E, 23 bytes
…[(*.∞sãʒ'*м„()„[]‚õ:õQ

Some of these features might have been implemented after the question was posted. Any suggestions are welcome!
Try it online!
How?
…[(* - the string '[(*'
.∞ - intersected mirror, '[(*'=>'[(*)]'
s - swap the top two items, which moves the input to the top
ã - cartesian power
ʒ ...  - filter by this code:
  '*м      - remove all occurrences of '*'
  „()„[]‚  - the array ["()","[]"]
  õ        - the empty string ""
  :        - infinite replacement (this repeatedly removes "()", "[]", and "*" from the string
  õQ       - test equality with the empty string

I don't know 05AB1E, but couldn't the * also be in the removal array? And could the õQ check be replaced with something like NOT?

The first suggestion won't save any bytes: '*м„()„[]‚õ: vs „()„[]‚'*«õ: (not tested), since there is no command to concatenate 3 values AFAIK. The second one won't work since there's no NOT that would operate like that on a string, AFAIK. (Where AFAIK represents "as far as I know")

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


text:
Tips for golfing in Wierd
What tips do you have for golfing in Wierd?  Tips for golfing other languages don't seem to help one golf Wierd programs so I'm looking for ideas that can be applied to code golf problems that are specific to Weird - especially if it helps me reduce the size of this answer at "Hello, World!"

I've never heard of this language and it looks very... interesting. I don't have much to add except I'll be looking at making my own Hello, World! program soon and coming up with some tips :)

@Tealpelican  my two favourites are Weird and ///

Currently mine is ><>, I've been able to come up with 'He' in wierd atm but it's not the easiest language to figure out aha.

@Tealpelican What it needs is a good editor that lets you clip rectangular pieces and rotate and flip them before reinserting them.

My primary advice for golfing in Wierd is: don't. :P Kidding aside, I'm impressed by your determination to improve your score in this ridiculously unwieldy and not entirely well specified language. :)

@MartinEnder  Thanks for the link - now I need to try to make a ZT program smaller than the one in the spec...

@MartinEnder  I have added a ZT answer to the Hello World question.  It is smaller than the example Hello World but probably not the smallest...

Don't forget about self modifying code
As Dennis showed in https://codegolf.stackexchange.com/a/142785/24812 a loop can be much shorter than a linear program and that there are clever ways to exit the loop.  The spec makes it clear that a 90 degree angle allows you to choose one of two different directions at runtime.  Dennis showed that you could modify the program at runtime - with amazing results.


text:
Tetris overlooked move counter
Playing tetris is fun.  Watching an AI play tetris is also fun.
Some tetris AIs will always ignore the possibility of maneuvering a piece under an overhang, which makes me sad.
It means that the programmer said to himself, "What are all the possible places the tile could be at the top of the board, and from each place, what happens when I hard drop the tile?"
The input of your program will be a game piece, a board, and a newline.
The output of your program will be two integers (with a space between them) and a newline.
Your program should generates all possible "moves", distinguishing those "moves" which could be produced by a naive AI (rotation and shifting left/right may only occur at the top), from those "moves" which can only be produced either the naive way or if rotation and horizontal shifting are allowed below the top.
The count of how many "moves" are in each of the two categories (smaller number first), are the two numbers output.
Each "move" is a game board where the tile has a + square below it, or where the tile would go off the edge of the grid if it were moved one row downward.
The format of the game piece is a single byte which is one of s z l j o i). The board consists of 180 bytes, each being either space () or a plus (+), representing a grid 10 squares wide by 18 tall.
Each piece starts with the top row of its bounding box on the top grid row, and is centered, rounding to the left.
The piece letters represent the same tetrominoes used by what's called the Super Rotation System, and obviously the same rotations.
When maneuvering a piece, it may be shifted left or right, rotated clockwise or counterclockwise, or moved one row down, except if doing so will cause part of the piece to go off the edge or top or bottom of the grid, or overlap with any of the + marks.  There are no wall kicks.
Shortest source code wins.
I suggest (but don't require) that you use some sort of transposition table to avoid infinite loops of repeatedly shifting left/right, or rotating infinitely, etc.

You need to include a description of how tetris pieces and boards and such work. Different tetris implementations handle rotating the I and Z/S pieces differently, and some do or don't allow rotating a piece into a space it couldn't otherwise move into.

I think it's best to assume that a piece CANNOT be rotated, only moved left right, as it goes down.

I like the idea, I just feel like this is the type of challenge that you need to post examples for.


text:
Check if 2 arrays contain the same element
Write a program which will take for input 2 integer arrays and return a truthy value if there exists an element which is present in both of arrays, or a falsy one otherwise. The obvious solution to this problem would be to iterate through each element in the first array and compare it against each element in the second, but here's the catch: Your program must have an algorithmic complexity of at most, in the worst case, O(NlogN), where N is the length of the longer array,
Test cases:
 {1,2,3,4,-5},{5,7,6,8} -> false
 {},{0}                 -> false
 {},{}                  -> false
 {1,2},{3,3}            -> false
 {3,2,1},{-4,3,5,6}     -> true
 {2,3},{2,2}            -> true

This is code-golf, so the shortest code in bytes wins.

Are the integers bound/small like in your example? E.g. is radixsort or a bitmap possible?

@Pavel The complexity depends very much on the set implementation, as far as I can tell. O(n log n) is doable in general, but the clarification about only handling native integers means that in some languages with limited integer ranges a linear solution is possible (e.g. by a 2^64 size lookup table)

By the way, I think that all hash-based solutions with arbitrary precision ranges should have to demonstrate that no collisions are possible or some other property to guarantee satisfaction of the requirement, because I'm not convinced about some of these answers... (with the current rules)

If the first array (N elements) is sorted it is Nlog(N) if for each element of 2 array search using "binary search" in 1 array it would be nlog(N) so the total is Nlog(N)+nlog(N)=(N+n)log(N) that is > to Nlog(N) claimed from the question ... So would remain "ascii tables"?

@RosLuP NLogN+NLogN is still O(NLogN)

I would not recommend accepting answers so quickly. It's recommended to wait at least for a week before accepting an answer.

@erikthegolfer yeah, who's going to beat a one byte solution?

@Pavel Did you notice that I removed the "The" from my name (I just now saw your reply)? A week is usually considered to be the norm before accepting an answer (although I use 14 days). It's your choice after all, but I think it's good practice to wait before you accept, because, technically, a 0-byte answer is also possible in a programming language that is buried deep on the internet and nobody except its creator knows about it (and in fact fits our definition of a programming language).

@Pavel Personally, I'm concerned about the validity of answers instead, because I'm not convinced most of the hash-based answers are valid (e.g. all the Python ones - see comments on the Actually answer)...

Actually, 1 byte
∩

Try it online!
This is merely the set intersection built-in. The resultant value is the intersection of the two sets - a non-empty list (which is a truthy value) if there is an intersection, and an empty list (which is a falsey value) otherwise.
Complexity
According to the Python Wiki, set intersection has a worst-case time complexity of O(N*M) (where N and M are the lengths of the two sets). However, the time complexity is only that bad when the two sets contain distinct objects that all have the same hash value (for example, {"some string"} & {hash("some string")}). Since the set elements are only integers in this case (and no two integers hash to the same value unless they are equal), the actual worst-case complexity is O(min(N, M)) (linear in the length of the smaller of the two sets). The construction of each set is O(N) (linear in the number of elements), so the overall complexity is O(max(N, M)) (the complexity is dominated by the construction of the larger set).

That's not a ASCII character, takes 3 bytes in UTF-8

@Kh40tiK Actually uses CP437 for encoding.

This can't possibly be O(min(N, M)). It takes O(max(M,N)) time simply to read in both arrays! Somehow I doubt set intersection can be done that quickly, either.

@ais523 You're partly right - I forgot to account for the time complexity of the construction of the sets. Set intersection via a hash table with no collisions absolutely can be done in linear time.

Right, I just figured that out too. Set intersection is indeed O(min(N, M)); but converting the arrays to sets takes O(max(N, M)) time. So we were both right.

The entire point of the complexity restriction was to prevent 1 or 2 byte solutions... Guess I underestimated the power of golfing languages.

I don't think the comment about "no two integers hash to the same value unless they are equal" is correct, especially for sufficiently large integers.

@Sp3000 Unless I read the source code wrong, int.__hash__ simply returns the int.

@Mego From memory, that's only true for small ints. At the very least, hash(10**10) != 10**10 in Python 2.7.11 and 3.5.2.

@Sp3000 hash truncates the object's __hash__ value.

@Mego As far as I can tell, this doesn't seem to be true, although on some Python versions/environments you might have to go higher than 10**10 to see a difference. Compare https://tio.run/#YS2Nl and changing one of the set initialisation lines to using *(2**61) instead of *(2**61-1). The only way I see this answer working is if there's a specific Python version where this works that I've missed, in which case it should be stated.

This is a pretty weird situation, because Python's being penalised for supporting integers. Perl doesn't, so it has a lower complexity for the same algorithm, because the choice of language is redefining what the problem is! We might need some rules on what counts as an integer, in order to make the problem fair. (Also, on whether randomized algorithms count if they run in O(n log n) for very high probability on any input; most languages have hash tables that work like that nowadays.)

Works in Dyalog APL too :-D

@Mego: Integers do not all hash to their own value. You're looking at the Python 2 int source code, intobject.c, when you should be looking at longobject.c, the code for the Python 3 int type and the Python 2 long type. Also, while hash does modify the output of __hash__ if it's out of range, it is this modified value, not the original __hash__ output, that is used for indexing into a dict or set's internal hash table.

Additionally, even if it were the case that all input integers had distinct hashes, you could still get quadratic runtime due to inputs with distinct hashes still mapping to the same hash table slot.

I'm not convinced it's possible to construct two integer sets whose intersection is worse than O(n log n) in Python 3 - it seems to me that only sets with non-numeric types will suffer from quadratic complexity. Perhaps someone who is smarter than me can look through the CPython source and prove me wrong.

@Mego Unless I've done something wrong, the tio.run link I provided was meant to be an example.

@Mego: Depending on the details of your Python interpreter, one of {i * (2**64-1) for i in range(100000)} or {i * (2**32 - 2) for i in range(100000)} should produce quadratic runtime, with all elements hashing to the same value. It's trickier but still possible to construct an example that causes quadratic runtime without equal hashes, by inducing large numbers of probe collisions.

TSQL, 40 37 36 bytes
SQL doesn't have arrays, it is using tables instead
Returns -1 for true or 0 for false
DECLARE @ table(a INT)
DECLARE @2 table(b INT)

INSERT @ values(1),(2),(3),(4),(-5)
INSERT @2 values(5),(6),(7),(8)

SELECT~-sign(min(abs(a-b)))FROM @,@2

Try it out

Yes! that's glorious

Does the execution plan generated for this query actually have the necessary runtime behavior?

@user2357112 a valid point. This does not scale well, I had to cut some corners to keep it short. Can we keep it between you and me... and the rest of the world ?

PowerShell, 88 78 77 23  bytes
!!(diff -Inc -Ex $A $B)
Thanks to @briantist for shaving off a whopping 54 bytes from my original, more verbose answer by shortening -IncludeEqual, -ExcludeDifferent, and -Not!
if(-Not(diff -IncludeEqual -ExcludeDifferent $A $B)){("false")}else{("true")}
I can't find the source for Compare-Object (diff is an alias for Compare-Object), so I'm not certain on the time complexity.

I also can't comment on complexity, but you can shorten that to 23 bytes: !!(diff -inc -ex $A $B)

If you specifically exclude PowerShell v5, I think you can shave off another 2 bytes bytes by using -i instead of -inc, but in 5+ the -Information* common parameters make -i ambiguous.

@briantist I wasn't aware that v5 had a stable release. I'll have to use that in the future. Thanks for the other tips as well! :)

My solution was complete; it was not meant to be put inside the if statement; you don't need it at all! Also v5 comes with Windows 10, and v5.1 comes with Server 2016. You can also download and install WMF5 as far back as, I believe, Windows 7/2008R2. It has been released for some time now!

Oh, well holy cow. I missed that completely. It's updated. I'll have to dabble with v5 now and pay closer attention. Thanks!

Nice to see another PowerShell user around here. Two things - without some sort of definitive time complexity evaluation for Compare-Object, I'm skeptical that this is O(NlogN). Second, taking input via pre-defined variables is a no-no, so you'd need a param($a,$b) in front or similar.

@TimmyD For some reason I can't get the ISE to accept param($A,$B);!!(diff -Inc -Ex $A $B). I think I'm stuck expanding it out to $A=1,2;$B=2,3;!!(diff -Inc -Ex $A $B) and hard coding the arrays in the program itself. :(

@wubs You shouldn't need the semicolon, so it's just param($A,$B)!!(diff -Inc -Ex $A $B) -- Then, save that as a .ps1 file and call it from the command line with the arrays as arguments, like PS C:\Scripts>.\same-element.ps1 @(1,2) @(2,3)

Axiom, 439 bytes
c:=0;s(x,y)==(free c;if x.1=%i and y.2=%i then(x.2<y.1=>return true;x.2>y.1=>return false;c:=1;return false);if x.2=%i and y.1=%i then(x.1<y.2=>return true;x.1>y.2=>return false;c:=1;return false);if x.1=%i and y.1=%i then(x.2<y.2=>return true;x.2>=y.2=>return false);if x.2=%i and y.2=%i then(x.1<y.1=>return true;x.1>=y.1=>return false);false);r(a,b)==(free c;c:=0;m:=[[%i,j] for j in a];n:=[[i,%i] for i in b];r:=merge(m,n);sort(s,r);c)

this convert the first list in a list as [[i,1], [i,2]...] the second list in a list as [[1,i], [0,i]...]
where i is the variable imaginary
than merge the 2 list, and make one sort that would find if there is one element of list 1 in the list 2
so it is at last O(N log N) where N=lenght list 1 + lenght list 2
ungolfed
-- i get [0,0,1,2,3] and [0,4,6,7]  and build [[%i,0],[%i,0],[%i,1],[%i,2] [%i,3],[0,%i],..[7,%i]]
c:=0
s(x:List Complex INT,y:List Complex INT):Boolean==
  free c  -- [%i,n]<[n,%i]
  if x.1=%i and y.2=%i then
    x.2<y.1=> return true
    x.2>y.1=> return false
    c:=1
    return false
  if x.2=%i and y.1=%i then
    x.1<y.2=>return true
    x.1>y.2=>return false
    c:=1
    return false
  if x.1=%i and y.1=%i then
    x.2< y.2=>return true
    x.2>=y.2=>return false
  if x.2=%i and y.2=%i then
    x.1< y.1=>return true
    x.1>=y.1=>return false
  false

r(a,b)==
  free c
  c:=0
  m:=[[%i, j]  for j in a]
  n:=[[ i,%i]  for i in b]
  r:=merge(m,n)
  sort(s, r)
  c

results
(12) -> r([1,2,3,4,-5], [5,7,6,8]), r([],[0]), r([],[]), r([1,2],[3,3]), r([3,2,1],[-4,3,5,6]), r([2,3],[2,2])
   Compiling function r with type (List PositiveInteger,List Integer)
       -> NonNegativeInteger
   Compiled code for r has been cleared.
   Compiled code for s has been cleared.
   Compiling function r with type (List PositiveInteger,List
  PositiveInteger) -> NonNegativeInteger
   Compiled code for r has been cleared.
   Compiling function s with type (List Complex Integer,List Complex
      Integer) -> Boolean
   Compiled code for s has been cleared.

   (12)  [0,0,0,0,1,1]
                                           Type: Tuple NonNegativeInteger

i dont understand why it "clears" code for r and s...

Perl, 25+1 = 26 bytes in collaboration with Dada
print 2<($a{$_}|=$.)for@F

Run with -a (1 byte penalty).
An improved version of the program below (which is kept around to see the history of the solution, and to show the solution I found by myself; it also has more explanation). The -a option reads space-separated arrays as the input, storing them in @F. We use the %a dictionary (accessed as $a{$_}) to store a bitmask of which input arrays the input is in, and print 1 every time we see an element in both arrays, i.e. a value higher than 2 inside the resulting bitmask (fortunately, a failing comparison returns the null string, so the print does nothing). We can't use say because a newline is truthy in Perl. Performance is asymptotically the same as the older version of the program (but faster in terms of constant factors).
Perl, 44+1 = 45 bytes
$a{"+$_"}|=$.for split}{$_={reverse%a}->{3}

Run with -p (1 byte penalty). Input one array per line, separating the elements by spaces.
This works via creating a hash table %a that stores a bitmask of the input arrays that a value has been seen in. If it's been seen in both the array on line 1 and on line 2, the bitmask will therefore store the value 3. Reversing the hash and seeing if 3 has a corresponding key lets us know if there are any values in common.
The complexity of this algorithm is O(n) if you consider hash creation to be constant time (it is, if you have bounded integers, like Perl does). If using bignum integers (which could be input into this program, as it leaves the input as a string), the complexity of the algorithm itself would nominally be O(n log n) for each hash creation, and O(n) for the hash reversal, which adds up to O(n log n). However, Perl's hashing algorithm suffers from potential O(n²) performance with maliciously selected input; the algorithm is randomized, though, to make it impossible to determine what that input is (and it's possible that it can't be triggered simply with integers), so it's debatable what complexity class it "morally" counts with. Luckily, this doesn't matter in the case where there's only finitely many possible distinct elements in the array.
This code will work for input other than integers, but it won't work for more than two arrays (because the 3 is hardcoded and because input on the third line wouldn't bitmask correctly, as it isn't a power of 2). Rather annoyingly, the code naturally returns one of the duplicate elements, which is truthy in almost all cases, but "0" is falsey in Perl and a valid duplicate element in the array. As such, I had to waste three bytes prepending a + to the output, which is the cheapest way I found to give a truthy output in the edge case of the arrays overlapping at 0. If I'm allowed to use notions of truthy and falsey from a language other than Perl (in which any nonempty string is truthy), you can change "+$_" to $_ to save three bytes.

perl -apE '$\|=($a{$_}|=$.)==3for@F}{' should have the same behavior for 17 less bytes ;-)

I was unaware of the -a flag. That does seem to help here, doesn't it? I think you can save another two bytes, though ($\|=}{ and print  are the same length, and the latter allows you to avoid the -p flag and thus a byte of penalties; and ==3 can be replaced by >2 for another byte). Such a pity that $1, etc., are already variables, or we could save another three bytes by using the entire space of variable names as a hash table.

-a (and -F) are quite convenient on PPCG (more than on anagolf since over there it costs more)! Since you need a space after the print, it's the same length as -p ... $\=}{, but why not. (yea, it's sad we can't modify $1 etc.)

It's a character shorter; you had p$\|=}{ (seven characters, with the p being a penalty); I have print  (six characters, including a space). I think you missed the | in your calculation just there.

(Also, anagolf has a penalty of 9 for the first option, 1 for each option beyond that. It's a pretty hefty penalty, but it's nonetheless often worth paying; those options are just worth so much. Penalties are so much cheaper on PPCG that they're nearly always worth incurring.)

Hum, you're right, I seem to be unable do count up to 6, such a shame.

Ruby, 37 bytes:
exit ($*.map{|x|eval x}.reduce:&)!=[]

As in the definition: "program which will take for input 2 integer arrays and return a truthy value if...", this is a program, accepts 2 arrays as strings in input, returns true or false.
as a function - 14 bytes:
->a,b{a&b!=[]}

Complexity:
The ruby documentation of the itnersection (&) operator says "It compares elements using their hash and eql? methods for efficiency.", which I suppose is exactly what we are looking for.
Empirically:
$ time ruby a.rb "[*1..1000001]" "[*1000001..2000000]"

real    0m0.375s
user    0m0.340s
sys 0m0.034s

$ time ruby a.rb "[*1..2000001]" "[*2000001..4000000]"

real    0m0.806s
user    0m0.772s
sys 0m0.032s

$ time ruby a.rb "[*1..4000001]" "[*4000001..8000000]"

real    0m1.932s
user    0m1.857s
sys 0m0.073s

$ time ruby a.rb "[*1..8000001]" "[*8000001..16000000]"

real    0m4.464s
user    0m4.336s
sys 0m0.119s

Which seems to confirm it.

Do you have any source to support that Ruby's built-in set intersection runs in O(n log n)?

No, but the runtime seems to confirm it.

Also, you should count the function, because the other version isn't a valid program, as it doesn't print anything at all.

Python2 - 41 30 bytes
lambda a,b:bool(set(a)&set(b))

Set intersection: O(min(N,M)) where N and M are the length of the sets.
Conversion from a list to a set: O(max(N,M))

Thanks to Jakube for saving 9 bytes! set(a).intersection(b) -> set(a)&set(b)
Thanks to Kade for saving 2 bytes! -> removed f=

You can use set(a)&set(b) instead of calling the intersection method.

If you do what Jakube says, remove the function definition and compare the intersection to {0} then you can get it down to 28 bytes: lambda a,b:set(a)&set(b)>{0}

Actually, {1}&{1} is truthy, while {1}&{2} is falsy. You can just do lambda a,b:a&b.

@SeeOneRhino I would have to take input as sets then, right? Lists do not implement intersection.

@Kade Doesn't seem to work :/ I tried Python2 and Python3. Removing f= does work though.

@TuukkaX Ok, but you still don't need the explicit call to bool. On PPCG, if bool(x) is truthy/falsy, then x is also considered truthy/falsy.

PHP, 15 bytes
array_intersect

Try it online!
A PHP built-in, as a callable/lambda function.  Return is a PHP truthy/falsey testable value.  Also, per the other PHP submission, this implementation should meet the challenge complexity requirements (StackExchange).

GolfScript, 1 byte
If taking the input directly as arrays on the stack is allowed, this one-byte GolfScript solution should meet the spec:
&

If text-based I/O is required, the input needs to be evaluated first, pushing the length up to two bytes:
~&

Both of these solutions use the GolfScript array intersection operator, which is implemented using the corresponding operator in Ruby.  They return an empty array (which is falsy) if the arrays contain no matching elements, or a non-empty array (which is truthy) containing all the matching elements otherwise.
I have so far not been able to find any documentation on the internal implementation or asymptotic complexity of the Ruby array intersection operator, beyond the brief statement that "It compares elements using their hash and eql? methods for efficiency."  However, a reasonable implementation using hash tables would run in O(n) time (assuming that hashing and comparisons are O(1)), and some quick performance testing suggests that this is indeed the case:

These tests were carried out using the GolfScript program ~2?.2*,/&, which takes an integer k, generates an arithmetic sequence of 2 × 2k elements, split it into two arrays of 2k elements and computes their (obviously empty) intersection.  The red stars show the measured execution time t in seconds (on a logarithmic scale) for various values of k, while the green line plots the function t = c × 2k, where the scaling constant c ≈ 2−17.075 was chosen to best fit the measured data.
(Note that, on a log-log plot like this, any polynomial function of the form t = c × (2k)a would yield a straight line.  However, the slope of the line depends on the exponent a, and the data is certainly consistent with a = 1 as shown by the green line above.  FWIW, the numerical best-fit exponent for this data set was a ≈ 1.00789.)

R, 23 bytes
sum(scan()%in%scan())>0

If we assume that there will always be one and only one element matching and that 1 is a truthy value (which it is in R), then we can write :
sum(scan()%in%scan())

which is 21 bytes.

If this is doing what I think it does (for each element in A, check whether it's in B), this has time complexity of O(n*m).

PHP, 55 51 bytes
<?=count(array_intersect($_GET[a],$_GET[b]))<1?0:1;

Usage: save in a file and call from browser:
intersect.php?a[]=1&a[]=2&a[]=3&b[]=0&b[]=4&b[]=5 outputs 0 for false.
intersect.php?a[]=1&a[]=2&a[]=3&b[]=0&b[]=4&b[]=1 outputs 1 for true.
About complexity, I couldn't find references but according to this StackOverflow's post the script should be OK

Do you have any source to support that PHP's built-in set intersection runs in O(n log n)?

@MartinEnder checking it...

Rust, 103 bytes
|a:&[i32],b:&[i32]|!b.iter().collect::<std::collections::HashSet<_>>().is_disjoint(&a.iter().collect())

Takes two array slices (or references to full arrays, they dereference to slices automatically), bundles them up into sets, and checks for non-disjointness. I'm not quite sure how set union is implemented in the Rust standard library, but it should be O(n + m) at worst.
Without using collections, the easiest alternative I see is to sort both arrays, then step over them carefully to look for duplicates. Something like this
fn overlapping(a: &Vec<i32>, b: &Vec<i32>) -> bool{
    let mut sa = a.clone();
    sa.sort();
    let mut sb = b.clone();
    sb.sort();
    let mut ai = 0;
    let mut bi = 0;
    while ai < a.len() && bi < b.len() {
        if sa[ai] < sb[bi] {
            ai += 1;
        } else if sa[ai] > sb[bi] {
            bi += 1;
        } else{
            return true;
        }
    }
    false
}

But that requires too much mutation to be fun to golf in Rust IMO :)

Axiom, 50 221 bytes
binSearch(x,v)==(l:=1;h:=#v;repeat(l>h=>break;m:=(l+h)quo 2;x<v.m=>(h:=m-1);x>v.m=>(l:=m+1);return m);0);g(a,b)==(if #a>#b then(v:=a;w:=b)else(v:=b;w:=a);c:=sort(v);for x in w repeat(if binSearch(x,c)~=0 then return 1);0)

ungolfed
--suppose v.1<=v.2<=....<=v.#v
--   binary serch of x in v, return the index i with v.i==x
--   return 0 if that index not exist
--traslated in Axiom from C  book
--Il Linguaggio C, II Edizione
--Brian W.Kerninghan, Dennis M.Ritchie
binSearch(x,v)==
    l:=1;h:=#v  --1  4
    repeat
       l>h=>break
       m:=(l+h)quo 2   --m=(4+1)/2=5/2=2
                       --output [l,m,h]
       x<v.m=>(h:=m-1) --l x m  h =>
       x>v.m=>(l:=m+1)
       return m
    0

g(a,b)==
  if #a>#b then (v:=a;w:=b)
  else          (v:=b;w:=a)
  c:=sort(v)
  --output c
  for x in w repeat(if binSearch(x,c)~=0 then return 1)
  0

g(a,b) gets the more big array beetwin a and b; suppose it has N elements:
sort that array, do binary search with elements that other array.
This would be O(Nlog(N)). It return 0 for no element of a in b, 1 otherwise.
results
(6) ->  g([1,2,3,4,-5], [5,7,6,8]), g([],[0]), g([],[]), g([1,2],[3,3]), g([3,2,1],[-4,3,5,6]), g([2,3],[2,2])
   Compiling function binSearch with type (PositiveInteger,List Integer
      ) -> NonNegativeInteger

   (6)  [0,0,0,0,1,1]
                                           Type: Tuple NonNegativeInteger

This works in O(n*m), doesn't it?

Yes it is O( n*m) but above they use set intersection that is O(n*m) too. Only my algo exit first than intersection...

Python, 11 bytes
set.__and__

Builtin that takes 2 sets and does an intersection on them

JavaScript (ES6), 39 bytes
(a,b,c=new Set(b))=>a.some(e=>c.has(e))

Will be worse than O(n+m) but hopefully not as bad as O(n*m).

Jelly, 2 bytes
œ&

Try it online!
Explanation
 œ&  Main link. Arguments: x y
⁸    (implicit) x
   ⁹ (implicit) y
 œ&  Intersection of x and y