Credit card Verification Haskell Code

{- Convert positive integer to list of digit -}
{- Input : 12345 o/p : [1, 2, 3, 4, 5 -}
toList :: Integer -> [Integer]
toList 0 = []
toList x = toList (x `div` 10) ++ [x `mod` 10]

{- Reverse the integer after converting it to list -}
-- toDigitsRev :: Integer -> [Integer]
toListReverse :: Integer -> [Integer]
toListReverse xs = (reverse . toList) xs

{- Double every second number -}
doubleSecondEach :: [Integer] -> [Integer]
doubleSecondEach [] = []
doubleSecondEach (x:[]) = [x]
doubleSecondEach (x:y:xs) = x : (2*y) : doubleSecondEach xs

{- Sum the digit in the number we are sure there is one digit number or two digit number -}
sum' :: Integer -> Integer
sum' x = (x `mod` 10) + (x `div` 10)

{- sum all the element in list -}
{- when a element is [13,5,6] we have to add like this: 1 + 3 + 5 + 6 -}
sumDigits :: [Integer] -> Integer
sumDigits [] = 0
sumDigits [x] = sum' x
sumDigits (x:xs) = sum' x + sumDigits xs

{- Validate the credit card number -}
validate :: Integer -> Bool
validate x = if (sumDigits $ doubleSecondEach $ toListReverse x ) `mod` 10 == 0 then True else False

It all requires one step, let us always take it

The time flows like a river, it is certain that it won’t wait and we can not travel back in time. The yesterday is history so we can not change it. In spite of not being able to change the history, we should analyze it and learn from it piece by piece. Today, me running at the age of 25 i feel that i have missed many opportunities because of not taking a simple step that would require for the great beginning.

Counting your breath to deal with Insomnia

It is certain that you usually do have trouble going into sleep after you lie down on bed. This is true for a lots of people these days, may he or she be student, housewife, lecturer, job holder and most of all software developer like me. These days i heard from a lots of people that they are having trouble sleeping even after they lie down in the bed for a long time, that is even couple of hour some times.

The importance of writing in my Life

I have always been passionate about writing and it is the only way by which i learn quickly. The time when i learn things by making a notes, i understand the matter sooner. In spite of this, my writing is not so good however, i always want to improve my writing.

C# code to shuffle Array

private T[] ShuffleArray<T>(T[] array) {
    System.Random r = new System.Random ();
    for(int i = array.Length; i > 0; i--) {
        int j = r.Next (i);
        T k = array [j];
        array [j] = array [i - 1];
        array [i - 1] = k;
    }

    return array;
}

How to find the game art for your Game Project

I am currently working on a game development, i do programming and in the game if i require graphics then i hire designer. I was curious about how other indie developers like me manage the game assets. I asked in a Facebook group about this topic. Hopefully i got reply from Dozens of people. In this post i will share how they manage the game assets being a Game Programmer.

Observer in Local Election Nepal 2074

I got a chance to Volunteer as a Observer in local election which was held in 31 Baisakh 2074 (14th of May 2017) from Forum for protection of Human Rights (FOPHUR/ मानब अधिकार संरक्षक मंच under Collective Campaign For Peace (COCAP).

I almost went for observation in 15 different Election Center in Pokhara Lekhnath Metropolitan, Kaski. The overall Election was peaceful in the places i observed.

10 days of Vipassana Meditation at Dhamma Pokhara - Before you go

So finally you are here because you’ve made a decision to take a Vipassana Meditation course at Dhamma Pokhara. That is great, you’ve made one of the best decision in your life. I have taken it from 1st of the April 2017 to 12th by A.T Khadga Karki and it was great, lifetime experience for me. In this post i will share more about Dhamma Pokhara so that it will be easier for you to plan before you go there.