WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2025 Poal.co

(post is archived)

[–] 5 pts

Black Then White are All I see In my infancy Red and yellow came to be Reaching out to me Let's me see

[–] 1 pt

There is so much more that beckons me To look through to these Infinite possibilities As below so above and beyond I imagine Drawn outside the lines of reason Push the envelope Watch it bend

[–] 4 pts

The Fibonacci sequence is exponential, so If your text has fewer than say a trillion words, then the easiest way would be to hard code the first 100 or so terms (see https://oeis.org/A000045/list) and start counting words against that list.

If you want something more elegant, it should be possible to count words and compute fibonacci recursively in a single pass. I am not a programmer. Completely untested and unguaranteed pseudocode below.

FibLow = 1 getword(1) FibHigh = 2 getword(2) currentword = 2 while (!EndOfFile) { nextword() currentword++ FibLow-- if FibLow == 0 { getword(currentword) FibLow <FibHigh FibHigh <currentword } }

[–] 1 pt (edited )

This is the correct answer.

Hardcode a list of the first 40 Fibonacci numbers, and iterate through the body of text, counting "n" as you go. When n= {fibonacci num on list} print word read next highest fibonacci num iterate some more.

"Infinite Jest" has 578,000 words. The 30th Fibonacci number is 832,040, so hardcoding the first 30 numbers will get you through most novels.

hardcoding the first 40 will get you through a word list of 102 million. This is more than double the size of the Encyclopedia Britannica's 40 million words.

[–] 1 pt

I doubt that hardcoding is the way to go. To calculate the next fibonacci is a single add of cpu registers. Looking things up in a table seems like it would actually take longer.

[–] 2 pts (edited )

Incorrect.

You'vr omitted all the steps necessary to get the next Fibonacci number loaded into a register. (ironically, this is what hardcoding accomplishes, btw)

Your way: A math operation is require loading value 1, mathop to calculate next fibonacco value, saving value 2, compare operation to index number.

My way: A hardcoded table gets turned into a memory resident space by the compiler, never gets swapped, and requires only a lookup, and a compare. Pointer just moves one byte to next stored number, then a compare of the two registers.

It's not just a little faster; it's probably 4x faster.

[–] 1 pt

Fibonacci has been "solved" in that it is boiled down to a simple equation to know if any given # is a a Fib number;

A number is Fibonacci if and only if one or both of (5n2 + 4) or (5n2 – 4) is a perfect square.

[–] [deleted] 3 pts

So only the words that are numbers?

[–] 1 pt

Yeah.

So if I take a long paragraph of text I would just have it spit out the words numbered 0, 1, 1, 2, 3 5, 8, etc...

I know this isn't actually a hard program to write, I just figure someone fag on here could lead me in the right way faster than learning how to code again.

Use python and find a library that can do it, maybe pandas

[–] 3 pts

You'll have to start with figuring out how to get paid for your writing. Then you can pay me to write this program.

[–] 3 pts (edited )

install ruby, run irb, paste the following with your own text subsituted:

text = "The quick brown fox jumps over the lazy dog"

words = text.split(' ')

f1 = 0 f2 = 1

words.each_with_index do |word, i| if i == f1 puts word f1 = f2 f2 = i + f1 redo if i == f1 end end

example output:

The quick quick brown fox over dog

[–] 1 pt

install ruby

lol no

[–] [deleted] 2 pts

Trying some encryption by obfuscation? Fun stuff.

[–] 2 pts (edited )

Generating a list of Fibonacci numbers is tricky since they get big quickly, so I just found a . I removed the numbering with cut -f2. Then run your file and this list through grep.

cat test.txt

1 2 3 4 5 6 7 8 9 10 11 12 13

cat fib.txt

0 1 1 2 3 5 8 ...

grep -w -F -f fib.txt test.txt

1 2 3 4 5 6 7 8 9 10 11 12 13

Add -o to only print the matched words, one per line.

grep -o -w -F -f fib.txt test.txt

1 2 3 5 8 13

Don't write code if you don't need to, unless this is an exercise to learn a particular language.

EDIT: I see, you want the nth words of a text, for only n that are in the Fibonacci sequence.

[–] 1 pt

So, you want to get every Fibonaccith word?

1st, 2nd, 3rd, 5th, 8th, etc...

You'd just write a tokenizer to split up the text into words, then iterate through them while keeping track of the current work number and the next fibonacci number, when they match, you spit out that word and calculate the next fibonacci number and move on. To calculate the next fibonacci number, you'd need to remember the previous one too, which is trivial.

[–] 1 pt

You could do it like this 1) Get max length of word list. 2) Create list/array of f_0, f_1, ... f_n where f_i is the ith Fibonacci number, and f_(n+1) is the smallest Fibonacci number greater than the max word length 3) For each f_i, search through the text for words with that length.

Load more (6 replies)