Skip to main content
Commonmark migration
Source Link

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

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.

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.

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.
Source Link
Xanderhall
  • 1.3k
  • 6
  • 14

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.