discrete-mathematics

Python, dictionaries, and chi-square contingency table

谁都会走 提交于 2019-12-24 07:15:34
问题 This is a problem I've been racking my brains on for a long time, so any help would be great. I have a file which contains several lines in the following format (word, time that the word occurred in, and frequency of documents containing the given word within the given instance in time). Below is an example of what the inputfile looks like. #inputfile <word, time, frequency> apple, 1, 3 banana, 1, 2 apple, 2, 1 banana, 2, 4 orange, 3, 1 I have Python class below that I used to create 2-D

How to define matching axis notches from existing “step list”

匆匆过客 提交于 2019-12-24 02:09:30
问题 I need a way to align tick marks on two separate axis, while being able to control the "step" value (value between tick marks), where both axis start at mark 0 and end on a different maximum value. Why this problem: Flot, the JS charting package has an option to align tick marks, but when I do, I cannot control the step value. I can however control the step value directly, but then I lose the ability to align tick marks. I can however revert to defining my own max and step values, to get what

Computing unique intersections of subsets

被刻印的时光 ゝ 提交于 2019-12-23 18:20:16
问题 Given a set S = {s i : {z j : z ∈ N } }, what is a time-efficient algorithm for computing the unique sets of intersections of the subsets of S ? For background, I am dealing with several versions of this problem, some larger than others. In the smallest one | S | ≈ 1,000, |s i | ≈ 10,000 and the values are zip codes. Tiny example for clarity: Input: S = {{},{1},{2,3},{3,4,5,6,7,8,9,10}} Output: {{},{1},{2,3},{3,4,5,6,7,8,9,10},{3}} | S | = 4 and there are 2 4 = 16 subsets of S . However,

Calculating check digit for ISBN

偶尔善良 提交于 2019-12-23 12:59:39
问题 This isn't actually homework, I'm just looking through some questions in a discrete maths book before I start computer science next week. Anyway, one of the questions asks me to write a program to perform this algorithm (which it explains). The part I'm stuck with is how to take the 9 digit number and "split" it into single integers, so the calculations can be performed on each digit. I thought of dividing the number by 100,000,000 and then taking the integer value of this to get the first

Why is the complement of a regular language still a regular language?

橙三吉。 提交于 2019-12-23 12:45:17
问题 According to my textbook, the complement of L1 = A* - L1 is a regular language as long as L1 is a regular language. Doesn't A* also include Context Free languages, Context Sensitive languages, and Recursively Enumerable languages? A*-L1 would include all of them too, wouldn't it? How can it be regular then? Under the representation of a Finite State Machine I understand why the complement is still a regular language. However, I can't understand the theory behind it. Also, A* - L1 = A*

Number of Sides Required to draw a circle in OpenGL

家住魔仙堡 提交于 2019-12-22 12:58:36
问题 Does anyone know some algorithm to calculate the number of sides required to approximate a circle using polygon, if radius, r of the circle and maximum departure of the polygon from circularity, D is given? I really need to find the number of sides as I need to draw the approximated circle in OpenGL. Also, we have the resolution of the screen in NDC coordinates per pixel given by P and solving D = P/2, we could guarantee that our circle is within half-pixel of accuracy. 回答1: What you're

Algorithm for finding smallest collection of components

让人想犯罪 __ 提交于 2019-12-21 04:21:33
问题 I'm looking for an algorithm to solve the following problem. I have a number of subsets (1-n) of a given set (a-h). I want to find the smallest collection of subsets that will allow me to construct, by combination, all of the given subsets. This collection can contain subsets that do not exist in 1-n yet. a b c d e f g h 1 1 2 1 1 3 1 1 1 4 1 1 5 1 1 6 1 1 1 1 7 1 1 1 1 8 1 1 1 9 1 1 1 Below are two possible collections, the smallest of which contains seven subsets. I have denoted new subsets

Nonlinear discrete optimization in R

旧时模样 提交于 2019-12-20 01:57:10
问题 I have a simple (indeed standard in economics) nonlinear constrained discrete maximisation problem to solve in R and am having trouble. I found solutions for parts of the problem (nonlinear maximisation; discrete maximisation) but not for the union of all the problems. Here is the problem. A consumer wants to buy three products (ananas, banana, cookie), knows the prices and has a budget of 20€. He likes variety (i.e., he wants to have all three products if possible) and his satisfaction is

Find two missing numbers

狂风中的少年 提交于 2019-12-18 11:59:56
问题 have a machine with O(1) memory. we want to pass n number (one by one) first time, and again we exclude two numbers and we will pass n-2 of them to machine. write an algorithm that finds missing numbers. This was an interview question and I couldn't solve it. 回答1: It can be done with O(1) memory. You only need a few integers to keep track of some running sums. The integers do not require log n bits (where n is the number of input integers), they only require 2b+1 bits, where b is the number

How to find multiplicative partitions of any integer?

自闭症网瘾萝莉.ら 提交于 2019-12-17 18:43:10
问题 I'm looking for an efficient algorithm for computing the multiplicative partitions for any given integer. For example, the number of such partitions for 12 is 4, which are 12 = 12 x 1 = 4 x 3 = 2 x 2 x 3 = 2 x 6 I've read the wikipedia article for this, but that doesn't really give me an algorithm for generating the partitions (it only talks about the number of such partitions, and to be honest, even that is not very clear to me!). The problem I'm looking at requires me to compute