repetition

Detecting repetition with infinite input

What is the most optimal way to find repetition in a infinite sequence of integers? i.e. if in the infinite sequence the number '5' appears twice then we will return 'false' the first time and 'true' the second time. In the end what we need is a function that returns 'true' if the integer appeared before and 'false' if the function rec...

assign member based on string value

I need start off with code because I am not sure what terminology to use. Lets say I have the following code: class Node { public: void Parse(rapidxml::xml_node<> *node) { for (rapidxml::xml_attribute<> *attr = node->first_attribute(); attr; attr = attr->next_attribute()) { std::stringstream converter;...

Repeating procedure for every item in class

Data.XX.NewValue := Data.XX.SavedValue; Data.XX.OldValue := Data.XX.SavedValue; I need to do the above a large number of times, where XX represents the value in the class. Pretending there were 3 items in the list: Tim, Bob, Steve. Is there any way to do the above for all three people without typing out the above code three times? ...

How can I repeat something for x minutes in Python?

I have a program (temptrack) where I need to download weather data every x minutes for x amount of hours. I have figured out how to download every x minutes using time.sleep(x*60), but I have no clue how to repeat this process for a certain amount of hours. UPDATE: Thank you to everyone who posted a solution. I marked the example using ...

Java: repetition, overuse -- problem?

I try to be as minimalist as possible. Repetition is a problem. I hate it. When is it really a problem? what is static-overuse? what is field-method overuse? what is class-overuse? are there more types of overuse? Problem A: when it is too much to use of static? private static class Data { private static String f...

NSArray: add multiple objects with same value

How can I add multiple objects to my NSArray? Each object will have the same value. Ex. I want the value "SO" added to my array 10 times ...

Regular expression with no maximum limit

I Need a regular expression which accepts all types of characters (alphabets, numbers and all special characters), and miniumum number of characters should be 15 and no limit for maximum characters. ...

Sequence reduction in R

Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is ineffi...

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators?

Is there a regex flavor that allows me to count the number of repetitions matched by the * and + operators? I'd specifically like to know if it's possible under the .NET Platform. ...

Using explicitly numbered repetition instead of question mark, star and plus

I've seen regex patterns that use explicitly numbered repetition instead of ?, * and +, i.e.: Explicit Shorthand (something){0,1} (something)? (something){1} (something) (something){0,} (something)* (something){1,} (something)+ The questions are: Are these two forms identical? What if you add possessive/re...

How to idiomatically call C++ functions based on variable value?

Suppose I have a data type enum TreeTypes { TallTree, ShortTree, MediumTree }. And I have to initialize some data based on one particular tree type. Currently I have written this code: int initialize(enum TreeTypes tree_type) { if (tree_type == TallTree) { init_tall_tree(); } else if (tree_type == ShortTree) { ...

Reorder the results of a mySQL query using PHP without performing another query

I don't know if this is possible. I display a table of results and want to be able to order the table by any of the columns. I don't need help making such a table; I just need information about reordering the results of a query without repeating it with a different ORDER BY instruction. ...

How to capture an arbitrary number of groups in JavaScript Regexp?

I would expect this line of JavaScript: "foo bar baz".match(/^(\s*\w+)+$/) to return something like: ["foo bar baz", "foo", " bar", " baz"] but instead it returns only the last captured match: ["foo bar baz", " baz"] Is there a way to get all the captured matches? ...

code factory method

I want to create something I can only describe as a "code factory method". To avoid code repetition, I want to create a method which contains the code to be executed, but with "placeholders" where the types are supposed to go. The method would of course take these types as parameters and place each one in its appropriate spot. For exa...

Tricky Regular Expression

Hi everyone. I need to allow only alphanumeric characters (with uppercase) from 0-25 chars length and no lazy all-repetition numeric value. I've got the first part: Regex.IsMatch(tmpResult, "^[0-9A-Z]{0,25}$"); (that's easy) 111112 - match AABD333434 - match 55555555 - no match 555 - no match Could anyone please help me with this? ...