Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 153917

An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

9 votes
Accepted

Optimizing a function to find the closest multiple of 10

The algorithm is: Get remainder of number with modulo by 10 If remainder is less than 5, return number minus remainder Else, return number + (10 - remainder) def closest_multiple_10(x): rem = x % …
Linny's user avatar
  • 10.4k
1 vote
2 answers
341 views

Find the shortest distance between two letters

I've been tasked with finding the distance between two letters in the alphabet. Below is my solution. My main concerns are if there is any shorter way to do this, and if there are any edge cases I'm n …
1 vote
2 answers
294 views

Generate a string that is not present in a list

Below is my solution, with a description of the algorithm is provided in the docstring. The main thing I'm worried about is my solution. … sequences.append(line.strip()) return sequences # PROVIDE YOUR SOLUTION BELOW # from typing import Tuple # For code clarity def find_excluded() -> Tuple[str, bool]: """ This algorithm
1 vote

My prime number generation program in Python

Remove print statements Printing to the console takes a significant amount of time, and you are printing for every iteration and every element in the list. Run it once with the statements, and once wi …
Linny's user avatar
  • 10.4k
1 vote

My implementation of bubble sort using Python

Your bubble sort algorithm has way too many variables. You don't need to keep track of the right and left item. …
Linny's user avatar
  • 10.4k
1 vote
Accepted

Python Combinatory Algorithm - A Binomial Coefficient application with n mutable and k fixed...

You should really only use comments to explain a design choice or a complicated equation/algorithm. Comments like #if the condition is satisfied just clutters your code. …
Linny's user avatar
  • 10.4k
6 votes
Accepted

Find all numbers that are factors of one array and factor into the second array, then print ...

Redundant calculations You calculate mult1 * mult2 three times. Instead, do this once, assign it to a variable, and use that. Since you want to never want to calculate when a value is 0, you can set …
Linny's user avatar
  • 10.4k
5 votes
Accepted

A simple Decryption Program using Python

Use built in methods! Your position_in_alphabets function can be reduced to one line. In fact, replace y = ... with the following: alphabets.index(character) + 1 index returns the first occurrence …
Linny's user avatar
  • 10.4k
1 vote

Python Sudoku Solver

Class Names Classes should be in PascalCase, not lowercase. So your class should be App. Operator Spacing There should be a space before and after every operator (+-*/=, etc) in your program. It im …
Linny's user avatar
  • 10.4k
7 votes

Are the sum of two numbers desired?

Your function code can be simplified to one line. from itertools import combinations from typing import List def array_sum(inputs: List[int], tests: List[int]) -> bool: """ Determines if any …
Linny's user avatar
  • 10.4k
1 vote

Trapezoidal rule for set of data

Just a few things I noticed. Utilize built in functions This S = 0 for k in range(1, N): S += function[a + k * h] can be this S = sum(function[a + k * h] for k in range(1, N)) Python3's su …
Toby Speight's user avatar
  • 81.7k
4 votes
Accepted

Tic-Tac-Toe with changeable board size (Part 2)

Winning Bug When the board is at this stage and the user gets the next move: | | X | O | X | | ---------------------- | | | O …
Community's user avatar
  • 1
4 votes
Accepted

Strong Password Checker (Python)

Imports I notice you import re three times, once for each password check function. Why? Just import the library once at the top of the file, and you can use it in all of your functions. Returning B …
Linny's user avatar
  • 10.4k
5 votes
2 answers
2k views

Sum of all digits in a string

I would really only like suggestions on the actual algorithm, but anything else is appreciated. …
5 votes
3 answers
597 views

Largest number order in string

I'd like feedback mainly on the algorithm, as I wrote this up very quickly. I used comprehension syntax to find the largest num, which I'm trying to use more. …

15 30 50 per page