Day 20 – Craggy Christmas Chronicles

Shortly before take off, Rudolph (who wanted to get his facts 100% right) asked his friend ChattyGPT “what are the crucial factors for a successful Sleigh ride?”

Creative Commons 2.0 generic (some rights reserved)

Certainly, said Chatty! Here are three calculations for Santa:

  1. Sleigh Speed and Distance Calculation:
  • Santa needs to calculate the optimal speed of his sleigh to cover the vast distances between homes around the world in a single night. This calculation involves factoring in variables such as the Earth’s rotation, to ensure he can reach every home within the limited time frame.
  1. Gift Weight Distribution:
  • Santa has to ensure that his sleigh is balanced with the right distribution of gifts. This calculation involves considering the weight of each gift, its size, and the overall weight capacity of the sleigh.
  1. Sleigh Energy Management:
  • In addition to distributing the gifts, Santa needs to optimize the energy efficiency of his sleigh. This calculation ensures that he can maintain the magical power required for the entire journey, taking into account the various stops and starts during gift deliveries.

How could Rudi check his numbers in time?

Calculator using RAku Grammars (CRAG)

Then he remembered that Raku, his favourite programming language could be used as a powerful Command Line calculator via the App::Crag module.

$ zef install App::Crag

1. Sleigh Speed and Distance Calculation

So, pondered Rudolph, let’s say I start at the North pole and head to the equator, how far is that?

$ crag 'say pos(|<90°N>,|<0°E>) .diff(pos(|<0°N>,|<0°E>)).d.in: <km>'
10007.54km

Hmm, he thought, that Napoleon was pretty close:

With the French Revolution (1789) came a desire to replace many features of the Ancien Régime, including the traditional units of measure. […] A new unit of length, the metre was introduced – defined as one ten-millionth of the shortest distance from the North Pole to the equator passing through Paris…

https://en.wikipedia.org/wiki/History_of_the_metre

And which way do I head to get there?

$ crag 'say pos(|<90°N>,|<0°E>) .diff(pos(|<0°N>,|<0°E>)).θ'       
180°S (T)

So, let’s say that there are about 19110349.077 (from Day 17) kids to visit. Since we know the radius of the earth:

$ crag 'say $r = (10007.54km * 4) / (2 * π)'
6371km

we can calculate the surface area of the earth:

$ crag 'say (4 * π * (6371km)**2).in: <sq km>'
510064471.91sq km

so that’s…

$ crag 'say (:<510064471.91 sq km> 19110349.077).in: <sq km>'
26.69sq km per kid

so, if I fly a path to cover all the kids then I need to cover a strip about 26.69km wide, but my total path length is about double that due to zig zagging to visit each chimney…

$ crag 'say (:<510064471.91 sq km> * 2 / 26.69km).in: <miles>'
23749671.71mile

and that’s a mean free path between chimneys of…

$ crag 'say :<510064471.91 mile> / 19110349.077'            
26.69mile

and, of course, I will leave at midnight following the setting sun and so I get 24 hours for the whole job, so that needs an average speed of…

$ crag 'say (:<510064471.91 mile> / :<24 hr>).in: <mph>'
21252686.33mph

which is…

$ crag 'say :<21252686.33 mph> * 100 / c'  
3.17① percent of the speed of light

aka – “fast”

2. Gift Weight Distribution

So, let’s take an approximate weight of 1lb mass per kid… the total is:

$ crag 'say (:<1 lbm> * 19110349.077).in: <kilotonnes>'
8.67kilotonnes

guess we can ignore the masses of Santa, the Sleigh and the Reindeer then

3. Sleigh Energy Management

Now, we just need enough energy to accelerate (and brake) the Sleigh so that it can stop at each chimbley. And to keep up the average speed Santa needs, the maximum speed will need to be double the average:

$ crag 'say :<21252686.33 mph> * 2'
42505372.66mph

to accelerate from rest to this speed, we can calculate the kinetic energy using the formula 1/2 mv²:

$ crag 'say <1/2> * :<1 lbm> * 19110349.077 * (:<21252686.33 mph> * 2)**2'
1564893512705620406435.84J

and then we need to do this twice (accelerate and brake) at each chimney:

$ crag 'say 1564893512705620406435.84J * 2 * 19110349.077'
59811322592274281413687039607.44J

let’s normalize this:

$ crag 'say (59811322592274281413687039607.44J).norm'
59811.32YJ  ('Yotta Joules')

which, thanks to Einstein, we know is:

$ crag 'say (59811.32YJ / (c²)).in: <gigatonnes>'
0.67gigatonnes

which is about 2000 times the mass of the Empire State building even if we can convert 100% of the nuclear mass into Sleigh drive energy

$ crag 'say :<0.67 gigatonnes> / :<365,000 tons>' 
2023.42①

errr … seems like we may need to use magic after all!

Under the Hood

I wrote App::Crag in response to a comment from a raku newb – they were looking for “the ultimate command line calculator”. That inspired me to pull together a bunch of raku modules into a unified command and to provide some sugar to avoid too much typing.

As with any raku CLI command, there is built in support for help text, just type ‘crag‘ on your terminal:

$ crag
Usage:
./crag [--help]
Examples:
[1] > crag 'say (1.6km / (60 * 60 * 1s)).in: ' #0.99mph
[2] > crag '$m=95kg; $a=♎️<9.81 m/s^2>; $f=$m*$a; say $f' #931.95N
[3] > crag 'say :<12.5 ft ±3%> .in: ' #3810mm ±114.3
[4] > crag '$λ=2.5nm; $ν=c/$λ; say $ν.norm' #119.91PHz
[5] > crag '$c=:<37 °C>; $f=:<98.6 °F>; say $f cmp $c' #Same
[6] > crag 'say |<80°T> + |<43°30′30″M> .T' #124°ESE (T)
[7] > crag 'say ♑️<5 days 4 hours 52 minutes>' #124:52:00
[8] > crag 'say @physics-constants-abbreviations.join: "\n"' # …
More info:
- https://github.com/librasteve/raku-Physics-Measure.git
- https://github.com/librasteve/raku-Physics-Unit.git
- https://github.com/librasteve/raku-Physics-Error.git
- https://github.com/librasteve/raku-Physics-Constants.git
- https://github.com/librasteve/raku-Physics-Navigation.git
- https://github.com/raku-community-modules/Time-Duration-Parser

As you can see, crag uses a bunch of Raku modules from the Physics::... family. [I am the author of most of these and contributions are very welcome!]

<merry christmas>.all

~librasteve

PS. Do not rely on this methodology for your StarShip calcs, Elon or anyone else – it is the invention of a mythical reindeer!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.