GitHub - jefflombard/fizzbuzz-ai

2 min read Original article ↗

A TypeScript package that uses OpenAI to solve FizzBuzz problems. This package provides an AI-powered solution to the classic FizzBuzz programming challenge.

Why?

To make a point. This package solves the classic FizzBuzz problem the same way many AI startups operate: by overcomplicating solutions with GPT. See index.ts:28

Using AI as a substitute for proper software engineering is pure tech debt — and that’s exactly why we should use it.

It’s not enough to know how to build something. You have to know what to build — and why — first.

These "GPT Wrappers" are qualifying real world problems. Once the problems are qualified, then we can invest the resources to remove the inefficiencies.

I, along with some cofounders, founded CX.dev on the premise that good software isn’t just about clean code — it’s about solving the right problems with the right level of effort at the right time. Only then can you get best value out of your technology investments.

Installation

Usage

First, make sure you have an OpenAI API key. You can either:

  1. Set it as an environment variable: OPENAI_API_KEY=your-api-key
  2. Pass it directly to the constructor

Basic Usage

import { FizzBuzzAI } from "fizzbuzz-ai";

// Initialize with default settings
const fizzbuzz = new FizzBuzzAI();

// Solve a single number
const result = await fizzbuzz.solve(15); // Returns "FizzBuzz"

// Solve a range of numbers
const results = await fizzbuzz.solveRange(1, 5); // Returns ["1", "2", "Fizz", "4", "Buzz"]

Advanced Configuration

import { FizzBuzzAI } from "fizzbuzz-ai";

const fizzbuzz = new FizzBuzzAI({
  apiKey: "your-api-key", // Optional: defaults to OPENAI_API_KEY environment variable
  model: "gpt-4", // Optional: defaults to 'gpt-3.5-turbo'
  temperature: 0.5, // Optional: defaults to 0.7
  maxTokens: 100, // Optional: defaults to 150
});

API Reference

FizzBuzzAI Class

Constructor

constructor(config?: FizzBuzzAIConfig)

Methods

solve(number: number): Promise<string>

Solves FizzBuzz for a single number.

solveRange(start: number, end: number): Promise<string[]>

Solves FizzBuzz for a range of numbers from start to end (inclusive).

License

ISC