Writing my first iPhone app – Day 2

I have to say so far I’m liking Swift a lot. It is a nice, straight forward language with some awesome feature like conditionals.

Ok so what I did today? (well yesterday, but whatever)

First of all I added some new views to my interface. I realized that i will need to record the user’s activity on the server so I will need some sort of identifier to them. Of course I could just use the device’s ID but its better to make them create an account and use their login name / user id as the identifier. Anyway, I needed to add a login view as the first responder of my app. For now I will just add a simple button to redirect the flow to the “play” view, will deal with the actual registration later. Also added a new view to my tab controller for editing the user profile / view activity. Here is how my storyboard looks like at the moment:

Screen Shot 2015-05-23 at 21.12.25

The code for my LoginViewController is really just a placeholder now

loginOverride just redirects the user to my tabController where the game code kicks off.

Made some good progress with the game itself as well. Actually pretty much the whole game logic is done. I did set up a fake API for getting the questions. Here is the not so interesting PHP code

Turns out implementing async requests in Swift is fairly simple. Just have to call NSURLConnection.sendAsynchronousRequest and parse the response. 

One thing I’ve learned about this and it is very important: never ever (EVER) try to update UI elements directly from the async request’s callback because it won’t take effect. It took me like half an hour to recognize that my code in fact works, but the UI elements are not updated. Clever people on stackoverflow told me that I should use dispatch_async to with dispatch_get_main_queue() to tell the main execution thread to update the UI.

As for rendering the question, it is pretty straight forward:

I want to allow the user 30 seconds to answer each question. I really hoped that the SDK has some sort of built in timer object, otherwise I should have implemented my own recursive async thing which I really didn’t want to do. Fortunately the SDK in fact has an NSTimer class so implementing the countdown was easy:

The only thing left to do is to hook up the answer buttons and check if the answer is correct. I simply added a tag to each button 0,1,2,3 and linked the touch up event to a new custom action:

Simples. If the clicked button’s tag equals to the one got from the (fake) API display a big green message, otherwise a red one. In the future the app will report the result to the server for logging purposes and of course to move the player on the global board but that is for the future.

Tomorrow I’m gonna start building the server side a little bit and try to make the registration / login view and hopefully add Facebook login too

Be Sociable, Share!

Writing my first iPhone app – Day 1

So I decided to step a little bit out of my comfort zone professionally and try myself outside the scope of web development. I took a beginner course on Udemy about developing iPhone apps using Swift, but up until today I didn’t write a single line of Swift code. I hereby challenge myself to write my first app in 14 days. Now the app itself most probably won’t be ready for the app store straight away since I’m mostly focusing on functionality and not usability / design but it will be a good learning experience for me.

The app: The app will be a very simple game. Imagine a massive, 1 billion step board game with one single player. Everyone who is using the app will move the same player by answering trivia questions. If a given user answers the question correctly the player moves forward 1 step, otherwise it moves backwards one. I know, not the most original idea but it really is just for learning.

So here is what I did today (keep in mind I have literally no idea what I’m doing so probably I’m doing it all wrong)

I started off building a basic interface. What really surprised me, coming from web development, is how un-intuitive xcode’s interface (storyboard) builder is when it comes to “responsive” design. It took me ages to figure out how to make a single button stretch when I switch the emulator from iPhone 5s mode to iPhone 6. Basically you have to define the relative distance between the elements and the main view and the buttons will stretch to fill the space. I mean it kinda makes sense but how hard would it be for to allow defining sizes in %? Anyway my lame interface looks like this at the moment:

Screen Shot 2015-05-23 at 17.17.33

I know, it looks fugly but it renders properly in the simulator (still fugly but at least symmetric)

Screen Shot 2015-05-23 at 17.19.06

I can’t believe I spent like 3 hours on this, but at least I learnt something. Besides the interface I defined my outlets and set up a base controller which will handle my interaction with the (so far non-existent API) and update the interface elements as needed.

Screen Shot 2015-05-23 at 17.22.55

It really is a frustrating yet very fulfilling experience to code for iOS. I mean it is one thing to switch from PHP to Python but it is completely different when you are switching from web dev to desktop / mobile dev. I think the last time I had to deal with pointers and complex types was when I was like 14 coding in Borland Pascal.

Tomorrow I’m gonna hook up my class with a stub API and do some actual work on the logic. Will keep you posted (not like anyone is reading this)

Be Sociable, Share!

That perfect ding

If I would ask you to think about the most used app on your phone and recall it’s most defining characteristic I guess most people would think about the icon or the app’s color scheme. But I do think that the most important feature of an application is the noise it makes.

When the Facebook app makes that “ding” noise it triggers and almost emotional reaction and excitement. Next time you are travelling by bus and hear that sound just look at the people. Guarantee you that more than a few of them will reach to their pockets with a hopeful expression on their face hoping they are the chosen one who got the message. Literally a pavlovian reflex. I think this is the reason why most of the popular apps are using custom sounds. Instant and free viral marketing.

Now, I never worked in the app business and definitely never worked for a multi billion dollar business like Facebook but I’m really interested in what kind of research these companies do to decide on the sounds.

  • Is it a single person who decides or is it a team?
  • How the hell those brainstorming meetings go? (“hey i have an idea. how about a swooshy noise?”, “don’t be ridiculous, that will never work. i think it should be more like a badabum sound”)
  • Are they using psychiatrists to maximize the viral effect?
  • Do they user test the noises with focus groups? (must be the weirdest temp job ever)

If you work for an app company please comment because I’m really interested.

PS: If you frequently use mass transportation please have the curtesy of muting your phone. It’s nice and all that you have a life but your Facebook app is giving us the false hope of someone thinking about us for a few seconds, and that constant disappointment is not a good way to start a day.

Be Sociable, Share!

Dear eBay, it’s 2014

<tldr> both eBay and PayPal should implement MANDATORY 2-step auth to protect both their buyers and sellers.</tldr>

I’ve never been a big fan of PayPal. The first ever decent money I made online was frozen by them and I never managed to recover the funds. It is the single worst payment system when it comes to sell digital goods. No matter what happens they always favor the buyer.

It is kind of OK when you sell software or ebooks:

  • When someone asks for an (un-rightful) refund for your software it sucks, but you don’t actually lose money. Also you can cancel the software’s license, if you have proper licensing
  • There are plenty of alternatives to process payments
  • You don’t have to rely on eBay’s buying power, you can just sell on your site or other marketplaces

But it sucks balls when it comes to sell products which you can’t recover after the transaction.

A couple of week ago I came up with a pretty profitable way to make money on eBay. I started selling voucher codes from cex.io. CEX is a cloud mining platform where you can buy hasing power to mine Bitcoin. You can only buy the hashing power with Bitcoin itself and Bitcoin is still fairly hard to aquire. So I was like what the hell, let’s buy a lot for cheap and try selling it on eBay for more. It is not against CEX’s nor eBay’s policy to sell such item.

And it worked. I had days where I made over £500 profit with very little effort. Nice passive income.

Then the kaka hit the fan. A bunch of “Unauthorized transaction” claims started coming in and PayPal always refunded the money to the buyers. Of course I had no way to recover my vouchers. Money down the drain.

Even at the beginning I was trying to be careful. Compared the buyer’s eBay details with their PayPal details and sent the codes to the PayPal email address. So a potential scammer should have access to all 3 accounts (eBay, PayPal, email). But its apparently wasn’t enough. It is kind of annoying that PayPal actually favors the buyer who is stupid enough to get 3 of their accounts hacked against the seller who did everything (almost) in his power to protect against scam, but that is a different story.

Since then I improved my verification method. I still do my email verification but I added 2 new ways of verification which my customers can choose from:

  1. Ask my customer for their Facebook account, if it’s match the name and the city of the PayPal details and it is relatively active I send the voucher as a Facebook message.
  2. While browsing the (surprisingly good) eBay knowledge base, I found an interesting link. This forms allows sellers to ask for the customers contact details. And guess what? eBay requires phone number on sign up. And that phone number is really hard to change. A 4 digit pin sent to the phone number and all is verified. Easy.

Well, it is not that simple. Turns out lots of people uses landline numbers for eBay so I have to call them up and ask them if they made the transaction or not. Since about 3 out of 5 times it is a hacked account this phone call takes ages. About an hour ago I had a 15 minutes conversation with a technologically impaired women explaining to her why she should use different passwords for all her accounts, and why should she change her password right now. Sigh.

So dear eBay (and PayPal): You are a billion dollar company dealing with millions and millions of transactions. Why? Why the hell aren’t you implementing a mandatory 2 step auth system? Would it so bad if both your sellers and buyers were happy and make transactions without any doubt that the person they are dealing with is legit? Would it be so bad to re-train the people in your payment review team to do something actually useful instead of clicking the “refund” button mindlessly?


Be Sociable, Share!

I guess I’m into crypto currencies now

I was mad at myself for a long while for not getting into Bitcoin when the price was as low as $10 / btc not too long ago. I guess the main reason why I never invested is because I never fully understood the technology. To be fair I still don’t understand it 100%.

Then came the rise of “altcoins”, the alternative crypto currencies. I got especially excited about DogeCoin. What sets this currency apart from the 100s of other ones?

  1. It started as a joke, “meme” currency and I fucking loves memes
  2. It is dubbed as a “tipping” currency which encourages the flow of the money. The doge community actually donated over $30.000 for the Jamaican bobsled team so they can attend to the winter olympics
  3. Mining is relatively easy even with CPU

With all new crypto currencies there are new marketplaces where you can buy / sell coins. One thing I realized the price of coin is varies wildly depending on how much risk does the seller have to take for a given transaction.

For example: on eBay the price of doge is about £1 / 1000 coins because eBay uses Paypal and Paypal transactions are reversible, while Doge transactions aren’t.

On dogeforsale.com the price currently around £0.6 / 1000 if you buy via UK bank account. The seller still takes a little risk but not nearly as much with Paypal.

And finally there is the cheapest but most complicated way: Buy Doge with BTC. There is absolutely no risk there and you can get a 1000 coins for like £0.42. Naturally I went with this option, which raised an other issue: I have to acquire some BTC. I was using bitbargain.co.uk which is a peer to peer exchange and bought my first 0.5 BTC. Then using coinedup I exchanged them to Doges.

Now for selling i was considering dogeforsale, but got into a price war with some of the other sellers which made the price as low as it no longer worth my time to do it. So I moved on to eBay. As I mentioned selling crypto currencies via paypal is risky. The biggest risk you face is when someone is using a stolen paypal account for the purchase, then later the original owner issues a refund request. There are a few ways to protect yourself though:

  1. Only sell for eBay members with 50+ ratings (100% positive)
  2. Always ask the buyer to send his wallet address from the paypal email address to your email address (so you validate that they actually have access to the email account)

With this I made some good profit, but its still pocket money. I was started looking at profitable ways of mining BTC so I can achieve close to 100% profits. Some people says mining BTC is dead. Well turns out its not strictly true.

I found this cloud mining platform called cex.io which makes it possible to mine profitably with a relative small investment. You can purchase gigahash / sec mining power from them. When you purchase lets say 1 Gh/sec you actually own the hardware behind it (they actually deliver it to your door if you want it). If you don’t want to use the mining power anymore you can sell it back to the system.

The price of Gh/sec is fluctuating (oddly, as I see it correlates to the price of BTC which makes no sense, but whatever), at the moment its at 0.01176013 BTC / Gh. Luckily I found my old external hard drive which held my old BTC wallet with 2.3 BTC in it (talk about found money) and invested a portion of it for 100 Gh / sec. This mining power gave me about 0.02 BTC / day which equals about £7 profit daily. If I convert this to doge that will be around 17.000 doge coins and I can push that on eBay for £14-£17. If I get bored of it, or just want to cash out, I will sell back my Gh and exchange my BTC back to cash.

I’m doing this for about a month now. Lots of research, got scammed a couple of times but it kind of worth it. It is just fun to play broker with these virtual currencies. Yesterday for a little while I was a doge millionaire. Too bad you can’t get a physical, monopoly money-esque version of these coins.

Be Sociable, Share!

Booze, Drugs & Rock ‘n’ Roll

The company I’m working for, for almost 6 years (omg) now has a great tradition: Every year, around Christmas we take a trip to a random, previously undisclosed surprise location to celebrate the year behind us. This year the secret location was Rotterdam in the Netherlands. During the last day we had a treasure hunt where the company was split into 4 teams and each of these teams had to do challenges in random pubs, roaming around the city. Obviously a lot of drinking took place. At the end all 4 teams ended up in the same restaurant where a company dinner took place.

Most of us were completely wasted. I remember thinking: “Wow, these bunch of functional alcoholics built a multi-million pound company. And people actually invested money into it, what are the chances?”.

Thinking this further it made me realize that there wouldn’t be tech without booze. Just think about a tech meetup for programmers without the mandatory free beer! It would be something like the beginning of a 6th grade elementary school dance. People would stand around awkwardly interacting with no-one. We are geeks after all, we need some encouragement. Same valid with high profile tech conferences. I’m pretty sure most of the industry’s big investment deals been rooted around a couple of pints or some bubbly. Not to mention great ideas. If someone tells me the idea for stuff like Foursquare not started in a pub then I call bullshit. The original idea might have been like “Fuck, I’m wasted but still want a drink, would be nice to know where my buddies are” (just guessing). So thank you alcohol for all the good stuff (and fuck you for all the inevitable bad decisions, but that is a different story)

Speaking of Rotterdam: Drugs. I myself never been big fan of drugs. I’m not against them but had more bad experiences than good. That being said I’m smoking a joint like at least once every two months. Not for partying, just at home. I quite like how it is messing with my brain and it gives me great ideas / new perspective for existing ideas. These are not world changing ideas, but little fun ones.

One of these ideas were responsible for a little media hack we did with my designer friends, which brought us almost 400.000 facebook fans in one night. About 9-10% of hungarian people are gypsies (roma). Now back then according to the law of Hungary you could name your child whatever you wanted, there was absolutely no regulation. For some reason the roma population started giving weird names to their kids, stuff like Nintendo Lakatos, Rambo Racz and my personal favorite Casette Olah. The government realized that this is not right and they made a law that every name must be approved. The news was full of it. I was fairly high when I saw this news piece and instantly though: we should capitalize on this. Asked my friend to design some funny background and quickly hacked together a facebook app. The user must like our page to get their “Gyspy name”. The app then generated the name on the background and shared it on the user’s wall with a link back to the app. I’m not proud of it (fuck yeah I’m), but it wasn’t against FB’s terms so why not. It went viral in minutes. The morning I woke up and we were up to 150k fans. It was all over the internet. Human rights people said its racist (70% of our users were gypsies so I don’t think they were offended), there were articles about privacy, it was even mentioned on national TV. All because of a joint.

Oh by the way, if you wonder about the quality of my code for this app I wrote while high. The best way to describe it is like this: My grandpa was a builder. As most builders he liked to lay bricks while drunk. One day he was particularly drunk while he was working on my mothers house. He managed to build a wall which was bent in three different ways (think about it how). My code was just like that: functioning, but nothing to be proud of, to say the least.

Now the title says “Booze, Drugs & Rock ‘n’ Roll” so lets talk about music and programming. (and yes, I know this post is about nothing)

For me music is one of the most important things in life. I listen to a bunch of different genres but my all time love is punk. I born in a country where all national holidays are celebrating a revolution so it is understandable that I listen to the music which celebrates the revolution against the “normal”. And by punk by the way I don’t just mean the genre. I mean any song that makes you think or makes you question things that everyone in your life accepts as a dogma. For example I consider Pink’s Mr. President as a fucking great punk track. I consider punk as a guide for out of the box thinking, much like I consider Bhagavad Gita not as a holy book of Krishna but a guide to live your life. (no I’m not a Krishna believer but found the book highly refreshing compared to any western holy books)

What does it have to do with programming? Well this will be highly generalized, I know a lot of people who are exception for this, but I think there are two kinds of coders (neither of the groups is better than the other, but they are different):

(again, this is just my humble opinion and there are more exception than rule)

There are the ones who listen to electronic music. They tend to be very accurate, efficient programmers, producing good code with the tools they been told to use (in school or [insert currently trending tech know-it-all place]). Everything by the book. They are the perfect people for a late stage start up or a big company.

On the other hand there are coders who listened to music their whole life with messages like “it’s ok to be hated”. We are the people who sit at planning meetings thinking stuff like “just fucking do it already”. We tend not to follow process. We would be happy to push an alpha release without QA even seeing the product. We tend to code way faster than the 1st group however most of the time our code is not as efficient / not as scalable. We are the perfect people for an early stage start up.

For example: Lets say there is a new API, pre-release, in a load testing phase. The API is way too slow.
– A group of coders from the 1st group discussing the problem. They decide to use a profiler so they have an argument on which profiler lib to use. They decide on the profiler and implement it. Lets say the implementation takes 2 hours. They find the buggy method and fix it
– A group of coders from the 2nd group get the task to solve the problem. They sit down around one of their computers. One coder adds print(time().”\n”); statements in the code before and after each method call they think could be problematic. They find the buggy method and fix it.
Which group is right? Both! It is just the way of thinking that is different.

Ok, this post was way too long to be about nothing. Sorry about that. To close this off. here is a video which perfectly sums what i think punk is (the band it self is not a big deal but this poem is spot on, especially the last verse)

“There’s a lesson to be learned, one that I will take home,
When I return to my normal reality zone,
Punk rock has the power to change the world,
It lies in every single punk rock boy and girl,
So don’t let anyone tell you you’re not worth the earth,
These streets are your streets, this turf is your turf,
Don’t let anyone tell you that you’ve got to give in,
Cos you can make a difference, you can change everything,
Just let your dreams be your pilot, your imagination your fuel,
Tear up the book and write your own damn rules,
Use all that heart, hope and soul that you’ve got,
And the love and the rage that you feel in your gut,
And realise that the other world that you’re always looking for,
Lies right here in front of us, just outside this door,
And it’s up to you to go out there and paint the canvas,
After all, you were put on the earth to do this,
So shine your light so bright that all can see,
Take pride in being whoever the fuck you want to be,
Throw your fist in the air in solidarity,
And shout “Viva la punk, just one life, anarchy”

Be Sociable, Share!

lePunk in MarketingLand – Week #1

I’ve launched my new product about 4 weeks ago. Sales been great, but my PPC bill is bit higher than I expected. Turns out I have competition. Well, this sucks balls, but I decided that instead of throwing money at the problem I do a little experiment.

I’ve read an article on Hacker News (i can’t find it anymore, sorry) about a guy who was doing one little growth hack a day to improve user experience and income / user. I decided to do a similar thing but with marketing. To be precise free / low cost marketing. Every night during the past week I spent an hour trying out different marketing “hacks” / methods to improve my search engine rankings, build my list and generally drive traffic and sales to my site. Here is what I did:

General on-site SEO:
When I launched my product I generally just wanted to get it out there without caring too much about SEO. My site content wasn’t keyword rich and i had the same title on every page. So I spent the first night with researching keywords and updating my site. I looked at the competition’s rankings and decided on some phrases where I think I can beat them. Updated my title, keywords and description tags. Not rocket science and I can’t tell if I did it right but will see on the long term.

Building backlinks:
SEO gurus say that Google don’t really care about backlinks anymore, unless they are coming from quality sites. I call bullshit on that one. On the 2nd night I found a guy onf Fiverr who were willing to send my link to 150 social bookmarking sites for $5. I gave him 10 different variations of titles and descriptions and asked him to spread the 150 bookmarks to 100 for inner pages and 50 for my main site. He delivered the work quickly and as of today I can see the improvements. My site is well indexed and GoogleBot is a regular visitor, which is nice if I want to try different on-page SEO strategies. Also I’m now on page 4 and 5 for my main keywords.

Video link juice
Before launching my site I made a pretty good promo video using Animoto. On Wednesday I found a nice Indian fella on Fiverr who was offering to upload my video to 50 different video hosts along with my descriptions and link back to my main site for a fiver. No brainer. He delivered the job promptly and provided me with a report with links to the videos. Then I hired the guy from Tuesday to social bookmark that 50 video links creating some link juice. As of today some of the videos are actually ranking on the 1st page of Google for my main keyword. Pretty good for 10 bucks

Script directories
On Thursday I submitted my site to Hotscripts and other similar script directories. According to my previous experience with selling scripts these directories are great for traffic, but not much of a help with SEO. Also it take ages for them to approve the links, but at least its done now.

On Friday I went out drinking. Fuck the system

List building
During the Saturday hangoverness I read some basic ebooks about how list building works. Basically you build your list buy giving away something for free in exchange for the user’s email address and name, and from that point you can send offers to that email address. Sounds straight forward. For the first step I fired up my pre-existing GetResponse account and did some further integration with my site. Now if someone orders my product, or uses the contact form he automatically has the option to opt-in to my list. Also I’m segmenting my list based on where the user in the process. My labels are “Interested”, “Registered” and “Ordered”.

Wrote an ebook
During the development of my script I set up a test site which I needed to promote to validate that the script itself will be profitable for my customers. In order to do that I developed a fairly unique promotion method for Pinterest. Today I decided to write down this method in a short, 7 pages long e-book, which I’m giving away for free. Don’t look at my squeeze page, it is ugly as hell but whatever. Will pretty it up whenever I have some time.

That is it for this week. I’m dedicated to do these kind of little improvements every day up until the point when I can just shut down my PPC campaigns and rely completely on organic traffic.

Be Sociable, Share!

Facebook Hacker Cup 2013: My solutions

Task 1: Beautiful strings

When John was a little kid he didn’t have much to do. There was no internet, no Facebook, and no programs to hack on. So he did the only thing he could… he evaluated the beauty of strings in a quest to discover the most beautiful string in the world.

Given a string s, little Johnny defined the beauty of the string as the sum of the beauty of the letters in it.

The beauty of each letter is an integer between 1 and 26, inclusive, and no two letters have the same beauty. Johnny doesn’t care about whether letters are uppercase or lowercase, so that doesn’t affect the beauty of a letter. (Uppercase ‘F’ is exactly as beautiful as lowercase ‘f’, for example.)

You’re a student writing a report on the youth of this famous hacker. You found the string that Johnny considered most beautiful. What is the maximum possible beauty of this string?

The input file consists of a single integer m followed by m lines.

Your output should consist of, for each test case, a line containing the string “Case #x: y” where x is the case number (with 1 being the first case in the input file, 2 being the second, etc.) and y is the maximum beauty for that test case.

5 ≤ m ≤ 50
2 ≤ length of s ≤ 500

My solution for this problem was fairly straight forward. Not the fastest solution I guess, but it works: get the string, count the unique alpha characters in it and add up the “beauty”

Task 2: Balanced Smileys

Your friend John uses a lot of emoticons when you talk to him on Messenger. In addition to being a person who likes to express himself through emoticons, he hates unbalanced parenthesis so much that it makes him go :(

Sometimes he puts emoticons within parentheses, and you find it hard to tell if a parenthesis really is a parenthesis or part of an emoticon.

A message has balanced parentheses if it consists of one of the following:
– An empty string “”
– One or more of the following characters: ‘a’ to ‘z’, ‘ ‘ (a space) or ‘:’ (a colon)
– An open parenthesis ‘(‘, followed by a message with balanced parentheses, followed by a close parenthesis ‘)’.
– A message with balanced parentheses followed by another message with balanced parentheses.
– A smiley face “:)” or a frowny face “:(”

Write a program that determines if there is a way to interpret his message while leaving the parentheses balanced.

The first line of the input contains a number T (1 ≤ T ≤ 50), the number of test cases.
The following T lines each contain a message of length s that you got from John.

For each of the test cases numbered in order from 1 to T, output “Case #i: ” followed by a string stating whether or not it is possible that the message had balanced parentheses. If it is, the string should be “YES”, else it should be “NO” (all quotes for clarity only)
1 ≤ length of s ≤ 100

I spent quite a lot of time, about 40 minutes on this one. I ended up with a recursive function which relies on a regular expression: “/(\(.*)(:\))?(:\()?(\))/U”. This regex will match the parts of the string which are in brackets even if the parts are containing a smiley. Then it is just a loop for counting the opening and closing parentheses.

Task 3: Find the min

After sending smileys, John decided to play with arrays. Did you know that hackers enjoy playing with arrays? John has a zero-based index array, m, which contains n non-negative integers. However, only the first k values of the array are known to him, and he wants to figure out the rest.

John knows the following: for each index i, where k <= i < n, m[i] is the minimum non-negative integer which is *not* contained in the previous *k* values of m.

For example, if k = 3, n = 4 and the known values of m are [2, 3, 0], he can figure out that m[3] = 1.

John is very busy making the world more open and connected, as such, he doesn't have time to figure out the rest of the array. It is your task to help him.

Given the first k values of m, calculate the nth value of this array. (i.e. m[n - 1]).

Because the values of n and k can be very large, we use a pseudo-random number generator to calculate the first k values of m. Given positive integers a, b, c and r, the known values of m can be calculated as follows:
m[0] = a
m[i] = (b * m[i - 1] + c) % r, 0 < i < k

The first line contains an integer T (T <= 20), the number of test cases.
This is followed by T test cases, consisting of 2 lines each.
The first line of each test case contains 2 space separated integers, n, k (1 <= k <= 10^5, k < n <= 10^9).
The second line of each test case contains 4 space separated integers a, b, c, r (0 <= a, b, c <= 10^9, 1 <= r <= 10^9).

For each test case, output a single line containing the case number and the nth element of m.

Well, I failed this task. Not because my solution wasn’t working. It wasn’t fast enough in some cases. I considered seed (it is not my first time on the Hacker cup) and tested it with large arrays but I missed a case when my script fails. The key speed up was when I realized that the analyzed array slices are repeating. They are repeating after every Kth element, therefor:

It gave me a huge speed up, but apparently not enough. I tried to run my script with the test cases provided by Facebook’s system and it didn’t finish in the 6 minutes limit even on the high-compute Amazon EC2 instances. Epic fail. Well next time. Anyway, my solution for task #3:

Be Sociable, Share!