All Questions
Tagged with programming-challenge haskell
98 questions
2
votes
0
answers
47
views
Last Stone Weight Problem in Haskell Using `fold`
A previous solution of this code has been posted on Code Review before.
This solution is more complicated then that one, but more performant (see the below)
Why is this another Question instead of a ...
4
votes
1
answer
173
views
Last Stone Weight Problem in Haskell using list `insert`
Background
Saw this problem on TheJobOverflow which seems to be a LeetCode question.
It bothered me that the "challenge" of this problem was to recognize the need for a specific data-type (...
3
votes
1
answer
113
views
Autocomplete system with prefix tree
I am quite new to Haskell, and this problem is from dailycodingproblem.com:
Implement an autocomplete system.
That is, given a query string s and a set of all ...
1
vote
1
answer
134
views
Count islands in a binary grid
This is the No of Island code challenge.
Please review my implementation in Haskell. I know there must be some better way of doing this.
Given an m x n 2D binary grid grid which represents a map of '...
1
vote
1
answer
80
views
Haskell solution to Day 2 problem of Advent of Code '21
I won't restate the problem in full, but in a nutshell you have to parse a file with a "direction" and a "magnitude", for instance:
...
3
votes
1
answer
139
views
Function to sum all Armstrong numbers within a range
I've tried to solve a challenge posted on a LinkedIn forum using Haskell - a language I'm still learning the basics of - and, while the code works correctly, I would like to get some feedback on the ...
2
votes
1
answer
119
views
Advent of Code 2021 Day 4
Here is my attempt at Advent of Code Day 4 using Haskell.
A file contains list of number in first line. And subsequent lines have the bingo Cards
...
2
votes
1
answer
180
views
AdventofCode 2021: Day 3 Solution
I am beginner to Haskell. Here is my solution to Advent of Code 2021 Day 3. Let me know what you think. I was looking at the transpose function and decided not to use head & tail function.
Given ...
3
votes
1
answer
258
views
Efficiently calculating perfect powers in Haskell
I'm trying to calculate perfect powers to solve this code wars challenge: https://www.codewars.com/kata/55f4e56315a375c1ed000159/haskell
The number 81 has a special property, a certain power of the ...
3
votes
0
answers
190
views
Advent of Code 2021, Day 3 in Haskell
This is a working solution to today's Advent of Code puzzle, written in Haskell. However, I feel like this solution is not optimal.
...
6
votes
2
answers
2k
views
Hamming distance between two strings
I wrote this module to find the Hamming distance between two strings. (It's a problem from exercism.io's Haskell track.)
As I saw it, the problem has two distinct ...
2
votes
0
answers
110
views
Partial Function composability in Haskell
Below is my solution for the CTFP chapter 4 challenges which essentially involves composing partial functions (that don't have defined outputs for all possible inputs i.e. returning a Maybe).
The ...
1
vote
1
answer
242
views
"Sequence full of colors" challenge on HackerRank
This is the challenge:
You are given a sequence of N balls in 4 colors: red, green, yellow and blue. The sequence is full of colors if and only if all of the ...
3
votes
0
answers
125
views
Performance issue regarding Project Euler #60 in Scheme
I solved Project Euler #60:
The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 ...
2
votes
1
answer
131
views
HackerRank - Binary tree to compute the Nth power of natural numbers that sum up to X
I'm trying to solve this challenge on HackerRank.
In short, given x and n, I have to determine how many ways I can pick numbers ...
2
votes
2
answers
92
views
HackerRank - Filter huge list for elements that occur more than a given number of times
I'm trying to solve this problem on HackerRank, which basically requires the solution to read an input like this (comments are mine)
...
5
votes
2
answers
101
views
Advent of Code 2019: Day 6 (with Trees)
I've been going through some 2019 AoC challenges and decided to solve Day 6 in Haskell with the help of Data.Tree.
In summary, the puzzle provides a list of orbits (...
2
votes
0
answers
120
views
Finding number of brackets sequences of length n containing a specific string s
I am trying to solve a problem where I need to find the number of bracket sequences \$p\$ and \$q\$ such that for a given bracket sequence s. I have that \$p + s + q\$ is a valid bracket sequence. ...
2
votes
0
answers
184
views
Project Euler #14: Longest Collatz sequence on HackerRank
The following is the conclusion in a long chain of attempts to solve Project Euler problem #14 (Longest Collatz sequence) on HackerRank in the Haskell programming language.
The problem is defined as ...
3
votes
1
answer
188
views
Project Euler Problem 54 poker hands in OCaml
I've been refactoring my OCaml solution for Project Euler problem 54, which is about comparing poker hands.
While I'm mostly satisfied with my second iteration of the refactor, I stumbled upon two ...
2
votes
2
answers
301
views
Yraglac's transit woes
I decided to dive into the world of functional programming since my programming so far has been mostly in C/C++, Java, and Python. I've gone through a couple Haskell tutorials and played around in ...
2
votes
1
answer
68
views
Compute text area given letter heights and a text
I have solved the designer pdf question with haskell. The code works. I am posting the code here to know how I could have done it better.
First line contains the weight of each alphabet
Second ...
4
votes
2
answers
1k
views
Introduction to Haskell: Validating credit card numbers
I have implemented the introductory challenge of University of Pennsylvania's CIS 194: Introduction to Haskell (Spring 2013) course. I have added the most important information of the problem ...
1
vote
1
answer
872
views
Hex string to Base64 in Haskell
This is my take on the first challenge on the cryptopals crypto challenges list. I think that i made it quite simple but i feel like it is possible to optimize it further. Any suggestion?
The code:
...
3
votes
2
answers
130
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 ...
4
votes
0
answers
403
views
Kattis Ants challenge
I am trying to learn Haskell doing some contest problems. I have worked a bit with the language but still have a very long way ahead.
Right now I am working with a problem called Ants:
An army of ...
2
votes
0
answers
187
views
Project Euler #81 in Haskell: minimal path sum through a matrix
I just completed Project Euler Problem 81 in Haskell:
In the 5 by 5 matrix below,
...
3
votes
1
answer
158
views
Find the length of a frequency-change cycle (Advent of Code 2018)
I tried to do the second part of the 1. December challenge of Advent of Code in Haskell. I'm fairly new to Haskell but I have plenty of experience in other (procedural) languages. I struggled with the ...
8
votes
1
answer
2k
views
Advent of Code 2018 day 1 part 2: find the first repeated number after some increases and decreases
Here is the problem:
Part Two
You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find
the first frequency it reaches twice.
For ...
3
votes
1
answer
308
views
Efficient Road Network
Intro
I've decided to learn haskell, because I've always enjoyed the functional aspect of Python and want to explore other languages that use this concept. I'm still stumbling in the dark most of the ...
4
votes
1
answer
1k
views
Solving the Burst Balloon problem using Dynamic Programming
Continuing where I left off previously to solve the problem described here, I've now solved the same using dynamic programming (following Tikhon Jelvis blog on DP).
To refresh, the challenge is to ...
4
votes
1
answer
158
views
Naive implementation of Burst Balloon
As part of learning Haskell, I'm solving few problems, usually solved imperatively.
I've come up with a naive solution for the problem described here, which is to find a sequence in which to burst a ...
5
votes
2
answers
827
views
Solving Sierpinski Triangle in Haskell
I am a Haskell beginner with a background in C++ and Python. I have been teaching myself Haskell for about half a year on and off and recently I started doing Hackerrank problems to improve my Haskell ...
3
votes
2
answers
953
views
CodeWars - Three-pass compiler for arithmetic expressions
I'm looking for feedback on my solution to the Tiny Three-Pass Compiler kata on CodeWars. The kata is to implement a compiler for an arithmetic language in three passes - parsing to an AST, constant ...
0
votes
1
answer
72
views
Optimized list filtering on implementation of Project Euler 23
I'm new to Haskell, the part of my code I'm concerned with is the isSumAbundant function. Surely there must be a better way, in an imperative language I might use a ...
3
votes
1
answer
162
views
Programming Contest - Snuke Festival
Problem Statement
The season for Snuke Festival has come again this year. First of all,
Ringo will perform a ritual to summon Snuke. For the ritual, he needs
an altar, which consists of three ...
12
votes
2
answers
707
views
Compute the perimeter of a polygon
This is taken from HackerRank, which I hope is okay.
I've been playing around with Haskell and I haven't really been able to find anything that really goes beyond toy examples in terms of how to ...
2
votes
1
answer
64
views
Ways of forming multiple elements in a list comprehension without duplicates (Euler #109)
I was working on Project Euler #109 (Potential spoilers for people who haven't done so yet); I got the correct solution, but I'm not satisfied with how one of my lines of code ended up looking, and ...
4
votes
1
answer
422
views
Prim's Lazy Minimum Spanning Tree Algorithm in Haskell (Project Euler# 107)
I have implemented Lazy version of Prim's Minimum Spanning Tree Algorithm. I want to improve the code structure, follow prevalent conventions and reduce code size. I am solving Project Euler #107.
...
2
votes
1
answer
97
views
Project Euler # 95 in Haskell - kind-of finding longest cycle in a graph
I am trying to solve Project Euler #95 in Haskell, though I have already solved it in Java (see). I found that writing imperatively, we can easily do the task this way:
Pseudocode
Define cache as an ...
0
votes
1
answer
364
views
Project Euler # 3 in Haskell: largest prime factor of some number
The program works, but is extremely slow.
Project Euler problem 3
Problem: What is the largest prime factor of the number 600851475143?
...
2
votes
1
answer
334
views
Euler #4: Refined Palindrome in Haskell
This is my attempt at the Problem Euler #4 in Haskell ("Find the largest palindrome made from the product of two 3-digit numbers.")
...
3
votes
3
answers
579
views
Project Euler #2 in Haskell
Problem
By considering the terms in the Fibonacci sequence whose values do not
exceed four million, find the sum of the even-valued terms.
My solution
...
5
votes
1
answer
181
views
Euler 1 but pointless
I've been teaching myself basic haskell this week in order to be able to better read literature about functional programming (about 80% of which in haskell by my completely off-the-cuff statistic). ...
4
votes
3
answers
2k
views
Leap year check in Haskell, using pattern matching or bind operator
One of the first Haskell puzzles on http://exercism.io/ is to implement a leap year check. I've done this twice.
Using pattern matching:
...
3
votes
1
answer
268
views
Parsing n lines to count vowels - HackerEarth
I have written a haskell program for the following 'Code Monk' Challenge at HackerEarth.
Here is the challenge description. Basically, we are looking for the number of vowels in a string. The first ...
3
votes
1
answer
79
views
Ricochet Challenge: Robust IO and working with different types of numbers in Haskell
Background
I've tried to solve /r/DailyProgrammer Challenge #303 [Easy]: Ricochet (summarised below) in Haskell. The code below is now the second Haskell script I've ever written, so I'd consider ...
1
vote
1
answer
277
views
Project Euler problem 2 in Haskell
I have just started Haskell, and I want to check if my code is following the spirit of the language.
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find ...
7
votes
1
answer
779
views
Shortest Path (BFS) through a maze
Background
I have decided to use this year's Advent Of Code to learn Haskell. I feel like I vaguely understand the language and can solve most of the problems with relative ease. However, the code I ...
4
votes
1
answer
986
views
Kattis, Speed limit; read irregular input
I am able to solve this challenge but when look at my code I know it is not good.
The challenge:
Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don’t know how ...