Challenging Programming Exercises Published Weekly
programmingpraxis.com
Challenging Programming Exercises Published Weekly
1–10 of 20 posts
Re: Challenging Programming Exercises Published Weekly
#2Re: Challenging Programming Exercises Published Weekly
#3Re: Challenging Programming Exercises Published Weekly
#4"Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems."
Re: Challenging Programming Exercises Published Weekly
#5Some suggestions:
* The font needs to be larger
* The color scheme could use a little more contrast
* Pasting source code needs to be easier
Re: Challenging Programming Exercises Published Weekly
#6Re: Challenging Programming Exercises Published Weekly
#7def gen(univ, n=5): return univ if n == 1 else [x+y for y in gen(univ,n-1) for x in univ if all([(x+y)[start:start+upto] != (x+y)[start+upto:start+upto*2] for start in range(len(x+y)) for upto in range(1,(len(x+y)-start+2)/2)])]
... god that looks ugly. Call it with
>>> gen(["1", "2", "3"], 5) ['13121', '23121', '21321', '31321', '12321', '12131', '32131', '21231', '31231', '13231', '13212', '23212', '21312', '12312', '32312', '12132', '32132', '23132', '21232', '31232', '31213', '13213', '23213', '12313', '32313', '32123', '13123', '23123', '21323', '31323']
Re: Challenging Programming Exercises Published Weekly
#8Re: Challenging Programming Exercises Published Weekly
#9Complete solution to today's problem in one line of python def gen(univ, n=5): return univ if n == 1 else [x+y for y in gen(univ,n-1) for x in univ if all([(x+y)[start:start+upto] != (x+y)[start+upto:start+upto*2] for start in range(len(x+y)) for upto in range(1,(len(x+y)-start+2)/2)])] ... god that looks ugly. Call it with >>> gen(["1", "2", "3"], 5) ['13121', '23121', '21321', '31321', '12321', '12131', '32131', '2…
sub solutions {
my ( $target_length, $alphabet, $head ) = @_;
$head //= '';
# Base Case our head is the right length
return $head if (length $head) == $target_length;
# General Case
return
map { generate( $target_length, $alphabet, $_ ) }
grep { ! /(.{2})\1/ }
map { $head . $_ }
@$alphabet;
}
eg: my @solutions = solutions( 5, [1..3] );Re: Challenging Programming Exercises Published Weekly
#10Complete solution to today's problem in one line of python def gen(univ, n=5): return univ if n == 1 else [x+y for y in gen(univ,n-1) for x in univ if all([(x+y)[start:start+upto] != (x+y)[start+upto:start+upto*2] for start in range(len(x+y)) for upto in range(1,(len(x+y)-start+2)/2)])] ... god that looks ugly. Call it with >>> gen(["1", "2", "3"], 5) ['13121', '23121', '21321', '31321', '12321', '12131', '32131', '2…
And in some rather nicer Perl: sub solutions { my ( $target_length, $alphabet, $head ) = @_; $head //= ''; # Base Case our head is the right length return $head if (length $head) == $target_length; # General Case return map { generate( $target_length, $alphabet, $_ ) } grep { ! /(.{2})\1/ } map { $head . $_ } @$alphabet; } eg: my @solutions = solutions( 5, [1..3] );