pywayne-maths
Mathematical utility functions for factorization, digit counting, and large integer multiplication using Karatsuba algorithm. Use when solving number theory problems, computing factors, counting digit occurrences, or performing optimized large integer multiplication.
What this skill does
# Pywayne Maths
Mathematical utility functions for number theory, digit analysis, and optimized integer operations.
## Quick Start
```python
from pywayne.maths import get_all_factors, digitCount, karatsuba_multiplication
# Get all factors of a number
factors = get_all_factors(28)
print(factors) # [1, 2, 4, 7, 14, 28]
# Count digit occurrences
count = digitCount(100, 1)
print(count) # 21 (digit 1 appears 21 times in 1-100)
# Large integer multiplication
product = karatsuba_multiplication(1234, 5678)
print(product) # 7006652
```
## Functions
### get_all_factors
Return all factors of a positive integer.
```python
get_all_factors(n: int) -> list
```
**Parameters:**
- `n` - Positive integer to factorize
**Returns:**
- List of all factors of `n`
**Use Cases:**
- Number theory problems
- Finding divisors
- Simplifying fractions
- Greatest common divisor (GCD) calculation
**Example:**
```python
from pywayne.maths import get_all_factors
factors = get_all_factors(36)
print(factors) # [1, 2, 3, 4, 6, 9, 12, 18, 36]
# Check if number is prime
n = 17
factors = get_all_factors(n)
if len(factors) == 2: # Only 1 and itself
print(f"{n} is prime")
else:
print(f"{n} is not prime")
```
### digitCount
Count occurrences of digit `k` from 1 to `n`.
```python
digitCount(n, k) -> int
```
**Parameters:**
- `n` - Positive integer, upper bound of counting range
- `k` - Digit to count (0-9)
**Returns:**
- Count of digit `k` in range [1, n]
**Special Case:**
- When `k = 0`, counts all numbers with trailing zeros after `n`
**Use Cases:**
- Digit frequency analysis
- Number theory problems
- Data analysis tasks
**Example:**
```python
from pywayne.maths import digitCount
# Count digit 1 from 1 to 100
count = digitCount(100, 1)
print(count) # 21
# Count each digit 0-9 in range 1-1000
for k in range(10):
count = digitCount(1000, k)
print(f"Digit {k}: {count} times")
```
### karatsuba_multiplication
Multiply two integers using Karatsuba's divide-and-conquer algorithm.
```python
karatsuba_multiplication(x: int, y: int) -> int
```
**Parameters:**
- `x` - Integer multiplier
- `y` - Integer multiplicand
**Returns:**
- Product of `x` and `y`
**Algorithm:**
- Karatsuba algorithm uses recursive divide-and-conquer to multiply large integers
- Time complexity: O(n^log₂3) ≈ O(n^1.585)
- More efficient than naive multiplication O(n²) for very large numbers
**Use Cases:**
- Large integer multiplication
- Algorithm optimization
- Competitive programming
- Cryptography applications
**Example:**
```python
from pywayne.maths import karatsuba_multiplication
# Compare with standard multiplication
a, b = 123456789, 987654321
result = karatsuba_multiplication(a, b)
print(result) # 121932631112635269
# Verify
assert result == a * b
```
## Common Applications
### Prime Number Detection
```python
from pywayne.maths import get_all_factors
def is_prime(n):
factors = get_all_factors(n)
return len(factors) == 2 and factors == [1, n]
print(is_prime(17)) # True
print(is_prime(18)) # False
```
### Greatest Common Divisor (GCD)
```python
from pywayne.maths import get_all_factors
def gcd(a, b):
factors_a = set(get_all_factors(a))
factors_b = set(get_all_factors(b))
common = factors_a & factors_b
return max(common)
print(gcd(24, 36)) # 12
```
### Digit Frequency Analysis
```python
from pywayne.maths import digitCount
def digit_frequency(n):
frequency = {}
for k in range(10):
frequency[k] = digitCount(n, k)
return frequency
print(digit_frequency(1000))
# {0: 189, 1: 301, 2: 300, 3: 300, ...}
```
### Large Number Calculations
```python
from pywayne.maths import karatsuba_multiplication
# Very large numbers
x = 123456789012345678901234567890
y = 9876543210987654321098765432109876
# Use Karatsuba for efficiency
product = karatsuba_multiplication(x, y)
```
## Notes
- `get_all_factors` returns sorted unique factors
- `digitCount` counts from 1 to n inclusive
- `karatsuba_multiplication` is optimized for large integers (hundreds+ of digits)
- For small integers, standard multiplication `*` may be faster due to overhead
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.