Skip to main content
Commonmark migration
Source Link

#Bash, 77 bytes

Bash, 77 bytes

IFS=$'\n '
f=(`factor $1`)
g=(`uniq<<<"${f[*]}"`)
echo $((${#f[*]}-${#g[*]}))

Complete program, with input in $1 and output to stdout.

We set IFS to begin with a newline, so that the expansion "${f[*]}" is newline-separated. We use arithmetic substitution to print the difference between the number of words in the factorisation with the result of filtering through uniq. The number itself is printed as a prefix by factor, but it is also present after filtering, so falls out in the subtraction.

#Bash, 77 bytes

IFS=$'\n '
f=(`factor $1`)
g=(`uniq<<<"${f[*]}"`)
echo $((${#f[*]}-${#g[*]}))

Complete program, with input in $1 and output to stdout.

We set IFS to begin with a newline, so that the expansion "${f[*]}" is newline-separated. We use arithmetic substitution to print the difference between the number of words in the factorisation with the result of filtering through uniq. The number itself is printed as a prefix by factor, but it is also present after filtering, so falls out in the subtraction.

Bash, 77 bytes

IFS=$'\n '
f=(`factor $1`)
g=(`uniq<<<"${f[*]}"`)
echo $((${#f[*]}-${#g[*]}))

Complete program, with input in $1 and output to stdout.

We set IFS to begin with a newline, so that the expansion "${f[*]}" is newline-separated. We use arithmetic substitution to print the difference between the number of words in the factorisation with the result of filtering through uniq. The number itself is printed as a prefix by factor, but it is also present after filtering, so falls out in the subtraction.

Source Link
Toby Speight
  • 6.5k
  • 1
  • 24
  • 41

#Bash, 77 bytes

IFS=$'\n '
f=(`factor $1`)
g=(`uniq<<<"${f[*]}"`)
echo $((${#f[*]}-${#g[*]}))

Complete program, with input in $1 and output to stdout.

We set IFS to begin with a newline, so that the expansion "${f[*]}" is newline-separated. We use arithmetic substitution to print the difference between the number of words in the factorisation with the result of filtering through uniq. The number itself is printed as a prefix by factor, but it is also present after filtering, so falls out in the subtraction.