5 kyu

Diophantine Equation

118 of 4,837g964

Description:

In mathematics, a Diophantine equation is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied.

In this kata we want to find all integers x, y (x >= 0, y >= 0) solutions of a diophantine equation of the form:

x24y2=n\quad x^2 - 4y^2 = n

(where the unknowns are x and y; and n is a given positive number) in decreasing order of the positive xix_i.

If there is no solution return [] or "[]" or "". (See "RUN SAMPLE TESTS" for examples of returns).

Examples:

90005 --> [[45003, 22501], [9003, 4499], [981, 467], [309, 37]]
90002 --> []

Hint:

x24y2=(x2y)(x+2y)\quad x^2 - 4y^2 = (x - 2y) \cdot (x + 2y)

Fundamentals
Mathematics
Algebra

More By Author:

Check out these other kata created by g964

Stats:

CreatedMay 10, 2015
PublishedMay 10, 2015
Warriors Trained31723
Total Skips12378
Total Code Submissions49149
Total Times Completed4837
Ruby Completions118
Python Completions1605
Clojure Completions22
Java Completions526
C# Completions241
Haskell Completions111
JavaScript Completions697
CoffeeScript Completions11
TypeScript Completions138
C++ Completions435
Elixir Completions44
PHP Completions103
Crystal Completions5
F# Completions26
C Completions188
Rust Completions176
Swift Completions80
Go Completions179
Shell Completions10
OCaml Completions18
Kotlin Completions102
Fortran Completions8
Julia Completions24
Scala Completions61
R Completions32
PowerShell Completions13
Nim Completions8
Racket Completions15
Reason Completions3
Prolog Completions10
Dart Completions77
Pascal Completions4
Factor Completions7
Raku Completions4
Lua Completions32
Perl Completions8
Elm Completions4
D Completions5
COBOL Completions5
Erlang Completions5
Total Stars863
% of votes with a positive feedback rating89% of 688
Total "Very Satisfied" Votes565
Total "Somewhat Satisfied" Votes92
Total "Not Satisfied" Votes31
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • anter69 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Voile Avatar
  • Bubbler Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad