5 kyu
Is my friend cheating?
161 of 18,137g964
Description:
- A friend of mine takes the sequence of all numbers from 1 to n (where n > 0).
- Within that sequence, he chooses two numbers, a and b.
- He says that the product of a and b should be equal to the sum of all numbers in the sequence, excluding a and b.
- Given a number n, could you tell me the numbers he excluded from the sequence?
The function takes the parameter: n
(n is always strictly greater than 0) and returns an array or a string (depending on the language) of the form:
[(a, b), ...] or [[a, b], ...] or {{a, b}, ...} or or [{a, b}, ...]
with all (a, b)
which are the possible removed numbers in the sequence 1 to n
.
[(a, b), ...] or [[a, b], ...] or {{a, b}, ...} or ...
will be sorted in increasing order of the "a".
It happens that there are several possible (a, b).
The function returns an empty array (or an empty string) if no possible numbers are found which will prove that my friend has not told the truth! (Go: in this case return nil
).
Examples:
removNb(26) should return [(15, 21), (21, 15)]
or
removNb(26) should return { {15, 21}, {21, 15} }
or
removeNb(26) should return [[15, 21], [21, 15]]
or
removNb(26) should return [ {15, 21}, {21, 15} ]
or
removNb(26) should return "15 21, 21 15"
or
in C:
removNb(26) should return {{15, 21}{21, 15}} tested by way of strings.
Function removNb should return a pointer to an allocated array of Pair pointers, each one also allocated.
Note
See examples of returns for each language in "RUN SAMPLE TESTS"
Fundamentals
Mathematics
Puzzles
Similar Kata:
Stats:
Created | May 4, 2015 |
Published | May 5, 2015 |
Warriors Trained | 77109 |
Total Skips | 22086 |
Total Code Submissions | 132160 |
Total Times Completed | 18137 |
Python Completions | 6104 |
Ruby Completions | 485 |
C# Completions | 1083 |
Java Completions | 1977 |
Clojure Completions | 86 |
JavaScript Completions | 4117 |
Haskell Completions | 289 |
CoffeeScript Completions | 28 |
TypeScript Completions | 561 |
C++ Completions | 1333 |
Elixir Completions | 100 |
PHP Completions | 505 |
Crystal Completions | 12 |
F# Completions | 55 |
C Completions | 312 |
Rust Completions | 405 |
Swift Completions | 242 |
Go Completions | 453 |
R Completions | 65 |
Shell Completions | 30 |
OCaml Completions | 26 |
Fortran Completions | 8 |
Julia Completions | 45 |
Scala Completions | 161 |
PowerShell Completions | 26 |
Nim Completions | 11 |
Racket Completions | 21 |
Reason Completions | 2 |
Kotlin Completions | 209 |
Prolog Completions | 12 |
Pascal Completions | 6 |
Factor Completions | 9 |
Raku Completions | 4 |
Perl Completions | 14 |
Elm Completions | 3 |
COBOL Completions | 8 |
D Completions | 4 |
Erlang Completions | 9 |
Total Stars | 1846 |
% of votes with a positive feedback rating | 89% of 2137 |
Total "Very Satisfied" Votes | 1738 |
Total "Somewhat Satisfied" Votes | 311 |
Total "Not Satisfied" Votes | 88 |