Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated.
5
votes
1answer
57 views
Navigating a bounded 2D list (Advent of Code, Day 2: “Bathroom Security”)
I'm trying to solve the following Advent of Code problem in F# for practice.
Description of problem (can be found here):
Basically, there's a 'key pad' that I need to figure the combination to. To ...
6
votes
0answers
32 views
American Checkers
I am implementing the logic for a Checkers game in F#. I am writing my code in a library so it can be called from any UI provider, and am trying to do it in good FP style. I currently have the ...
3
votes
0answers
364 views
Creating a pipeline operator in Java
I wrote the following as more of an experiment than anything else, but I thought it would be fun to share and maybe get some feedback!
Motivation: I started looking at some functional languages and ...
3
votes
0answers
48 views
Voting app in JavaScript using Ramda
I'm just learning functional programming in JavaScript using Ramda.
I took this tutorial and implemented the server core.js component using Ramda.
The idea is that we'll have a collection of ...
1
vote
1answer
54 views
Cons List in Python
It make sense to not allow links to external code hosting, so I restated my question. This is classical cons list in python using Abstract Base Class interface. Constructor is in fact out of the Cons ...
3
votes
0answers
34 views
Computing nth roots of a number - SICP exercise 1.45
From SICP
Exercise 1.45:
We saw in 1.3.3 that attempting to compute square roots
by naively finding a fixed point of x/y does not converge, and that
this can be fixed by average damping.
...
7
votes
2answers
78 views
Probabilistic Matrix Inspection - Suggested by a paper, implemented by me
I have read this paper and I actually found it interesting.
This is an attempt to implement the proposed algorithm. I would like to know:
Is my algorithm correct by what is discribed in the paper?
...
1
vote
1answer
30 views
Validating Input concerns
I would like to find out if there's a cleaner way to go about validating input before it goes into a function. What I'm doing seems like a lot of code, I'm sure there's a better way. I would also ...
1
vote
1answer
52 views
7
votes
2answers
90 views
Recursive higher-order function
I have implemented a through function for myself in a project.
Since I am still quite new in python and want to learn it correctly, I would be happy about any ...
0
votes
1answer
32 views
Highest number in a list with Racket
I am trying to build a function to find the highest number in a list without using the built-in functions of "apply" and "max".
I created the following code:
...
5
votes
2answers
130 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) = ...
3
votes
0answers
72 views
D3.js multi-line graph
Here is my JS code which uses the D3.js library (mostly snipped from other examples). I want to graph the acceleration of a point in 3D-space which changes with respect to time. The X-axis of the ...
2
votes
0answers
48 views
Algebraic Effect Monad to separate pure and impure code
I want to write my C# code in a way which makes effects (state, I/O, etc) explicit in the type signature. I have started to understand monads, and have some acquaintance with algebraic effects, though ...
3
votes
0answers
41 views
OAuth 1.0 signature using Ramda
I created an OAuth 1.0 signature generator using Ramda based on this.
I'm just getting to grips with it, so was wondering if someone more familiar with Ramda and functional programming would give me ...
3
votes
1answer
61 views
JavaScript Functional Programming Bank Account, Shop and Customer
Motivation
I have worked extensively with JavaScript and have grown fond of some of its functional aspects. This got me wondering how one could implement the canonical example of a bank account - and ...
12
votes
1answer
280 views
Cat fight (with rockets)
My code is attempting to implement FP in an efficient / readable manner into some of my video games. I realize this may be a bit subjective, but I feel there is enough merit / objectivity to be of ...
2
votes
1answer
41 views
Comparing corresponding elements of two equal-length arrays
I have a helper function I wrote, but it feels like something _.lodash already does or could do if I knew the library better.
...
3
votes
1answer
52 views
Naive JS implementation of tidyr's gather function
Tidyr is an R package for creating tidy data.
(tl;dr)
In short, it provides an interface (gather) for restructuring a table into a "tidy" format. For our purposes ...
3
votes
0answers
47 views
Calculating a snowballing investment
I'm currently taking a JavaScript class. I was fairly familiar with JavaScript and coding in general, so I decided to teach myself functional programming on the side. It's been great, my teacher's ...
5
votes
1answer
37 views
Python-like enumerate and join
I'm new to Rust and trying to convert some Python to Rust. I have the following in Python:
...
1
vote
1answer
45 views
Reverse the order of a list in Racket
I am using the SICP book. There is an exercise in which you need to create a function that will receive a list as an argument and return a list with the same elements in a reverse order.
I know there ...
2
votes
2answers
80 views
A trip down the single method interface rabbit hole
I responded to this question about designing around interdependant methods with the strategy pattern.
Afterwards I started thinking about the functional additions to java 8 and wondered if I was ...
6
votes
0answers
94 views
PLZ HELP MEH IMPROVA MEH LOLCAT CODEZ, WHUCH CALCULUTS FAWCTORIALS
SUNCE MEH BEEN WRUTEN CODEZ IN MUNY DIFFRNT PROGRAMMING LANGUAGES, MEH THOUGHTZ THAT ME TRY TO WRITE CODEZ IN AN ESOTERIC LANGUAGE. MEH CODEZ CALCULUTS A FAWCTORIAL OF UH USR INPUTTED NUMBAH IN ...
5
votes
1answer
43 views
“Guess My Number” with Racket
I am using the book "Realm of Racket" which was written by the people behind the Racket and Dr. Racket projects. It is a great book based on games, similar to the famous "Land of Lisp".
The first ...
3
votes
1answer
71 views
F# Active Pattern with Poker and Playing Cards
From this question and John Palmers answer about active pattern I discovered a gap in my knowledge about F# and took the challenge to code me into some level of understanding this technique.
The ...
1
vote
1answer
138 views
HackerRank: Left Array Rotation in Python
Here is the problem on HackerRank. I want to know how I can improve this code. I am mainly trying to improve the following skills: Documentation, functional programming (top-down approach), accurately ...
2
votes
2answers
85 views
A Scala Maze Generator in Functional Style
I'm wondering if there is more I can do to incorporate more idiomatic scala and functional programming principles. I know the maze itself is mutable but i didn't see an easy solution to making it ...
5
votes
1answer
150 views
Reporting the highest satisfied poker hand in F#
I'm learning F# by doing various small projects. One of them is a problem where the program reads Poker hands and rates them. It's Texas Hold'Em, so for each player it tries every five card selection ...
3
votes
2answers
45 views
Project Euler #11 - Largest product in a grid
Problem statement
I've tried to solve the following Euler problem in a very straight-forward way, ideally avoiding recursion if possible and writing it in a functional style.
What is the greatest ...
1
vote
2answers
59 views
A double search function that looks in a list for one value and then the other alternatively
I'm writing in Python (3.4) a double search function that looks in a list for one value and then the other alternatively. That is, start searching the second value once you find first the first value (...
2
votes
1answer
41 views
Stateless Maximum Beauty of String implementation
Inspired by The Beauty and the Strings question, I tried to implement the "Maximum Beauty of String" in a stateless fashion using ES6. Unfortunately, I ran into two places where I had to assign ...
1
vote
1answer
31 views
Project Euler #6 - Sum square difference
I'd like to get the code below reviewed on all aspects, specifically I wonder if it's common usage to use let like this, as currently more computations are done in ...
1
vote
0answers
24 views
Implementation of catch test framework in Racket
As an exercise in learning how to use Racket macros I decided to implement a subset of the features in the catch test framework for C++. In particular the catch test framework has a unique feature ...
4
votes
2answers
50 views
Project Euler #3
I'd like to have the code below reviewed on all aspects.
Task: Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ...
2
votes
1answer
51 views
Project Euler #1 - Revisited
I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects. I'm marking this as follow-up of Project Euler #1 because I answered my own question and implemented ...
4
votes
1answer
37 views
Project Euler #1
I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects and have one specific question. This is also my first Functional Programming language, I have however ...
1
vote
0answers
56 views
String and Date manipulation exercise using functional programming style
I was reading a question on stackoverflow recently and I became a little curious/interested in the philosophy behind Ramda (functional programming for Javascript). So I thought I would try an exercise....
14
votes
1answer
191 views
Grand Chess domain model and helper functions
So I am trying to write, essentially from a blank slate, a program that plays Grand Chess. In short, it is a chess variant that is played with two extra pieces, on a 10x10 board, no castling, and ...
5
votes
1answer
112 views
Battleship Game
Inspired by this question, I went on with the following version. My goal was to focus on pure functions, to avoid mutable variables and to be strictly functional.
I have ignored the computer player ...
11
votes
2answers
143 views
You can't sink me
Here is a Battlehips game in F#. Now, before you start jumping up and down on my code, please understand that, for all its awesomeness, F# has a serious limitation: Its compilation is linear, and the ...
3
votes
1answer
69 views
Church Numerals
Here is exercise 2.6 from SICP:
Exercise 2.6: In case representing pairs as procedures wasn’t
mind-boggling enough, consider that, in a language that can manipulate
procedures, we can get by ...
7
votes
1answer
107 views
Hangman in stateless JavaScript
I just want some feedback to improve readability and structure for this implementation of Hangman. The goal was to write it in a purely functional way. However, coming from an imperative background, I ...
1
vote
1answer
27 views
JavaScript function that composes other functions to create a master function
I wrote a little Compose function, which takes a variable number of arguments of type function and then calls each of those in ...
5
votes
2answers
353 views
GCD of two numbers in Ruby
I am trying to implement a algorithm for the GCD of two numbers in a functional approach. Can this be improved further, also with regards to performance?
...
1
vote
0answers
34 views
Extensible factory method for starting D3 charts
I'm working on refactoring some existing code to be a bit more extensible and am wanting to create a generic factory API for starting D3 charts.
Currently, my factory looks like this:
...
4
votes
1answer
45 views
Lambda to obtain a new merged object
The requirement is to iterate over a list of Foos, and when 2 Foos have the same id merge ...
2
votes
3answers
101 views
Calculate average of array of objects per key value using reduce
I want to find average of an array of objects based on their key values using the new functional programming style. I found my way around array reduce and solved my ...
3
votes
2answers
77 views
Functional Conway's Game of Life in JavaScript
In this code, I tried to integrate my little knowledge of(and great fascination towards) functional programming. I'd like to make this code more functional, and faster, if that's possible.
...
4
votes
2answers
42 views
Maximise adjacent numbers in a functional style (PE#11)
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the [provided] 20×20 grid? [source]
This solution works, and works effectively ...