npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fzbz

v1.1.0

Published

fzbz is a fizz-buzz solution

Downloads

211

Readme

FZBZ

A generic Fizz Buzz Solution package.

Installation

npm i fzbz

Introduction

Since before the dawn of civilization around (time_t) -1 the question of which numbers fizz, which of them buzz, and whatever can we say about the ones that do both, has commanded the attention of many a computer scientist. It is said that Silicon could be an analogue for Carbon as a chemical basis for life elsewhere in the Universe, we however, must find ways of demeaning the element other than having it be part of such a sorry state of affairs like organic life... which leads us to this package.

In the interest of solving the general fizzbuzz question, I have forcefully convinced the Silicon-demons in your think-box to partake in a fittingly cursed implementation of the famous problem.

Usage

There are essentially two things that you might care in this package: the generic_engine_factory and the Agent. The latter is a straightforward wrapper of the former, which merely proxies access through the [] operator to the engine, possibly with some caching if a cache factory was provided. The engine factory, however, requires more concepts to be described.

Fizzpecification

If 𝓕 ⊣ 𝓤 : 𝐒𝐞𝐭 → 𝐌𝐨𝐧 is the adjoint functor pair comprised of the FreeMonoid and Forget functors and 𝖀 is the set of Unicode characters that can comprise an identifier, then one can roughly think of an unordered fizzpecification as the subobject of 𝐒𝐞𝐭(𝓤𝓕𝖀, 𝓤ℕ ⨿ {⊥}) comprised of the monic partial functions of finite support, which we'll denote Fᵤₙ.

Parallel to that, one has the following scenario: 𝓤𝓕𝖀 × 𝓤ℕ ≃ 𝓤(𝓕𝖀 × ℕ), on which we we apply the monad 𝓤𝓕 yielding 𝓤𝓕𝓤(𝓕𝖀 × ℕ). For the sake of simplicity one may assume 𝓤𝓕𝓤(𝓕𝖀 × ℕ) is given by ∐(m:ℕ) m → ∐(n:ℕ) (n → 𝖀)×ℕ; We say that (m, f) is “nice” whenever π₁f, and π₂f are monic (we disregard the monicity of π₀f). It is thus possible to describe what we should call Fₒᵣ in terms of limits of some sort or another, suffice to say Fₒᵣ is merely the subobject of 𝓤𝓕𝓤(𝓕𝖀 × ℕ) containing only the nice ones out of the lot.

It shouldn't be hard to see how to establish a relation between Fₒᵣ and Fᵤₙ, but an isomorphism cannot be established since Fₒᵣ has order information because each m:ℕ is ordered, whereas Fᵤₙ disregards that information. This is the crux of the matter as to why we allow these two representations. One could rectify the situation and obtain an isormorphism by providing total order on the support of each function but that is beyond the scope of this package.

Therefore, a Fizzpecification is an instance of the following type: Fₒᵣ ⨿ Fᵤₙ.

Less precisely, it's either a dictionary like {"fizz" : 3, "buzz" : 5}, or a list of pairs like [["fizz", 3], ["buzz", 5]], with the list ensuring "fizz" comes before "buzz" when the number is a fizzer and a buzzer, while the dictionary just ensures fizzing and buzzing will happen and won't opine on which happens first.

Usage (cont.)

An engine is merely a function that exposes numbers that fizz or buzz according to a fizzpecification, the generic engine factory implements a cutting edge, fully ethereal, branching minimal, general fizz-buzz classifying algorithm given a fizzpecification:

function generic_fb_engine(𝔂s, y = (𝑦, γ) => (γ % 𝑦) == 0) {
	let λ = (𝑦, 𝔂) => (γ, у) => y(𝑦, γ)? 𝑦 => у("") + 𝔂: у;
	let ꭚ = 0;
	let ү = [ỿ => 𝑦 => 𝑦];
	let үү = (𝔂, ʸ, у) => ү.push(ỿ => λ(ʸ, 𝔂)(ỿ, ү[у](ỿ)));
	if (Array.isArray(𝔂s)) for (let [𝔂, ʸ] of 𝔂s)
		үү(𝔂, ʸ, ꭚ++);
	else for (const 𝔂 in 𝔂s)
		үү(𝔂, 𝔂s[𝔂], ꭚ++);
	return ỿ => ү[ү.length - 1](ỿ)(ỿ);
}

Most of the time you will probably want the default engine, which can be obtained by talking to the default_engine_provider, which constructs a default fizz-buzz engine for you. Don't forget to thank him.

As mentioned, an Agent merely wraps a potential cache + an engine. Typically you could integrate caching with the solution itself, but the solution is pure and this way is far more extensible and customizable for the user, amirite.

Examples

const engie = require('./fzbz.js').default_engine_provider
const fzbz  = engie.provide();
engie.thank();
for (let i of Array.from(Array(30).keys())) 
	console.log(fzbz(i))

License

See dedicated file