Let's Have Some Fun with Game Of Life:& Learn to Think Functionally Along the Way Venkat Subramaniam
ฝัง
- เผยแพร่เมื่อ 1 ต.ค. 2024
- Game of Life is an intriguing game. At first look it looks simple, but as you look closer, it appears to be quite complex. How can we implement this game with different constraints, what are the constraints? Is it possible to use functional programming for this, to honor immutability? You see, it is intriguing. We will discuss the constraints, think about how we may be able to solve them, and along the way discover how functional programming can play a role. We will have a fully working program, using live coding, at the end of this session, to illustrate some nice ideas that will emerge from our discussions.
For more on-demand content, visit: saltmarch.com/...
the kid at 21:00😅 is super annoying
He forgot the first law of power: Never outshine the master.
To anyone interest , this is my solution
static Set nextGeneration(List liveCells) {
var cells = generateSignalsForCells(liveCells);
return countSignals(cells)
.entrySet()
.stream()
.filter(entry -> {
var cell = entry.getKey();
var count = entry.getValue();
return count == 3 || (count == 2 && liveCells.contains(cell));
}).map(Map.Entry::getKey)
.collect(Collectors.toSet());
}