Sha256: 7f9b2640c128d8cf0218073a06b84ad41031597484987dc8114f62d54fc0f96a

Contents?: true

Size: 689 Bytes

Versions: 19

Compression:

Stored size: 689 Bytes

Contents

#!/usr/bin/env ruby

require 'isna'

UNIVERSE = (0..9).to_a
ROT = 5
DIGIT_REGEX = /^\d$/

def resolve(set, candidate)
  needle = set.index(candidate)
  if (needle + ROT) > set.size
    return (needle - set.size + ROT)
  end
  if (needle + ROT) < set.size
    return needle + ROT
  end
  if (needle == 5)
    return 0
  end
end

STDIN.each_char do |char|
  next if char.chomp == ''
  unless char =~ DIGIT_REGEX
    print char
    next
  end
  rotation = resolve(UNIVERSE, char.to_i)
  m = (0..9).to_a.map do |n|
    if n.to_s == char
      char.to_ansi.green.to_s
    else
      n.to_s
    end
  end
  # puts "#{rotation.to_s.to_ansi.red.to_s} = [" + (m * ', ') + "]"
  print rotation
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ix-cli-0.0.27 bin/ix-rot5
ix-cli-0.0.26 bin/ix-rot5
ix-cli-0.0.25 bin/ix-rot5
ix-cli-0.0.24 bin/ix-rot5
ix-cli-0.0.23 bin/ix-rot5
ix-cli-0.0.22 bin/ix-rot5
ix-cli-0.0.21 bin/ix-rot5
ix-cli-0.0.20 bin/ix-rot5
ix-cli-0.0.19 bin/ix-rot5
ix-cli-0.0.18 bin/ix-rot5
ix-cli-0.0.17 bin/ix-rot5
ix-cli-0.0.16 bin/ix-rot5
ix-cli-0.0.15 bin/ix-rot5
ix-cli-0.0.14 bin/ix-rot5
ix-cli-0.0.13 bin/ix-rot5
ix-cli-0.0.12 bin/ix-rot5
ix-cli-0.0.11 bin/ix-rot5
ix-cli-0.0.10 bin/ix-rot5
ix-cli-0.0.9 bin/ix-rot5