This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
typedef struct | |
{ | |
int x, y; | |
} Vector2d; | |
#define WALL "#" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (let i = 1; i <= 100; i++) { | |
let text = "" | |
if (i % 3 === 0) text += "Crackle" | |
if (i % 5 === 0) text += "Pop" | |
console.log(text || i) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<svg | |
xmlns="http://www.w3.org/2000/svg" | |
height="6rem" | |
viewBox="0 0 210 107" | |
style="position: fixed" | |
> | |
<path | |
d="M118.895,20.346c0,0-13.743,16.922-13.04,18.001c0.975-1.079-4.934-18.186-4.934-18.186s-1.233-3.597-5.102-15.387H81.81H47.812H22.175l-2.56,11.068h19.299h4.579c12.415,0,19.995,5.132,17.878,14.225c-2.287,9.901-13.123,14.128-24.665,14.128H32.39l5.552-24.208H18.647l-8.192,35.368h27.398c20.612,0,40.166-11.067,43.692-25.288c0.617-2.614,0.53-9.185-1.054-13.053c0-0.093-0.091-0.271-0.178-0.537c-0.087-0.093-0.178-0.722,0.178-0.814c0.172-0.092,0.525,0.271,0.525,0.358c0,0,0.179,0.456,0.351,0.813l17.44,50.315l44.404-51.216l18.761-0.092h4.579c12.424,0,20.09,5.132,17.969,14.225c-2.29,9.901-13.205,14.128-24.75,14.128h-4.405L161,19.987h-19.287l-8.198,35.368h27.398c20.611,0,40.343-11.067,43.604-25.288c3.347-14.225-11.101-25.293-31.89-25.293h-18.143h-22.727C120.923,17.823,118.895,20.346,118.895,20.346L118.895,20.346z" | |
/> | |
<path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <array> | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
vector<vector<int>> parseInput(const string &fileName) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MakePathAndConnect(Maze *mazeData, Vector2 pos1, Vector2 pos2) | |
{ | |
const Vector2 inbetweenWall = (Vector2){ | |
(pos1.x + pos2.x) / 2, | |
(pos1.y + pos2.y) / 2}; | |
MakePath(mazeData, inbetweenWall); | |
MakePath(mazeData, pos2); | |
} | |
void PrintMaze(const Maze *mazeData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool IsWall(const Maze *mazeData, Vector2 pos) | |
{ | |
const int mazeSize = mazeData->size; | |
if (pos.x < 0 || pos.y < 0 || pos.x >= mazeSize || pos.y >= mazeSize) | |
return false; //out of bounds neighbors not considered | |
return (mazeData->grid[mazeSize * pos.y + pos.x]) == WALL; | |
} | |
int GetWalledNeighbors(const Maze *mazeData, Vector2 neighbors[4], Vector2 pos) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GenerateMaze(Maze *mazeData, Vector2 pos) | |
{ | |
Vector2 neighbors[4]; | |
const int neighborAmount = GetWalledNeighbors(mazeData, neighbors, pos); | |
if (neighborAmount == 0) | |
return; | |
const int randNeighborNum = rand() % neighborAmount; | |
const Vector2 randNeighbor = neighbors[randNeighborNum]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void MakePath(Maze *mazeData, Vector2 pos) | |
{ | |
const int gridSize = mazeData->size; | |
mazeData->grid[pos.y * gridSize + pos.x] = PATH; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector2 PickRandomStart(int userSize) | |
{ | |
srand(time(NULL)); // use current time as seed for rand | |
Vector2 randPoint = {rand() % userSize, rand() % userSize}; | |
randPoint.x = randPoint.x * 2 + 1; | |
randPoint.y = randPoint.y * 2 + 1; | |
return randPoint; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maze InitializeMazeData(int userSize) | |
{ | |
const int gridSize = userSize * 2 + 1; | |
return (Maze){ | |
calloc(sizeof(bool), gridSize * gridSize), | |
gridSize}; | |
} |
NewerOlder