A Pen by Dan Couper on CodePen.
This file contains hidden or 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
| /** | |
| * Dunno how to phrase this as I'm at a very early stage of learning OCaml/Reason, | |
| * but I'm writing a calculator as first semi-complex toy app, and not sure if what | |
| * I'm trying to do is completely wrongheaded (& if I'm making some futile attempt | |
| * to replicate Erlang tagged tuple conventions using the OCaml type system). | |
| * Calculator takes a sequential stream of inputs, and I need to parse those as | |
| * they come in. To facilitate pattern matching, I wanted to set it up so that each | |
| * input is a tuple of `type * displayValue`, eg `(Digit One, "1")` or | |
| * `(Number Int, "1234")` or `(Op Div, "÷")`, so I can do basically all | |
| * processing using the type system, and configure how the display looks by |
This file contains hidden or 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
| #app |
This file contains hidden or 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
| <div id="wrapper"> | |
| <div id="app"></div> | |
| </div> |
This file contains hidden or 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
| <!-- | |
| Nothing here, the app will render on the Body. | |
| Sorry. | |
| --> |
This file contains hidden or 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
| <!--FCC Tic Tac Toe--> | |
| <header></header> | |
| <main> | |
| <button onclick='gameData.reset()'>New Game</button> | |
| <section id='gameOverall'> | |
| <div id='gameCentral' class='gameCentralDefault'></div> | |
| </section> | |
| </main> |
So you have an array and you want to add it up. Here:
var arr = [1,2,3]
var accumulator = 0
for (var i = 0; i < arr.length; i++) {
accumulator = accumulator + arr[i]
}
return accumulator
This file contains hidden or 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
| defmodule Dice do | |
| @moduledoc """ | |
| Fragile function that turns a string into a list of rolls - _e.g._ | |
| > Dice.roll("2d6") | |
| [4, 3] | |
| > Dice.roll("d12") | |
| [11] | |
| """ |
By Mark Damon Hughes [email protected]
The original Rogue algorithm is pretty nifty. Any time you need a random dungeon, give this a try:
- Divide the map into a grid (Rogue uses 3x3, but any size will work).
- Give each grid a flag indicating if it's "connected" or not, and an array of which grid numbers it's connected to.
- Pick a random room to start with, and mark it "connected".
- While there are unconnected neighbor rooms, connect to one of them, make that the current room, mark it "connected", and repeat.
- While there are unconnected rooms, try to connect them to a random connected neighbor (if a room has no connected neighbors yet, just keep cycling, you'll fill out to it eventually).
- All rooms are now connected at least once.