Skip to main content
added 35 characters in body
Source Link
Uriel
  • 13.3k
  • 4
  • 18
  • 45

APL (Dyalog), 50 2929 25 bytes

Look 'ma, no built-in totient!

4 bytes saved thanks to @H.PWiz

0{⍵=1:⍺⋄(⍺+1)∇+0⋄1+∇+/1=⍵∨⍳⍵}¨1+⍳99 

Try it online!Try it online!

How?

Apparently I went for the longer (and harder) totient formula first. See revisions history.

⍳⍵ - 1 to n

⍵∨ - gcd with n

1= - equal to 1?

+/ - sum 'em all

This is the totient. All the rest is wrapper for the counting (1+∇) and applying on the range 2..100 (¨1+⍳99).

APL (Dyalog), 50 29 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇+/1=⍵∨⍳⍵}¨1+⍳99 

Try it online!

How?

Apparently I went for the longer (and harder) totient formula first. See revisions history.

⍳⍵ - 1 to n

⍵∨ - gcd with n

1= - equal to 1?

+/ - sum 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

APL (Dyalog), 50 29 25 bytes

Look 'ma, no built-in totient!

4 bytes saved thanks to @H.PWiz

{⍵=1:0⋄1+∇+/1=⍵∨⍳⍵}¨1+⍳99 

Try it online!

How?

Apparently I went for the longer (and harder) totient formula first. See revisions history.

⍳⍵ - 1 to n

⍵∨ - gcd with n

1= - equal to 1?

+/ - sum 'em all

This is the totient. All the rest is wrapper for the counting (1+∇) and applying on the range 2..100 (¨1+⍳99).

deleted 91 characters in body
Source Link
Uriel
  • 13.3k
  • 4
  • 18
  • 45

APL (Dyalog), 5050 29 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇×/⍵,1-÷o∇+/⍨0=⍵|⍨o←(⊢~∘.×⍨)1+⍳⍵1=⍵∨⍳⍵}¨1+⍳99 

Try it online!Try it online!

How?

Apparently I went for the longer (and harder) totient formula first. See revisions history.

(⊢~∘.×⍨)1+⍳⍵⍳⍵ - primes (better don't ask)

o/⍨1 to - filter byn

0=⍵|⍨o⍵∨ - divisibility bygcd with n

1-÷o1= - array wise 1- recipeocalequal to 1?

×+/⍵, - prepend n, and multiplysum 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

APL (Dyalog), 50 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇×/⍵,1-÷o/⍨0=⍵|⍨o←(⊢~∘.×⍨)1+⍳⍵}¨1+⍳99 

Try it online!

How?

(⊢~∘.×⍨)1+⍳⍵ - primes (better don't ask)

o/⍨ - filter by

0=⍵|⍨o - divisibility by n

1-÷o - array wise 1- recipeocal

×/⍵, - prepend n, and multiply 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

APL (Dyalog), 50 29 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇+/1=⍵∨⍳⍵}¨1+⍳99 

Try it online!

How?

Apparently I went for the longer (and harder) totient formula first. See revisions history.

⍳⍵ - 1 to n

⍵∨ - gcd with n

1= - equal to 1?

+/ - sum 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

added 289 characters in body
Source Link
Uriel
  • 13.3k
  • 4
  • 18
  • 45

APL (Dyalog), 50 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇×/⍵,1-÷o/⍨0=⍵|⍨o←(⊢~∘.×⍨)1+⍳⍵}¨1+⍳99 

Try it online!

How?

(⊢~∘.×⍨)1+⍳⍵ - primes (better don't ask)

o/⍨ - filter by

0=⍵|⍨o - divisibility by n

1-÷o - array wise 1- recipeocal

×/⍵, - prepend n, and multiply 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

APL (Dyalog), 50 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇×/⍵,1-÷o/⍨0=⍵|⍨o←(⊢~∘.×⍨)1+⍳⍵}¨1+⍳99 

Try it online!

APL (Dyalog), 50 bytes

Look 'ma, no built-in totient!

0{⍵=1:⍺⋄(⍺+1)∇×/⍵,1-÷o/⍨0=⍵|⍨o←(⊢~∘.×⍨)1+⍳⍵}¨1+⍳99 

Try it online!

How?

(⊢~∘.×⍨)1+⍳⍵ - primes (better don't ask)

o/⍨ - filter by

0=⍵|⍨o - divisibility by n

1-÷o - array wise 1- recipeocal

×/⍵, - prepend n, and multiply 'em all

This is the totient. All the rest is wrapper for the counting and applying on 2..100.

Source Link
Uriel
  • 13.3k
  • 4
  • 18
  • 45
Loading