5 kyu

Diophantine Equation

529 of 4,874g964

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 Trained31897
Total Skips12411
Total Code Submissions49326
Total Times Completed4874
Ruby Completions119
Python Completions1615
Clojure Completions23
Java Completions529
C# Completions242
Haskell Completions112
JavaScript Completions701
CoffeeScript Completions12
TypeScript Completions146
C++ Completions441
Elixir Completions45
PHP Completions106
Crystal Completions6
F# Completions27
C Completions189
Rust Completions177
Swift Completions84
Go Completions181
Shell Completions10
OCaml Completions19
Kotlin Completions103
Fortran Completions9
Julia Completions25
Scala Completions62
R Completions33
PowerShell Completions14
Nim Completions9
Racket Completions16
Reason Completions4
Prolog Completions11
Dart Completions82
Pascal Completions5
Factor Completions8
Raku Completions5
Lua Completions35
Perl Completions9
Elm Completions5
D Completions6
COBOL Completions6
Erlang Completions6
Total Stars865
% of votes with a positive feedback rating89% of 689
Total "Very Satisfied" Votes565
Total "Somewhat Satisfied" Votes93
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