mscroggs.co.uk
mscroggs.co.uk

subscribe

Comment

Comments

Comments in green were written by me. Comments in blue were not written by me.
@Oleg: Happy new year!

I just added this:

#if 0
int last_idx_before_mid = 31 - __lzcnt32(off_mask); // 31 - LZCNT ==> index of MSb
#else

// if off_mask can never be zero, no need for check to override BSR result
assert(off_mask);
// a '9' run didn't reveal any 0 [you would know for sure for other sizes]

// need unsigned long result
unsigned long last_idx_before_mid;

// get index of MSb [no need for adjustment if off_mask can never be zero]
_BitScanReverse(&last_idx_before_mid, off_mask);
#endif

a run of '9' now produces the correct result: 1,730,280 :)
Lord Sméagol
on /blog/119
               

Archive

Show me a random blog post
 2026 

Feb 2026

Christmas (2025) is over
 2025 
▼ show ▼
 2024 
▼ show ▼
 2023 
▼ show ▼
 2022 
▼ show ▼
 2021 
▼ show ▼
 2020 
▼ show ▼
 2019 
▼ show ▼
 2018 
▼ show ▼
 2017 
▼ show ▼
 2016 
▼ show ▼
 2015 
▼ show ▼
 2014 
▼ show ▼
 2013 
▼ show ▼
 2012 
▼ show ▼

Tags

chebyshev alphabets mathsteroids probability inline code error bars data runge's phenomenon hats crochet frobel finite element method squares pythagoras fonts a gamut of games draughts logo dinosaurs guest posts rugby zines dragon curves simultaneous equations oeis gather town quadrilaterals countdown regular expressions coventry preconditioning manchester science festival london underground mean matrix multiplication european cup tmip talking maths in public plastic ratio python curvature bots javascript manchester final fantasy chess bempp weak imposition datasaurus dozen palindromes misleading statistics hexapawn phd kenilworth triangles news approximation gaussian elimination christmas card matt parker video games fence posts geogebra football stirling numbers databet latex ucl crossnumber bubble bobble turtles light reuleaux polygons matrix of cofactors harriss spiral braiding coins numerical analysis game show probability rust polynomials asteroids nonograms raspberry pi binary big internet math-off bodmas standard deviation chalkdust magazine warwick puzzles the aperiodical finite group dataset accuracy books folding tube maps world cup mathsjam fractals go martin gardner national lottery people maths graph theory golden ratio crossnumbers pi approximation day boundary element methods pac-man games rhombicuboctahedron thirteen weather station captain scarlet wave scattering anscombe's quartet errors sound london exponential growth convergence computational complexity php royal institution map projections golden spiral statistics numbers menace live stream data visualisation pi graphs stickers trigonometry partridge puzzle sorting tennis sport estimation gerry anderson dates mathslogicbot pizza cutting propositional calculus interpolation machine learning platonic solids inverse matrices flexagons arithmetic advent calendar logic recursion game of life youtube hyperbolic surfaces signorini conditions craft matrix of minors reddit cross stitch noughts and crosses folding paper hannah fry logs nine men's morris speed sobolev spaces crosswords programming matrices determinants kings wool correlation cambridge radio 4 newcastle friendly squares electromagnetic field royal baby realhats pascal's triangle christmas ternary 24 hour maths geometry edinburgh

Archive

Show me a random blog post
▼ show ▼
© Matthew Scroggs 2012–2026