Vagif Abilov Playing functional Conway’s game of life.

Slides:



Advertisements
Similar presentations
Homework Assignment. Assignment One Ready for the next challenge. Great! Time to pick an affiliate product to promote. Go to ClickBank.com and go to the.
Advertisements

How to be a good teacher? What makes a good teacher?
Mini Golf Laurie DiGregorio Germantown Hills Middle School, Metamora, IL Teresa Yazujian Eureka Middle School, Eureka, IL Nancy.
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Slide 1 FastFacts Feature Presentation June 14, 2011 We are using audio during this session, so please dial in to our conference line… Phone number:
Connecticut Mastery Test Larry Hillman, Presenter
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
How to be SAFE when you use the internet..
MA 1128: Lecture 18 – 6/19/13 Completing the Square.
CSE 160 – Lecture 9 Speed-up, Amdahl’s Law, Gustafson’s Law, efficiency, basic performance metrics.
FB Lead By Brian Lim Ea sy.
© 2012 WakeUpNow, Inc. All Rights Reserved.. It doesn’t matter HOW good WakeUpNow is if you don’t know HOW to share the business.
6.4 Best Approximation; Least Squares
Prime Times for Learning
Karla Goldhahn Mathematics Instructional Lead teacher Patrick Henry Academies Math Games at Home.
Big Idea Video Podcast. Pretest 1. Define the Associative Property. Give an example. 2. Define the Commutative Property. Give an example. 3. Tanya has.
AE1APS Algorithmic Problem Solving John Drake
Lecture 20 – Boolean Operators Dr. Patricia J. Riddle.
Inferences Summaries Literary devices Imagery Sensory details Mrs. Wendele Reading Class.
Welcome to this quick guide/presentation of M2TIEMPOS We’re an easy way to buy spare parts, engines and power.
Order of Operations And Real Number Operations
Customers Request the Darndest Things* 10 Challenges for VUI Designers Eduardo Olvera User Interface Designer.
MA 1165: Special Assignment Completing the Square.
© Mailbarrow Spreadsheet Professional Getting Your Spreadsheet Numbers Under Control A 5 minute presentation by Mailbarrow
Announcements You survived midterm 2! No Class / No Office hours Friday.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Mutability SWE 332 Fall 2011 Paul Ammann. SWE 3322 Data Abstraction Operation Categories Creators Create objects of a data abstraction Producers Create.
{ John Conway’s Game of Life.  John von Neumann  Wanted to find/create a machine that could replicate itself  Found an answer, but it was very complex.
Game of Life Rules and Games Linh Tran ECE 573. What is Life? Life is just one example of a cellular automaton, which is any system in which rules are.
1 The Game of Life Supplement 2. 2 Background The Game of Life was devised by the British mathematician John Horton Conway in More sophisticated.
A small part of what you should know about continuations, but were too afraid to ask Nick Benton.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Threading Part 3 CS221 – 4/24/09. Teacher Survey Fill out the survey in next week’s lab You will be asked to assess: – The Course – The Teacher – The.
Week 2: Primitive Data Types 1.  Programming in Java  Everything goes inside a class  The main() method is the starting point for executing instructions.
Chapter 25 GRASP: More Objects with Responsibilities 1CS6359 Fall 2011 John Cole.
CELLULAR AUTOMATON Presented by Rajini Singh.
Conway’s Game of Life Andrew Williams
Project 1CS-4513, D-Term Programming Project #1 Concurrent Game of Life Due Friday, March 20.
Objective I can find zeros by completing the square.
04/25/13 Halting Problem Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1
Introduction To Logarithms. Logarithms were originally developed to simplify complex arithmetic calculations. They were designed to transform multiplicative.
Introduction Computational Challenges Serial Solutions Distributed Memory Solution Shared Memory Solution Parallel Analysis Conclusion Introduction: 
Reflective practice Session 4 – Working together.
WRITING EFFECTIVE S. Before writing the Make a plan! Think about the purpose of the Think about the person who will read the and.
March 21, 2011 Bassett High School Bloom’s Taxonomy Revised and Revisited.
Towers of Hanoi. Introduction This problem is discussed in many maths texts, And in computer science an AI as an illustration of recursion and problem.
Unit 11, Part 2: Introduction To Logarithms. Logarithms were originally developed to simplify complex arithmetic calculations. They were designed to transform.
Unit 11, Part 2: Introduction To Logarithms. Logarithms were originally developed to simplify complex arithmetic calculations. They were designed to transform.
MOM! Phineas and Ferb are … Aims:
Big Ideas & Better Questions, Part II Marian Small May, ©Marian Small, 2009.
English tongue twisters If you understand, say "understand". If you don't understand, say "don't understand". but if you understand and say "don't understand".
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Activity 2-1: The Game of Life
Introduction to Lattice Simulations. Cellular Automata What are Cellular Automata or CA? A cellular automata is a discrete model used to study a range.
Cellular Automata. The Game The Game of Life is not your typical computer game. It is a 'cellular automation', and was invented by the Cambridge mathematician.
Fractals. In colloquial usage, a fractal is "a rough or fragmented geometric shape that can be subdivided in parts, each of which is (at least approximately)
Parallel Programming 0024 Spring Semester 2010 May 6, 2010.
Activity 1-19: The Propositional Calculus
Hack for HHVM Converting Facebook Julien Verlaguet Software Engineer.
M1G Introduction to Programming 2 5. Completing the program.
1 Project designed and created by M. Shajith Kumar.
In Google Earth, we can find the fabric of the block is the standard type of old urban.
What are The Traits of Writing? A trait can be defined as a characteristic needed for a successful performance. Just as there are traits for good.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Conway’s Game of Life Jess Barak Game Theory. History Invented by John Conway in 1970 Wanted to simplify problem from 1940s presented by John von Neumann.
ORDER OF OPERATIONS. Did you get one of these numbers as an answer? 18? 12? SOLVE THIS PROBLEM.
Bumble Bee Class Supporting Your Child with Reading 15 th January 2015.
Presentation transcript:

Vagif Abilov Playing functional Conway’s game of life

About myself Mail: GitHub: object BitBucket: object Blog: Articles: The source code for this presentation can be found at

Conway’s game of life Invented in 1970 by the British mathematician John Conway Zero-player game, its evolution is fully determined by its initial state The universe of the Game of Life is an infinite two- dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead Source: Wikipedia

Rules of Conway’s game of life 1.Any live cell with fewer than two live neighbours dies, as if caused by under-population. 2.Any live cell with two or three live neighbours lives on to the next generation. 3.Any live cell with more than three live neighbours dies, as if by overcrowding. 4.Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

Impelemening Conway’s game How would you approach the implementation? A small quiz: what names should we introduce? Classes Class properties Class methods Structs Enums

What people say on Twitter “How is writing Java like writing classic Russian literature? You have to introduce 100 names before anything can

Speaking about Russian literature Nightingales, a sigh, a whisper In a shady nook And the lullaby in silver Of a lazy brook. … A short poem by Afanasy Fet (1850) 12 lines, not a single verb

Checking other implementations Source: Conway-s-Game-of-Life-using-State-Pattern

Implementation code metrics 5 classes (including 2 subclasses) 5 properties 5 methods 316 lines of code 64 effective lines of code (calculated using VS code metrics)

Cell state definition Discussion in comments about cell state definition Class (base class with 2 subclasses implementing State pattern) Enum (Dead, Alive) Boolean What would you choose?

Cell state choice consequence No matter what type you choose to represent cell state, you will need a cell property to hold it Having cells with different property values (Dead and Alive) encourages design where both types of cells are stored Storing cells with different states has negative impact on the scalability Moreover: it limits the solution to boards of fixed size Adding names add constraints!

Imperative languages lessons Extra definitions may better clarify your intentions but may also lead to increased system complexity Names are opinionated, more names – more opinions More names – more constraints Design patterns are often introduced to patch up shortcomings in the language

Entering functional programming Conway’s game of life is about transforming cell generations What if we focus just on functional transformations?

Implementation plan 1.Classical game of life 2.Multidimensional game of life 3.Concurrent game of life 4.Game of life visualization 5.Something completely different

Classical game of life

Observation It’s possible to write clean code without class hierarchies

Multidimensional game of life

Observation You don’t need to revise your code to make it generic: with type inference it just happens to you

Asynchronous game of life

Asynchronous burden Asynchronous support requires revision of API and its implementation It is common to offer two (significantly different) versions of API: one for synchronous and one for asynchronous execution Mutable nature of imperative languages require major changes if not complete rewrite of components to become thread-safe and support asynchronous or parallel execution

Asynchronous programming model Synchronous: –Execute (can be any verb, e.g. Read) Asynchronous: –BeginExecute (receives AsyncCallback, returns IAsyncResult) –EndExecute (receives IAsyncResult object) – method (receives IAsyncResult) File IO example: –Read –BeginRead, EndRead,

Benchmark results Pattern size*C# LinqF#F# AsyncF# PSeq 10**0: : : : : : : : : : : : : : : : * Pattern size N corresponds to a square N * N used to generate a pattern of N * N / 2 elements ** Pattern size 10 was used to warm up the text fixture

Observation Immutable data structures make it trivial to execute parts of your code asynchronously or in parallel

Game of life visualization

Observation It’s simple to send your data to external components when data are exposed via primitive types

Time for surprises Something completely different Living with no sense of monad

Song time! Living With No Sense of Monads Originally performed by Smokie with slightly different words

Living with no sense of monads I first met Alice in a small bookstore, "What book, - I asked, - are you looking for?" And she said: "About monads." I understood that's a key to her heart, I had no doubts that I was smart. It should be easy reading, an easy start...

Living with no sense of monads But I still don't get this wisdom, It's really mystic word I guess it has it's reasons, Someone gets it, but I don't. 'Cos for twenty-four years I've been trying to understand the monads.

Living with no sense of monads Twenty-four years Just waiting for a chance, I have to keep on reading, Maybe get a second glance, I will never get used to not understanding sense of monads

Living with no sense of monads Grew up together, Went to the same class, And to be honest: I was better in math Than Alice.

Living with no sense of monads Too old for rock-n-roll - I'm forty four, Too young for monads - still have a hope. That the day will come When I let Alice know...

Living with no sense of monads But I still don't get this wisdom, It's really mystic word I guess it has it's reasons, Someone gets it, but I don't. 'Cos for twenty-four years I've been trying to understand the monads. (all together): Monads! What the f*ck is monads?!

Living with no sense of monads Twenty-four years Just waiting for a chance, I have to keep on reading, Maybe get a second glance, I will never get used to not understanding sense of monads

Thank you! Mail: GitHub: object BitBucket: object Blog: Articles: The source code for this presentation can be found at