Skip to main content

Math - 3N+1

Longest non self loop interaction

  • 2022-04-13: 860 @ 295,147,905,179,352,826,087 [0.295 E21]

Code from 1


#!/bin/bash

i=1
while true; do
  c=1
  n=$i
  printf "$n"
  while [[ $n != "1" ]]; do
    # bc has no limit for the number of digits (as much as memory can hold)
    case $n in
    *0 | *2 | *4 | *6 | *8) n=$( echo "$n / 2"|bc) ;;
    *) n=$( echo "$n * 3 + 1"|bc) ;;
    esac
    printf " -> $n"
    c=$((c+1))
  done
  echo " [$c]"
  # maybe use bc ....
  i=$((i+1))
done

Code from 2^68

#!/bin/bash

export BC_LINE_LENGTH=0
i=295147905179352825856
while true; do
  c=1
  n=$i
  printf "$n"
  while [[ $n != "1" ]]; do
    case $n in
    *0 | *2 | *4 | *6 | *8) n=$( echo "$n / 2"|bc) ;;
    *)         n=$( echo "$n * 3 + 1"|bc)
    esac
    printf " -> $n"
    c=$((c+1))
  done
  echo " [$c]"
  i=$( echo "$i+1"|bc)
done

Comments

Popular posts from this blog

TV Series - The Brokenwood Mysteries [NZ] (2014) - Season 10

 

Movie - Sin City: A Dame to Kill For (2014)

 

Movies - Deadpool & Wolverine (2024)