Skip to content

Commit

Permalink
category-cycles: code formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Oct 21, 2024
1 parent 6dc324d commit c05478d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 46 deletions.
82 changes: 41 additions & 41 deletions category-cycles/find_cycles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,56 @@ unordered_map<int,int> edgeTo;
bool first = true;

void dfs(int v) {
visited.insert(v);
onStack.insert(v);
for (int i : graph[v]) {
if (visited.find(i) == visited.end()) { // unvisited
edgeTo[i] = v;
dfs(i);
} else if (onStack.find(i) != onStack.end()) {
if (first) {
cout << "[";
first = false;
} else {
cout << ",[";
}
int x = v;
while (x != i) {
cout << x << ",";
x = edgeTo[x];
}
cout << i << "]";
}
}
onStack.erase(onStack.find(v));
visited.insert(v);
onStack.insert(v);
for (int i : graph[v]) {
if (visited.find(i) == visited.end()) { // unvisited
edgeTo[i] = v;
dfs(i);
} else if (onStack.find(i) != onStack.end()) {
if (first) {
cout << "[";
first = false;
} else {
cout << ",[";
}
int x = v;
while (x != i) {
cout << x << ",";
x = edgeTo[x];
}
cout << i << "]";
}
}
onStack.erase(onStack.find(v));
}

int main() {
// Speed up I/O
ios_base::sync_with_stdio(0);
cin.tie(0);

int parent, sub;
while (1) {
cin >> sub;
if (sub == -1) { // end of input
break;
}
cin >> parent;
int parent, sub;
while (1) {
cin >> sub;
if (sub == -1) { // end of input
break;
}
cin >> parent;

// Build adjacency list representation
graph[parent].insert(sub);
}
// cout << "Finished generating subcategory graph...\n";
// Build adjacency list representation
graph[parent].insert(sub);
}
// cout << "Finished generating subcategory graph...\n";

cout << "[";
cout << "[";

// Begin DFS
for (auto p: graph) {
if (visited.find(p.first) == visited.end()) {
dfs(p.first);
}
}
// Begin DFS
for (auto p: graph) {
if (visited.find(p.first) == visited.end()) {
dfs(p.first);
}
}

cout << "]";
cout << "]";
}
9 changes: 4 additions & 5 deletions category-cycles/prettify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {bot, log} = require('../botbase');
const PAGE_SIZE_MAX_LIMIT = 60000;
const MAX_PAGES = 100;
const ROOT_PAGE = process.env.ROOT_PAGE || 'User:SDZeroBot/Category cycles';
const PAGE_LEAD = `{{${ROOT_PAGE}/header}}\n`;
const PAGE_LEAD = '{{' + ROOT_PAGE + '/header}}\n';

process.chdir(__dirname);

Expand Down Expand Up @@ -56,16 +56,15 @@ let cycles = require('./cycles.json').sort((a, b) => a.length - b.length);
}
}

const wiki_page_name = num => `${ROOT_PAGE}/${num}`

let pageNumber = 1;
let page = PAGE_LEAD;

for (let cycle of cycles) {
page += '*' + cycle.map(e => `[[:Category:${map[e]}|${map[e]}]]`).join(' → ') + '\n';
if (page.length > PAGE_SIZE_MAX_LIMIT) {
await bot.save(wiki_page_name(pageNumber), page, 'Updating category cycles');
log(`[+] Saved ${wiki_page_name(pageNumber)}`);
const pageName = ROOT_PAGE + '/' + pageNumber;
await bot.save(pageName, page, 'Updating category cycles');
log(`[+] Saved ${pageName}`);
pageNumber++;
page = PAGE_LEAD;
if (pageNumber > MAX_PAGES) {
Expand Down

0 comments on commit c05478d

Please sign in to comment.