5 kyu

Is my friend cheating?

4,121 of 18,170g964

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 Trained77187
Total Skips22116
Total Code Submissions132338
Total Times Completed18170
Python Completions6118
Ruby Completions486
C# Completions1086
Java Completions1980
Clojure Completions87
JavaScript Completions4121
Haskell Completions290
CoffeeScript Completions29
TypeScript Completions561
C++ Completions1339
Elixir Completions101
PHP Completions507
Crystal Completions13
F# Completions57
C Completions314
Rust Completions410
Swift Completions243
Go Completions455
R Completions66
Shell Completions31
OCaml Completions27
Fortran Completions9
Julia Completions46
Scala Completions162
PowerShell Completions27
Nim Completions12
Racket Completions22
Reason Completions3
Kotlin Completions210
Prolog Completions13
Pascal Completions7
Factor Completions10
Raku Completions5
Perl Completions15
Elm Completions4
COBOL Completions9
D Completions5
Erlang Completions10
Total Stars1845
% of votes with a positive feedback rating89% of 2142
Total "Very Satisfied" Votes1743
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