Learn Kotlin (Part 2) - Array, Collection and Range

Sudeep Acharya
Post Series: Part 1: Hello world and Basic Data Types Part 2: Array, Collection and Range Part 3: Control Flow Part 4: Function Part 5: Class In this post we will discuss about the Array, Collection and Range in Kotlin. Array In Kotlin, we can create array using two different ways. First one is by using arrayOf() function and next one is by using Array() constructor. Using arrayOf() function val accountInfo = arrayOf("Sudeep", 34000) The accountInfo array is of type Array<Any>.

Learn Kotlin (Part 1) - Hello world and Basic Data Types

Sudeep Acharya
Post Series: Part 1: Hello world and Basic Data Types Part 2: Array, Collection and Range Part 3: Control Flow Part 4: Function Part 5: Class Since Kotlin is already a official programming language for Android Apps development, I have been learning Kotlin lately. In this post, i will take you through basic hello world skeleton program to data types, variables in Kotlin. Hello World Program for Kotlin fun main(args: Array) { println("Hello World!

When the wind blows through my window!

Sudeep Acharya
Today the wind blows in my room through my window making sound with my curtains forced me to write something on itself. चन्द्रको उज्यालोको सितलता बुझ्न सके उढेर चन्द्रमा छुन किन पर्थ्यो र? हावाको झोकाको इस्पर्स बुझ्न सके बियोग को पिडामा तिमिलाइ सम्झी रातभर छटपत्याउन किन पर्थ्यो र? गज्रिदै बगेको खोलाको चट्टानको र चत्याङ्ग पर्दा को पहाडको मौनता बुझ्न सके शान्ति खोज्दै एकान्तमा बस्न किन पर्थ्यो र?

Recursive directory traverse and append .png file to list

Sudeep Acharya
Python Developer’s Meetup Nepal #13 Question Solution Q: Write a python script that recursively walks all sub-directories and searches all files with extension *.png or *.PNG and append them to the list. Solution: import os # list variable to store the .png and .PNG file png_file_list = [] # Recursive function to traverse all the sub-dirctory and check for png files def traverse_directory(dir_path): for child in os.listdir(dir_path): path = os.path.join(dir_path, child) if os.

म, अद्यात्म र मेरो समाज

Sudeep Acharya
ब्याचलर भ्याएको लगभग १ वर्ष बितिसकेको थियो, म केहि काम परेर फेरी आफुले पढेको कलेज गएको थिए| म तेहा पुगेपछि आफुलाई पडाएको गुरु देखे र नमस्कार गरे| अनि उहाले के गर्दै छौ, के कस्तो छ भन्नु भयो| कुरा चल्दै गयो र पछि उहाले मलाई सोध्नुभयो बाबु तिम्लाई के को दुखः छ र? मैले उहालाई सोधे “किन र सर? तेस्तो त केहि छैन”| यो प्रश्न मलाई चिन्तित देखेर अथवा कुनै कारण ले सोधिएको थिएन| म एस प्रश्नले खासै चकित पनि थिइन किनकि मैले अद्यात्म तिर लागेर फसेबूकमा ध्यान गरेको, तेस्तै कार्यक्रममा सहभागी भएको र अद्यात्म सम्बन्धित पोस्टहरु गरेको देखेर मलाई हिजो आज धेरै ले एस्तो खाल्को कुरा भन्नु हुन्न्छ, मलाई बडो अचम्म लाग्छ|

रत्न पार्कमा औठी बेच्न बसेका ति मानिस

Sudeep Acharya
(सेतोपाती मा प्रकाशित) प्रकाशित मिति: मङ्गलबार, मंसिर १२, २०७४ ०९:२१:१२ मंसिर महिनाको ८ गतेको दिन थियो, दिन भर ल्यापटपमा काम गरे पछि बेलुका ५ बजे तिर सरिर तन्काउन पर्यो भनेर म होस्टेल बाट निस्किए| म पुतलीसडक बाट बागबजार हुदै घण्टा घर भएर जादै थिए, बाटोमा माछापुछ्रे बैंकको ATM देखे | तेस पछि मैले होस्टेलमा तिर्ने पैसा निकाल्ने निर्णय गरे| त्यो बेलामा होस्टेल मा महिनाको ११ हजार रुपैया तिर्नु पर्ने थियो| आम्दानी खासै न भएकोले गर्दा यो धेरै ठुलो रकम थियो, तेस माथिपनि आफैले दुख गरेर कमाएको पैसा ATM बाट स्वात्तै घटेको देख्दा मन चसक्क हुदो रहेछ|

Credit card Verification Haskell Code

Sudeep Acharya
{- 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

Sudeep Acharya
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

Sudeep Acharya
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

Sudeep Acharya
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. I remember when i started learning by writing, it was some class of around 4th grade but i am not sure.