From 4ec709f326872dcbc565cf1d7fb093adf80e8eb5 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 17:59:13 -0400 Subject: initial commit --- challenge-323/adam-russell/blog.txt | 1 + .../adam-russell/perl/IncrementDecrement.pm | 220 +++++++++++++++++++++ .../adam-russell/perl/IncrementDecrement.yp | 89 +++++++++ challenge-323/adam-russell/perl/ch-1.pl | 43 ++++ challenge-323/adam-russell/perl/ch-2.pl | 37 ++++ 5 files changed, 390 insertions(+) create mode 100644 challenge-323/adam-russell/blog.txt create mode 100644 challenge-323/adam-russell/perl/IncrementDecrement.pm create mode 100644 challenge-323/adam-russell/perl/IncrementDecrement.yp create mode 100644 challenge-323/adam-russell/perl/ch-1.pl create mode 100644 challenge-323/adam-russell/perl/ch-2.pl diff --git a/challenge-323/adam-russell/blog.txt b/challenge-323/adam-russell/blog.txt new file mode 100644 index 0000000000..f3b5f56af8 --- /dev/null +++ b/challenge-323/adam-russell/blog.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2025/06/05 diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.pm b/challenge-323/adam-russell/perl/IncrementDecrement.pm new file mode 100644 index 0000000000..41b6b03dd5 --- /dev/null +++ b/challenge-323/adam-russell/perl/IncrementDecrement.pm @@ -0,0 +1,220 @@ +#################################################################### +# +# This file was generated using Parse::Yapp version 1.21. +# +# Don't edit this file, use source file instead. +# +# ANY CHANGE MADE HERE WILL BE LOST ! +# +#################################################################### +package IncrementDecrement; +use vars qw ( @ISA ); +use strict; + +@ISA= qw ( Parse::Yapp::Driver ); +use Parse::Yapp::Driver; + +#line 10 "perl/IncrementDecrement.yp" + + my $variable_state = {}; + + +sub new { + my($class)=shift; + ref($class) + and $class=ref($class); + + my($self)=$class->SUPER::new( yyversion => '1.21', + yystates => +[ + {#State 0 + ACTIONS => { + 'DECREMENT' => 2, + 'INCREMENT' => 7, + 'LETTER' => 1 + }, + GOTOS => { + 'program' => 9, + 'decrement_variable' => 8, + 'increment_decrement' => 4, + 'increment_variable' => 3, + 'variable_declaration' => 6, + 'statement' => 5 + } + }, + {#State 1 + ACTIONS => { + 'INCREMENT' => 11, + 'DECREMENT' => 10 + }, + DEFAULT => -5 + }, + {#State 2 + ACTIONS => { + 'LETTER' => 12 + } + }, + {#State 3 + DEFAULT => -6 + }, + {#State 4 + DEFAULT => -4 + }, + {#State 5 + DEFAULT => -1 + }, + {#State 6 + DEFAULT => -3 + }, + {#State 7 + ACTIONS => { + 'LETTER' => 13 + } + }, + {#State 8 + DEFAULT => -7 + }, + {#State 9 + ACTIONS => { + '' => 15, + 'LETTER' => 1, + 'INCREMENT' => 7, + 'DECREMENT' => 2 + }, + GOTOS => { + 'statement' => 14, + 'variable_declaration' => 6, + 'increment_variable' => 3, + 'decrement_variable' => 8, + 'increment_decrement' => 4 + } + }, + {#State 10 + DEFAULT => -11 + }, + {#State 11 + DEFAULT => -9 + }, + {#State 12 + DEFAULT => -10 + }, + {#State 13 + DEFAULT => -8 + }, + {#State 14 + DEFAULT => -2 + }, + {#State 15 + DEFAULT => 0 + } +], + yyrules => +[ + [#Rule 0 + '$start', 2, undef + ], + [#Rule 1 + 'program', 1, +sub +#line 19 "perl/IncrementDecrement.yp" +{$variable_state} + ], + [#Rule 2 + 'program', 2, undef + ], + [#Rule 3 + 'statement', 1, undef + ], + [#Rule 4 + 'statement', 1, undef + ], + [#Rule 5 + 'variable_declaration', 1, +sub +#line 27 "perl/IncrementDecrement.yp" +{$variable_state->{$_[1]} = 0} + ], + [#Rule 6 + 'increment_decrement', 1, undef + ], + [#Rule 7 + 'increment_decrement', 1, undef + ], + [#Rule 8 + 'increment_variable', 2, +sub +#line 34 "perl/IncrementDecrement.yp" +{$variable_state->{$_[2]}++} + ], + [#Rule 9 + 'increment_variable', 2, +sub +#line 35 "perl/IncrementDecrement.yp" +{$variable_state->{$_[1]}++} + ], + [#Rule 10 + 'decrement_variable', 2, +sub +#line 38 "perl/IncrementDecrement.yp" +{$variable_state->{$_[2]}--} + ], + [#Rule 11 + 'decrement_variable', 2, +sub +#line 39 "perl/IncrementDecrement.yp" +{$variable_state->{$_[1]}--} + ] +], + @_); + bless($self,$class); +} + +#line 44 "perl/IncrementDecrement.yp" + + + + + sub lexer{ + my($parser) = @_; + $parser->YYData->{INPUT} or return(q//, undef); + $parser->YYData->{INPUT} =~ s/^[ \t]//g; + ## + # send tokens to parser + ## + for($parser->YYData->{INPUT}){ + s/^(\s+)// and return (q/SPACE/, $1); + s/^([a-z]{1})// and return (q/LETTER/, $1); + s/^(\+\+)// and return (q/INCREMENT/, $1); + s/^(--)// and return (q/DECREMENT/, $1); + } + } + + + sub parse{ + my($self, $input) = @_; + $input =~ tr/\t/ /s; + $input =~ tr/\n/ /s; + $self->YYData->{INPUT} = $input; + my $result = $self->YYParse(yylex => \&lexer, yyerror => \&error); + return $result; + } + + + sub error{ + exists $_[0]->YYData->{ERRMSG} + and do{ + print $_[0]->YYData->{ERRMSG}; + return; + }; + print "syntax error\n"; + } + + + sub clear{ + my($self) = @_; + $variable_state = {}; + } + + + +1; diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.yp b/challenge-323/adam-russell/perl/IncrementDecrement.yp new file mode 100644 index 0000000000..9883cc9494 --- /dev/null +++ b/challenge-323/adam-russell/perl/IncrementDecrement.yp @@ -0,0 +1,89 @@ + + + + %token INCREMENT + %token DECREMENT + %token LETTER + %expect 2 + + + %{ + my $variable_state = {}; + %} + + + + %% + + + program: statement {$variable_state} + | program statement + ; + + statement: variable_declaration #{$variable_state} + | increment_decrement + ; + + variable_declaration: LETTER {$variable_state->{$_[1]} = 0} + ; + + increment_decrement: increment_variable + | decrement_variable + ; + + increment_variable: INCREMENT LETTER {$variable_state->{$_[2]}++} + | LETTER INCREMENT {$variable_state->{$_[1]}++} + ; + + decrement_variable: DECREMENT LETTER {$variable_state->{$_[2]}--} + | LETTER DECREMENT {$variable_state->{$_[1]}--} + ; + + + + %% + + + + sub lexer{ + my($parser) = @_; + $parser->YYData->{INPUT} or return(q//, undef); + $parser->YYData->{INPUT} =~ s/^[ \t]//g; + ## + # send tokens to parser + ## + for($parser->YYData->{INPUT}){ + s/^(\s+)// and return (q/SPACE/, $1); + s/^([a-z]{1})// and return (q/LETTER/, $1); + s/^(\+\+)// and return (q/INCREMENT/, $1); + s/^(--)// and return (q/DECREMENT/, $1); + } + } + + + sub parse{ + my($self, $input) = @_; + $input =~ tr/\t/ /s; + $input =~ tr/\n/ /s; + $self->YYData->{INPUT} = $input; + my $result = $self->YYParse(yylex => \&lexer, yyerror => \&error); + return $result; + } + + + sub error{ + exists $_[0]->YYData->{ERRMSG} + and do{ + print $_[0]->YYData->{ERRMSG}; + return; + }; + print "syntax error\n"; + } + + + sub clear{ + my($self) = @_; + $variable_state = {}; + } + + diff --git a/challenge-323/adam-russell/perl/ch-1.pl b/challenge-323/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..28698eecb8 --- /dev/null +++ b/challenge-323/adam-russell/perl/ch-1.pl @@ -0,0 +1,43 @@ + + + use v5.40; + use IncrementDecrement; + +use constant TEST0 => q/--x x++ x++/; +use constant TEST1 => q/x++ ++x x++/; +use constant TEST2 => q/x++ ++x --x x--/; +use constant COMPLEX_TEST => <<~END_TEST; + a b c + a++ b++ c++ + ++a ++b ++c + --a --b --c + a-- b-- c-- + a++ ++b c++ + END_TEST + + + + sub print_variables{ + my($results) = @_; + for my $k (keys %{$results}){ + print $k; + say qq/:\t$results->{$k}/; + } + } + + +MAIN:{ + my $parser = IncrementDecrement->new(); + say TEST0; + say print_variables $parser->parse(TEST0); + say TEST1; + $parser->clear(); + say print_variables $parser->parse(TEST1); + say TEST2; + $parser->clear(); + say print_variables $parser->parse(TEST2); + say COMPLEX_TEST; + $parser->clear(); + say print_variables $parser->parse(COMPLEX_TEST); +} + diff --git a/challenge-323/adam-russell/perl/ch-2.pl b/challenge-323/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..fc05d1e33f --- /dev/null +++ b/challenge-323/adam-russell/perl/ch-2.pl @@ -0,0 +1,37 @@ + + use v5.40; + + sub calculate_tax{ + my($income, $tax_brackets) = @_; + + $tax_brackets = [sort {$a->[0] <=> $b->[0]} @{$tax_brackets}]; + use Data::Dump q/pp/; + + my $tax = 0; + my $taxed = 0; + my $taxable = 0; + + { + my $tax_bracket = shift @{$tax_brackets}; + if($tax_bracket->[0] <= $income){ + $taxable = $tax_bracket->[0] - $taxable; + $tax += ($taxable * ($tax_bracket->[1]/100)); + $taxed += $taxable; + } + else{ + $tax += (($income - $taxed) * ($tax_bracket->[1]/100)); + $taxed = $income; + } + redo unless $taxed >= $income || @{$tax_brackets} == 0; + } + + return $tax; + } + + +MAIN:{ + say calculate_tax 10, [[3, 50], [7, 10], [12,25]]; + say calculate_tax 2, [[1, 0], [4, 25], [5,50]]; + say calculate_tax 0, [[2, 50]]; +} + -- cgit From b3aa6e68dadb04e7cc2e90c8b7c76de8f46945f4 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 18:00:16 -0400 Subject: removed generated file --- .../adam-russell/perl/IncrementDecrement.pm | 220 --------------------- 1 file changed, 220 deletions(-) delete mode 100644 challenge-323/adam-russell/perl/IncrementDecrement.pm diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.pm b/challenge-323/adam-russell/perl/IncrementDecrement.pm deleted file mode 100644 index 41b6b03dd5..0000000000 --- a/challenge-323/adam-russell/perl/IncrementDecrement.pm +++ /dev/null @@ -1,220 +0,0 @@ -#################################################################### -# -# This file was generated using Parse::Yapp version 1.21. -# -# Don't edit this file, use source file instead. -# -# ANY CHANGE MADE HERE WILL BE LOST ! -# -#################################################################### -package IncrementDecrement; -use vars qw ( @ISA ); -use strict; - -@ISA= qw ( Parse::Yapp::Driver ); -use Parse::Yapp::Driver; - -#line 10 "perl/IncrementDecrement.yp" - - my $variable_state = {}; - - -sub new { - my($class)=shift; - ref($class) - and $class=ref($class); - - my($self)=$class->SUPER::new( yyversion => '1.21', - yystates => -[ - {#State 0 - ACTIONS => { - 'DECREMENT' => 2, - 'INCREMENT' => 7, - 'LETTER' => 1 - }, - GOTOS => { - 'program' => 9, - 'decrement_variable' => 8, - 'increment_decrement' => 4, - 'increment_variable' => 3, - 'variable_declaration' => 6, - 'statement' => 5 - } - }, - {#State 1 - ACTIONS => { - 'INCREMENT' => 11, - 'DECREMENT' => 10 - }, - DEFAULT => -5 - }, - {#State 2 - ACTIONS => { - 'LETTER' => 12 - } - }, - {#State 3 - DEFAULT => -6 - }, - {#State 4 - DEFAULT => -4 - }, - {#State 5 - DEFAULT => -1 - }, - {#State 6 - DEFAULT => -3 - }, - {#State 7 - ACTIONS => { - 'LETTER' => 13 - } - }, - {#State 8 - DEFAULT => -7 - }, - {#State 9 - ACTIONS => { - '' => 15, - 'LETTER' => 1, - 'INCREMENT' => 7, - 'DECREMENT' => 2 - }, - GOTOS => { - 'statement' => 14, - 'variable_declaration' => 6, - 'increment_variable' => 3, - 'decrement_variable' => 8, - 'increment_decrement' => 4 - } - }, - {#State 10 - DEFAULT => -11 - }, - {#State 11 - DEFAULT => -9 - }, - {#State 12 - DEFAULT => -10 - }, - {#State 13 - DEFAULT => -8 - }, - {#State 14 - DEFAULT => -2 - }, - {#State 15 - DEFAULT => 0 - } -], - yyrules => -[ - [#Rule 0 - '$start', 2, undef - ], - [#Rule 1 - 'program', 1, -sub -#line 19 "perl/IncrementDecrement.yp" -{$variable_state} - ], - [#Rule 2 - 'program', 2, undef - ], - [#Rule 3 - 'statement', 1, undef - ], - [#Rule 4 - 'statement', 1, undef - ], - [#Rule 5 - 'variable_declaration', 1, -sub -#line 27 "perl/IncrementDecrement.yp" -{$variable_state->{$_[1]} = 0} - ], - [#Rule 6 - 'increment_decrement', 1, undef - ], - [#Rule 7 - 'increment_decrement', 1, undef - ], - [#Rule 8 - 'increment_variable', 2, -sub -#line 34 "perl/IncrementDecrement.yp" -{$variable_state->{$_[2]}++} - ], - [#Rule 9 - 'increment_variable', 2, -sub -#line 35 "perl/IncrementDecrement.yp" -{$variable_state->{$_[1]}++} - ], - [#Rule 10 - 'decrement_variable', 2, -sub -#line 38 "perl/IncrementDecrement.yp" -{$variable_state->{$_[2]}--} - ], - [#Rule 11 - 'decrement_variable', 2, -sub -#line 39 "perl/IncrementDecrement.yp" -{$variable_state->{$_[1]}--} - ] -], - @_); - bless($self,$class); -} - -#line 44 "perl/IncrementDecrement.yp" - - - - - sub lexer{ - my($parser) = @_; - $parser->YYData->{INPUT} or return(q//, undef); - $parser->YYData->{INPUT} =~ s/^[ \t]//g; - ## - # send tokens to parser - ## - for($parser->YYData->{INPUT}){ - s/^(\s+)// and return (q/SPACE/, $1); - s/^([a-z]{1})// and return (q/LETTER/, $1); - s/^(\+\+)// and return (q/INCREMENT/, $1); - s/^(--)// and return (q/DECREMENT/, $1); - } - } - - - sub parse{ - my($self, $input) = @_; - $input =~ tr/\t/ /s; - $input =~ tr/\n/ /s; - $self->YYData->{INPUT} = $input; - my $result = $self->YYParse(yylex => \&lexer, yyerror => \&error); - return $result; - } - - - sub error{ - exists $_[0]->YYData->{ERRMSG} - and do{ - print $_[0]->YYData->{ERRMSG}; - return; - }; - print "syntax error\n"; - } - - - sub clear{ - my($self) = @_; - $variable_state = {}; - } - - - -1; -- cgit From 426df3d1009447c2775eeaa33b23450daac791dc Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 22:34:13 -0400 Subject: cleaned up code --- challenge-323/adam-russell/perl/IncrementDecrement.yp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.yp b/challenge-323/adam-russell/perl/IncrementDecrement.yp index 9883cc9494..5c4761d969 100644 --- a/challenge-323/adam-russell/perl/IncrementDecrement.yp +++ b/challenge-323/adam-russell/perl/IncrementDecrement.yp @@ -20,7 +20,7 @@ | program statement ; - statement: variable_declaration #{$variable_state} + statement: variable_declaration | increment_decrement ; -- cgit From a8614953438b4e11da928314fed7a6b494c7d6c7 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 22:40:42 -0400 Subject: cleaned up code --- challenge-323/adam-russell/perl/IncrementDecrement.yp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.yp b/challenge-323/adam-russell/perl/IncrementDecrement.yp index 5c4761d969..6f5afc2036 100644 --- a/challenge-323/adam-russell/perl/IncrementDecrement.yp +++ b/challenge-323/adam-russell/perl/IncrementDecrement.yp @@ -21,15 +21,16 @@ ; statement: variable_declaration - | increment_decrement + | increment_variable + | decrement_variable ; variable_declaration: LETTER {$variable_state->{$_[1]} = 0} ; - increment_decrement: increment_variable - | decrement_variable - ; + #increment_decrement: increment_variable + #| decrement_variable + #; increment_variable: INCREMENT LETTER {$variable_state->{$_[2]}++} | LETTER INCREMENT {$variable_state->{$_[1]}++} -- cgit From c5f4794a3c2b949baaec8994f157f36f4fd8615f Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 22:49:47 -0400 Subject: cleaned up code --- challenge-323/adam-russell/perl/IncrementDecrement.yp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/challenge-323/adam-russell/perl/IncrementDecrement.yp b/challenge-323/adam-russell/perl/IncrementDecrement.yp index 6f5afc2036..bd2e48d352 100644 --- a/challenge-323/adam-russell/perl/IncrementDecrement.yp +++ b/challenge-323/adam-russell/perl/IncrementDecrement.yp @@ -28,10 +28,6 @@ variable_declaration: LETTER {$variable_state->{$_[1]} = 0} ; - #increment_decrement: increment_variable - #| decrement_variable - #; - increment_variable: INCREMENT LETTER {$variable_state->{$_[2]}++} | LETTER INCREMENT {$variable_state->{$_[1]}++} ; @@ -83,7 +79,6 @@ sub clear{ - my($self) = @_; $variable_state = {}; } -- cgit From 876a21ea9e12bf3a98daf932f8beeac6c961ed8a Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Thu, 5 Jun 2025 22:52:43 -0400 Subject: cleaned up code --- challenge-323/adam-russell/perl/ch-2.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/challenge-323/adam-russell/perl/ch-2.pl b/challenge-323/adam-russell/perl/ch-2.pl index fc05d1e33f..6ecc78586f 100644 --- a/challenge-323/adam-russell/perl/ch-2.pl +++ b/challenge-323/adam-russell/perl/ch-2.pl @@ -5,7 +5,6 @@ my($income, $tax_brackets) = @_; $tax_brackets = [sort {$a->[0] <=> $b->[0]} @{$tax_brackets}]; - use Data::Dump q/pp/; my $tax = 0; my $taxed = 0; -- cgit From 943d453f171775aed6b2bd3cd85228e932595c52 Mon Sep 17 00:00:00 2001 From: Adam Russell Date: Fri, 6 Jun 2025 17:06:26 -0400 Subject: added Prolog solutions and blog --- challenge-323/adam-russell/blog1.txt | 1 + challenge-323/adam-russell/prolog/ch-1.p | 73 ++++++++++++++++++++++++++++++++ challenge-323/adam-russell/prolog/ch-2.p | 15 +++++++ 3 files changed, 89 insertions(+) create mode 100644 challenge-323/adam-russell/blog1.txt create mode 100644 challenge-323/adam-russell/prolog/ch-1.p create mode 100644 challenge-323/adam-russell/prolog/ch-2.p diff --git a/challenge-323/adam-russell/blog1.txt b/challenge-323/adam-russell/blog1.txt new file mode 100644 index 0000000000..9b3302d2c2 --- /dev/null +++ b/challenge-323/adam-russell/blog1.txt @@ -0,0 +1 @@ +http://www.rabbitfarm.com/cgi-bin/blosxom/prolog/2025/06/06 diff --git a/challenge-323/adam-russell/prolog/ch-1.p b/challenge-323/adam-russell/prolog/ch-1.p new file mode 100644 index 0000000000..0ae1ce8088 --- /dev/null +++ b/challenge-323/adam-russell/prolog/ch-1.p @@ -0,0 +1,73 @@ + + + increment_variable(X, U, V):- + member(X-I, U), + delete(U, X-I, U1), + I1 is I + 1, + append([X-I1], U1, V). + increment_variable(X, U, V):- + \+ member(X-_, U), + append([X-1], U, V). + decrement_variable(X, U, V):- + member(X-I, U), + delete(U, X-I, U1), + I1 is I - 1, + append([X-I1], U1, V). + decrement_variable(X, U, V):- + \+ member(X-_, U), + append([X-(-1)], U, V). + declare_variable(X, U, V):- + delete(U, X-_, U1), + append([X-0], U1, V). + + + variables(VariableState), [VariableState] --> [VariableState]. + variables(V, VariableState), [VariableState] --> [V]. + + + process(Input) --> variables(V, VariableState), + {Input = [Code1, Code2, Code3 | Codes], + Code1 == 43, Code2 == 43, Code3 >= 97, + Code3 =< 122, + increment_variable(Code3, V, VariableState)}, + process(Codes). + process(Input) --> variables(V, VariableState), + {Input = [Code1, Code2, Code3 | Codes], + Code2 == 43, Code3 == 43, Code1 >= 97, + Code1 =< 122, + increment_variable(Code1, V, VariableState)}, + process(Codes). + process(Input) --> variables(V, VariableState), + {Input = [Code1, Code2, Code3 | Codes], + Code1 == 45, Code2 == 45, Code3 >= 97, + Code3 =< 122, + decrement_variable(Code3, V, VariableState)}, + process(Codes). + process(Input) --> variables(V, VariableState), + {Input = [Code1, Code2, Code3 | Codes], + Code2 == 45, Code3 == 45, Code1 >= 97, + Code1 =< 122, + decrement_variable(Code1, V, VariableState)}, + process(Codes). + process(Input) --> variables(V, VariableState), + {Input = [Code | Codes], + Code >= 97, Code =< 122, + declare_variable(Code, V, VariableState)}, + process(Codes). + process(Input) --> {Input = [Code | Codes], + Code == 32}, + process(Codes). + process([]) --> []. + + + show_variables(X-I):- + atom_codes(A, [X]), + write(A), + write(': '), + write(I), nl. + + + increment_decrement(Input):- + phrase(process(Input), [[]], [Output]), !, + maplist(show_variables, Output). + diff --git a/challenge-323/adam-russell/prolog/ch-2.p b/challenge-323/adam-russell/prolog/ch-2.p new file mode 100644 index 0000000000..9af958e248 --- /dev/null +++ b/challenge-323/adam-russell/prolog/ch-2.p @@ -0,0 +1,15 @@ + + + compute_taxes(Income, TaxBrackets, Tax):- + compute_taxes(Income, TaxBrackets, 0, 0, Tax). + compute_taxes(0, _, 0, 0, 0). + compute_taxes(Income, [[Limit, Rate]|TaxBrackets], Taxable, Taxed, Tax):- + Limit =< Income, + Taxable1 is Limit - Taxable, + Taxed1 is Taxed + Taxable1, + compute_taxes(Income, TaxBrackets, Taxable1, Taxed1, Tax1), + Tax is Tax1 + (Taxable1 * (Rate/100)). + compute_taxes(Income, [[Limit, Rate]|_], _, Taxed, Tax):- + Limit > Income, + Tax is ((Income - Taxed) * (Rate/100)). + -- cgit