Skip to main content
Commonmark migration
Source Link

###GolfScript, 16 characters###

GolfScript, 16 characters

~.`:s{48-s,?-}/! 

Input must be given on STDIN, output is 0 or 1 indicating non-narcissistic / narcissistic number.

Explanation of the code:

~ # Evaluate the input to get a number . # Accumulator (initially the number itself) `:s # Convert number to string and assign to variable s { # Loop over characters of the string 48- # Reduce character value by 48 s, # Push length of input number ? # Power - # Subtract result from accumulator }/ ! # Not! (i.e. iff accumulator was zero it was a narcissistic number) 

###GolfScript, 16 characters###

~.`:s{48-s,?-}/! 

Input must be given on STDIN, output is 0 or 1 indicating non-narcissistic / narcissistic number.

Explanation of the code:

~ # Evaluate the input to get a number . # Accumulator (initially the number itself) `:s # Convert number to string and assign to variable s { # Loop over characters of the string 48- # Reduce character value by 48 s, # Push length of input number ? # Power - # Subtract result from accumulator }/ ! # Not! (i.e. iff accumulator was zero it was a narcissistic number) 

GolfScript, 16 characters

~.`:s{48-s,?-}/! 

Input must be given on STDIN, output is 0 or 1 indicating non-narcissistic / narcissistic number.

Explanation of the code:

~ # Evaluate the input to get a number . # Accumulator (initially the number itself) `:s # Convert number to string and assign to variable s { # Loop over characters of the string 48- # Reduce character value by 48 s, # Push length of input number ? # Power - # Subtract result from accumulator }/ ! # Not! (i.e. iff accumulator was zero it was a narcissistic number) 
Source Link
Howard
  • 23.6k
  • 2
  • 45
  • 83

###GolfScript, 16 characters###

~.`:s{48-s,?-}/! 

Input must be given on STDIN, output is 0 or 1 indicating non-narcissistic / narcissistic number.

Explanation of the code:

~ # Evaluate the input to get a number . # Accumulator (initially the number itself) `:s # Convert number to string and assign to variable s { # Loop over characters of the string 48- # Reduce character value by 48 s, # Push length of input number ? # Power - # Subtract result from accumulator }/ ! # Not! (i.e. iff accumulator was zero it was a narcissistic number)