Questions tagged [python-3.x]

Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag.

Filter by
Sorted by
Tagged with
2
votes
1answer
66 views

Updateable Priority Queue

I've implemented an updateable priority queue as a part of implementing some single-source-shortest-path algorithms (Dijkstra, BF). I'm relatively new to Python. ...
2
votes
2answers
37 views

Consolidating a dictionary from nested dictionary

Currently learning from "LPTHW - Zed Shaw" and "Automating the boring stuff". There is a nested dictionary of the type ...
3
votes
2answers
70 views

Project Euler # 56 Powerful digit sum in Python

A googol (\$10^{100}\$) is a massive number: one followed by one-hundred zeros; \$100^{100}\$ is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits ...
7
votes
1answer
117 views

Linny: An Interpreted Programming Language

There is a follow up question here. I've undertaken the project of creating my own programming language, Linny. It's a very, very simple language, with only variable creation, variable changing, and ...
7
votes
3answers
1k views

Determine if a triangle is equilateral, isosceles, or scalene

I've been fiddling around with some easy code challenges and there's one about determining if a triangle is equilateral, isosceles, or scalene. I've come up with a working solution, but I feel this ...
3
votes
1answer
65 views

Project Euler # 53 Combinatoric selections in Python

There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345 In combinatorics, we use the notation, 5C3=10. In general, nCr = n! / r! (n−r)!, ...
2
votes
2answers
67 views

Project Euler # 52 Permuted multiples in Python

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order. Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, ...
2
votes
2answers
79 views

Determine whether three sides form a valid triangle, and classify the triangle

This is a my first Python program, and whilst I am new to Python I would like to keep in good practice Below is a short program to work out what type a triangle is and if it makes a valid triangle ...
0
votes
0answers
34 views

Python script to import MySQL tables to PostgreSQL

I'm using the below Python script to port few table data from a remote server (MySQL database) to my data warehouse server (PostgreSQL DB), The script is working fine (I'm using foreign data wrapper), ...
1
vote
1answer
34 views

Optimising the BFS

The input graph to the bfs function is in the form of edge list representation. ...
2
votes
1answer
48 views

Traversing two trees until a common value has been found

I am traversing two objects that may share a common ancestor. To make the code small enough to show here, I have changed it into two dictionaries with values. As you can see, ...
1
vote
0answers
32 views

Invoking parallel threads of a nslookup command in python

I've written below python script just to invoke parallel threads of a command nslookup linux-host01 dns-server, i'm Just trying to flood the DNS Server ...
-2
votes
1answer
117 views

Project Euler # 50 Consecutive prime sum in Python

The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a prime below one-hundred. The longest sum ...
2
votes
2answers
75 views

Caesar Cipher Guesser

I've written a Caesar Cipher in python (a more in-depth explanation is provided in the docstring at the top of the program). At first, it was supposed to just be the cipher, but I expanded it to have ...
0
votes
0answers
19 views

Grouping by on Pandas df with focus on performance

I am doing a group by on a subset of a dataframe. I am working with 9m+ rows atm, subject to sharp increase. I tried different approaches already and wanted to know if i could squeeze a bit more ...
2
votes
1answer
240 views

Project Euler # 49 Prime permutations in Python

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are ...
0
votes
1answer
72 views

Project Euler # 48 Self powers in Python

The series, \$1^1 + 2^2 + 3^3 + \ldots + 10^{10} = 10405071317\$. Find the last ten digits of the series, \$1^1 + 2^2 + 3^3 + \ldots + 1000^{1000}\$. ...
3
votes
1answer
48 views

File compressor

I have written a file compressor in python. The program generates a file filled with sequences of the same character with a random length, and compresses that file. I would like feedback on code ...
5
votes
2answers
68 views

Grouping sorted coordinates based on proximity to each other

I created an algotrithm that groups a sorted list of coordinates into buckets based on their proximity (30) to one another. Steps: Create a new key with a list ...
1
vote
3answers
88 views

Project Euler # Triangular, pentagonal and hexagonal in Python

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle: \$T_n=\frac{n(n+1)}{2}\$ 1, 3, 6, 10, 15, … Pentagonal: \$...
1
vote
1answer
73 views

Project Euler # 44 Pentagon numbers in Python

Pentagonal numbers are generated by the formula, \$P_n=\frac{n(3n−1)}{2}\$. The first ten pentagonal numbers are: 1, 5, 12, 22, 35, 51, 70, 92, 117, 145 ...
-1
votes
2answers
67 views

Project Euler # 43 Sub-string divisibility in Python

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property. Let \...
1
vote
0answers
49 views

Project Euler # 42 Coded triangle number in Python

The nth term of the sequence of triangle numbers is given by, \$t_n = \frac{n(n+1)}{2}\$; so the first ten triangle numbers are: ...
1
vote
0answers
47 views

Project Euler # 38 Pandigital multiples in Python

Take the number 192 and multiply it by each of 1, 2, and 3: 192 × 1 = 192 192 × 2 = 384 192 × 3 = 576 By concatenating each product we get the 1 to 9 pandigital, 192384576. We will ...
0
votes
1answer
50 views

Project Euler # 37 Truncatable primes in Python

The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can ...
5
votes
1answer
45 views

A view for Python list slices

As you probably know, Python slices like arr[1:3] etc. do NOT provide a view onto list and instead creates a copy of the list, what can be not optimal performance ...
1
vote
1answer
68 views

Project Euler # 36 Double-base palindromes in Python

The decimal number, 585 = 1001001001 (binary), is palindromic in both bases. Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2. (Please note ...
3
votes
1answer
113 views

Project Euler # 35 Circular primes in Python

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, ...
1
vote
1answer
70 views

Project Euler 34 # Digit Factorials in Python

145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not ...
1
vote
1answer
65 views

Project Euler # 30 Digits fifth power in Python

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: \$1634 = 1^4 + 6^4 + 3^4 + 4^4\$ \$8208 = 8^4 + 2^4 + 0^4 + 8^4\$ \$9474 = 9^4 + ...
1
vote
1answer
38 views

Project Euler # 29: Distinct powers in Python

Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: 2 ** 2 = 4, 2 ** 3 = 8, 2 ** 4 = 16, 2 ** 5 = 32 3 ** 2 = 9, 3 ** 3 = 27, 3 ** 4 = 81, 3 * 5 = 243 4 ** 2 = 16, 4 ** 3 = ...
1
vote
0answers
23 views

Project Euler # 28: Number spiral diagonals in Python

Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: ...
3
votes
2answers
60 views

Checking the strength of a password using regexes

I'm a beginner in Python and I made a password checker. I'm following these rules: I have to use regex password must be at least 8 characters must have at least one lower case character must have at ...
15
votes
5answers
3k views

Project Euler # 25 The 1000 digit Fibonacci index

The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 ...
2
votes
2answers
46 views

Project Euler # 24 Lexicographic permutations in Python

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we ...
5
votes
1answer
154 views

Sim survival game

The objective of the game is to survive as long as possible. You have a need and that is hunger. Your hunger decreases by 10 every 3 minutes and if your hunger reaches 0 you will die and the amount of ...
4
votes
1answer
43 views

Project Euler # 22 names scores in Python

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. ...
3
votes
2answers
75 views

Importing data into PostgreSQL from remote text file using ftplib class

I need to read a remote file using FTP and process it and insert the processed data to a PostgreSQL database in another server. The below code is working fine, but i want some advice to modify few ...
1
vote
1answer
61 views

Project Euler # 21 amicable numbers Python

Let \$d(n)\$ be defined as the sum of proper divisors of \$n\$ (numbers less than \$n\$ which divide evenly into \$n\$). If \$d(a) = b\$ and \$d(b) = a\$, where \$a ≠ b\$, then \$a\$ and \$b\$ are an ...
3
votes
1answer
55 views

Project Euler # 20 factorial digit sum in Python

n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. Find the sum of the ...
2
votes
1answer
42 views

Project Euler # 19 Counting Sundays in Python

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have ...
1
vote
1answer
39 views

Integer field in Python with extra constraints (Testable class)

I am trying to write an integer field in Python with the following attributes: Minimum Exclusive minimum Maximum Exclusive maximum Multiple of Value Basically, given the constraints and the value, ...
1
vote
1answer
125 views

HarckerRank 2D Arrays Hourglass challenge

About this 2D Arrays HackerRank problem. The task is to find the maximum sum of a region in a 2D array. Specifically, it is to find the maximum sum of an "hourglass" region, defined as a 3x3 square ...
2
votes
1answer
38 views

Store coordinates in 2d grid

I`m writing a function for small pygame program. The ideas is that I have a 500 pixels square screen and I want to place 5 objects per row with the size of width and height in random order and I need ...
3
votes
1answer
73 views

Hurst Exponent calculator

I am aiming to compute the Hurst Exponent of a 1-D signal time series in Python. For now, I have one existing function hurst(sig) which returns the Hurst exponent ...
0
votes
1answer
46 views

leetcode 987. Vertical Order Traversal of a Binary Tree

anyone can provide some suggestion about my answer for the questions 987. Vertical Order Traversal of a Binary Tree Given a binary tree, return the vertical order traversal of its nodes values. ...
2
votes
2answers
108 views

Staircase challenge - Python

Your task is to print all unique ways to climb a staircase of length n where, from each step, you can take steps of size x where ...
2
votes
1answer
51 views

Find Todos by Line Number (or any other reference) in Python - Revised as functions

A new function based version of the code from this question as suggested by @Hlib Babii I write a lot of TODO's but I never keep track of where they are. This program will search through files (and ...
0
votes
4answers
147 views

Rock, paper, scissors game in Python 3

as a beginner in Python I made a rock, paper, scissors game and was wondering if my code was a bit weird and could be simplified??? ...
3
votes
1answer
43 views

Kruskals MST Algorithm

This code computes the Minimum Spanning Tree of a given graph using Kruskals Algorithm. It works successfully and I have provided test cases within the code. I would like feedback on code efficiency ...