Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit28c27d9

Browse files
appgurueuraklaptudirm
authored andcommitted
chore: format using prettier
1 parent0b9fad8 commit28c27d9

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

‎Backtracking/MColoringProblem.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@
66
*@see https://en.wikipedia.org/wiki/Graph_coloring
77
*/
88
functionmColoring(graph,m){
9-
constcolors=newArray(graph.length).fill(0);
9+
constcolors=newArray(graph.length).fill(0)
1010

1111
// Check if it's safe to color a vertex with a given color.
1212
functionisSafe(vertex,color){
1313
for(leti=0;i<graph.length;i++){
1414
if(graph[vertex][i]&&colors[i]===color){
15-
returnfalse;
15+
returnfalse
1616
}
1717
}
18-
returntrue;
18+
returntrue
1919
}
2020

2121
// Use backtracking to try and color the graph.
2222
functionsolveColoring(vertex=0){
2323
if(vertex===graph.length){
24-
returntrue;
24+
returntrue
2525
}
2626

2727
for(letcolor=1;color<=m;color++){
2828
if(isSafe(vertex,color)){
29-
colors[vertex]=color;
30-
29+
colors[vertex]=color
30+
3131
if(solveColoring(vertex+1)){
32-
returntrue;
32+
returntrue
3333
}
3434

3535
// If no solution, backtrack.
36-
colors[vertex]=0;
36+
colors[vertex]=0
3737
}
3838
}
39-
returnfalse;
39+
returnfalse
4040
}
4141

4242
// If coloring is possible, return the colors.
4343
if(solveColoring()){
44-
returncolors;
44+
returncolors
4545
}
46-
returnnull;
46+
returnnull
4747
}
4848

49-
export{mColoring};
49+
export{mColoring}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import{mColoring}from'../MColoringProblem';
1+
import{mColoring}from'../MColoringProblem'
22

33
describe('MColoringProblem',()=>{
44
it('should color a triangle with 3 colors',()=>{
55
constgraph=[
66
[0,1,1],
77
[1,0,1],
88
[1,1,0]
9-
];
10-
constsolution=mColoring(graph,3);
11-
expect(solution).not.toBeNull();
12-
});
9+
]
10+
constsolution=mColoring(graph,3)
11+
expect(solution).not.toBeNull()
12+
})
1313

1414
it('should not color a triangle with 2 colors',()=>{
1515
constgraph=[
1616
[0,1,1],
1717
[1,0,1],
1818
[1,1,0]
19-
];
20-
constsolution=mColoring(graph,2);
21-
expect(solution).toBeNull();
22-
});
23-
});
19+
]
20+
constsolution=mColoring(graph,2)
21+
expect(solution).toBeNull()
22+
})
23+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp