Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 17 lines (13 sloc) 0.51 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(*
 * Solution to Project Euler problem 31
 * By Nayuki Minase
 *
 * http://nayuki.eigenstate.org/page/project-euler-solutions
 * https://github.com/nayuki/Project-Euler-solutions
 *)


(* Use this in Wolfram Mathematica *)

Coins = {1, 2, 5, 10, 20, 50, 100, 200};
Ways[coinIndex_, total_] := Ways[coinIndex, total] = (* Memoization *)
  If[coinIndex == 0, Boole[total == 0],
    Sum[Ways[coinIndex - 1, total - i * Coins[[coinIndex]]], {i, 0, Floor[total / Coins[[coinIndex]]]}]]
Ways[Length[Coins], 200]
Something went wrong with that request. Please try again.