Skip to content

Instantly share code, notes, and snippets.

@neuthral
Created November 23, 2022 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuthral/1cda78af564a8cb609854952d9e4553d to your computer and use it in GitHub Desktop.
Save neuthral/1cda78af564a8cb609854952d9e4553d to your computer and use it in GitHub Desktop.
count together numbers in a string until only one number from 1 - 9 remains [??vortex math??]
#!/bin/bash
STRING=$1
NUM=0
until [[ $STRING -lt 10 ]] do;
foreach n in $(echo $STRING | fold -w1); do
echo "$NUM + $n";
((NUM=NUM+n));
echo " = $NUM";
done;
((STRING=NUM));
((NUM=0));
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment