repeat

Relooping a function over its own output

社会主义新天地 提交于 2019-12-24 14:24:22
问题 I have defined a function which I want to reapply to its own output multiple times. I tried replicate(1000,myfunction) but realised that this is just applying my function to my initial input 1000 times, rather than applying my function to the new output each time. In effect what I desire is: function(function(...function(x_0)...)) 1000 times over and being able to see the changes at each stage. I have previous defined b as a certain vector of length 7. b_0=b C=matrix(0,7,1000) for(k in 1:1000

Check for repeating dates

非 Y 不嫁゛ 提交于 2019-12-24 09:16:28
问题 I am creating a calendar in PHP and in the database have a date, let's say 6-10-10. Sometimes I have repeating events, stored as weekly repeating, so if the date is 6-10-10, and I am repeating an event every two weeks from that day (including that day) what is the best way to find dates for every two weeks from 6-10-10? For example, let's say the date is 7-8-10, how can I check to see that date meets my criteria? 回答1: What's up with the looping?! Discrete Math 101: How do you figure out if a

How to get multiple copies of a cell in a single row by n-number?

Deadly 提交于 2019-12-24 08:20:09
问题 I would like to use vba code that can sort this problem out. I have a row and i want multiple copies of each cell in the same row. It needs to copy the cell by n-numbers. In row 1 will be the information to be copied. and in row 2 the n-number. So the example: Input: (say the n-number = 3) John Hendrik Sara Output: John John John Hendrik Hendrik Hendrik Hendrik Sara Sara Sara .... Hope someone could help me out! 回答1: From: To: Use this code: Option Explicit Sub CopyInAWeirdWay() Dim sh As

string Multiplication in C++

落花浮王杯 提交于 2019-12-24 01:58:04
问题 There is already a question for this here: How to repeat a string a variable number of times in C++? However because the question was poorly formulated primarily answers about character multiplication were given. There are two correct, but expensive answers, so I'll be sharpening the requirement here. Perl provides the x operator: http://perldoc.perl.org/perlop.html#Multiplicative-Operators which would let me do this: $foo = "0, " x $bar; I understand that I can do this with the helper

Java repetitive pattern matching

我怕爱的太早我们不能终老 提交于 2019-12-24 00:17:26
问题 I am trying to get each of the repetitive matches of a simple regular expression in Java: (\\[[^\\[]*\\])* which matches any string enclosed in [], as long as it does not contain the [ character. For example, it would match [a][nice][repetitive][pattern] There is no prior knowledge of how many such groups exist and I cannot find a way of accessing the individual matching groups via a pattern matcher, i.e. can't get [a], [nice], [repetitive], [pattern] (or, even better, the text without the

Cartesian product match

夙愿已清 提交于 2019-12-23 20:40:52
问题 I have two sets of incomplete types (i.e. struct names, missing generic parameters and lifetimes), and I need to have some code executed for each possible pair of combinations: // these are my types struct A<T> { ... } struct B<'a, 'b, T> { ... } struct C { ... } struct X<T> { ... } struct Y { ... } struct W<'a> { ... } struct Z<T, D> { ... } // this is the code I need to generate match (first_key, second_key) { ("a", "x") => { ... A ... X ... } ("a", "y") => { ... A ... Y ... } ("a", "w") =>

minimal checks to find repeats in a list

≡放荡痞女 提交于 2019-12-23 17:36:59
问题 Given a sequence (d1, d2, ..., dn), I want to evaluate the product (1 - Dij) for all i != j where Dij = 1 if di = dj and 0 otherwise. The code I have only checks Dij when i prod = 1; for (int i=1; i<n; ++i) { for (int j=i; j<=n; ++j) { prod *= (1 - Dij); } } I know I can stop when I get Dij=1, but what I'm trying to do is get a minimal expression of the Dij's to check. This way I have one expression and then I can use difference sequences and evaluate it. So I know that I can do i<j instead

Python: Counting repeating values of a dictionary

空扰寡人 提交于 2019-12-23 12:44:30
问题 I have a dictionary as follows: dictA = { ('unit1','test1') : 'alpha' , ('unit1','test2') : 'beta', ('unit2','test1') : 'alpha', ('unit2','test2') : 'gamma' , ('unit3','test1') : 'delta' , ('unit3','test2') : 'gamma' } How can I count the number of repeating values per each test independent of units? i.e. in 'test1' there is 2x 'alpha', 1x 'delta' in 'test2' there is 1x 'beta', 2x 'gamma' Any inputs? Many Thanks. 回答1: In Python 2.7 or 3.1 or above, you can use collections.Counter : from

Repeat a scipy csr sparse matrix along axis 0

℡╲_俬逩灬. 提交于 2019-12-23 10:26:34
问题 I wanted to repeat the rows of a scipy csr sparse matrix, but when I tried to call numpy's repeat method, it simply treats the sparse matrix like an object, and would only repeat it as an object in an ndarray. I looked through the documentation, but I couldn't find any utility to repeats the rows of a scipy csr sparse matrix. I wrote the following code that operates on the internal data, which seems to work def csr_repeat(csr, repeats): if isinstance(repeats, int): repeats = np.repeat(repeats

functional programming algorithm for finding repeated characters

别等时光非礼了梦想. 提交于 2019-12-22 18:47:09
问题 I am converting the "zxcvbn" password strength algorithm from JavaScript to Scala. I am looking for a pure functional algorithm for finding sequences of repeating characters in a string. I know that I can translate the imperative version from JavaScript, but I would like to keep this as side-effect free as possible, for all the reasons usually given for functional programming. The algorithm can be in Scala, Clojure, Haskell, F#, or even pseudocode. Thanks. 回答1: Using Haskell's standard higher