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
#!/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
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
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
# 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
# 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
""" | |
A generalized coupon collector problem. | |
An experiment with n possible outcomes is repeated until each of the possible | |
outcomes is observed at least once. Each outcome i has a fixed non-zero | |
probability p[i], and each trial is independent of the previous trials. | |
What is the expected number of trials? | |
For example, what is the expected number of times that two dice must be rolled | |
until all of the possible totals (from 2 to 12) have appeared at least once? |
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 draws a Sudoku graph with the vertices arranged in a circle. | |
David Radcliffe | |
[email protected] | |
25 December 2019 | |
The sudoku_graph() function below is being considered for a future version of NetworkX. | |
""" |
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
There are 2020 ways to choose 4 nonempty subsets of {1,2,3,4,5} so that no set contains another. | |
(Sperner systems with 4 blocks) | |
{{1}, {2}, {3}, {4}} | |
{{1}, {2}, {3}, {5}} | |
{{1}, {2}, {3}, {4, 5}} | |
{{1}, {2}, {4}, {5}} | |
{{1}, {2}, {4}, {3, 5}} | |
{{1}, {2}, {3, 4}, {5}} |
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
# File: plot_circles.py | |
# | |
# This code is used with Qiskit to display the circle plot representation of the state vector | |
# of a quantum register. The state vector for an N-qubit quantum register has 2^N components, | |
# which are called amplitudes. Each amplitude is a complex number, and the squared magnitudes | |
# add up to 1. | |
# | |
# The circle plot has a circle of radius 1 for each amplitude, with a filled-in circle inside it. | |
# The radius of the filled-in circle is equal to the magnitude. The circle also contains a line | |
# segment from the center of the circle to the circumference. The line segment is rotated to show |