Skip to main content
added 507 characters in body
Source Link
Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291

J, 11 bytes

+/@(1=+.)i. 

Usage

>> f =: +/@(1=+.)i. >> f 44 << 20 

where >> is STDIN and << is STDOUT.

Explanation

+/ @ ( 1 = +. ) i. │ ┌───────────┴┐ +/@(1=+.) i. │ ┌─┼──┐ +/ @ 1=+. ┌─┼─┐ 1 = +. >> (i.) 44 NB. generate range << 0 1 2 3 4 ... 43 >> (+.i.) 44 NB. calculate gcd of each with input << 44 1 2 1 4 ... 1 >> ((1=+.)i.) 44 NB. then test if each is one (1 if yes, 0 if no) << 0 1 0 1 0 ... 1 >> (+/@(1=+.)i.) 44 NB. sum of all the tests << 20 

J, 11 bytes

+/@(1=+.)i. 

Usage

>> f =: +/@(1=+.)i. >> f 44 << 20 

where >> is STDIN and << is STDOUT.

J, 11 bytes

+/@(1=+.)i. 

Usage

>> f =: +/@(1=+.)i. >> f 44 << 20 

where >> is STDIN and << is STDOUT.

Explanation

+/ @ ( 1 = +. ) i. │ ┌───────────┴┐ +/@(1=+.) i. │ ┌─┼──┐ +/ @ 1=+. ┌─┼─┐ 1 = +. >> (i.) 44 NB. generate range << 0 1 2 3 4 ... 43 >> (+.i.) 44 NB. calculate gcd of each with input << 44 1 2 1 4 ... 1 >> ((1=+.)i.) 44 NB. then test if each is one (1 if yes, 0 if no) << 0 1 0 1 0 ... 1 >> (+/@(1=+.)i.) 44 NB. sum of all the tests << 20 
Source Link
Leaky Nun
  • 50.6k
  • 6
  • 115
  • 291

J, 11 bytes

+/@(1=+.)i. 

Usage

>> f =: +/@(1=+.)i. >> f 44 << 20 

where >> is STDIN and << is STDOUT.