This repository contains Haskell solutions to competitive programming problems from Kattis.
Problem | Solution File | Kattis Link |
---|---|---|
A Different Problem | Different.hs | https://open.kattis.com/problems/different |
Army Strength | ArmyStrength.hs | https://open.kattis.com/problems/armystrengthhard / https://open.kattis.com/problems/armystrengtheasy |
Ceiling Function | Ceiling.hs | https://open.kattis.com/problems/ceiling |
Pot | Pot.hs | https://open.kattis.com/problems/pot |
Popular Vote | Vote.hs | https://open.kattis.com/problems/vote |
Build all solutions:
cabal build
Run a specific solution:
cabal run different # or pot, vote
Test all solutions:
cabal test
This project uses minimal external dependencies:
- mtl (^>=2.3.1) - Monad transformer library (used by Scanner utility)
Install GHC and Cabal using GHCup:
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
ghcup install ghc 9.10.1
ghcup install cabal recommended
Each solution follows a functional programming pattern using:
- Function composition with the
>>>
operator - Point-free style programming
- The
interact
function for I/O processing
Solutions are organized as separate executables in the solutions/
directory, with shared utilities in src/
.
Since Kattis only accepts single-file submissions without imports, each solution is tested in submission/Main.hs
before uploading to Kattis. The submission file contains the complete solution code without any module imports or dependencies. After testing, this file is overwritten and reused for the next solution submission.
This project includes a CLAUDE.md
file that provides guidance to Claude Code (claude.ai/code) when working with the codebase. This file contains:
- Project overview and architecture details
- Build commands and development workflow
- Coding patterns and conventions used in solutions
- Instructions for maintaining the functional programming style
The CLAUDE.md
file helps ensure consistent development practices when using AI assistance for solving new Kattis problems or maintaining existing solutions.
This project is all about learning, especially writing many small haskell programs to be familiar with the language. To that end, I have made some specific choices in AI usage.
- Github Copilot is disabled on haskell files
- I hand code my solution and validate it against input, then I will prompt claude on improvements to the solutions. During the solutioning, if I can't resolve compile errors my normal search, I will bring in AI for assistance.
- I review the suggested improvements and adopt them as necessary.
This process for me strikes a balance of learning concepts and then building directly on that knowledge to see how it could be improved. Ultimately, I hope it will improve my mastery of the language.
If you encounter the error invalid argument (cannot encode character '\8216')
when using the Haskell Language Server eval plugin, add the following environment variables to your shell configuration:
export GHC_NO_UNICODE=true
export GHC_CHARENC=GHC_NO_UNICODE
Add these lines to your shell configuration file (e.g., ~/.bashrc
, ~/.zshrc
, or ~/.profile
) and restart your terminal or source the configuration file.
This error typically occurs when the HLS eval plugin tries to display Unicode characters that cannot be encoded in your terminal's character set. The environment variables disable Unicode output from GHC, resolving the encoding issue.
For more information about GHC environment variables, see the GHC User's Guide.
This section lists articles and repositories that were studied while working on these solutions:
- Competitive Programming in Haskell: Scanner - Blog post about scanner utilities for competitive programming
- comprog-hs Scanner.hs - Scanner utilities were copied from this repository
- Competitive Programming in Haskell: reading large inputs with ByteString - When to abandon using
String
for efficiency - Compititive Programming Book: Methods to solve - hints on underlying theory to solve problems