Questions tagged [f#]

F# is a succinct, expressive, and efficient functional and object-oriented language for .NET

Filter by
Sorted by
Tagged with
4 votes
2 answers
370 views

F# code to check whether there are three same digits within a given number

I came across this problem by accident and gave it a go. I think my solution works as it has passed all the unit tests I wrote. Given I just started learning F# a couple of weeks I would love to have ...
5 votes
1 answer
188 views

Solving adventcode day 6 puzzle: toggling lights in a grid

I have solved the day 6 adventcode problem: --- Day 6: Probably a Fire Hazard --- Because your neighbors keep defeating you in the holiday house decorating contest year after year, you've ...
  • 151
9 votes
1 answer
751 views

Prime factorization in F#

In the pursuit of learning F#, I have been working through some Project Euler problems. This is my solution for problem 3: ...
4 votes
1 answer
77 views

Finding the largest prime factor

As many people will undoubtedly recognise, this is a question in a well known series of problems that I won't name ;) It's been a long time since I've written any F# and I'm not sure I've ever come ...
  • 16.7k
7 votes
1 answer
118 views

World's worst Christmas tree

Inspired by this question, I decided to grow my own fractal tree. The problem is: given an integer \$n\$, \$0 \leq n \leq 5\$, print the \$n\$th iteration of the fractal tree. The tree is probably ...
  • 16.2k
5 votes
2 answers
221 views

Constructing a simple tree with ASCII in F#

This is just a basic HackerRank challenge I was working on to better understand F#. Its purpose is just to print a tree that has a straight 'trunk' of \$n\$, splits into 2 branches which diverge to \$...
  • 361
15 votes
4 answers
959 views

Project Euler 6: Difference between sum of squares and square of sum

I've created a (very) simple solution for Project Euler problem 6: Project Euler Problem 6: Sum square difference The sum of the squares of the first ten natural numbers is, $$ 1^2 + 2^2 +...
6 votes
1 answer
633 views

Project Euler Problems #1-#5

Since I've been playing with F#, I decided to try my hand at implementing some of the Project Euler problems, and I've been having a blast doing it. (f#-is-fun) So, I'm going to list all the Project ...
10 votes
2 answers
363 views

F#zzBuzz: Learning the easy way

So I made a quick programme in F# to do FizzBuzz, I'm trying to learn more languages, so I figured I'd do something functional for a change. (Haskell is also on the list.) FizzBuzz is pretty self-...
3 votes
2 answers
79 views

Find unique variants of a product

I am writing a piece of code that returns all the unique variants that a product is available in for an ecommerce app. For example, a shirt product can be available in different colors, sizes, and ...
2 votes
1 answer
101 views

Digit Power Sum with BigInteger

This is my 1st F# program so I'm open to any and all criticism on my syntax and the way I approached the problem. Challenge Project Euler 16: Power Digit Sum 2^15 = 32768 and the sum of its digits ...
  • 1,970
3 votes
2 answers
69 views

Summations and products and factorials oh my

The proper title of this question should be "Summations and products, and factorials oh my!". After getting quite a bit of useful feedback on this question from @mjolka, and a comment, I decided that ...
3 votes
1 answer
199 views

Trying to do Type-Driven Development in F#

I've been wanting to try out F# for some real world programming so I decided to try rewriting a program that is being used at work. It can be reduced to a few steps: Get report templates. In this ...
2 votes
1 answer
311 views

Summations and products in F#

I was bored, and looking to do something that involved anonymous functions, and it was suggested by @Quill, that I create a summation function. I decided to also include a product function as well to ...
3 votes
1 answer
78 views

Renaming video files based on episode title lookup

I'm new to F#, so I've ported an old Python script I have to F#. It scans a directory for files named something like Game.Of.Thrones.S01E02.xvidblahblah.mp4 or <...
1 vote
1 answer
61 views

Creating a structured category list in F#

This takes a list of categories and organizes them into a tree-type structure based on their parentId. This code works, but is obviously a little over-complicated. ...
1 vote
1 answer
169 views

Create random list of size n using 2 enums in F#

...
5 votes
1 answer
168 views

Lindenmayer System String Generator in F#

Lindenmayer Systems or L-systems are fractals that can be constructed by applying replacement rules to a string for a certain amount of iterations. For example: ...
  • 93
10 votes
1 answer
960 views

Small game written in F#

I'm trying to wrap my head around F#. I'd like your honest opinion about this simple game source code that I wrote. Rules are simple: Every player has soldiers and territory Player can recruit ...
  • 203
4 votes
1 answer
159 views

Utopian Tree in F#

This is the Utopian Tree in F# (from HackerRank) The Utopian tree goes through 2 cycles of growth every year. The first growth cycle of the tree occurs during the monsoon, when it doubles in ...
  • 361
6 votes
1 answer
124 views

Hello Functional World: Counting occurrences of each letter

Coming from a OO (C#) background, I am trying to learn some FP. To help me transition, I am trying to learn F#. I am taking baby steps. I set myself a simple challenge to count the instances of each ...
5 votes
2 answers
794 views

Add two numbers stored as a list in F#

I am solving the following problem: You are given two lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two ...
6 votes
1 answer
902 views

Game of life in F#

First attempt at doing anything F#-y from a very heavy C# background, think I've grasped the fundamentals of FP, but always good to get other eyes on it: ...
  • 213
8 votes
2 answers
1k views

Mock/Stub out filesystem in F# for unit testing

I'm looking to do some basic verification testing on my functions that write to the filesystem. I took a hint from here on how to mock out the filesystem using an interface, but I'm kinda bummed on ...
  • 183
4 votes
2 answers
594 views

Reverse Polish Notation in F#

In my question to learn F#, I've decided to get one step closer to creating a programming language, and implement this simple Reverse Polish Notation "interpreter" of sorts. It does not allow for ...
7 votes
1 answer
567 views

Efficient generic type conversion between numeric types in F#

It's easy to write a function that adds two ints in F#: let add x y = x + y Actually, it's the same as: ...
10 votes
2 answers
230 views

F# inventory system - Part 2

I've refactored my previous inventory system, and added a few features like removing items from the Inventory class, easily obtaining the current selected item ...
7 votes
1 answer
565 views

F# inventory system

To learn F#, I've implemented this very simple inventory system. While I'm proud that that it's my first program, and that it works, there are still a few areas that I'd like tips on, namely these: I ...
12 votes
2 answers
11k views

Reading input from console in F# (as a sequence of lines)

Consuming input line-by-line until the end is often useful. In C# I would write the following loop: while ((line = Console.ReadLine()) != null) { // ... I ...
  • 559
2 votes
1 answer
720 views

Building and flattening a dependency graph

The Problem Given a list of dependencies ('a * 'a) list where the first item has a dependency on the second item, construct a dependency graph and then 'flatten' ...
  • 339
3 votes
1 answer
63 views

Projecting future positions

My code takes a starting position (which must be completed) and a list of updates (each element of which is optional). It then projects future positions, using the appropriate value from each update, ...
5 votes
1 answer
437 views

Sudoku game logic

I am trying to create a Sudoku game in F# and I'm having a bit of trouble with the file reading and writing. But since I've also just started programming in f# I would like to check if my thinking is ...
0 votes
2 answers
418 views

Extracting meta data from nupkg file with F# looks like C# Linq

The code snippet below examines a nuget package file (zip file with meta) and extracts all file names referenced inside. The final result should be a ...
  • 185
1 vote
1 answer
835 views

Saving an uploaded file and returning form data

I am new to F#. This code is basically a port I did from C#. I am sure there is room for a ton of improvement, so how can I improve and make this more efficient? ...
4 votes
0 answers
252 views

Aggregation of values over a hierarchy

I have a number of objects of a type Workplace that exist in a hierarchy that is given by some properties (Department, ...
6 votes
1 answer
214 views

Test file word cloud in F#

This code is meant to take in a command line argument and output a 'tag cloud'. It's more of an exercise in learning F# for me because this is my first non-tutorial code file. How could this code be ...
  • 361
7 votes
1 answer
214 views

Small console app to execute some remote scripts

I'm learning F# and functional programming, from a background in C# and imperative/OOP. I've ported a small, one-off console app from C# to F#. The port worked (the app behaves the same way), but I'd ...
  • 211
9 votes
1 answer
311 views

Brainfuck interpreter in F#

I have some concerns, like the updateValue function. I was trying to follow the functional paradigm, but I wonder if I could use another approach or something. My ...
  • 582
1 vote
2 answers
64 views

Better yielding tuple-d union case values in list generation

I have a situation where I'm stitching three different unions into a triplet tuple for building a map/dictionary of strongly typed values keyed on a string. One of the union cases is very large, the ...
  • 653
4 votes
1 answer
401 views

Command Dispatcher for messaging using MailboxProcessor

This code is intended to process commands in a CQRS+Messaging system. It will parallelize the message processing to the degree you specify by the msgToIdFn ...
3 votes
1 answer
99 views

Finding a customer's gender

I have been playing with Async/parallel execution in entity framework for while. I'm not sure if I'm doing it right. I have two entity contexts: one for reading and one for writing. The reading ...
2 votes
1 answer
80 views

Extracting a maximum from zipped lists

I have code that zips 3 lists, finds a maximum and extracts part of the max tuple. Isn't there a shorter way to do this in F#? ...
  • 123
8 votes
1 answer
1k views

Generic build script using Fake

I have something like a generic build script for a group of projects. I am using Fake but my F# skills are pretty bad. Would you please take a look and point where I can improve it? ORIGINAL ...
  • 185
4 votes
1 answer
985 views

CRUD (database layer) for F# with TypeProviders

I am a newbie in F# and I am thinking about use F# in my next project. The project will work the database and I need to store and retrieve instances of objects in the Db. Could you please check my ...
  • 772
2 votes
1 answer
58 views

Structuring Test Data

I'm just getting started with F# and was writing some unit tests for some functionality I had written. In the interest of brevity, I decided to create some lists of the different test cases and just ...
5 votes
1 answer
577 views

Lightweight TicTacToe in F#

This is more of a 'model' of TicTacToe, as you'll see it's not "gameified" in the sense that it will allow for inputs and outputs nor will it record any "active" state of the game but those things are ...
3 votes
2 answers
1k views

Select some indexes in a list of lists

I have a record type which holds a list of table rows. Each row is also a list. The first row is assumed to be the header row. In addition the type optionally defines a filter - a list of columns (the ...
  • 512
1 vote
2 answers
253 views

Future in f# is this an unavoidable use of a mutable variable?

I have this type: ...
  • 113
3 votes
0 answers
152 views

DSL design for iOS Autolayout

I am building a small DSL for iOS' autolayout feature. Obviously I want to have a typesafe way to define autolayouts instead of doing VSL. I came up with the following: ...
  • 129
3 votes
1 answer
266 views

Decompose a value as a sum of square numbers

My daughter had a question on her maths homework which was to write a value as a sum of 4 or fewer square numbers. For example, x = 73 could be 36 + 36 + 1. I came up with a really brute force ...
  • 133

1
4
5
6 7 8