How to read dale-chall mathematical notation? [closed] - algorithm

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
How do I calculate this dale-chall mathematical notation? or how is it converted to easier pseudo code?
I am trying to understand this concept to implement a text readability analyzer.
Is it like the following? altough ... how is what comes after 0.1579 and 0.0496 calculated?
0.1579 ( (difficult words - words) * 100 ) + 0.0496 (words - sentences)

The given formula will be written as follows in the most common programming languages:
(0.1579 * ((difficultWords / words) * 100)) + (0.0496 * (words / sentences))
The above expression will work in Python, Ruby, Javascript, Java, C, C++, C#, etc. Notice that we use * for multiplication (you can't omit the operator) and / for division, and we add as many parentheses as needed to eliminate any ambiguities in evaluation order.
When you're actually implementing the above code you'll have to be careful with divisions - some languages (for example: Java, Python 2.x) will truncate decimals if both operands are integer values. To get around this problem you can either declare the variables difficultWords, words and sentences using a data type that allows for decimals (say, double) or you can explicitly convert the variables to a decimal data type at the time of performing the division. For example, the formula will look like this in Java:
(0.1579 * (((double) difficultWords / words) * 100)) + (0.0496 * ((double) words / sentences))

Related

K-consistent but not strongly K-consistent [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
A CSP is k-consistent if, for any set of k - 1 variables and for any consistent assignment to those variables, a consistent value can always be assigned to any _k_th variable. A CSP is strongly k-consistent if it is k-consistent and is also (k - 1)-consistent, (k - 2)-consistent, ... all the way down to 1-consistent.
From the definition above, I do not understand how a CSP can just be k-consistent but not strongly k-consistent.
If the CSP is k-consistent, doesn't it necessarily have to be k-1-consistent too? If not, could you provide an example?
Consider, for example, the problem of completing a partially-filled-in Latin square.
Any consistent grid with just one blank cell can always be completed. Since only one cell is blank, the row that cell is in must be missing exactly one digit (if it's missing more than one, then some other digit must appear twice in that row by the pigeonhole principle, making the partial grid inconsistent). The same applies for the blank cell's column, and in fact it must be the same digit missing (proof is left as an exercise to the reader; hint: count the occurrences of each digit). It follows that this missing digit can be consistently assigned to that blank cell. So the CSP of n×n Latin squares is n2-consistent.
On the other hand, there are lots of consistent partial grids (i.e. grids whose filled-in digits haven't broken any of the rules so far) which cannot be filled in without breaking any rules, for example the following 2×2 grid cannot be made into a Latin square by filling in the blanks, because each of the blanks has no consistent assignment:
1 .
. 2
So this is a consistent set of assignments to two variables with no consistent assignment to a third variable, meaning that the CSP of 2×2 Latin squares is not 3-consistent; we already showed that it is 4-consistent, but now we have shown it is not strongly 4-consistent.

Solving Inequalities In Programming [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We are given a variable that have some constraints over its range of value, we have to overall find out a set that denotes it overall range.
For example and conditions are as follows
x< 10
x> -6
x>= 0
I can do it on real number line and mark the intersection but how to do it logically in programming.
Note : Only > , >= , < , <= are allowed.
ANSWER=[0, 10)
You have to figure out the logic of your solution, then implement that logic in C++. You say you "can do it", which I assume means you find it "easy" to solve as a humain being. What makes it so easy? Identify the method you're using, then write that method in C++.
There are two types of inequalities: > and <. Well, there are also <= and >=, but I suggest leaving those aside until you've written a program that handles < and > correctly.
Imagine you have:
x > 5
x > 7
x > 6
x < 11
x < 10
x < 12.
What is the solution in this case? Try to find the solution without drawing the number line. Then try to describe with words the way you arrived to this solution.
Then try to write pseudo-code that describes the algorithm more formally.
Finally, you're ready to write C++ code that performs the same steps. I suggest not trying to write C++ until you have written pseudo-code. When writing C++ you'll encounter a few cumbersome details; for instance, how to parse each expression, such as x < 5, to find out what inequality it is and which number it's comparing x to. These "details" are not uninteresting but they will get in the way of your logic so it's best to keep them for last.

What determines the result of overflowed operations? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Example:
int max = a > b ? a : b;
int min = a + b - max;
What determines whether this will work? The processor? The hardware? The language? Help me understand this at as deep a level as possible.
The processor IS the hardware (at least for the purposes of this question).
The language is purely a way for you to express things in such a way as to allow it to convert it to what the processor itself expects. The role of the language here would be to define what "int" means, what arithmetic operators are/do, and what their exceptional behavior is. In the low-level languages (like C/C++), it leaves several things to be "implementation defined", like the overflow behavior of integers. Other languages (like Python) may define "int" to be an abstract (not a hardware) concept and thereby change some of the rules (like detecting overflows and doing custom behavior).
If the language leaves something implementation defined and the implementation offloads that decision to the hardware, then the hardware is what defines the behavior of your code.
The high level programming language provides a way for humans to describe what they want to happen. A compiler reduces that down into a language the processor understands, (ultimately) machine code. The instruction set for a particular processor is designed to be useful for doing tasks, general purpose processors for general purpose tasks including the ones you have described. Unlike pencil and paper math where if we need another column another power of ten, 99+1 = 100 for example two digits wide going in, 3 digits coming put. Processors have a fixed with for their registers, that doesnt mean you cant get creative, but the language and the resources (memory, disk space, etc) have limits. And the processor either directly in the logic or the compiler implementing the right sequence of instructions, can and will detect an overflow if you ask it to, in general. Some processors harder than others and some processors are not general purpose enough, but I dont think we need to worry about those, the one you are reading this web page in definitely can handle this.
Computers(hardware) represent numbers in two's complement. Check this for details of two's complement, and why computers use it.
In two's complement signed numbers(not floating ones for now, for sake of simplicity) have a sign bit as most significant bit. For example:
01111111
Represents 127 in two's complement. And
10000000
represents -128. In both example, the first bit is sign bit, if it's 0, then the number is positive, else negative.
8-bit signed numbers can represent numbers between -128 and 127, so if you add 127 and 3, you won't get 130, you will get -126 because of overflow. Let's see why:
01111111
00000011
+________
10000010 which is a negative number, -126 in two's complement.
How hardware understand if an overflow occurred? In addition for example, if you add two positive numbers and the result gets negative, it means overflow. And if you add two negative numbers and result gets positive it means overflow again.
I hope that would be a nice example for how these things are happening in hardware level.

Make a recursive ruby function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Make a RECURSIVE ruby function "double_fact(n)" defined as follows –
n!! = 1 if n = −1 or n = 0 or n = 1;
n(n − 2)!! otherwise.
Outputs the result of double_fact() respecting to a value specified
from the command line.
//Hint: Ruby has the usual "and", "or" and "not" operators. You may
need "or" to test multiple conditions here. Also, doublefact(8) = 384.
The problem statement is very misleading. You don't need any boolean operators at all, you can just translate the mathematical definition 1:1 into Ruby:
def doublefact(n)
return 1 if (-1..1).include?(n)
n * doublefact(n-2)
end

Working with digits [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need an explanation for the pattern before the % mark in:
("%012d" % 10)
What is the role of % operator in this?
Need to look first Kernel#sprtintf :
The syntax of a format sequence is follows.
%[flags][width][.precision]type
A format sequence consists of a percent sign, followed by optional flags, width, and precision indicators, then terminated with a field type character. The field type controls how the corresponding sprintf argument is to be interpreted, while the flags modify that interpretation.
The field width is an optional integer, followed optionally by a period and a precision. The width specifies the minimum number of characters that will be written to the result for this field.
Now coming to your example : "%012d" % 10.
"%012d" called format string. The type d means - Convert argument as a decimal number.
012 means you are specifying 12 as a minimum number of characters that will be written to the result for this field.
Now look at the documentation of String#%
Format—Uses str as a format specification, and returns the result of applying it to arg. If the format specification contains more than one substitution, then arg must be an Array or Hash containing the values to be substituted. See Kernel::sprintf for details of the format string.

Resources