Skip to content

Instantly share code, notes, and snippets.

@BenoitZugmeyer
Created May 14, 2018 22:12
Show Gist options
  • Save BenoitZugmeyer/d08d41881d6bb5474d449a7088ab998d to your computer and use it in GitHub Desktop.
Save BenoitZugmeyer/d08d41881d6bb5474d449a7088ab998d to your computer and use it in GitHub Desktop.
const assert = require('assert')
const rowCount = 7
const maxCellsCount = 40
const cellsPerDomain = 24
const domainCount = Math.floor(maxCellsCount / cellsPerDomain)
const cellsCount = domainCount * cellsPerDomain
const columnCount = Math.ceil(cellsCount / rowCount)
const cellRow = c => rowCount - 1 - c % rowCount
const cellColumn = c => columnCount - 1 - Math.floor(c / rowCount)
const domainFirstCell = d => d * cellsPerDomain
const domainLastCell = d => domainFirstCell(d + 1) - 1
const cellToDomain = c => Math.floor(c / cellsPerDomain)
assert.equal(domainCount, 1)
assert.equal(cellsCount, 24)
assert.equal(columnCount, 4)
assert.equal(cellRow(0), 6)
assert.equal(cellRow(6), 0)
assert.equal(cellRow(13), 0)
assert.equal(cellColumn(0), 3)
assert.equal(cellColumn(7), 2)
assert.equal(domainFirstCell(0), 0)
assert.equal(domainLastCell(0), 23)
assert.equal(domainFirstCell(1), 24)
console.log("OK")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment