r/fibonaccithread • u/ambral • Jun 11 '12
Useful code snippets
What programs are you guys using? I figured there's need for a place "on the surface" to exchange useful code snippets, or something, to fascilitate higher participation.
10
Upvotes
4
u/ambral Jun 11 '12
Found this comment by Bloodshot025
Download this, run with (in same directory as the .jar):
2
u/ambral Jun 13 '12 edited Jun 13 '12
For anyone who doesn't have access to Java: Here's a Javascript snippet you can copy and paste into the address bar to generate formatted Fibonacci numbers (I couldn't make a link out of it for some reason):
EDIT: Chrome and IE strips the "javascript:" at the beginning when you paste it, so you have to manually type that in, if you're using any of those browsers.
End of EDIT.
It has two input variables that are declared right at the beginning:
Here's the code nicely formatted: Source
I used and modified Leemon Baird's BigInt public domain library.
2
u/ambral Jun 15 '12 edited Jun 15 '12
For those of you that - like me - are frustrated at your comments not being submitted, here's a preliminary solution:
Using this method, I've avoided the wait times completely.
The userscript is far from perfect; there is lots of room for improvement so if anyone is interested to improve it, be my guest.
5
u/Bloodshot025 Jun 12 '12 edited Jun 12 '12
All right, guys, here it is.
This works on sh-like options, having both short (-f, -b, -p) and nominal (--format, --bare, --print) names, and commands. With this, it's easy to do something like
Which will format the number without the term number (F (xxxx)), will not copy it, and will print it, using the radix of 16.
Is just as possible, which skips the next term and calculates the one after, and it is also equivalent to
You can also set defaults, so, for example, it will always use a certain radix. This is achieved by
or
I hope this is pretty intuitive.
Commands and Options are kept in Enums and are pretty easily modifiable. I don't have anything really commented, so I'll release the source in a bit.
EDIT: Fixed a bug (-x as the first option in a set would not work. There was a reader.reset() where there shouldn't've been.), and here's the source.
2
u/Bloodshot025 Jun 12 '12
Updated Again.
Source.
Again, enter 'help' for commands.
2
u/Bloodshot025 Jun 11 '12
Here you go.
Enter 'help'.
Source
I'll probably update it a bit more later.
1
u/chickendodo Jun 12 '12
In case anyone was wondering, we could make it to the 47852nd fib number if we convert to hex.