Skip to content

Instantly share code, notes, and snippets.

@neuthral
Created November 23, 2022 03:00
Show Gist options
  • Select an option

  • Save neuthral/1cda78af564a8cb609854952d9e4553d to your computer and use it in GitHub Desktop.

Select an option

Save neuthral/1cda78af564a8cb609854952d9e4553d to your computer and use it in GitHub Desktop.

Revisions

  1. neuthral revised this gist Nov 23, 2022. No changes.
  2. neuthral created this gist Nov 23, 2022.
    13 changes: 13 additions & 0 deletions reduce.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/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;