Skip to content

Instantly share code, notes, and snippets.

@wo0dyn
Last active March 8, 2023 21:32
Show Gist options
  • Save wo0dyn/7412646 to your computer and use it in GitHub Desktop.
Save wo0dyn/7412646 to your computer and use it in GitHub Desktop.

Math trick

Math trick: works with any number 16/64 = 1/4 and 26/65 = 2/5

(Source: https://twitter.com/Perspective_pic/status/399718664540520448)

Code (python)

from __future__ import division

for i in range(1, 10):
    for j in range(10):
        for k in range(10):
            dividend = int(str(i) + str(j))
            divisor  = int(str(j) + str(k))
            try:
                if dividend / divisor == i / k:
                    print '{dividend}/{divisor} = {i}/{k} = {result}'.format(
                        dividend=dividend, divisor=divisor, i=i, k=k, result=dividend/divisor)
            except ZeroDivisionError:
                pass

Result

11/11 = 1/1 = 1.0
16/64 = 1/4 = 0.25
19/95 = 1/5 = 0.2
22/22 = 2/2 = 1.0
26/65 = 2/5 = 0.4
33/33 = 3/3 = 1.0
44/44 = 4/4 = 1.0
49/98 = 4/8 = 0.5
55/55 = 5/5 = 1.0
66/66 = 6/6 = 1.0
77/77 = 7/7 = 1.0
88/88 = 8/8 = 1.0
99/99 = 9/9 = 1.0

Alternative

Code

# -*- coding: utf-8 -*-

from __future__ import print_function, division

for i in range(1, 10):
    for j in range(10):
        for k in range(10):
            dividend = int(str(i) + str(j))
            divisor = int(str(j) + str(k))
            try:
                assert not i == j == k
                if dividend / divisor == i / k:
                    print(' {i}{j}   {i}{j}̶   {i}\n —— = —— = — = {result}\n {j}{k}   {j}̶{k}   {k}\n'.format(
                        i=i, j=j, k=k, result=dividend/divisor))
            except AssertionError:
                pass
            except ZeroDivisionError:
                pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment