MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / IsAutomorphic

Function IsAutomorphic

math/isautomorphic.go:16–32  ·  view source on GitHub ↗
(n T)

Source from the content-addressed store, hash-verified

14)
15
16func IsAutomorphic[T constraints.Integer](n T) bool {
17 // handling the negetive number case
18 if n < 0 {
19 return false
20 }
21
22 n_sq := n * n
23 for n > 0 {
24 if (n % 10) != (n_sq % 10) {
25 return false
26 }
27 n /= 10
28 n_sq /= 10
29 }
30
31 return true
32}

Callers 1

TestIsAutomorphicFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsAutomorphicFunction · 0.68