Sum of digits without modulo

Sometimes you need to calculate the sum of digits of an integer.

A straightforward approach is:

int sumDigits(int num) {
    int result = 0;

    while (num > 0) {
        result += num % 10;
        num /= 10;
    }

    return result;
}

This implementation performs both a modulo (%) and an integer division (/) on every iteration.

Reformulating the Problem

For simplicity, assume:

0 <= num <= 9999

Represent the number as:

Behavior trees

There are two typical ways to handle model state transitions:

  1. state-machines (known typically from computer science)
  2. behavior trees (adopted heavily by game industry)

[Here]((https://queenofsquiggles.github.io/guides/fsm-vs-bt/) is a nice article that:

  1. explains high level concept
  2. highlights pros and cons
  3. provides simple speculative examples

The paper ‘A robust layered control system for a mobile robot’ written by Rodney Brooks that created the foundation that was adopted and generalized later by game industry to model behavior of non-player characters.

Git: duplicated refs with different case

Some file system are case insensitive, other are not. When you try to checkout git repository, it’s possible to face this kind of error:

error: You’re on a case-insensitive filesystem, and the remote you are trying to fetch from has references that only differ in casing. It is impossible to store such references with the ‘files’ backend. You can either accept this as-is, in which case you won’t be able to store all remote references on disk. Or you can alternatively migrate your repository to use the ‘reftable’ backend with the following command:

The scripting language

source

TLDR: use main language of the project to write scripts.
+1 +2 :)

Additional couple of remarks:

  1. at some moment you can think about writing tests;
  2. at some moment you need to reuse something else from the project (also it’s possible to duplicate\reimplement something from the project using scripting language);
  3. at some moment you can think about integrating functionality implemented inside the script to the main project (admin endpoint\UI\background job\etc).

That’s why it’s better to write additional logic not using a script but using the main language from the very beginning.