Skip to content
/ roots Public

Ada demos, including hash collisions, polynomial roots and word jumbles.

License

Notifications You must be signed in to change notification settings

trashgod/roots

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ada Demonstration Programs

Ada demonstration programs, including hash collisions, complex polynomial roots, shared libraries, stream hex dump, and word jumbles.

Collisions in a Hashed Table

This program examines collisions in a hashed table. In the program's output, the rows labeled 0..7 represent occupancy classes. Row zero is unused table entries; row one is table entries occupied by a single word; row two is table entries occupied by two words; etc. Next to each count is the percentage of words hashed to that occupancy class. In the example shown, 55% of the 235,886 words have unique hashes; in the worst case, seven words hash to the same table entry. See also hash/examples and Hash Table.

$ gprbuild collisions && ./obj/collisions
…
/usr/share/dict/words
Hash count: 235886
Table size: 393241
Load factor: 59.99%
 0: 215725 (0.00%)
 1: 129710 (54.99%)
 2: 38727 (32.84%)
 3: 7768 (9.88%)
 4: 1153 (1.96%)
 5: 143 (0.30%)
 6: 14 (0.04%)
 7: 1 (0.00%)

Roots of Polynomials with Complex Coefficients

Complex polynomial roots using the Durand-Kerner-Weierstrass method in Ada. An example of instantiating Generic_Roots and invoking it may be found here. See roots/examples; complete output is shown here.

$ gprbuild croot && ./obj/croot
…
Roots of assorted monic polynomials:
Poly:  1.00x^2 - 3.00x^1 + 2.00
Real:  1.00000000000000000E+00
Real:  2.00000000000000000E+00
Largest error: < 1.00000000000000000E-18

Poly:  1.00x^2 - 2.00x^1 + 1.00
Real:  1.00000000000000000E+00
Real:  1.00000000000000000E+00
Largest error: < 1.00000000000000000E-18

Poly:  1.00x^2 + 0.00x^1 + 4.00
Comp:  0.00000000000000000E+00 +- 2.00000000000000000E+00i
Largest error: < 1.00000000000000000E-18
…

Shared Library

A simple, shared library that mixes Ada and C. Executing shared/examples runs a simple client that uses the library. A more complex, aggregate library may be found in Samples GPR Aggregate Libs. While the examples are nominally cross-platform, some MacOS specific issues are examined here.

$ ./shared/examples.sh
Hello from Ada!
Hello from C!

Stream Hex Dump

A hexadecimal dump utility that reads from either

  • A named file using Ada.Streams.Stream_IO, or
  • Standard input using Ada.Text_IO.Text_Streams.

See stream/examples for more examples.

$ gprbuild hd && ./obj/hd -h
HexDump: hd [file | stdin]
$ echo "Hello, world." | ./obj/hd
000000: 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 2e 0a        Hello, world..

Word Jumble

Jumble is an Ada program intended to unscramble jumbled words. You can use it to solve word puzzles; or, when making your own puzzles, you can check that a jumbled word doesn't unscramble to more than one word. It implements the first algorithm outlined here. The output of several examples is shown below.

$ ./words/examples.sh 
…
Checking 215843 entries.
jumble [-h] [word …]
Checking 215843 entries.
zzxxzz: no match.
acert: caret carte cater crate creat creta react recta trace 
eerst: ester estre reest reset steer stere stree terse tsere 
9 Antu Tuan Tuna antu aunt naut taun tuan tuna 
9 Canari Carian Crania acinar arnica canari carina crania narica 
9 Merat Trema armet mater metra ramet tamer terma trame 
9 caret carte cater crate creat creta react recta trace 
9 ester estre reest reset steer stere stree terse tsere 
10 Easter Eastre Teresa asteer easter reseat saeter seater staree teaser 
10 Elaps Lepas Pales lapse salep saple sepal slape spale speal 
11 Orang Ronga angor argon goran grano groan nagor orang organ rogan 

About

Ada demos, including hash collisions, polynomial roots and word jumbles.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages