List the nth term of Rozhenko’s inventory sequence - MATLAB Cody - MATLAB Central

Problem 56593. List the nth term of Rozhenko’s inventory sequence

Difficulty:Rate
Consider a sequence constructed by repeated inventories. A new inventory begins each time a zero is encountered. The first few inventories are
0
1, 1, 0
2, 2, 2, 0
3, 2, 4, 1, 1, 0
4, 4, 4, 1, 4, 0
When the sequence is empty, there are zero 0s. We start a new inventory on the second line—looking at all numbers written so far: one 0, one 1, zero 2s. The zero triggers a new inventory, and the third line reports two 0s, two 1s, two 2s (from the beginning of the third line), and zero 3s. And so on. The sequence then is the rows strung together. For example, the 19th term is 4.
This sequence produces interesting plots and music. See the related Numberphile video for more.
Write a function to report the nth term of this sequence.

Solution Stats

81.82% Correct | 18.18% Incorrect
Last Solution submitted on May 06, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

YouTube-inspired Image
YouTube-inspired
  • 15 Problems
  • 2 Finishers

Problem Recent Solvers9

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!