g | x | w | all
Bytes Lang Time Link
032AWK250331T155456Zxrs
nan230616T031026ZDadsdy
029Arturo230615T004132Zchunes
061Rockstar230614T224114ZShaggy
003Thunno 2230614T172345ZThe Thon
021Factor + math.extras math.unicode221012T080851Zchunes
003Vyxal221012T071938ZDialFros
046C# Visual C# Interactive Compiler190923T164755Zauhmaan
052Java 8190310T042218ZBenjamin
097C#180301T165626ZJames m
019Attache180116T004828ZConor O&
025Ruby + n180120T124328ZAsone Tu
032JavaScript180115T225335ZShaggy
4437Stax180222T054142ZWeijun Z
047Microsoft Excel 47 Bytes180116T080711ZJarom C
014Befunge98 PyFunge180216T194943ZMercyBea
021Octave180115T210352ZSteadybo
040R180115T224406ZGiuseppe
067tinylisp180120T070145ZDLosc
027Haskell180115T221159Ztotallyh
004Jelly180119T004749Zchromati
013J180115T204121Zcole
070BrainFlak180118T012359ZJo King
052PHP180118T044458Zth3pirat
030JavaScript Node.js180117T212516Zzworek
007Pip180117T200547ZDLosc
006Pyth180117T192240ZSteven H
026Julia 0.6180117T082658ZFrames C
034Pari/GP180117T141930Zalephalp
045Java OpenJDK 8180117T134457ZOlivier
078C# .NET Core180117T110223Zkakkarot
027Ruby180115T214823ZHåv
007Pyth180117T000933ZDave
039C gcc180115T204348ZSteadybo
033Julia 0.6180116T233159Zgggg
083SNOBOL4 CSNOBOL4180116T211247ZGiuseppe
007K oK180115T212353Zmkst
051Java 8180116T082449ZKevin Cr
nanPerl 5180116T153758ZXcali
033JavaScript Node.js180115T223255ZWilson J
058Javascript180116T113439Zdavid
068Red180116T113623ZGalen Iv
040dc180116T055614ZWildcard
004Husk180116T084634Zბიმო
005Brachylog180116T072224ZFatalize
022Befunge180115T233434ZJames Ho
078Batch180116T004337ZNeil
nan180116T001637ZBrad Gil
023Bash + coreutils + sed + bc180115T213403ZDennis
005MATL180115T230304ZLuis Men
005Japt180115T211856ZShaggy
028JavaScript ES6180115T223135ZArnauld
009Pyth180115T215836ZKarlKast
045Lua180115T214312ZJonathan
007APL Dyalog180115T203951ZUriel
062Forth gforth180115T212631Zreffu
056Clojure180115T210533ZCarcigen
088BrainFlak180115T203714ZDJMcMayh
004Jelly180115T204027Zcaird co
044Python 2180115T204227ZChas Bro
003Pyt180115T211302Zmudkip20
009APL+WIN180115T210848ZGraham
055Clean180115T210652ZΟurous
012Add++180115T205548Zcaird co
034Python 2180115T205002ZDennis
043Python 2180115T204942ZRod
019><>180115T204605ZEmigna
005Jelly180115T202106ZDJMcMayh
00405AB1E180115T203526ZEmigna
036Haskell180115T203017ZCristian

AWK, 32 bytes

{for(x=1;++i<NF;)x*=$i?$i:1}$0=x

Attempt This Online!

{for(x=1;   # no multiply by zero
++i<NF;)    # until last digit
x*=         # product
$i?$i:1     # check if digit is zero
}$0=x       # set output

(,), 175 Chars or \$175\log_{256}(3)\approx34.67\$ Bytes

(()()()(),()()()()()()())(()(),())(,((),(())(),,,(()()())(),(())(()()()(),,,,(),,(()()()())))(()(),(()(),,,,(),,(())))((),(,,,,,())),,,(,(()()(),((()))))(()()()),())(,,(()()))

TIO

Arturo, 29 bytes

$=>[∏filter digits&=>[0=&]]

Try it!

$=>[                   ; a function; assign input to &
    ∏                  ; product of...
    filter digits&=>[  ; digits of the input that aren't...
        0=&            ; equal to zero
    ]                  ; end filter
]                      ; end function

Rockstar, 61 bytes

Listen to N
Cut N
O's 1
While N
Let O be*roll N-0 or 1

Say O

Try it (Code will need to be pasted in)

Thunno 2, 3 bytes

0op

Attempt This Online!

Explanation

0op  # Implicit input
0o   # Remove 0s
  p  # Product
     # (Yes, both of those work on numbers)
     # Implicit output

Factor + math.extras math.unicode, 21 bytes

[ 48 v-n nonzero Π ]

Attempt This Online!

Takes input as a string and gives output as an integer.

Vyxal, 3 bytes

fꜝΠ

Try it Online!

Pyt isn't the only language to do 3 bytes :3

Explained

fꜝΠ
f   # flatten to a list
 ꜝ  # remove all 0's
  Π # product

C# (Visual C# Interactive Compiler), 46 bytes

i.Select(c=>c>48?c-48:1).Aggregate((p,c)=>p*c)

Try it online!

Java 8, 52 bytes

n->(n+"").chars().reduce(1,(x,y)->x*=(y-=48)>0?y:1);

Try it online!
Obligatory stream answer.

C#, 97 Bytes (First code golf)

static int X(int y){var z=y.ToString();int r=1;foreach(var q in z){if(q!=48){r*=q-48;}}return r;}

Not sure if i had to wrap it in a method or not so just included it to be safe.

Takes an Int in, converts it to a string and returns the multiple of each of the characters ignoring 0's. Had to minus 48 due to the program using the ascii value as it reads it as a char.

Attache, 20 19 bytes

Prod##Max&1=>Digits

Try it online! Function that takes an integer as an argument and returns an integer.

Explanation

This first takes the Digits of the input number, then each number's Max with 1 is taken, then the Product is taken.

Other solutions

Prod@Larger&1@Digits
Prod@Map[Max&1]@Digits
Prod@Map&:(Max&1)@Digits
{Prod[Max&1=>Digits[_]]}

Ruby + -n, 25 bytes

p eval ($_.chars-[?0])*?*

Try it online!

Ruby (vanilla), 27 bytes

p eval (gets.chars-[?0])*?*

Try it online!

JavaScript, 33 32 bytes

Feels like ages since I've done an array mapping solution in JS!

Takes input as a string.

n=>[...n].map(x=>t*=+x||1,t=1)|t

Try it

o.innerText=(f=
n=>[...n].map(x=>t*=+x||1,t=1)|t
)(i.value="361218402");oninput=_=>o.innerText=f(i.value)
<input id=i type=number><pre id=o>

Stax, 4 bytesCP437

┤caü

5 bytes when unpacked,

E0-k*

Run and debug online!

Explanation

E         Convert number to digits
 0-       Remove all zeros
   k*     Reduce array with multiplication

Microsoft Excel - 62 47 Bytes

{=PRODUCT(IFERROR(1/(1/MID(A1,ROW(A:A),1)),1))}

Explanation

Converts value in cell A1 to array of digits, changes 0s to 1s using absolute value, then multiplies.

15 bytes saved thanks to Engineer Toast

Befunge-98 (PyFunge), 14 bytes

1<*+!:-0'~.j@#

Try it online!

Octave, 21 bytes

Thanks to @Luis Mendo for saving a byte and thanks to @alephalpha for saving another byte!

@(n)prod((k=n-48)+~k)

Takes input as a string of digits.

Try it online!

30 bytes:

@(n)prod((k=num2str(n)-48)+~k)

Takes input as a number.

Try it online!

R, 40 bytes

cat(prod((x=scan()%/%10^(0:12)%%10)+!x))

Try it online!

Since input is guaranteed to have no more than 12 digits, this should work nicely. Computes the digits as x (including leading zeros), then replaces zeros with 1 and computes the product.

cat(					#output
    prod(				#take the product of
         (x=				#set X to
	    scan()			#stdin
		  %/%10^(0:12)%%10)	#integer divide by powers of 10, mod 10, yields digits of the input, with leading zeros. So x is the digits of the input
                                   +!x  #add logical negation, elementwise. !x maps 0->1 and nonzero->0. adding this to x yields 0->1, leaving others unchanged
                                      ))

tinylisp, 67 bytes

(load library
(d f(q((N)(i N(*(i(mod N 10)(mod N 10)1)(f(/ N 10)))1

Try it online!

Explanation + ungolfed

The function f computes the non-zero digit product of its argument N. It uses a divmod algorithm to process the digits: If N is nonzero, it computes (N mod 10 if N mod 10 is nonzero, 1 otherwise), and multiplies that quantity by the result of recursing on N divided by 10. Once N becomes zero, all the digits have been processed and we return 1.

(load library)

(def digit-product
 (lambda (num)
  (if num
   (*
    (if (mod num 10) (mod num 10) 1)
    (digit-product (/ num 10)))
   1)))

This implementation commits the cardinal sin of not using tail recursion. It's not a problem for the size of number this challenge requires us to handle, but for big enough numbers, we would eventually hit the max recursion depth. Here's a proper tail-recursive implementation (with helper function) in 83 bytes:

(load library
(d _(q((N P)(i N(_(/ N 10)(*(i(mod N 10)(mod N 10)1)P))P
(q((N)(_ N 1

Try it online!

Ungolfed:

(load library)

(def _digit-product
 (lambda (num accum)
  (if num
   (_digit-product
    (/ num 10)
    (*
     (if (mod num 10) (mod num 10) 1)
     accum))
   accum)))

(lambda (num) (_digit-product num 1))

Haskell, 27 bytes

foldr((*).max 1.read.pure)1

Try it online!

Ungolfed with UniHaskell and -XUnicodeSyntax

import UniHaskell

f ∷ String → Int
f = product ∘ map (max 1 ∘ read ∘ pure)

Explanation

I'll start with what I initially had:

product.map(max 1.read.pure)

This is a point-free expression that evaluates to a function taking a string (or a list of characters) s ("301") as an argument. It maps max 1.read.pure over s, essentially taking each character i, injecting it into a list (which makes it a string) (["3", "0", "1"]), then reading it, which evaluates the string ([3, 0, 1]) and finally taking the greater of i and 1 ([3, 1, 1]). Then it takes the product of the resulting list of integers (3).

I then golfed it by a byte with:

foldr((*).max 1.read.pure)1

This works because product is equivalent to foldr (*) 1. Instead of mapping and folding, I combined the two by folding with (*).max 1.read.pure which takes each non-zero digit and multiplies it with the accumulator.

Jelly, 4 bytes

Dḟ0P

Try it online!

Dḟ0P    main link

D       int to dec
 ḟ0     filter out 0
   P    product of list

J, 17 14 13 bytes

-4 bytes courtesy of @GalenIvanov

[:*/1>.,.&.":

Try it online!

Probably can be improved some. Edit: and so it was.

Explanation

[: */ 1 >. ,.&.":
                 ": Convert to string
             ,.     Convert row to column vector
               &.   Convert to numbers
      1 >.        Maximum of each element with 1 (convert 0 to 1)
   */              Product
[:                 Cap fork

&.-under is a nifty adverb that applies the verb on the right, then the verb on the left, then the inverse of the verb on the right. Also converting back to numbers is technically using eval (".-do).

Brain-Flak, 74 72 70 bytes

-2 thanks to Nitrodon for suggesting getting the negation of the number so that you only have to increment rather than decrement later

{([{}]((((()()()){}){}){}){}){({<({}())><>([[]](){})<>}<><{}>)<>}{}}<>

Try it online!

There might be a few ways to golf this further, such as redoing the multiplication to avoid having to initialise the total with 1. (-2 bytes)

How It Works:

{ Loop over every number
  ([{}]((((()()()){}){}){}){}) Add 48 to the negative of the ASCII to get the negation of the digit
  { If the number is not 0
     ({<({}())><>([[]](){})<>}<><{}>)<> Multiply the total by the number
                                          If the total is on an empty stack, add 1
  } 
  {} Pop the excess 0
}<> Switch to the stack with the total

PHP, 52 Bytes

$t=1;foreach(array_filter(str_split($n))as$b)$t*=$b;

JavaScript (Node.js), 30 bytes

f=([a,...b])=>a?(+a||1)*f(b):1

Try it online!

Takes string as an input, treats it as array, and by array destructuring separates the first element [a,...b]. +a||1 returns digit corresponding to a character. I guess that rest is self explaining..

Pip, 7 bytes

$*YaDC0

Try it online!

Delete Character 0 from the argument a and fold ($) on multiplication (*). The Yank operator is used to adjust the precedence of the subexpression (one byte shorter than $*(aDC0)).

Pyth, 6 bytes

*F #sM

Try it Online!

Explanation:

    sM   Get digits of implicit string input
   #     Filter on identity, removing 0s
*F       Fold on multiplication

Julia 0.6, 26 bytes

!x=prod(max.(digits(x),1))

Example of use:

julia> !54
20

Try it online!

Pari/GP, 34 bytes

n->fold((a,b)->a*(b+!b),digits(n))

Try it online!

Java (OpenJDK 8), 45 bytes

s->s.chars().reduce(1,(a,b)->b<49?a:a*(b-48))

Try it online!

C# (.NET Core), 78 bytes

using System.Linq

n=>n.Replace("0","").Select(c=>c-'0').Aggregate(1,(a,b)=>a*b)

Try it online!

Ruby, 42 40 35 32 27 bytes

p eval (gets.chars-[?0])*?*

Assumes no newlines in input Major influence

-2 bytes thanks to @GolfWolf

-5 bytes thanks to @Conor O'Brien

Pyth, 7 bytes

*FsMs#Q

Try it online!


*FsMs#Q Full program, takes input in "" from stdin and prints to stdout
    s#Q Filter input for truthiness of int-parse(digit), then
  sM    map int-parse to this,
*F      then fold over multiplication

C (gcc), 39 bytes

k;f(n){for(k=1;n;n/=10)k*=n%10?:1;k=k;}

Needs to be compiled without optimizations (which is the default setting for gcc, anyway).

Try it online!

Julia 0.6, 33 bytes

x->prod(filter(x->x>0,digits(x)))

Try it online!

SNOBOL4 (CSNOBOL4), 83 bytes

	DEFINE('O(N)')
O	O =1
R	N LEN(1) . X REM . N	:F(RETURN)
	X =EQ(X) 1
	O =O * X	:(R)

Try it online!

A function that takes input as a string.

K (oK), 10 7 bytes

Solution:

*/1|.:'

Try it online!

Example:

*/1|.:'"4969279"
244944

Explanation:

Convert the input string to a list of integers, take max compared to 1 (inspiration from the J solution) and then multiply over the list.

Evaluation is performed right to left.

*/1|.:' / the solution
    .:' / value (.:) each (')
  1|    / or with 1 ( 0=>1, 1=>1, 2=>2 )
*/      / multiply (*) over (/) 

Java 8, 55 54 53 51 bytes

int f(int n){return n>0?(n%10>0?n%10:1)*f(n/10):1;}

Port of @Dennis' Python 2 answer.
-1 byte thanks to @RiaD.

Try it here.

55 54 bytes version:

n->{int r=1;for(;n>0;n/=10)r*=n%10>0?n%10:1;return r;}

Try it online.

Perl 5, 23 + 1 (-p) = 24 bytes

$\=1;s/./$\*=$&||1/ge}{

Try it online!

JavaScript (Node.js), 36 33 bytes

Simple Javascript (ES6) method that takes input as number string, spreads it into an array, then reduces it through multiplication or returns the value if the result is 0.

3 bytes saved thanks to Shaggy

s=>[...s].reduce((a,b)=>b*a||a,1)

Try it online!

Javascript, 58 bytes

f=a=>{b=1;for(i=0;a[i];i++){(a[i]>0)&&(b=+b*a[i])}alert(b)

Input via function(arg) outputs alert

Red, 68 bytes

func[n][p: 1 while[n > 0][d: n // 10 n: n / 10 if d > 0[p: p * d]]p]

Try it online!

Since 100000000000 is beyond the integer range of the Red language, here's another approach that solves this issue, using string manipulation:

Red, 74 bytes

func[n][p: 1 foreach c to-string n[if c >#"0"[p: p * to-integer c - 48]]p]

Try it online!

dc, 40 bytes

Sad to see dc so underrepresented here.

This is essentially my first code golf post, so if I've misjudged how bytes should be counted, go easy on me! :)

?[1+]sc[10~rdZ1<a]dsax1[rd0=c*z1<b]dsbxp

You can run this in the terminal like so:

$ echo 361218402 | dc -e '?[1+]sc[10~rdZ1<a]dsax1[rd0=c*z1<b]dsbxp'
2304

Or you can try it online!


Explanation (probably too verbose):

? # Read and execute a line from standard input
  # (A number just goes on the stack)
[ # Begin a literal string (ended by a matched ']')
1 # Push 1 onto the stack (when this string is executed as a macro)
+ # Pop top two numbers, add them, push result
] # End literal string
s # Pop top of stack (the string) and store it in...
c # ...register c
[
10 # Push 10 (duh)
~ # Pop top two numbers, divide second popped by first popped, push quotient and then remainder
r # Reverse top two numbers of stack
d # Duplicate top of stack (pop and then push it twice)
Z # Pop top of stack and push its length in digits
1
< # Pop two numbers and compare; if first popped is less than second then...
a # ...run macro stored in register a (a recursive call, here)
] # End string
d # Duplicate top of stack
s # Store in...
a # ...register a
x # Execute the top of stack!
  # At this point the stack will consist of one digit entries, the digits of input
1
[
r # Reverse
d # Duplicate
0
= # If top two numbers are equal then...
c # ...run macro in register c
* # Pop two, multiply, push product
z # Push "height" of stack
1
< # If height of stack is greater than 1 then...
b # ...run macro b
]
d # Duplicate the string on the stack
sb # Store it as macro b
x # Execute!
p # Print top of stack

Husk, 4 bytes

ΠfId

Try it online!

ΠfId  -- implicit input N, for example 1607
   d  -- digigts: [1,6,0,7]
 fI   -- filter by identity function: [1,6,7]
Π     -- product: 42

Brachylog, 5 bytes

⊇ẹ×ℕ₁

Try it online!

Explanation

⊇        Take a subset of the input
 ẹ       Split the subset into a list of digits
  ×      Product
   ℕ₁    This product must be in [1, +∞)

This works because unifies from large subsets to small subsets, so the first one that will result in a non-zero product is when all zeroes are excluded and nothing else.

Befunge, 23 22 bytes

1<*_$#`.#0@#:+!:-"0"~$

Try it online!

Explanation

1<                        Push 1, turn back left, and push a second 1.       
                     $    Drop one of them, leaving a single 1, the initial product.

                -"0"~     Read a char and subtract ASCII '0', converting to a number.
             +!:          If it's 0, make it 1 (this is n + !n).
      `  0  :             Then test if it's greater than 0, to check for EOF.
   _                      If it is greater than 0, it wasn't EOF, so we continue left.
  *                       Multiply with the current product, becoming the new product.
1<                        Now we repeat the loop, but this time push only a single 1...
                     $    ...which is immediately dropped, leaving the current product.

   _                      On EOF, the input value will be negative, so we branch right.
    $                     We don't need the input, so drop it.
       .  @               Leaving us with the product, which we output, then exit.

Batch, 78 bytes

@set/ap=%2+0,p+=!p,d=%1%%10,p*=d+!d,n=%1/10
@if %1 gtr 0 %0 %n% %p%
@echo %2

Previous 80-byte solution:

@set/an=%1,p=1
:l
@set/ad=n%%10,p*=d+!d,n/=10
@if %n% gtr 0 goto l
@echo %p%

(This version outputs 1 for an input of zero, rather than failing.)

Perl 6, 19 bytes

{[*] grep +*,.comb}

Test it

Expanded:

{  # bare block lambda with implicit parameter 「$_」

  [*]        # reduce using &infix:«*»

    grep     # find the values
      +*,    # that aren't "0"
      .comb  # split 「$_」 into digits (returns single character strings)
}

Bash + coreutils + sed + bc, 27 24 23 bytes

tr 0 1|sed s/\\B/*/g|bc

Try it online!

MATL, 5 bytes

!UXzp

Input is taken as a string

Try it at MATL Online! Or verify test cases in Try It Online!

Explanation

!     % Implicit input: string (row vector of chars). Transpose into
      % a column vector of chars
U     % Convert from string to number. Treats each row independently,
      % producing a column vector of numbers
Xz    % Keep only nonzeros
p     % Product. Implicit display

Japt, 5 bytes

ì f ×

Test it here


Explanation

In order: split to an array of digits, filter to remove zeroes and reduce by multiplication.

JavaScript (ES6), 28 bytes

Designed for 32-bit integers.

f=n=>!n||(n%10||1)*f(n/10|0)

Test cases

f=n=>!n||(n%10||1)*f(n/10|0)

console.log(f(1))        // => 1
console.log(f(10))       // => 1
console.log(f(20))       // => 2
console.log(f(100))      // => 1
console.log(f(999))      // => 729
console.log(f(21333))    // => 54
console.log(f(17801))    // => 56
console.log(f(4969279))  // => 244944

Pyth, 10 9 Bytes

.U*s!BsZs

Try it!

Explanation

.U*s!BsZs
.U        Q     Fold over the implicit input string
      sZ        Convert each char to int
   s!B          Form the list [d,not d] and sum it, so that 0 becomes 1
  *     sb      Multiply by the prev product (implicit). s needed because 1st value is char

Lua, 45 bytes

a=1(...):gsub("[^0]",load("a=a*..."))print(a)

Try it online!

APL (Dyalog), 11 7 bytes

4 bytes saved thanks to @EriktheOutgolfer

×/0~⍨⍎¨

Try it online!

Forth (gforth), 62 bytes

: f 1 swap begin ?dup while 10 /mod -rot 1 max * swap repeat ;

Try it online!

Clojure, 56 bytes

(fn[n](apply *(replace{0 1}(map #(-(int %)48)(str n)))))

Pretty basic. Turns the number into a string, then subtracts 48 from each character to turn them back into numbers. It then replaces each 0 with a 1, and applies * to the resulting list of numbers (which reduces * over the list). Can accept a number, or a stringified number.

Try it online!

(defn non-zero-prod [n]
  (let [; Abusing strings to get each digit individually
        str-n (str n)
        
        ; Then turn them back into numbers
        digits (map #(- (int %) 48) str-n)

        ; Substitute each 0 for a 1
        replaced (replace {0 1} digits)]
    
    ; Then get the product
    (apply * replaced)))

Brain-Flak, 88 bytes

Readable version:

#Push a 1 onto the alternate stack. Return to the main stack
(<>())<>

#While True:
{

    #Push the current digit minus 48 (the ASCII value of '0') onto the alternate stack
    ({}[((((()()()){}){}){}){}]<>)

    #If it's not 0...
    {
        (<

            #Multiply the top two values (the current digit and the current product that started at 1)
            ({}<>)({<({}[()])><>({})<>}{}<><{}>)

        #Also push a 0
        >)

    #Endwhile
    }

    #Pop the 0
    {}

    #Return to the main stack
    <>

#Endwhile
}

#Toggle to the alternate stack, and implicitly display
<>

Try it online!

Jelly, 4 bytes

Do1P

Try it online! or see the test suite

How it works

Do1P - Main link. Argument: n (integer)  e.g. 1230456
D    - Digits                                 [1, 2, 3, 0, 4, 5, 6]
 o1  - Replace 0 with 1                       [1, 2, 3, 1, 4, 5, 6]
   P - Product                                720

Python 2, 46 44 bytes

f=lambda n,v=1:n and f(n/10,n%10*v or v)or v

Try it online!

2 bytes thx to Lynn.

Pyt, 3 bytes

ąžΠ

Explanation:

ą       Convert input to array of digits (implicit input as stack is empty)
 ž      Remove all zeroes from the array
  Π     Get the product of the elements of the array

Try it online!

APL+WIN, 9 bytes

×/(⍎¨⎕)~0

Prompts for screen input as a character string, convert to digits, drop zeros and multiply all.

Clean, 55 bytes

import StdEnv
@n=prod[toInt c-48\\c<-:toString n|c>'0']

Try it online!

Add++, 12 bytes

L,EDBFEZB]B*

Try it online!

Python 2, 34 bytes

f=lambda n:n<1or(n%10or 1)*f(n/10)

Try it online!

Python 2, 43 bytes

lambda n:eval('*'.join(`n`.replace(*'01')))

Try it online!

><>, 19 bytes

1i:&0(?n&c4*-:0=+*!

Try it online!

Jelly, 6, 5 bytes

ṢU×\Ṁ

Try it online!

05AB1E, 4 bytes

0KSP

Try it online!

Explanation

0K     # remove zeroes
  S    # split to list of digits
   P   # product

Haskell, 36 bytes

f n=product[read[d]|d<-show n,d>'0']

Same byte count:

f n=product[max 1$read[d]|d<-show n]

Try it online!