Skip to content

Instantly share code, notes, and snippets.

@Shadowbeetle
Last active November 7, 2022 19:27
Show Gist options
  • Save Shadowbeetle/7263abc7e9731c381ffcbe545f2424fe to your computer and use it in GitHub Desktop.
Save Shadowbeetle/7263abc7e9731c381ffcbe545f2424fe to your computer and use it in GitHub Desktop.

Anti-divisor

Solution

even_anti_divisor? = fn nmodk, k -> nmodk == k / 2 end
odd_anti_divisor? = fn nmodk, k -> nmodk == (k - 1) / 2 or nmodk == (k + 1) / 2 end
anti_divisor? = fn nmodk, k -> even_anti_divisor?.(nmodk, k) or odd_anti_divisor?.(nmodk, k) end

anti_divisors = fn n ->
  for k <- 2..(n - 1),
      n > 2 and anti_divisor?.(rem(n, k), k),
      into: [],
      do: k
end
anti_divisors.(1)
# []
anti_divisors.(2)
# []
anti_divisors.(3)
# [2]
anti_divisors.(5)
# [2, 3]
anti_divisors.(10)
# [3, 4, 7]
anti_divisors.(234)
# [4, 7, 12, 36, 52, 67, 156]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment