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

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 4, 2015
PublishedMay 5, 2015
Warriors Trained77109
Total Skips22086
Total Code Submissions132160
Total Times Completed18137
Python Completions6104
Ruby Completions485
C# Completions1083
Java Completions1977
Clojure Completions86
JavaScript Completions4117
Haskell Completions289
CoffeeScript Completions28
TypeScript Completions561
C++ Completions1333
Elixir Completions100
PHP Completions505
Crystal Completions12
F# Completions55
C Completions312
Rust Completions405
Swift Completions242
Go Completions453
R Completions65
Shell Completions30
OCaml Completions26
Fortran Completions8
Julia Completions45
Scala Completions161
PowerShell Completions26
Nim Completions11
Racket Completions21
Reason Completions2
Kotlin Completions209
Prolog Completions12
Pascal Completions6
Factor Completions9
Raku Completions4
Perl Completions14
Elm Completions3
COBOL Completions8
D Completions4
Erlang Completions9
Total Stars1846
% of votes with a positive feedback rating89% of 2137
Total "Very Satisfied" Votes1738
Total "Somewhat Satisfied" Votes311
Total "Not Satisfied" Votes88
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • Abbe Avatar
  • Blind4Basics Avatar
  • wneumann Avatar
  • Voile Avatar
  • rxe Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • 4500zenja1 Avatar
Ad