Published
Edited
Jan 1, 2019
1 fork
Importers
2 stars
Insert cell
Insert cell
replacement = item => (item == "1")? [ "φ" ] : [ "1", "φ" ]
Insert cell
Insert cell
symbolSequence( 7 )
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
symbolSequence = function( depth ){
function recurrence( arr ){
return arr .reduce( (acc, item) => {
return [ ...acc, ...replacement( item ) ]
}, [] )
}
var seq = [ "1" ]
for (var i = 0; i < depth; i++) {
seq = recurrence( seq )
}
return seq
}
Insert cell
Insert cell
goldenSequence = function( depth ){
return symbolSequence( depth ) .map( symbol => ( ( symbol == "1" )? [1,0,1] : [0,1,1] ) )
}
Insert cell
Insert cell
goldenSequence( 5 )
Insert cell
Insert cell
goldenSequence( 5 ) .map( numberString )
Insert cell
Insert cell
goldenSequence( 5 ) .map( toFixed )
Insert cell
Insert cell
goldenSeries = function( depth ) {
return goldenSequence( depth ) .reduce( function( r, a ) {
if (r.length > 0)
a = gradd( a, r[r.length - 1] );
r .push( a );
return r;
}, [])
}
Insert cell
Insert cell
goldenSeries( 5 ) .map( numberString )
Insert cell
Insert cell
unitGoldenSeries = function( depth ) {
const divisor = grpow( [,1], depth )
return [ [0], ...goldenSeries( depth ) .map( gr => grdiv( gr, divisor ) ) ]
}
Insert cell
Insert cell
unitGoldenSeries( 5 ) .map( numberString )
Insert cell
Insert cell
unitGoldenSeries( 5 ) .map( toFixed )
Insert cell
Insert cell
unitGoldenSlider = function( depth ) {
const values = unitGoldenSeries( depth );
return slider({
value: this ? this.input.value : 0, step: 1, max: values.length - 1,
getValue: n => values[n.value],
display: valueAndString
});
}
Insert cell
Insert cell
findGoldenNumber = function( value, depth )
{
if ( value < 0 )
return null // not yet ready to deal with negatives
if ( value > 1 )
return null
const targets = unitGoldenSeries( depth )
const values = targets .map( grfloat )
function checkRange( minIndex, maxIndex ) {
if ( minIndex >= maxIndex )
// just to be safe, though this should never happen
return targets[ maxIndex ]
else {
const lowDiff = value - values[ minIndex ]
const highDiff = values[ maxIndex ] - value
if ( maxIndex == minIndex + 1 ) {
return ( highDiff < lowDiff )? targets[ maxIndex ] : targets[ minIndex ]
} else {
const midIndex = Math.floor( ( maxIndex + minIndex ) / 2 )
return ( highDiff < lowDiff )? checkRange( midIndex, maxIndex ) : checkRange( minIndex, midIndex )
}
}
}
return checkRange( 0, targets.length -1 )
}
Insert cell
Insert cell
toFixed = v => Number( grfloat( v ) .toPrecision( 7 ) )
Insert cell
valueAndString = v => grfloat( v ) .toFixed( 6 ) + " = " + numberString( v )
Insert cell
import {numberString} from "@vorth/wip-observable-vzome"
Insert cell
import { gradd, grfloat, grdiv, grpow } from '@jrus/zome-arithmetic'
Insert cell
import {slider} from '@jashkenas/inputs'
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more