5. Find Element in Unary Array

The fairground at Dorpat unfolded like a fever dream across the muddy square: bright pennants flapping against a gray Baltic sky, the smell of roasted nuts mingling with horse dung and pipe smoke. Children darted between booths, and music from a hurdy-gurdy danced over the clamor like a spell half-forgotten.

Johann, cheeks flushed with cider and enthusiasm, tugged Mihkel by the sleeve. „You must see this woman—she sees through time, they say. Knows things before they happen!“ Mihkel followed, more intrigued by Johann’s conviction than the promise of prophecy.

In a curtained tent lit by greenish lamplight sat Leena, the Romani fortune-teller. Her dark eyes were lined with age or artifice—Mihkel could not tell. Before her lay a lacquered board covered in painted glyphs, each symbol repeated a strange number of times. She spoke with slow ceremony, voice low and rich: „Choose the number of your soul, then speak it. I shall find the symbol that belongs to you.“

Johann leaned in, grinning. „Third one.“

Leena hummed and began tapping the board. Once, twice, thrice—then laid her finger on a glyph shaped like a twisted sun. Johann gasped. „That was the symbol I dreamed last night!“ Mihkel, meanwhile, narrowed his eyes. The glyphs… weren’t magical. They were repeated. Repeated vertically. Five marks, then eight, then four. And the „chosen number“? An index. A position.

Leena’s ritual, Mihkel realized, was little more than a lookup operation—hidden in flair and incense.

Later, as Johann bought candied almonds, Mihkel copied the structure into his notebook: An index—in unary. Then values, separated by glyphs or commas. Could the Mill parse this too?

That evening, back in his room, Mihkel fed a tape into the Mill: ||:|||,|||||,||||||||,|||| Second element. Five bars. If the Mill could walk through each value, counting as it went…

He wound the crank and let the gears walk the path of the fortune-teller’s finger—but this time, without mystery.

On the input tape, you get an array index and then a list of positive numbers in the unary format separated by comma. Your task is to find the number at the given index and output it on the output tape. The index starts from 1. For example, if the input tape is ||:|||,|||||,||||||||,||||, your output should be ||||| (2nd element of the array is 5).

Logic Mill specs

Sign in to submit your solution.