标签:#r
找到 26755 篇相关文章
# Understanding Backtracking Through a Tetris Optimizer in Go
When I first heard the term backtracking , it sounded like a complicated algorithm reserved for computer scientists. After spending the last couple of weeks learning it and implementing it in a Tetris Optimizer project, I realized something surprising: Backtracking is simply the art of making a decision, checking whether it works, and if it doesn't, undoing it and trying something else. This article explains backtracking using a practical project instead of abstract examples. The Problem Imagine you have several Tetris pieces (tetrominoes), and your goal is to fit all of them into the smallest possible square . It might look something like this: A A A A B B B B C C C C D D D D The challenge is to arrange every piece so that: No pieces overlap. No piece extends outside the board. Every piece is used exactly once. The board is as small as possible. This is much harder than it looks. My First Thought Initially, I thought I could simply place one piece after another. Place A Place B Place C Place D Done! Unfortunately, programming isn't always that kind. Sometimes the first position you choose for piece A makes it impossible to place D later. The mistake wasn't with D . The mistake happened much earlier. Enter Backtracking Backtracking works like this: Place a piece. Try placing the next one. If you get stuck... Remove the last piece. Try a different position. Repeat until every piece fits. It's essentially saying: "If this path doesn't work, let's go back and explore another one." Visualizing the Search Suppose we have four tetrominoes. Start ├── Put A at (0,0) │ ├── Put B │ │ ├── Put C │ │ │ ├── D fits ✅ │ │ │ └── D fails ❌ │ │ └── Try another position │ └── Move A elsewhere └── Try another position for A Every branch represents another possibility. Backtracking explores these branches until it finds one that works. How It Looks in Go The heart of the algorithm is surprisingly small. func solve ( index int ) bool { if index == len ( pieces ) { return true } for every
JavaScript has no sorted containers. I built one for TypeScript.
JavaScript ships with Array , Set , and Map — but nothing that keeps its elements sorted as you insert. If you've ever built a leaderboard, an order book, or anything that answers "give me the items between X and Y", you know the workaround: push into an array and .sort() after every insertion. It works, until scale punishes you — you're paying O(n log n) over and over for data that was already 99.9% sorted. Python solved this years ago with sortedcontainers , built on an elegant "list of lists" design instead of balanced trees. I just published sorted-collections , which brings that idea to TypeScript — with full credit to the original as its inspiration. What you get SortedList, SortedSet, SortedMap — always sorted, no manual re-sorting, range queries built in. O(log n) insertions, O(√n) positional access via sqrt-decomposition into buckets. Zero runtime dependencies , ~2KB gzip, types included, dual ESM/CJS. Package quality gated in CI with publint , arethetypeswrong , and size-limit . The API in 30 seconds import { SortedList , SortedSet , SortedMap } from " sorted-collections " ; // SortedList: stays sorted on every insert const list = new SortedList ([ 5 , 1 , 4 , 2 , 3 ]); list . add ( 0 ); console . log ([... list ]); // [0, 1, 2, 3, 4, 5] console . log ( list . at ( 2 )); // 2 — positional access on sorted order // SortedSet: no duplicates, plus set algebra const a = new SortedSet ([ 1 , 2 , 3 , 4 ]); const b = new SortedSet ([ 3 , 4 , 5 ]); console . log ([... a . intersection ( b )]); // [3, 4] // SortedMap: keys always in order, range queries built in const prices = new SortedMap < number , string > ([ [ 104.5 , " order-3 " ], [ 99.2 , " order-1 " ], [ 101.0 , " order-2 " ], ]); for ( const [ price , id ] of prices . irange ( 100 , 105 )) { console . log ( price , id ); // 101.0 order-2, then 104.5 order-3 } Custom comparators are fully typed: number and string get natural ordering for free; for your own types, TypeScript requires a comparator at compile
Why not LLMs?
The Strange Phenomenon of 'Terminal Lucidity'
US military sent explosive drone boats into combat for the first time
US military’s drone boats struck an Iranian naval port as war heats up again.
Cursor 0day: When Full Disclosure Becomes the Only Protection Left
MoonBASIC: A modern BASIC for building 2D and 3D games
Reverse Sprinkler Physics Problem
Bonsai 27B (1-bit LLM): The First 27B-Class Model to Run on a Phone
DeepMind CEO calls for an independent standards body to regulate frontier AI
DeepMind CEO Demis Hassabis is proposing an AI "standards body" modeled after FINRA, to test frontier models and develop best practices for their release.
Philips Hue’s budget-friendly Essential starter kit has hit a new low price
Although most of Prime Day’s unusually good Philips Hue deals have ended, a few remain, and some, including the black Philips Hue Twilight Sleep and Wake-Up Light, are even cheaper. None, however, have fallen to a new all-time low price like Philips Hue’s Essential starter kit. Right now, you can buy a bundle containing four […]
Plex is down
Plex services have been experiencing some major issues today, with multiple users reporting problems on Plex's forums and on Reddit. Many people use Plex as a way to stream shows and movies they host locally, but users are upset because today's problems are reportedly affecting their ability to do that. "Basically all Plex is down […]
Crates.io: Development Update
Nintendo’s Switch 2 bundle that includes a game is $50 off
Discounts on the Nintendo Switch 2 are rare, but they do happen on occasion. There’s one happening now, actually, on the company’s $499.99 console bundle that includes a digital game (Mario Kart World, Donkey Kong Bananza, or Pokémon Pokopia). Usually, the bundle saves you $20 or $30, depending on the game you choose, but for […]
Meta accused of using biased AI targeting for mass layoffs
A group of 26 former Meta employees is suing the company over claims that it used AI tools to unfairly target workers on leave with layoffs, as reported earlier by Reuters. In the lawsuit, the employees allege Meta determined which workers to dismiss based on performance data collected by a "constellation" of internal AI tools, […]
AI Spend Console by Rippling
Track your AI spend and connect it to business outcomes Discussion | Link
How To Watch the 2026 FIFA World Cup Semifinals: France vs Spain
The end of the FIFA Men’s World Cup is nigh. Here’s how to watch the final games and the first ever World Cup halftime show.