Quantcast
Channel: Lattice points visible from the origin - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 15

Answer by Kevin Cruijssen for Lattice points visible from the origin

$
0
0

05AB1E, 13 bytes

(ŸÄDδ¿Θ»T„. ‡

Try it online or verify all test cases.

Explanation:

(              # Negate the (implicit) input-integerŸ             # Push a list in the range [(implicit) input, -input]Ä            # Take the absolute value of each: [n,n-1,...,0,...,n-1,n]   Dδ¿         # Create a GCD-table of this list:   D           #  Duplicate the list:δ          #  Pop both lists, and apply double-vectorized:¿         #   Greatest Common DivisorΘ        # Check which values are 1 (1 if 1; 0 otherwise)»       # Join each inner list by spaces, and then each string by newlines        T      # Push 10„.    # Push ". "‡  # Transliterate all 1s to "."s and all 0s to spaces               # (after which the result is output implicitly)

Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images