#
# Number puzzle 4
# 
# From Richard Wiseman It's the Friday Puzzle 2010-02-26
# http://richardwiseman.wordpress.com/2010/02/26/its-the-friday-puzzle-48/
# """
# Imagine that you have to make the number 8 from the numbers 4, 7, 6 and 3.  
# The rules are simple.  You cannot join the numbers together (so 4 and 7 cannot become 47),  
# have to use each number once and only once, and are only allowed to add, subtract, 
# multiply or divide them.  You might do something like this.....
# 4+7 = 11
# 11-6=5
# and 5+3=8
# 
# So, here is the puzzle....can you make the number 24 with the number 5, 5, 5, and 1 
# (again, you cannot join the numbers together, have to use each number once and only 
# once, and are only allowed to add, subtract, multiply or divide them)?
# """
# 
# The answer involves some trickery
# http://richardwiseman.wordpress.com/2010/03/01/answer-to-the-friday-puzzle-41/
# """
# Most people assume that the solution involves whole numbers.  
# In fact, once you break that assumption, the puzzle becomes much easier.
# 
#   1 / 5 = .2
#   5 – . 2 = 4.8
#   4.8 x 5 =24
#
# """ 
# I.e.:
#  (5 - 1/5) x 5 = 24
#  
# which is something like
#   (a - d/b) * c
#
# where a, b, and c all can change places.
# 
#
# This example generates many solutions. However, the requirement that
# a, b, c, and d is used exactly once was not possible to implement in this
# version of SymbolicRegression. So I implemented
#   alldifferent_variables  <boolean> <penalty if no all different>
# 
# However, after many runs this solution actually came
# with min_nodes: 7 but without alldifferent_variables set
#    (a - (d / b)) * c
# 
# With both min_nodes: 7 and alldifferent_variables: true
# They come easy (although not every time), e.g.:
#    (c - (d / a)) * b
#    b * (c - (d / a))
#
# Also, note that it is just one fitness case.
#
# A solution with ForLoopD:
#    for(int i=0;i<b;i++) { (c - (d / a)) }
#
# which is just a gloryfied version of this:
#   b*(c - (d / a))
#
# For the 4 7 6 3  8 problem some of the solutions found:
#   a * (d + (c - b)) [113976]
#  (a + b) + (d - c) [164]
#  (a - c) + (d + b) [152]
# (the number in brackets are the number of found occurrences)
#  
# For the 1 2 3 4  5 problem:
#  d + (a / (c - b)) [87184]
#  d + ((a * c) - b) [16724]
#  (c - b) * (a + d) [3965]
#  d + (c / (b + a)) [569]
#
#
presentation: Puzzle
return_type: DoubleClass
num_input_variables: 4
variable_names: a b c d e
# With ForLoopD
# functions: Multiply,Divide,Add,Subtract,ForLoopD
functions: Multiply,Divide,Add,Subtract
# We don't use any numeric terminals
no_terminals: true
max_init_depth: 4
population_size: 1000
max_crossover_depth: 4
num_evolutions: 400
max_nodes: 7
min_nodes: 7 100
# all_different_variables: <boolean> <penalty if not all different>
alldifferent_variables: true 100
show_similiar: true
# similiar_sort_method: length
show_population: false
data
5 5 5 1  24

# The first problem mentioned in the text.
# 4 7 6 3  8

# and as an extra
# 1 2 3 4  5
