44
votes
Accepted
Should we be friends?
SWI-Prolog, 62 47 41 bytes
X*Y:-X+Y;Y+X;X==Y.
X?Y:-not(X*Y),X*Z,Y*Z.
Prolog isn't too often useful, but when it is it's just beautiful. We'll use ...
27
votes
Is it a valid chemical?
Python 3, 61 60 59 58 51 bytes
lambda x:len(x)-2<~sum(x)%2*all(x)*sum(x)/2>=max(x)
Try it online!
-1 thanks to @Kevin Cruijssen
-7 thanks to @xnor
Uses ...
23
votes
Get to the Zone!
JavaScript (ES6), 30 bytes
Takes input as (N)(M).
N=>g=M=>M>N?M%2-~g(M+1>>1):N-M
Try it online!
How?
Instead of ...
20
votes
Is it bipartite?
Wolfram Language (Mathematica), 26 25 bytes
Tr[#//.x_:>#.#.Clip@x]<1&
Try it online!
How it works
Given an adjacency matrix A, we find the fixed ...
16
votes
Somewhere On The Tube ...But On Which Lines?
ES6, Node.js / Chrome, 989 977 931 892 889 887 bytes
...
16
votes
Accepted
15
votes
Arranging Bubbles
Python 2, 92 87 bytes
a=lambda n:n<2or sum((k%d<1)*d*a(d)*a(n-k)for k in range(1,n)for d in range(1,1+k))/~-n
In plain english: to compute ...
15
votes
15
votes
Hexcellent Minesweeping
7 5 vertices, 14 10 edges
(Graph made with this online tool and paint.)
A-F are our six nodes, and ...
15
votes
14
votes
14
votes
13
votes
Enumerate binary trees
Haskell, 68 bytes
t 0=[""]
t 1=["0"]
t n=['(':x++y++")"|k<-[1..n-1],x<-t k,y<-t$n-k-1]
Terminal nodes are represented by ...
13
votes
13
votes
Do the NP: find the largest clique
Mathematica, 34 bytes
Tr[1^#&@@FindClique[#<->#2&@@@#]]&
Basically FindClique does the job and "finds a largest clique in the graph g."
All ...
13
votes
Drawing one-liner
Python, 31 bytes
lambda l:sum(n%2for n in l)|2<3
Try it online!
We use k|2<3 to check that ...
13
votes
Accepted
13
votes
Ways to paint a backbone on a tree
Python, 238 bytes
-7 bytes thanks to @Neil
-8 bytes thanks to @emanresu A
-5 bytes thanks to @xnor
+72 bytes due to a very serious bug (pointed out by @Jonathan Allan); bugged version
...
12
votes
Should we be friends?
CMD (Batch), 50 + 20 + 135 = 205 bytes
FRIEND.CMD
@for %%f in (%1.%1 %1.%2 %2.%2 %2.%1)do @set %%f=1
KNOW.CMD
...
12
votes
Knight Distance
Wolfram Language (Mathematica), 64 bytes
Using the built-in KnightTourGraph.
Saved 2 bytes thanks to Mathe172.
...
12
votes
12
votes
Who Is Kevin Bacon?
BQN*, 53 45 bytesSBCS
{1+⊑⍒+˝+´(∨∨∨˝∘×⎉1‿∞)⍟n˜∨⟜⍉∨˝𝕩≡⌜1+⋈⌜˜n←↕⌈´∾𝕩}
Run online!
Theory:
Let \$k\$ be the maximum node id. Then the node IDs are \$\{1, 2, ..., k\}...
12
votes
Detect round trips on a dodecahedron
Python 2, 79 bytes
lambda s:all(n==reduce(lambda n,c:-~[n,n%3+n%4][c>'L']%5,s,n)for n in range(5))
Try it online!
This uses the group-theoretic approach from ...
11
votes
11
votes
Accepted
Surface of the 3x3x3 cube as a graph
APL (Dyalog Classic), 34 30 bytes
-4 thanks to jimmy23013
4≥+/¨|∘.-⍨,(⍳3)∘.⌽7 ¯1∘.,○⍳3 3
Try it online!
outputs an adjacency matrix with each vertex adjacent ...
11
votes
Accepted
Complete the grid-filling meander
JavaScript (ES7), 236 ... 193 185 bytes
Outputs by modifying the input matrix.
...
11
votes
Accepted
Count all binary relations
APL (Dyalog Extended), 99 93 bytes
r←0∊0 0⍉⊢
R←r~
s←⊢≢⍉
S←1∊⊢∧⍉
t←0∊⊢≥∨.∧⍨
T←1∊⊢∧∨.∧⍨
{×⍵:+/∧⌿~(⍺,'0'){(⍎⍺)⊣⍵}\⍵-⍛↑∘⊤¨,⍳⍵⍴2*⍵⋄1}
Try it online!
-5 bytes thanks to ...
11
votes
11
votes
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
graph-theory × 205code-golf × 178
decision-problem × 32
grid × 22
math × 19
path-finding × 16
combinatorics × 15
code-challenge × 12
optimization × 9
ascii-art × 7
array × 7
sequence × 6
fastest-code × 6
maze × 6
chess × 5
string × 4
geometry × 4
game × 4
matrix × 4
permutations × 4
fastest-algorithm × 4
binary-matrix × 4
graphical-output × 3
sorting × 3
atomic-code-golf × 3