I'm learning Groovy. I want an array of numbers from 0 to n with interval 0.1.
double arr=[0,0.1,0.2....n]
I could write a java style for-loop, but is there a easier syntax to do this? I know Groovy has a lot of syntactic sugar.
I would go with 0.0..10.0.collect{it/10.0} but maybe there is clever way to do it by specifying increments.
there was an exact question here earlier
n=10;(0..10*n).collect{it/10}
there are no decimal step values for Groovy's ranges
currently
Related
I have multiple versions of scripts files within the same directory. I want ansible via the find: module, through some sort of sorting comparison to always choose the highest version file it can. The issue is that the integer sorting I desire won't work because the strings in question aren't a pure integer comparison, and the lexicographic sorting won't give me the proper expected version. These filenames have a naming "convention" but there is no exact hard-coded filename versioning to work with, the versions are random within each project, but if integer ordering could be used, I/we could determine which file to use for each task.
Example, lets say I have the following 3 strings:
script_v3.sh
script_v9.sh
script_v10.sh
The normal sorting methods/filters within ansible (such as the sort filter) will try to do a lexicographic comparison of these strings in order. This means the one with the "highest" value will be script_v9.sh which is bad as I/we expect it should be script_v10.sh this is no good, as it will try to use script_v9.sh and then cause the rest of that process/task to fail. I would love to turn them into integers to do an integer comparison/sort, but as there are other non-numerical characters in the string every attempt so far to do so has been a failure. Note that I/we also need to occasionally use the lowest version in some tasks as well, which also screws up utilizing our example if lexicographic sorting is used.
I would like to know if this is possible to accomplish through some convenient comparison method, or filter which I have overlooked, or if anyone has any better ideas? The only thing I could possibly come up with is to use a regex to strip out the integers, compare them by themselves as integers, and then finally match up the result to the filename which contains the highest 10 value and then have the task use that. However, I'm horrible at regular expressions, and I'm not even certain that's the most elegant way to approach this. Anyone who could help me out would be highly appreciated.
Let me start off with, I am new at this, so bear with me.
I am pulling data in from an excel file and I need an expression that can look at one of my rows that has both decimals and percentages in it. I need them to be uniform and just have decimal format. So basically, some of fields have either 5% (shown with the % sign) and others have .05. I need all of my output to have the .05 type. I have been trying to figure this out for hours and am at a loss.
Currently I am using (DT_DECIMAL,6)REPLACE(TRIM([Percentage Off]),"%","") but that seems to just be stripping the percentage sign off and it doesn't convert the number to a percentage. Any help would be kindly appreciated.
The set of links below will likely get you to the answer.
Note that you may need only a CAST, not a REPLACE.
I do not have a system at hand where to test this, but I expect it to be useful (if not providing the explicit answer) for you.
Cast (SSIS Expression).
Syntax:
(type_spec) expression
REPLACE (SSIS Expression).
Syntax:
REPLACE(character_expression,searchstring,replacementstring)
? : (Conditional) (SSIS Expression).
Syntax:
boolean_expression?expression1:expression2
Operators (SSIS Expression).
SSIS Converting Percent to Decimal.
Reading android code I find out is not uncommon to fill the xml with the second variant, like here.
To be honest, this alone would be enough for my head to torment me with the question, but then I see code in which the two notations are even mixed, like in this StackOverflow question.
Google wasn't of help, and I couldn't find this question on SO.
Anyone knows what's the difference, if any?
EDIT
Based on the firsts question I got here, there seems to be no improvement in performance or other things like that when using the second variant, so writing them as float when they can be integers just tells people they can insert decimal values in there. Anything else?
If that's the only reason, I think using the second option it's just like polluting the xml for little to no reason, are there other opinions?
Check out this link: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension. It shows the possible values for dimensions. They are all floats. So, you can write them either way.
The 5.0 version is because certain properties accept a float/double value. All in all, 5.0 is the same as 5 when DP are involved.
one is an int the other is a float. They are types of primitives
It is the same. They both have the same values. 5 and 5.0 are of different types. 5 is of type int and 5.0 is of type float/double.
Is it possible to express arithmetic progression in a list without listing them all?
In Haskell, you could do it with the range function.
[2,4..10] == [2,4,6,8,10]
Is there a similar way to do it with Elixir ?
Stream.iterate/2 does what you want:
Stream.iterate(2, &(&1+2))
You can use Erlang's lists:seq function, from Elixir:
:lists.seq(2,10,2)
As I can see, there is a Stream.seq() added a month ago:
Add Stream.seq() for generating potentially infinite streams of values
Add a range/step/seq function
My company maintains a domain-specific language that syntactically resembles the Excel formula language. We're considering adding new builtins to the language. One way to do this is to identify verbose commands that are repeatedly used in our codebase. For example, if we see people always write the same 100-character command to trim whitespace from the beginning and end of a string, that suggests we should add a trim function.
Seeing a list of frequent substrings in the codebase would be a good start (though sometimes the frequently used commands differ by a few characters because of different variable names used).
I know there are well-established algorithms for doing this, but first I want to see if I can avoid reinventing the wheel. For example, I know this concept is the basis of many compression algorithms, so is there a compression module that lets me retrieve the dictionary of frequent substrings? Any other ideas would be appreciated.
The string matching is just the low hanging fruit, the obvious cases. The harder cases are where you're doing similar things but in different order. For example suppose you have:
X+Y
Y+X
Your string matching approach won't realize that those are effectively the same. If you want to go a bit deeper I think you need to parse the formulas into an AST and actually compare the AST's. If you did that you could see that the tree's are actually the same since the binary operator '+' is commutative.
You could also apply reduction rules so you could evaluate complex functions into simpler ones, for example:
(X * A) + ( X * B)
X * ( A + B )
Those are also the same! String matching won't help you there.
Parse into AST
Reduce and Optimize the functions
Compare the resulting AST to other ASTs
If you find a match then replace them with a call to a shared function.
I would think you could use an existing full-text indexer like Lucene, and implement your own Analyzer and Tokenizer that is specific to your formula language.
You then would be able to run queries, and be able to see the most used formulas, which ones appear next to each other, etc.
Here's a quick article to get you started:
Lucene Analyzer, Tokenizer and TokenFilter
You might want to look into tag-cloud generators. I couldn't find any source in the minute that I spent looking, but here's an online one:
http://tagcloud.oclc.org/tagcloud/TagCloudDemo which probably won't work since it uses spaces as delimiters.