From 71330cc5e4f4829b1eb3c1c7b501cf0cd691c358 Mon Sep 17 00:00:00 2001 From: NatanLucena <44265910+NatanLucena@users.noreply.github.com> Date: Tue, 22 Oct 2019 16:47:50 -0300 Subject: [PATCH] Create DivisibleBy7.py --- allalgorithms/numeric/DivisibleBy7.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 allalgorithms/numeric/DivisibleBy7.py diff --git a/allalgorithms/numeric/DivisibleBy7.py b/allalgorithms/numeric/DivisibleBy7.py new file mode 100644 index 0000000..ab7187d --- /dev/null +++ b/allalgorithms/numeric/DivisibleBy7.py @@ -0,0 +1,21 @@ +# -*- coding: UTF-8 -*- +# +# Divisible by 7 algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Natan Lucena +# Github: @NatanLucena +# + +def isDivisibleBy7(num) : + + if num < 0 : + return isDivisibleBy7( -num ) + + if( num == 0 or num == 7 ) : + return True + + if( num < 10 ) : + return False + + return isDivisibleBy7( num / 10 - 2 * ( num - num / 10 * 10 ) )