discrete-mathematics

Pohlig–Hellman algorithm for computing discrete logarithms

Hi Folks, I'm working on coding the Pohlig-Hellman Algorithm but I am having problem understand the steps in the algorithm based on the definition of the algorithm. Going by the Wiki of the algorithm: http://en.wikipedia.org/wiki/Pohlig%E2%80%93Hellman_algorithm I know the first part 1) is to calculate the prime factor of p-1 - which i...

Counting problem: possible sudoko tables?

Hi, I'm working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm. in order to analyzing problem, i want to know what is the count of possible valid and invalid sudoko tables? -> a 9*9 table that have 9 one, 9 two, ... , 9 nine. (this isn't exact dupl...

Discrete mathematics problem - Probability theory and counting

Hello All, I'm taking a discrete mathematics course, and I encountered a question and I need your help. I don't know if this is the right place for that though :) It says: Each user on a computer system has a password, which is six to eight characters long, where each character is an uppercase letter or a digit. Each password must con...

How would you solve this graph theory handshake problem in python?

I graduated college last year with a degree in Psychology, but I also took a lot of math for fun. I recently got the book "Introductory Graph Theory" by Gary Chartrand to brush up on my math and have some fun. Here is an exercise from the book that I'm finding particularly befuddling: Suppose you and your husband attended a party w...

finding ALL cycles in a huge sparse matrix

Hi there, First of all I'm quite a Java beginner, so I'm not sure if this is even possible! Basically I have a huge (3+million) data source of relational data (i.e. A is friends with B+C+D, B is friends with D+G+Z (but not A - i.e. unmutual) etc.) and I want to find every cycle within this (not necessarily connected) directed graph. I...

A hard Question ?

Hi Guys , I try To find a solution to a question .... we have a number , example : 20 ... and we have 6 number :{ a ,b , c , d , e , f} < 20 , t try to find all values of these numbers , but only if we can combinate (whit + or -) whit 2 of this numbers and getting all the value below to 20 : for example we choose 31 : a = 22 ...

What would be a good general algorithm for approaching integer sequence problems?

Say the input will always be the same number N of numbers (e.g., 5) and assume the integers actually have a mathematical relation (no lengths of the numbers 'one', 'two', days in the nth month, etc.). The output would be either the next integer and the rule discovered or a message that no rule could be detected. I was thinking to have in...

Is it possible to implement bitwise operators using integer arithmetic?

Hello World! I am facing a rather peculiar problem. I am working on a compiler for an architecture that doesn't support bitwise operations. However, it handles signed 16 bit integer arithmetics and I was wondering if it would be possible to implement bitwise operations using only: Addition (c = a + b) Subtraction (c = a - b) Division...

Select which satisfies at least N conditions from M available.

Hi, there is a question floated. It's set in basic SQL terms, but its nature is pure math (so maybe I should visit http://mathoverflow.com too). I have a table in some theoretical database with 6 fields, all are numbers. Also we have basic conditions, such as Field_1 > Field_5, Field_4 = 3 etc., 7 conditions total. I need to write a sel...

Python, dictionaries, and chi-square contingency table

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 li...

Books linking Problem Solving to Math Concepts (like discrete mathematics)?

Hi! I'm a few years into my Computer Science Education, and I had to transfer to a new school in the between years. The problem I'm having is that the "intro" classes at my first school focused first on Mostly professional programming skills, like problem design, and put the mathematics concepts in later courses, and when I transferred, ...

Optimization problem - finding a maximum

I have a problem at hand which can be reduced to something like this : Assume a bunch of random points in a two-dimension plane X-Y where for each Y, there could be multiple points on X and for each X, there could be multiple points on Y. Whenever a point (Xi,Yi) is chosen, no other point with X = Xi OR Y = Yi can be chosen. We have ...

Check if wind direction is within a specified range

I am representing wind directions using integer values (an Enum) ranging from 0 for North, through to 15 for North-North-West. I need to check if a given wind direction (integer value between 0 and 15) is within a certain range. I specify my WindDirectionFrom value first moving clockwise to WindDirectionTo to specify the range of allowa...

How do you calculate log base 2 in Java for integers?

I use following function to calculate log base 2 for integers: public static int log2(int n){ if(n <= 0) throw new IllegalArgumentException(); return 31 - Integer.numberOfLeadingZeros(n); } Does it has optimal performance? Does someone know ready J2SE API function for that purpose? UPD1 Surprisingly for me, float point arith...

Regex that defines a regular language with {a,b} without a substring with exactly 3 b's (bbb)

Pretty much what the question says. I came up with (ba)?(a + bb + bbbbb + aba)*(ab)? Is there anything more readable? Or is this incorrect? I know you shouldn't really be doing this sorta thing with Regex when you can just go !~/bbb/ in your code, but it's a theory exercise. Thanks. Edit for Clarification: I'm not using | to repre...

Where has this cluster search algorithm been presented before?

See: http://kks.cabal.fi/GoodEnoughSearch I have gone through quite many papers and sites. I have not found where this algorithm has been presented before, or that someone has made something similar, but better or more general. The algorithm is pretty simple and thus should be found quite easily by anyone facing the same kind of problem...

Sum of numbers making a sequence

While watching the rugby last night I was wondering if any scores were impossible given you can only score points in lots of 3, 5 or 7. It didn't take long to work out that any number greater than 4 is attainable. 5=5, 6=3+3, 7=7, 8=3+5, 9=3+3+3, 10=5+5 and so on. Extending on that idea for 5, 7 and 9 yields the following possible score...

Statistical calculations

hi, I have a large dataset with name and values. I want to categorize all these values into a meaningful category: eg: 25% names with certain range of values fall in category 1 50% names with certain range of values fall in category 2. Tried using percentile calculation: but this ends up giving me inconsistent categorization. I was look...

Write an algorithm to return the prime numbers of an integer, for example if your input is 10 the output is list a with elements 2 and 5

this one i get as assignment in discrete maths. i try to do like this. procedure prime_numbers (x) n:= 1 for i:= to n<=x do n mod i=1 then return (prime) end prime_number. ...

Algorithm for two-dimensional rebinning

I have a 12-by-50 array that needs rebinning. The array represents a bivariate probability distribution, p(a,b), where a and b are non-Cartesian coordinates. However, I want to rebin it so that I have a distribution in Cartesian coordinates, p(x,y). a and b are (mildly) nonlinearly related to x and y, however I make the simplifying ass...