Created
December 9, 2020 05:39
-
-
Save themaxhero/6c2b13c37b0d342098f4ca27558ebc14 to your computer and use it in GitHub Desktop.
Revert Subtraction using Percentage by adding percentage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bigdecimal' | |
@percentages = [ | |
BigDecimal("0.99"), | |
BigDecimal("0.98"), | |
BigDecimal("0.97"), | |
BigDecimal("0.96"), | |
BigDecimal("0.95"), | |
BigDecimal("0.94"), | |
BigDecimal("0.93"), | |
BigDecimal("0.92"), | |
BigDecimal("0.91"), | |
BigDecimal("0.90"), | |
BigDecimal("0.89"), | |
BigDecimal("0.88"), | |
BigDecimal("0.87"), | |
BigDecimal("0.86"), | |
BigDecimal("0.85"), | |
BigDecimal("0.84"), | |
BigDecimal("0.83"), | |
BigDecimal("0.82"), | |
BigDecimal("0.81"), | |
BigDecimal("0.80"), | |
BigDecimal("0.79"), | |
BigDecimal("0.78"), | |
BigDecimal("0.77"), | |
BigDecimal("0.76"), | |
BigDecimal("0.75"), | |
BigDecimal("0.74"), | |
BigDecimal("0.73"), | |
BigDecimal("0.72"), | |
BigDecimal("0.71"), | |
BigDecimal("0.70"), | |
BigDecimal("0.69"), | |
BigDecimal("0.68"), | |
BigDecimal("0.67"), | |
BigDecimal("0.66"), | |
BigDecimal("0.65"), | |
BigDecimal("0.64"), | |
BigDecimal("0.63"), | |
BigDecimal("0.62"), | |
BigDecimal("0.61"), | |
BigDecimal("0.60"), | |
BigDecimal("0.59"), | |
BigDecimal("0.58"), | |
BigDecimal("0.57"), | |
BigDecimal("0.56"), | |
BigDecimal("0.55"), | |
BigDecimal("0.54"), | |
BigDecimal("0.53"), | |
BigDecimal("0.52"), | |
BigDecimal("0.51"), | |
BigDecimal("0.50"), | |
BigDecimal("0.49"), | |
BigDecimal("0.48"), | |
BigDecimal("0.47"), | |
BigDecimal("0.46"), | |
BigDecimal("0.45"), | |
BigDecimal("0.44"), | |
BigDecimal("0.43"), | |
BigDecimal("0.42"), | |
BigDecimal("0.41"), | |
BigDecimal("0.40"), | |
BigDecimal("0.39"), | |
BigDecimal("0.38"), | |
BigDecimal("0.37"), | |
BigDecimal("0.36"), | |
BigDecimal("0.35"), | |
BigDecimal("0.34"), | |
BigDecimal("0.33"), | |
BigDecimal("0.32"), | |
BigDecimal("0.31"), | |
BigDecimal("0.30"), | |
BigDecimal("0.29"), | |
BigDecimal("0.28"), | |
BigDecimal("0.27"), | |
BigDecimal("0.26"), | |
BigDecimal("0.25"), | |
BigDecimal("0.24"), | |
BigDecimal("0.23"), | |
BigDecimal("0.22"), | |
BigDecimal("0.21"), | |
BigDecimal("0.20"), | |
BigDecimal("0.19"), | |
BigDecimal("0.18"), | |
BigDecimal("0.17"), | |
BigDecimal("0.16"), | |
BigDecimal("0.15"), | |
BigDecimal("0.14"), | |
BigDecimal("0.13"), | |
BigDecimal("0.12"), | |
BigDecimal("0.11"), | |
BigDecimal("0.00"), | |
BigDecimal("0.09"), | |
BigDecimal("0.08"), | |
BigDecimal("0.07"), | |
BigDecimal("0.06"), | |
BigDecimal("0.05"), | |
BigDecimal("0.04"), | |
BigDecimal("0.03"), | |
BigDecimal("0.02"), | |
BigDecimal("0.01"), | |
] | |
def calculation(x, y) | |
return ((((1 - x) * y) * 100) / (x * y)).to_s("F") | |
end | |
puts @percentages.reduce(""){|acc, v| acc + "\nTo get the original number back after subtracting #{((1 - v) * 100).to_s("F")}%, you will need to add #{calculation(v, 100)}% of into the result of subtraction." } | |
csv = @percentages.reduce({}){|acc, v| acc["#{((1 - v) * 100).to_s("F")}%"] = "#{calculation(v, 100)}%"; acc }.reduce("Porcentagem Removida, Porcentagem para \"Recuperação\" do valor original\n"){|acc, (k, v)| acc + "#{k},#{v}\n" } | |
File.open("./percentages.csv", 'w'){| file | file.write(csv) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment