A simple number cruncher?
July 10, 2008 10:25 PM   RSS feed for this thread Subscribe

Is there an online or otherwise calculator utility that can produce a multiplication column to the nearest integer if I need to (and I do need to) multiply a given integer (specifically, 8.57143) by all the integers from 1 to about 600, displayed in a list so that I don't have to multiply it each time? I may need to do other 600-deep columns with other decimally numbers, a few at most. I need to see the result, better yet print it.

For even reasonably numerate folks, this is probably cake. But my brain has long since dealt with anything besides simple ratios, and I can't remember how this sort of thing is done.

If anyone's curious, it's so that I can split up a 24 fps film into a 168 bpm click track. Each beat is 1/2.8 second. 24 / 2.8 = 8.57143... And I think I need to use as many places on that as I can so as not to throw off the tempo later in the film. It's only a 3 1/2 minute-r, but that's almost 600 beats!
posted by gorgor_balabala to science & nature (18 comments total) 2 users marked this as a favorite
In Mac OS X or Linux, if you run bash and have GNU calc installed:

frameIndex=1; while [ "$frameIndex" -le 600 ]; do calc $frameIndex*8.57143; frameIndex =$(($frameIndex +1)); done

If you want to do this all on one line and send it to a file:

frameIndex=1; while [ "$frameIndex" -le 600 ]; do calc $frameIndex*8.57143; frameIndex =$(($frameIndex +1)); done > output.txt

If you want to do this all on one line and print it:

frameIndex=1; while [ "$frameIndex" -le 600 ]; do calc $frameIndex*8.57143; frameIndex =$(($frameIndex +1)); done | lpr
posted by Blazecock Pileon at 10:35 PM on July 10


You'll want to remove the first space in frameIndex =$(($frameIndex +1)), to read: frameIndex=$(($frameIndex +1))
posted by Blazecock Pileon at 10:37 PM on July 10


I just spotted this typo (top of question): Of course 8.57143 is not an integer.
posted by gorgor_balabala at 10:39 PM on July 10


% seq 1 600|perl -nle 'print "$_ " . $_ * 8.57143;'

there's neat ways to do this with awk or bc, but perl's the most flexible for re-formatting the outage and reusing the data.
posted by kcm at 10:39 PM on July 10


(you can of course replace the "8.57143" with "(24/2.8)" there for more precision..)
posted by kcm at 10:42 PM on July 10


If you want more precision:

ratio=`calc 24/2.8`; frameIndex=1; while [ "$frameIndex" -le 600 ]; do calc $frameIndex*$ratio; frameIndex=$(($frameIndex +1)); done
posted by Blazecock Pileon at 10:47 PM on July 10


I think you meant:

`calc 24/2.8|tr -d '~'`
posted by kcm at 10:55 PM on July 10


You're right, I should have tested it:

ratio=`calc 24/2.8 | tr -d '~'`; frameIndex=1; while [ "$frameIndex" -le 600 ]; do calc $frameIndex*$ratio; frameIndex=$(($frameIndex +1)); done

This gives you a little more precision than perl, but with a bit of rounding error on multiples.

If you want more control over the output, use perl or gawk, e.g.:

gawk 'BEGIN {ratio=24/2.8; i=1; maxFrame=600}; { for (i=1; i<>
posted by Blazecock Pileon at 11:09 PM on July 10


Let's try that again:

gawk 'BEGIN {ratio=24/2.8; i=1; maxFrame=600}; { for (i=1; i<=maxFrame; i++) print i,"\t",i*ratio; exit 0; }';

Hopefully, the mods will one day fix it so that we can post code.
posted by Blazecock Pileon at 11:10 PM on July 10


I think this is what spreadsheets are for.

Here's your table for 8.57143 times 1 to 100 using googledocs.
posted by randomstriker at 11:25 PM on July 10 [3 favorites]


Seconding spreadsheets - I think randomstriker has it.

Maybe I am missing something important here, but it seems like this would take under a minute in Excel. I would make a column of 1 to 600 (drag and fill), throw 8.57143 or whatever number you want in another cell, and then drag out another column of the products. If you aren't at all familiar with Excel, I would be happy to reply to a MeFi Mail with more details/the completed spreadsheet. I haven't looked at the googledoc, though, and it's likely that something very similar is already there waiting for you.
posted by Bun at 11:51 PM on July 10


I just tweaked the above sheet to go from 1 to 600.
posted by randomstriker at 11:54 PM on July 10


Copy and paste this line into your browser's url bar and hit enter:

javascript:var s="";for(var i=0;i<=600;i++){s=s+i+"09;"+i*8.57143+"\n";};"<pre>'"+s+"</pre>";

Tested on Firefox 3 and Internet Explorer 7. You can save this as a bookmark and use it whenever you need it. For other numbers, simply change the 8.57143 in the above to whatever you need.

If you want it without the leading number (eg. for copying and pasting into a spreadsheet), that would be:

javascript:var s="";for(var i=0;i<=600;i++){s=s+(i*8.57143)+"\n";};"<pre>"+s+"<pre>";
posted by xchmp at 3:03 AM on July 11 [1 favorite]


Oops, that first one should be:

javascript:var s="";for(var i=0;i<=600;i++){s=s+i+"09;"+i*8.57143+"\n";};"<pre>"+s+"</pre>";

(I removed a spurious quote character that sneaked in somewhere.)
posted by xchmp at 3:07 AM on July 11


On Opera 9.51 that 09; works as a tab if you make it %09. I'm not really sure why.

xchmp's script with rounding:

javascript:var s="";for(var i=0;i<=600;i++){s=s+i+"09;"+Math.round(i*8.57143)+"\n";};"<pre>"+s+"</pre>";
posted by BrotherCaine at 4:22 AM on July 11


You could do it with Google Docs like this.
posted by wheat at 6:04 AM on July 11


I'd just like to say that the variety of answers here is fantastic, especially the URL javascript version, very clever!
posted by odinsdream at 7:06 AM on July 11


Jus for completeness' sake, in Python:
for i in range(600):
print i,int(i*24/2.8)

posted by signal at 9:12 AM on July 11


« Older My friend has her first novel ...   |   My friend's apartment just bur... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Blow my Mind July 20, 2008
What are some mindblowing scientific concepts? June 4, 2008
Shell scripting or something better? May 9, 2008
Math is cool, right? March 27, 2008
Difficult as ABC September 16, 2007