Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
12f107b
feat: Add pronic number implementation
itsAkshayDubey Oct 27, 2022
859ae7b
test: Add unit tests for pronic number
itsAkshayDubey Oct 27, 2022
fa17bc2
refactor: Remove error from return type
itsAkshayDubey Oct 28, 2022
a047f1b
refactor: Change tests struct acc to new method sign
itsAkshayDubey Oct 28, 2022
f34c04c
refactor: Add odd check condition
itsAkshayDubey Oct 28, 2022
e69e842
refactor: Optimize default case in switch statement
itsAkshayDubey Oct 28, 2022
c5b7ba6
refactor: Import golang math package as stdMath
itsAkshayDubey Oct 29, 2022
18cefa0
refactor: Add if statement instead of switch case
itsAkshayDubey Oct 29, 2022
fb715ca
docs: Documentation fixes
itsAkshayDubey Oct 31, 2022
3495e15
test: Add test for largest 32-bit pronic number
itsAkshayDubey Oct 31, 2022
420d63c
test: Add test for largest 64-bit pronic number
itsAkshayDubey Nov 7, 2022
5bc8fbc
fix: Remove incorrect test for largest pronic number
itsAkshayDubey Nov 8, 2022
6a6dc03
fix: Type conversion fix
itsAkshayDubey Nov 8, 2022
16b3adf
test: Add test for largest 64-bit pronic number
itsAkshayDubey Nov 8, 2022
7affb1d
test: Add test from 64-bit non pronic number
itsAkshayDubey Nov 8, 2022
7ffec37
test: Change unit test names in tests struct
itsAkshayDubey Nov 9, 2022
734eb63
docs: Remove description from pronicnumber_test.go
itsAkshayDubey Nov 9, 2022
4ff06a8
docs: Fix details block with proper definition
itsAkshayDubey Nov 9, 2022
c7b766c
Merge branch 'master' into algorithm-pronic-number
raklaptudirm Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions math/pronicnumber.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// pronicnumber.go
// description: Returns true if the number is pronic and false otherwise
// details:
// Pronic number: For any integer n, if there exists integer m
// such that n = m * (m + 1) then n is called a pronic number.
// wikipedia: https://en.wikipedia.org/wiki/Pronic_number
// author: Akshay Dubey (https://github.com/itsAkshayDubey)
// see pronicnumber_test.go

package math

import stdMath "math"

// PronicNumber returns true if argument passed to the function is pronic and false otherwise.
func PronicNumber(n int) bool {
if n < 0 || n%2 == 1 {
return false
}
x := int(stdMath.Sqrt(float64(n)))
return n == x*(x+1)
}
Loading