Created
October 20, 2024 03:56
-
-
Save segmond/8992a8ec5976ff6533d797caafe151fa to your computer and use it in GitHub Desktop.
various correct solutions with different local models
This file contains 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
# see - https://news.ycombinator.com/item?id=41890158 | |
deepseekcoder2.5.py | |
------------------------ | |
def find_combinations(target_product): | |
combinations = [] | |
for i in range(1, target_product): | |
for j in range(i + 1, target_product): | |
k = target_product // (i * j) | |
if k > j and i * j * k == target_product: | |
combinations.append((i, j, k)) | |
return combinations | |
target_product = 108 | |
combinations = find_combinations(target_product) | |
print(f"All combinations of three distinct positive integers that multiply to {target_product}:") | |
for combo in combinations: | |
print(combo) | |
------------------------ | |
gemma27b.py | |
------------------------ | |
from itertools import permutations | |
def find_factors(target): | |
"""Finds all unique combinations of three distinct positive integers that multiply to the target.""" | |
factors = [] | |
for i in range(1, int(target**0.33) + 1): # Optimize by checking up to cube root | |
for j in range(i + 1, int(target**(0.5)) + 1): # Optimize by checking up to square root | |
k = target // (i * j) | |
if i * j * k == target and i < j < k: # Ensure distinct and ordered | |
factors.append((i, j, k)) | |
return factors | |
target = 108 | |
result = find_factors(target) | |
print(f"The ways to express {target} as a product of three distinct positive integers are:") | |
for factor_set in result: | |
print(factor_set) | |
------------------------ | |
llama405b.py | |
------------------------ | |
def find_triplets(product): | |
""" | |
Find all distinct triplets of positive integers that multiply to the given product. | |
Args: | |
product (int): The target product. | |
Returns: | |
list[tuple[int, int, int]]: A list of distinct triplets. | |
""" | |
triplets = set() # Use a set to avoid duplicates | |
factors = [i for i in range(1, product + 1) if product % i == 0] | |
for a in factors: | |
for b in factors: | |
if a != b: # Ensure a and b are distinct | |
c = product // (a * b) | |
if a != c and b != c and a * b * c == product: # Ensure c is distinct and product matches | |
triplet = tuple(sorted((a, b, c))) # Sort to ensure uniqueness | |
triplets.add(triplet) | |
return list(triplets) | |
# Example usage | |
product = 108 | |
triplets = find_triplets(product) | |
print(f"Distinct triplets with a product of {product}:") | |
for triplet in triplets: | |
print(triplet) | |
------------------------ | |
llama70b.py | |
------------------------ | |
import itertools | |
def find_triplets(): | |
# Define the target product | |
target_product = 108 | |
# Generate all possible triplets of distinct positive integers | |
triplets = list(itertools.combinations(range(1, target_product + 1), 3)) | |
# Filter the triplets that have a product of 108 | |
valid_triplets = [triplet for triplet in triplets if triplet[0] * triplet[1] * triplet[2] == target_product] | |
return valid_triplets | |
# Find and print all valid triplets | |
triplets = find_triplets() | |
for i, triplet in enumerate(triplets): | |
print(f"Triplet {i+1}: {triplet}") | |
------------------------ | |
mistral.py | |
------------------------ | |
def find_triplets(product): | |
solutions = [] | |
# Loop through all possible values for the first number | |
for i in range(1, int(product**(1/3)) + 1): | |
if product % i == 0: | |
# Loop through all possible values for the second number | |
for j in range(i + 1, int((product / i)**(1/2)) + 1): | |
if product % j == 0: | |
# Calculate the third number | |
k = product // (i * j) | |
# Check if the third number is distinct from the first two numbers | |
if k > j: | |
solutions.append((i, j, k)) | |
return solutions | |
# Define the product | |
product = 108 | |
# Find and print all the solutions | |
solutions = find_triplets(product) | |
for solution in solutions: | |
print(solution) | |
------------------------ | |
qwen2.5-72b.py | |
------------------------ | |
def find_triplets(product): | |
triplets = [] | |
# Iterate through possible values for the first integer | |
for i in range(1, product + 1): | |
if product % i == 0: | |
# Iterate through possible values for the second integer | |
for j in range(i + 1, product // i + 1): | |
if (product // i) % j == 0: | |
k = product // (i * j) | |
if j < k: | |
triplets.append((i, j, k)) | |
return triplets | |
# Define the product | |
product = 108 | |
# Find all triplets | |
triplets = find_triplets(product) | |
# Print the results | |
print("The triplets of distinct positive integers whose product is 108 are:") | |
for triplet in triplets: | |
print(triplet) | |
------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment