keisanjaku

keisanjaku is a terminal slide rule simulator. It runs on Ruby's standard library only and provides ANSI text rendering, an interactive sandbox, expression demos, and drill practice.

Requirements

  • Ruby 3.x or later
  • A terminal with at least 100 columns is recommended
  • No external gems are required

Usage

exe/keisanjaku --version
exe/keisanjaku --render-only --slide=0.3 --cursor=0.477 --width=100
exe/keisanjaku --no-anim --demo='2*3'
exe/keisanjaku --sandbox
exe/keisanjaku --drill --tolerance=1.0

Installation

Build and install the gem locally:

gem build keisanjaku.gemspec
gem install keisanjaku-0.1.0.gem

Publish to RubyGems after signing in with gem signin:

gem push keisanjaku-0.1.0.gem

In interactive modes, omitting --width=N makes the display follow the current terminal width. Unix-like terminals use SIGWINCH; Windows terminals use a polling fallback. Use NO_COLOR=1 or --no-color for plain monochrome output.

The expression parser accepts:

  • Multiplication: 2*3 or 2×3
  • Division: 6/2 or 6÷2
  • Powers: 2^2, 2^3
  • Functions: sqrt(2), cbrt(8), log(2), sin(30), cos(60), tan(30)

Example Output

      +--------------------------------------------------------------------------------------------+
     K||      |   |  |   || || | |      |   |   |  | | | | ||      |    |  |  | | || || | | ||
      |1      2   3  4   56 78 9 1      2   3   4  5 6 7 891      2    3  4  5 6 78 9 1 |
     A||          |     |    |   |   | |  | | | |          |     |    |   |  |  | | | | ||
      |1          2     3    4   5   6 7  8 9 1          2     3    4   5  6  7 8 9 1 |
      +--------------------------------------------------------------------------------------------+
     B|........................|.............|........|.....|....|...|..|..|.|.....................|
      |........................1.............2........3.....4....5...6..7..8.9.....................|
    CI|........................|...|..:..|.:.|..:..|...|....:....|.....:......|...........:........|
      |........................1...9.....8...7.....6...5.........4............3....................|
     C|........................|....................|............:........|.......:.....|....:...|.|
      |........................1....................2....................3.............4............|
      +--------------------------------------------------------------------------------------------+
     D||            :       |         :       |      :    |   :    |  :  |  : |  : | :  | : | : ||
      |1                    2                 3           4        5     6     7    8    9      1|
     L||        |        |        |        |        |        |        |        |        |        ||
      |0       .1       .2       .3       .4       .5       .6       .7       .8       .9        1|
      +--------------------------------------------------------------------------------------------+
cursor=0.4770 slide=+0.3000 face=front K=26.977 A=8.995 B=2.2594 CI=6.6527 C=1.5 D=2.9997 L=0.477

Controls

Sandbox:

  • h / l: move the slide left or right in coarse steps
  • H / L, or , / .: move the slide in fine steps
  • c / j / k: switch arrow-key control between the cursor and slide
  • Left / Right: move the selected target
  • Tab: flip between the front and back slide faces
  • ?: toggle the value readout
  • r: reset
  • q: quit

Drill:

  • Choose the problem range at startup, for example multiply,sin
  • Press Enter or o for the slide-rule workspace and answer entry
  • Type a numeric answer in the workspace and press Enter to submit it
  • g: show the worked demo
  • s: skip the workspace and answer as plain text
  • Correct answers report whether the exact operation sequence matched the model steps, including scale, value, and side information such as MOVE_CURSOR(D, 2)

Demo:

  • Enter / Space: advance one step
  • b: go back one step
  • a: toggle autoplay
  • 1 / 2 / 3: change autoplay speed
  • q: quit

Principle

The C and D scales are modeled with positions based on log10(x). Multiplication is addition of distances: align the C scale index with a value on the D scale, move the cursor to the other factor on the C scale, and read the mantissa of the product on the D scale.

When the result would fall outside the frame, use the opposite slide index to wrap the operation. A slide rule reads mantissas, so the final power-of-ten place must be determined separately. Demo mode prints that place-value explanation at the end.

Tests

bundle install
rake test
ruby -w -Ilib -rkeisanjaku -e 'puts Keisanjaku::VERSION'

License

MIT. See LICENSE.txt.