summary refs log tree commit diff stats
path: root/tests/rectest.nim
blob: 54815e1f690d93c2be4aaedc7facd891118f3140 (plain) (blame)
1
2
3
4
5
6
# Test the error message

proc main() =
  main()

main()
: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "sum_of_multiples.h"
#include <stdlib.h>
#include <stdbool.h>

unsigned int sum(const unsigned int *factors,
                 const size_t number_of_factors, const unsigned int limit) {
    unsigned int total = 0;
    bool *seen = calloc(limit, sizeof(*seen));
    for (size_t idx = 0; idx < number_of_factors; idx++)
        for (size_t num = 0; num < limit; num++)
            // factors[idx] shouldn't be 0. (% fails)
            if (!seen[num] && factors[idx] && !(num % factors[idx])) {
                total += num;
                seen[num] = true;
            }
    return total;
}