Posts

Conway's Game of Life implemented in Python

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 10 down vote favorite I'm a Python novice and decided to give Game of Life a try in Python 3: import os import time import curses class Cell: newlabel = '' def __init__(self,row,col,label): self.row = row self.col = col self.label = label def updatecell(self,celllist, boardsize): liveneighbours = self.getliveneighbours(celllist, boardsize) if liveneighbours < 2 or liveneighbours > 3: #Kills cell if it has <2 or >3 neighbours self.newlabel = ' ' elif liveneighbours == 2 and self.label == ' ': #Cell doesn't come alive if it is dead and only has 2 neighbours self.newlabel = ' ' else: #Cell comes alive if it is already alive and has 2/3 neighbours or if it is dead and has 3 neighbours self.newlabel = 0 def getliveneighbours(self,celllist,boardsize): count = 0 for row in range(self...

Creating URL with Builder pattern

Image
Clash Royale CLAN TAG #URR8PPP .everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0; up vote 6 down vote favorite What do you think about this piece of code? How would you design the builder pattern in this situation? #ifndef CPP_URL #define CPP_URL #include<iostream> #include<vector> #include<map> using std::string; enum protocol HTTP, HTTPS ; static string map(protocol scheme) switch(scheme) case HTTP: return "http"; default: return "https"; static int defaultPort(protocol scheme) switch (scheme) case HTTP: return 80; default: return 440; class url final private: using list = std::vector<std::string>; using pairs = std::map<std::string, std::string>; const list paths; const pairs queries; const protocol scheme; const string domain; const string fragment; const string username; const string password; mutable int port; public: class builder friend url; privat...