A generator is a generalization of a subroutine, primarily used to simplify the writing of iterators. The yield statement in a generator does not specify a co-routine to jump to, but rather passes a value back to a parent routine.
-3
votes
0answers
35 views
Random number generator without duplicates in C [on hold]
I'm making a mastermind game in C and i want to generate the colors without any duplications
...
3
votes
1answer
588 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, ...
4
votes
1answer
62 views
Combining fragments of data in a generator pipeline
Edit: it seems flow based (or reactive) programming approach would help here; there are some libraries in python that try that.
I tried to follow the generator pipeline style (see David Beazley's ...
3
votes
2answers
159 views
Transforming a list of two-dimensional coordinates into a flat list of relative changes
I have a little function that parse a nested list of coordinates into a flat list of compressed coordinates. By compressed coordinates, I mean that only the delta (distance) between each coordinates ...
4
votes
3answers
511 views
Testing a Random number generator
Firstly, would appreciate some code-review feedback, from a TDD and design perspective.
Secondly, what are your thoughts on implementing test case: ...
1
vote
2answers
62 views
Infinite prime generator
This code acts as an infinite generator of prime numbers.
As new prime numbers are found, they are added to a set. Then, a number x is found to be prime if none of the numbers in the prime set are ...
3
votes
2answers
104 views
Retrieving the nth term of an infinite stream
I recently learned how generators can be infinite in Python. For example, the infinite sequence can be the triangular numbers:
$$1, 3, 6, 10,...$$
...
9
votes
1answer
108 views
Using generators to print the tree-like structure of a project
The goal of this code is to print the entity tree of a VHDL project. There are a readme and very minimal tests on the github repo.
I am trying to refactor the code to use generators in order to ...
4
votes
3answers
144 views
Concatenating two IEnumerables with a limit
I've been playing around with generators, generics and extension methods in C# (5.0) and wanted to create an extension method for IEnumerable, which would append ...
3
votes
1answer
101 views
Extracting specific rows and columns from a CSV file
I have written a function to selectively extract data from a file.
I want to be able to extract only from a certain line and only given rows.
Would convert this function into a generator improve the ...
3
votes
2answers
1k views
Searching a 2D matrix for a consecutive sequence
I've been solving problems on checkio (and trying to digest other's code) in order to improve my Python.
My main goals are to learn to write more idiomatic Python and to explore the language more ...
6
votes
2answers
82 views
Random name generation in ruby
I created this program as an exercise for me to learn ruby. It is a random name generator with a set of rules defined to generate pretty decent and usually pronouncable names. Ruby isn't exactly my ...
3
votes
0answers
107 views
C++11 generator implementation emulating Python's yield keyword
C++11's range-based loops allow convenient and easy iteration over containers, but what about more complicated iterations such as tree traversal? Usually this involves a lot of boilerplate code and ...
2
votes
2answers
108 views
Fibonacci sequence methods
Decided to get a little JDK 8 practice in today, so I built two methods to print out the golden ratio, one uses the Stream API the other does not. Wanted to request general feedback on how well I ...
2
votes
1answer
48 views
Exponential backoff generator
Exponential backoff in the context of various networking protocols looks something like this:
When a collision first occurs, send a “Jamming signal” to prevent further data being sent.
...
11
votes
7answers
2k views
French animal generator
I'm learning Python. I'm making a random animal generator, from 5 txt files. Each file is a list of words for respectively the specie of the animal, an adjective, an origin, and a bodypart with a ...
4
votes
2answers
1k views
Range iterator in ES6 similar to Python and Ruby for
Background and Purpose
For those unaccustomed to Ruby, Ruby supports range literals i.e. 1..4 meaning 1, 2, 3, 4 and ...
3
votes
1answer
117 views
Recursive flattening of Swift sequences - an overly complicated approach
I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
3
votes
2answers
232 views
Python prime number generator
I'm trying to get a better grasp on generators in Python because I don't use them enough (I think generators are cool). To do so I wrote a generator for prime numbers:
...
1
vote
0answers
99 views
Scan over parameter iterator for model simulation
I'm writing a small Python application that performs model simulation for many different parameters. The iterator of parameters isn't completely known ahead of time. Rather, the iterator needs to ...
3
votes
1answer
211 views
Generators in Javascript; Project Euler #2
I'm trying to learn javascript using project euler and I decided to try to force myself to learn about generators in javascript using problem number 2 which asks us to: ...
3
votes
5answers
132 views
Determining whether a loop iterated at least one element in generator function
I have a case in which I need to determine whether a for loop yielded at least one element:
...
1
vote
0answers
348 views
Scrabble word finder
I have been working on a Scrabble Word Finder for a couple of days now and have it working pretty much but would love to improve the efficiency.
The code is made up of 2 classes: one for creating and ...
2
votes
1answer
98 views
Project Euler #2: sum of even Fibonacci numbers, using generators
I am currently working on Project Euler problem #2 which requires you to print the sum of all even fibonacci numbers below 4 million.
I just recently learned about generators and from my ...
9
votes
2answers
2k views
4chan Tripcode Explorer in Python
Background information for those of you who don't know what 4chan tripcodes are:
Via Wikipedia:
A tripcode is the hashed result of a password that allows one's identity to be recognized without ...
1
vote
0answers
41 views
99 bottles of beer on the wall + EcmaScript 6
Today, a solution written in Python was posted to this challenge, and since I was inspired by it, I made a version in EcmaScript 6.
I tried to explore some new language constructs:
arrow functions
...
2
votes
2answers
225 views
Split up an iterable into batches
I was writing a program that had a list of e-mail messages. It needed to group them into batches, with the condition that each batch must have at max 20 messages, and be maximally 50k in size (no ...
1
vote
1answer
55 views
Aggregating search results from multiple databases, in smaller work units
I have a large function that performs a search over a data set given a set of parameters. This function goes through multiple databases which all hold data that would comprise one final entry from the ...
7
votes
2answers
198 views
Generate all combinations of certain digits
Related to another answer of mine on Project Euler 35, I found the need to calculate all combinations of certain digits, i.e. 1, 3, 7 and 9, below a given n. I ...
5
votes
1answer
55 views
Using generators to build up a maze
In prepping to teach a workshop on recursion I wrote this code that uses a maze-building algorithm. In doing so I found it really natural to use generators a lot. I feel pretty happy with how the code ...
8
votes
2answers
1k views
Generating (presumably) unique `nonce` fields for Twitter OAuth
This is code that's part of a library (closed source) that I have that generates a unique nonce value for Twitter OAuth. Essentially, it generates a random number, ...
2
votes
1answer
115 views
Poker deck class /w generator function and list comprehensions
There are multiple aspects in the code I do not really like. [card for card in ...] looks really lame, also ...
4
votes
1answer
236 views
Python exception-raising generator function
I want my generator function to raise as soon as it can. If I make it yield the elements directly, then the KeyError won't happen until iteration begins. Is the ...
5
votes
1answer
538 views
Random Topic Generator
I've written a python module that randomly generates a list of ideas that
can be used as the premises for furthur research. For instance, it would be useful in situations where a new thesis topic is ...
5
votes
2answers
5k views
Python generator function that yields combinations of elements in a sequence sorted by subset order
In Python, itertools.combinations yields combinations of elements in a sequence sorted by lexicographical order. In the course of solving certain math problems, I ...
19
votes
1answer
419 views
Ultimate FizzBuzz
Swift's SequenceType is a useful means of generating a sequence of values, and it makes it particularly useful iterate over these values.
I don't really have much ...
2
votes
1answer
83 views
Avoid branching code for degenerate cases in Fibonacci generator
I was writing a simple function that would return the Fibonacci sequence up to the nth term and for whatever reason started wasting a lot of time on it. Here's what I came up with:
...
4
votes
2answers
199 views
19
votes
2answers
956 views
A header-only linear-time C++11 PEG parser generator supporting left-recursion and grammar ambiguity
I've rewritten my original parser generator to a header-only library which uses templates and functionals for better type safety and clarity. The generated parser creates an abstract syntax tree which ...
0
votes
1answer
121 views
Portable bitfields code generator [closed]
I am working on a project that involves quite a lot of instantiated objects, with tons of properties, most of which have only a few possible values, so the prospect of saving on memory is quite ...
4
votes
1answer
969 views
Iterator and Generator versions of Python's range()
I have created iterator and generator versions of Python's range():
Generator version
...
2
votes
1answer
422 views
Reading from a file and connect all data in one big data than to use generators
Is there better way to read from a file and connect all data in one big data than to use generators?
At the moment, I do the following:
use generators to read data from files.
use NumPy to pack all ...
7
votes
4answers
156 views
5
votes
3answers
910 views
Optimization for SQLite result set parsing
I am retrieving information from an SQLite database that gives me back around 20 million rows that I need to process. This information is then transformed into a dict of lists which I need to use. I ...
1
vote
0answers
107 views
A class with a function pointer instead of a generator
I am building TiKZ files, one pdf for each image I have. The purpose is to add text to each separately. The images are legion, so I created a script to generate the text files instead of generating ...
3
votes
3answers
489 views
Simple randomization program
I'm a few months into learning C++ programming and I want to know if I'm moving generally in the right direction or not with the following code. This is the most advanced thing I've created so far, ...
7
votes
2answers
312 views
Wrapping my head around generators
I am going on with refactoring my code base while migrating from Python 2 to Python 3. I am using generators to make reusable components this time as I am more comfortable with them this time then ...
2
votes
3answers
34k views
Random String generator in C
I created this small function just to practice C code. It's a simple random string generator.
...
0
votes
1answer
1k views
Filtering a long list of files through a set of ignore patterns using iterators
I have a backup job that walks across a huge directory with potentially millions of files. Python's os.walk() works just fine.
Now, I have implemented a feature to ignore files based in a black list ...
5
votes
1answer
912 views
Subscriptable/Indexable generator
I'm not a Python developper, but I enjoy programming with it, and for a project I wanted to have generators that I can easily index. Using python's slice model is obviously the way to go, and here's ...