Giter VIP home page Giter VIP logo

challenge-hotplate's Introduction

challenge-Hotplate

Hotplate coding problem I heard about on Javascript Jabber (https://gist.github.com/coolaj86/6033171)

HotPlate

You have a 16x16 grid of which the 4 centermost cells are always 100 degrees and the cornermost cells are always 0 degrees. All other cells start at 50 degrees.

For example, a 6x6 grid would look like this:

|  0  | 50  | 50  | 50  | 50  |  0  |
| 50  | 50  | 50  | 50  | 50  | 50  |
| 50  | 50  | 100 | 100 | 50  | 50  |
| 50  | 50  | 100 | 100 | 50  | 50  |
| 50  | 50  | 50  | 50  | 50  | 50  |
|  0  | 50  | 50  | 50  | 50  |  0  |

Each turn the temperature of each cell (aside from the 4 hot and 4 cold) changes to be the average of the 4 adjacent cells left, right, up, and down.

The goal is to determine how many turns it takes until not a single cell has changes more than 0.001 degrees and then print out the grid.

For example, the result of running on a 6x6 grid would be this:

Grid: 6x6
Turns: 57
Diff: 0.001
   0.00  33.33  49.99  49.99  33.33   0.00
  33.33  50.00  66.66  66.66  50.00  33.33
  49.99  66.66 100.00 100.00  66.66  49.99
  49.99  66.66 100.00 100.00  66.66  49.99
  33.33  50.00  66.66  66.66  50.00  33.33
   0.00  33.33  49.99  49.99  33.33   0.00
Actual Diff: 0.0009489096904715666

Or with a splash of color:

"Fancy Grid"

Bonus: Print out a colorful web page grid using jQuery. You'll need a function to convert from wavelength to rgb. Instead of a tight loop, only do one turn per millisecond and update the grid each turn so that you can watch it update (or 10 milliseconds, whatever number seems visually appealing).

Hint

Many find it conceptually simpler to use 2-dimensional arrays for this problem, however, it's easier to solve programmatically with a 1-dimensional array. Either approach will work. The former is easier to understand, the second is easier to code.

challenge-hotplate's People

Contributors

danielmcmullen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.