Tagged Questions
-2
votes
0answers
9 views
hailstone sequence using recursion in python [on hold]
Does it make sense to implement using recursion? I wrote some bad solution below. Please correct me.
...
1
vote
1answer
70 views
Modifying nested dictionaries in Python
My task was to take a configuration specified as a dictionary and run some function with it (the actual function is not relevant here). After implementing that, I was asked to allow some "sweeping" of ...
2
votes
1answer
41 views
Python script to find large folders
I wrote this script a few days ago to find all files which were taking up over a certain threshold of memory on the hard drive. A hard drive on one of my computers had just 6 GB left, so I needed to ...
4
votes
2answers
60 views
3
votes
2answers
58 views
Optimizing a recursion code over lists
I'm writing three functions which iterate over lists, I want do this recursively, but I think this code is not as efficient as it could be.
...
2
votes
2answers
50 views
How might we make this Python Merge Sort implementation more Pythonic?
I've implemented a (version of) Merge Sort algorithm in Python. My goal here is two-fold:
Improve understanding of Merge Sort and recursion in a language agnostic way.
Improve understanding of ...
0
votes
1answer
63 views
Understand recursion
I'm trying to improve my understanding of recursive and iterative
processes. I've started with SICP, but have branched off to try and
find a few exercises when I started having difficulty. Currently ...
3
votes
2answers
121 views
Recursive uniform cost search that needs to be optimized
I have this uniform cost search that I created to solve Project Euler Questions 18 and 67. It takes the numbers in the txt file, places them into a two dimensional list, and then traverses them in a ...
4
votes
1answer
80 views
Is recursion like this safe with a task queue on GAE?
I've written a function to call with the deferred library to generate a large task queue, and at first without the recursion it timed out (deadlineexceeded) so now I'm trying with a recursion but is ...
5
votes
2answers
188 views
Map color problem: Optimize using a heap?
I've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and ...
12
votes
3answers
563 views
Improving knapsack branch and bound: how to forward filter?
I've coded branch and bound to solve the knapsack problem, and use a greedy linear relaxation to find an upper bound on a node I'm currently exploring. What I mean by this is that I first sort the ...
6
votes
1answer
101 views
Functional, but not recursive, tree traversal
To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
4
votes
2answers
190 views
2
votes
3answers
175 views
Python script to touch files of a particular pattern in all folders of a given name
The intent of this script is to hunt down all "*/testResults/*.xml" files and touch them, so that our build system doesn't issue errors that the files are too old ...
3
votes
1answer
309 views
Recursively convert a list of lists into a dict of dicts
As a challenge to myself, I wrote a solution to this Stack Overflow question. For completeness, the bulk of the question is as follows:
Problem
Input:
...
15
votes
2answers
406 views
Sudoku using 'exact cover' solver
1. Introduction
This is a solution to Weekend Challenge #3: a Sudoku solver in Python. It works by translating a Sudoku puzzle into an exact cover problem, and then solving the exact cover problem ...
4
votes
3answers
867 views
Using pycparser to parse C header files
I have a small program which makes uses of pycparser to parse C header files. The code, unfortunately, kinda sprawls out everywhere to handle the different cases (example below).
What's the best way ...
10
votes
2answers
723 views
Sudoku solver using simple deductions and brute-force guessing
Here's my attempt at Weekend Challenge #3.
Key characteristics of this Python entry are:
The strategy is to alternate between "auto-complete" (making simple deductions such as naked singles and ...
3
votes
5answers
374 views
count all array[index] == index occurrences
The method foo gets a sorted list with different numbers as a parameter and returns the count of all the occurrences such that: ...
3
votes
0answers
481 views
Recursive JSON walk in Python [closed]
I wrote this JSON walker to help with moving objects around while updating Legacy JSONs to match a new schema. Please let me know how I could further optimize it, or more importantly, make it easier ...
1
vote
1answer
620 views
Finding strongly connected components of directed graph, kosaraju
Given a graph in [[sourcevertex,targetvertex],...] format with all the directed edges of the graph I am trying to optimize the code here because it still hasn't ...
2
votes
2answers
175 views
Python code snippet could probably be more elegant
I'm looking to let people define arbitrarily nested lists of lists and return a random json document for them. Right now the assumption is that if you have a structure like this:
...
2
votes
2answers
131 views
I'm practicing turning for loops into recursive functions. what do you think?
I am trying to turn this function:
collection = ['hey', 5, 'd']
for x in collection:
print(x)
Into this one:
...
1
vote
1answer
75 views
Improve file-path finding method
I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: ...
3
votes
3answers
164 views
2
votes
1answer
201 views
Iterative Collatz with memoization
I'm trying to write efficient code for calculating the chain-length of each number.
For example, ...
4
votes
1answer
257 views
Recursive XML2JSON parser
I made a Python function that takes an XML file as a parameter and returns a JSON.
My goal is to convert some XML get from an old API to convert into Restful API.
This function works, but it is ...
2
votes
1answer
260 views
Efficiency of Recursive Checkers Legal Move Generator
I'm implementing a checkers engine for a scientific experiment. I found out through profiling that this is one of the functions that takes up a lot of time. I'm not looking for an in-depth analysis, ...
1
vote
3answers
286 views
How to improve this functional python fast exponentiation routine?
I have the following python functions for exponentiation by squaring :
...
1
vote
1answer
583 views
shortest path recursive algorithm [closed]
This is the first time I come to this site, even though I tried to post in Stack Overflow but was told that this would be a better place to ask. So I hope this is the right place for my question.
...
6
votes
1answer
128 views
Calculate highscores based on sales data
The background is my question is SO How to create a list of totals for durations?
where I found a recursive solution that I want to review. I could not test it for higher levels than 1 but to the best ...
4
votes
1answer
1k views
Selection sort using recursion
How does this recursive selection sort look to everyone here? Am I missing anything 'pythonic' about the way I have done it?
...