Snippets in category Puzzles

  • Largest Palindrome Number from Product of Two Three Digit Numbers

    Here is an improved version twice shorter, than original

    35 people like this
    Posted: 1 years ago by Nick Canzoneri

  • Project Euler #1

    This snippet is code that solves first Project Euler problem. It finds the sum of all the multiples of 3 or 5 below 1000. Please add other (more efficient, succinct or interesting) solutions to this snippet.

    37 people like this
    Posted: 1 years ago by Eugene Gavrin

  • Project Euler #2

    Solution to Project Euler problem 2: Find sum of even terms in fibonacci sequence which do not exceed four million. Comments about the first version: 1. It does't use memoize becouse of recursive call to unmemoized function "fibs". So it take over 20 sec to get answer. A minor change ("fibs" to "fibs' ") reduces this time to 140ms.

    25 people like this
    Posted: 1 years ago by D

  • Project Euler #182

    The RSA encryption is based on the following procedure: Generate two distinct primes p and q. Compute n=pq and phi=(p-1)(q-1). Find an integer e, 1<e<phi, such that gcd(e,phi)=1. There exist values of e and m such that m^(e) mod n=m. We call messages m for which m^(e) mod n=m unconcealed messages. Choose p=1009 and q=3643. Find the sum of all values of e, so that the number of unconcealed messages for this value of e is at a minimum.

    20 people like this
    Posted: 1 years ago by Natallie Baikevich

  • Anagrams

    Let's use the fundamental theorem of arithmetic to determine if two words are anagrams of each other. How? The theorem states (roughly) that each number can be written as a product of prime numbers in only one unique way. For instance 42 = 7 * 2 * 3 = 3 * 7 * 2. Now what will happen if you associate a letter with a unique prime number? You can see that "team" [71*11*2*41] = "meat" [41*11*2*71]. Oh, the possibilities. Note that in the code below big integers are used since the product of many primes will overflow a 32- or even a 64-bit integer.

    15 people like this
    Posted: 1 years ago by Arjen Kopinga

  • Lazily split string

    Splits strings lazily, instead of splitting entire string into an array like System.String.Split. Especially useful for very large strings.

    6 people like this
    Posted: 1 years ago by Daniel Robinson

  • Change identifier case

    Converts string to Pascal or camel case. Useful mostly for identifiers. Uses case changes to determine word boundaries.

    4 people like this
    Posted: 1 years ago by Daniel Robinson

  • A simple Quine

    A simple Quine in F#

    16 people like this
    Posted: 1 years ago by Nick Palladinos

  • Primitive Pythagorean triples

    Primitive Pythagorean triples generator. It uses an Algorithm found on Wolfram MathWorld and the F# PowerPack matrix library.

    31 people like this
    Posted: 1 years ago by Cesar Mendoza

  • Combinatorial functions

    Here is my F# take on some combinatorial functions from the book "Introduction to Functional Programming" by Richard Bird and Philip Wadler.

    5 people like this
    Posted: 1 years ago by Cesar Mendoza

  • palindromes

    Find every substring that is a palindrome. A bit lazier than the original.

    0 people like this
    Posted: 1 years ago by Kevin Cantu

  • Very Fast Permutations

    I spent a lot of time this week profiling different permutation functions from various places on the internet. The following was by far the fastest:

    4 people like this
    Posted: 1 years ago by Rick Minerich

  • The repmin problem

    The repmin problem is to replace all elements of a tree of numbers by the minimum element, making only a single pass over the original tree. Repmin is a very ingenious example of Circular Programming.

    1 people like this
    Posted: 1 years ago by Nick Palladinos

  • one to nine puzzle

    Solve the one to nine puzzle with a utility function that handles the depth first search. First saw the puzzle here: http://msdn.microsoft.com/en-us/vcsharp/ee957404

    0 people like this
    Posted: 10 months ago by dave jones

  • N-Queens

    Code to solve the N-Queens problem.

    1 people like this
    Posted: 10 months ago by dave jones

  • Sudoku with general solve function

    Using the general solve function to solve Sudoku. The puzzle specific code was translated from Norvig's Sudoku code, but any errors are mine. Reuses code from fssnip.net/6m and fssnip.net/6n

    0 people like this
    Posted: 10 months ago by dave jones

  • Euler #5

    Euler #5 solution

    3 people like this
    Posted: 8 months ago by Michael Falanga

  • Calculating when the 1000th XKCD will appear

    Calculate's when a the nth XKCD will appear, starting from XKCD 946. For a full explanation this snippet see: http://strangelights.com/blog/archive/2011/09/02/calculating-when-the-1000th-xkcd-will-appear.aspx

    2 people like this
    Posted: 8 months ago by Robert Pickering

  • Minesweeper in 99 lines of code

    This program is written in only 99 lines of actual code and remains enough readability. I used few short-coding technics. 1. no XAML. 2. pre-calculate every useful data for the purpose of eliminating useless states 3. using record type with set property as an alternative of view-model 4. initialize everything in one place. 5. encapsulate all states in one place.

    14 people like this
    Posted: 8 months ago by nagat01

  • Project Euler Problem 19

    How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

    2 people like this
    Posted: 8 months ago by Gene Belitski

  • Project Euler Problem 31

    In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1x£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p How many different ways can £2 be made using any number of coins?

    3 people like this
    Posted: 8 months ago by Gene Belitski

  • Gluing-up sequence members

    While thinking on Project Euler Problem 40 solution (http://projecteuler.net/index.php?section=problems&id=40) the following subproblem has surfaced: how to glue up string presentations of a sequence members to reach a given length of result string. The snippet gives at least 3 different implementations of such function with performance comparison; as a bonus a solution to Problem 40 is given.

    2 people like this
    Posted: 8 months ago by Gene Belitski

  • Read roman numerals

    Function that parses a Roman-numeral string and return the number it represents.

    3 people like this
    Posted: 7 months ago by Naveen

  • Write roman numerals

    Just a pendant to Naveen's readromannumerals; takes an int and produces a roman numeral string

    4 people like this
    Posted: 7 months ago by Jonas Avelin

  • Longest Increasing Sub Seq

    Find the longest consecutive sub-sequence of increasing numbers.

    0 people like this
    Posted: 7 months ago by Naveen

  • Concatenate two strings together

    Concatenates two strings together: ML or OCaml style

    2 people like this
    Posted: 6 months ago by Cameron Frederick

  • How many words can you spell on a calculator?

    We all know about BOOBIES - but how many other dictionary words can you spell upside-down on a calculator?

    2 people like this
    Posted: 2 months ago by Kit Eason