Skip to content

Instantly share code, notes, and snippets.

View BillOTei's full-sized avatar
🏠
Working from home

Alex T BillOTei

🏠
Working from home
View GitHub Profile
@BillOTei
BillOTei / gist:e91286ad7a000b54e2d8
Created October 4, 2014 06:37
Luhn algorithm in python
def validate(n):
def process_1(index, nb, odd):
result = (nb * 2 if index % 2 else nb) if odd else (nb * 2 if 0 == index % 2 else nb)
return result - 9 if result > 9 else result
n = [int(i) for i in str(n)]
if len(n) % 2:
n = [process_1(index, nb, True) for index, nb in enumerate(n)]
else:
n = [process_1(index, nb, False) for index, nb in enumerate(n)]
return sum(n) % 10 == 0
package models
import dao.Dao
import com.avaje.ebean.annotation.CreatedTimestamp
import com.avaje.ebean.annotation.UpdatedTimestamp
import play.data.validation.Constraints
import javax.persistence._

Keybase proof

I hereby claim:

  • I am billotei on github.
  • I am alexte (https://keybase.io/alexte) on keybase.
  • I have a public key ASBKq1zHLVchylFSQc6Pbkz-fMzyJ1lv43t3tRgdcDaFTwo

To claim this, I am signing this object:

@BillOTei
BillOTei / Application.scala
Last active January 23, 2023 08:08
Quick sort algorithm in scala
object Application extends App {
def quickSort(l: Array[Int], low: Int, high: Int): Unit = {
if (low < high) {
val pivotIdx = partition(l, low, high)
quickSort(l, low, pivotIdx - 1)
quickSort(l, pivotIdx + 1, high)
}
}