This file contains hidden or 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
# This script calculates Sequence A0308479, the least k such that k*n and (k+1)*n | |
# fail to have a common nonzero digit, or 0 if this property never occurs. | |
# | |
# See: https://oeis.org/A308479 | |
# | |
# Author: David Radcliffe | |
# 9 June 2019 | |
def share_digit(m, n): | |
return set(str(m)) & set(str(n)) - set('0') |
This file contains hidden or 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
# Python script to calculate the binomial coefficient C(n, k) | |
# where n is an integer or floating point number and k is an integer. | |
# | |
# We use the following general definition: | |
# C(n, k) = n(n-1)(n-2)...(n-k+1) / k! if k >= 0, | |
# 0 if k < 0. | |
# | |
# For n < 0, we use the negative binomial identity | |
# C(n, k) = (-1)^k * C(k - n - 1, k) | |
# |
This file contains hidden or 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
def phi_2_5(m): | |
"""Computes the totient of a number m whose only prime factors are 2 or 5.""" | |
if m % 2 == 0: | |
m //= 2 | |
if m % 5 == 0: | |
m = (m * 4) // 5 | |
return m | |
def tower_mod(a, n, m): | |
"""Evaluates the power tower a^a^a^..^a, with height n, modulo m. |
This file contains hidden or 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
31414143134141341341111344411133114141331444144114343444333433431441441134343314 | |
34441433411413111343334144331331311444341314314131443334334444313114114134413113 | |
41341113314141433141133343113113413111133334143441131333134441311433131143331343 | |
43314443313433441134444414341114313333433313331413431341341144411331143314314334 | |
13431443414444333141341144133431334411413411433443331131331114344414131433444441 | |
31334341331431414133433144414144113344433413333434133143444343333131143343134113 | |
13434434313311343111114434344143343443111333131433344314331133434441333131433311 | |
43331133443133313141413441111331311413443311111114413144334111313343333434333443 | |
11111441441444113444111444133144114333341431141141143414111331344134143144413143 | |
34441441143343113331141443344433111314114411444313331413131413144444331413331433 |
This file contains hidden or 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
#!/usr/bin/env python3 | |
# | |
# This Python script searches a database of over 500 million passwords | |
# to determine whether a given password has been exposed in a data breach. | |
# | |
# Thanks to Troy Hunt for creating the API that is used by this script. | |
# See https://haveibeenpwned.com/API/v2#PwnedPasswords for more information. | |
# | |
# Author: David Radcliffe ([email protected]) | |
# Date: 20 January 2019 |
This file contains hidden or 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
-module(powermod). | |
-export([powmod/2]). | |
powmod(A, B, M) -> powmod(A, B, M, 1). | |
powmod(_, 0, _, R) -> R; | |
powmod(A, B, M, R) when B rem 2 == 1 -> powmod(A, B-1, M, A*R rem M); | |
powmod(A, B, M, R) -> powmod(A*A rem M, B div 2, M, R). |
This file contains hidden or 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
-module(power). | |
-export([pow/2]). | |
pow(A, B) -> pow(A, B, 1). | |
pow(_, 0, C) -> C; | |
pow(A, B, C) when B rem 2 == 1 -> pow(A, B-1, A*C); | |
pow(A, B, C) -> pow(A*A, B div 2, C). |
This file contains hidden or 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
-module(multiply). | |
-export([mul/2]). | |
mul(A, B) -> mul(A, B, 0). | |
mul(_, 0, C) -> C; | |
mul(A, B, C) when B rem 2 == 1 -> mul(A, B-1, A+C); | |
mul(A, B, C) -> mul(A + A, B div 2, C). |
This file contains hidden or 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
-module(multiply). | |
-export([mul/2]). | |
mul(A, B) -> mul(A, B, 0). | |
mul(_, 0, C) -> C; | |
mul(A, B, C) -> mul(A, B-1, A+C). |
This file contains hidden or 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
-module(multiply). | |
-export([mul/2]). | |
mul(_, 0) -> 0; | |
mul(A, B) -> mul(A, B-1) + A. |