All Questions
Tagged with combinatorics haskell
15 questions
4
votes
1
answer
1k
views
Generate possible combinations by range and length
I am learning Haskell and I implemented a recursive function that generates possible strings by length and array (e.g. ['a'..'z']):
...
3
votes
2
answers
141
views
Number of possible numbers in roman number string
I just started learning programming a few months ago, and I'm intrigued by Haskell. To learn a bit I tried to adapt some code I have in Java so I can see what are equivalent solutions in Haskell.
The ...
5
votes
1
answer
206
views
Combinatoric problem in Haskell
I am new to functional programming. Just now I solved my first "real world" task using Haskell and now I'm wondering whether I got it "right" and what can be improved.
The problem arises from tensor ...
0
votes
3
answers
815
views
All possible combinations of colors for Mastermind
Just started out with CIS 194 on Haskell and wonder what the more idiomatic way to solve this problem would have been.
This code is supposed to generate all possible combinations of 6 given colors up ...
5
votes
2
answers
709
views
Calculating the count of integer partitions of a number (uses stateful vectors internally)
I've written a Haskell function to count the number of partitions of an integer - it's basically an implementation of the same algorithm as this one, using Euler's Pentagonal Number Theorem:
$$P(n) = ...
7
votes
5
answers
504
views
Pizza Hut math problem #1 in Haskell
I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my ...
3
votes
2
answers
2k
views
N-queens problem in Haskell by bruteforce
I wrote a Haskell program to solve the N-queens problem by bruteforce. It works and I find it reasonably readable
But it is pretty slow:
5 seconds for one solution of 8 queens.
1 minute for one ...
6
votes
1
answer
3k
views
Permutations of a list in Haskell
I have this piece of code which given a list returns another list which combines every element with every other element (without repetitions) using a given function as a combiner. I came up with three ...
5
votes
2
answers
440
views
Applicative permutation to generate knight moves
I want to understand Haskell better by trying to stretch possibilities of Functor, Applicative, and Monad as much as possible and study how they behave. So in Learn You a Haskell there's an exercise ...
10
votes
1
answer
233
views
Counting unordered factorizations with distinct parts
Trying to solve this combinatorics problem, I wrote some functions to count the number of unordered distinct factorizations of an integer n into ...
3
votes
1
answer
200
views
Generating alphanumeric combinations
I was happy with my shell script that needed to generate alphanumeric combinations of length N (in this case, 3)
for i in {a..z}{a..z}{a..z}; do ...
Now I became ...
2
votes
1
answer
106
views
Accessing list elements when counting the number of rectilinear paths
I am trying to solve the RIVALS problem on SPOJ: Starting from (0, 0), how many paths are there to reach point (X, Y), only taking one-unit steps moving to the right or up? Constraints: 0 ≤ X ≤ 106, ...
5
votes
1
answer
263
views
Project Euler #15 in haskell
I've solved Project Euler #15 in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types:
...
41
votes
1
answer
2k
views
Finding minimum scalar product using ST Monad
Inspired by a Stack Overflow question, I decided to practice my Haskell by taking a crack at the Google Code Jam's Minimum Scalar Product problem:
Given two vectors \$\mathbf{v_1}=(x_1,x_2,\ldots,...
2
votes
1
answer
372
views
Organizing matches between sports teams
How could I improve this algorithm? The goal is to organize matches between sport teams such that:
Each team affront each other
A minimum number of team should start a match after just finishing one
...