The Advent of Void: Day 18: sc

We’ve all been there. We have important numbers to crunch, and don’t want to break out a program as user-friendly as bc. So you go for your favorite tool: spreadsheets. So you start installing libreoffice to get yourself LibreOffice Calc.

$ sudo xbps-install -S libreoffice
Size to download:              437MB
Size required on disk:       1934MB
Space available on disk:      1024MB

No. We need something lighter.

$ sudo xbps-install sc

Name         Action    Version           New version            Download size
ncurses-libs install   -                 6.1_2                  248KB
sc           install   -                 7.16_3                 194KB

Size to download:              443KB
Size required on disk:        1967KB
Space available on disk:      1024MB

Do you want to continue? [Y/n]

This is something I can get behind. Yes!

When you type sc at a prompt, you are greeted with a very unhelpful looking display.

sc 7.16:  Type '?' for help.

        A         B         C         D         E

(not shown is the sweet color coding, showing A0 to be the active cell).

In this, sc is slightly more helpful than vim, because if I type q I quit, and if I type ? I get a friendly looking prompt (this command-line spreadsheet has it all!)

Which Screen? [a-p, q]


     A:   This overview
     B:   Toggle Options
     C:   Set Options
     D:   Cursor movement commands
     E:   Cell entry and editing commands
     F:   Line Editing
     G:   File commands
     H:   Row and column commands
     I:   Range commands
     J:   Miscellaneous commands
     K:   Variable names/Expressions
     L:   Range functions
     M:   Numeric functions
     N:   String functions
     O:   Financial functions
     P:   Time and date functions

     Q:   Return to main spreadsheet

Now, here’s a guilty admission. I don’t know a hundredth of the capabilities this tool has to offer. So because I want to learn, I pick “Financial Functions” at random, and am told:

Which Screen? [a-p, q]

     O: Financial functions:

         @pmt(e1,e2,e3)    @pmt(60000,.01,360) computes the monthly
                           payments for a $60000 mortgage at 12%
                           annual interest (.01 per month) for 30
                           years (360 months).

         @fv(e1,e2,e3)     @fv(100,.005,36) computes the future value
                           of 36 monthly payments of $100 at 6%
                           interest (.005 per month).  It answers the
                           question:  ``How much will I have in 36
                           months if I deposit $100 per month in a
                           savings account paying 6% interest com-
                           pounded monthly?''

         @pv(e1,e2,e3)     @pv(1000,.015,36) computes the present
                           value of an ordinary annuity of 36
                           monthly payments of $1000 at 18% annual
                           interest.  It answers the question: ``How
                           much can I borrow at 18% for 30 years if I
                           pay $1000 per month?''

Oooh, mortgages! Well, I don’t want to calculate that right now, it’s too depressing for the season, so let’s look at something else.

Well, I plugged in values to Drake’s equation, it was amazing. My text titles were very long though, so I ended up finding out that if I pressed f then held down l, the cell got wider! So I went from narrow cells to:

G0 (59 2 0) |"Fraction of civilizations that release detectable signals"

                                 G                                                      H
  0  Fraction of civilizations that release detectable signals Length of time they bother talking to the universe
  1                                                        0.80                                         1000000.00

Frankly, it doesn’t look too bad. At the end, my cell looks like:

A1 (10 2 0) [@prod(B1:H1)]

And I tell you, Drake’s equation is not particularly useful, but I can tinker with values, and I get instant recalculation! So if we get some favorable numbers, eventually we get lots of future civilizations we can talk to. Something to anticipate!

How does sc work for saving these wonderful spreadsheets? Phello.sc followed by a newline will Put the database into a file called hello.sc. Then I ZZ to save and exit (another throwback to the more usable cousin vim).

And if I look at hello.txt?

# This data file was generated by the Spreadsheet Calculator.
# You almost certainly shouldn't edit it.

format B 29 2 0
format C 34 2 0
format D 72 2 0
format E 68 2 0
format F 56 2 0
format G 59 2 0
format H 51 2 0
label A0 = "Num Civs"
label B0 = "Rate of Star Formation"
label C0 = "Fraction of stars with planets"
label D0 = "Average number of planets per star with planets that can support life"
label E0 = "Fraction of planets that could support life that eventually do"
label F0 = "Fraction of planets with life that go on to get life"
label G0 = "Fraction of civilizations that release detectable signals"
label H0 = "Length of time they bother talking to the universe"
let A1 = @prod(B1:H1)
let B1 = 1
let C1 = 0.2
let D1 = 2
let E1 = 0.1
let F1 = 0.1
let G1 = 0.8
let H1 = 100
goto B1 A0

Now, is sc user friendly? No. Not nearly. It’s a tool that takes looking up the man page to do basic things. How do you make a label (text)? \ or | or / depending on how you want to justify it. = will actually drop you into an editable line where x deletes and <DEL> backspaces. It takes some keyboard flailing to make it work.

But it works, on most terminals (here’s looking at you over there, with the actual teletype), and works on plain text documents. Why not!

For more information please read the sc(1) manpage.