Reply To: Challenge 10B
A Tale of 2 Secrets › Forums › T.E.M.P.E.S.T. › Challenge 10B › Reply To: Challenge 10B
@AES_of_spades
To be honest, I learned Python during GCSEs, but just the basics to get me a good grade. Having never done any programming before that, most of my coding experience came from writing solutions for the cipher challenge problems, which in turn helped me in A-Level and just improving thinking skills in general. I’m at uni now and most of the skills I’ve learned is thanks to the experienced gained by taking part in this competition.
I might be biased, but I genuinely think the best way to learn is by just doing projects. Every now and then I start a new maths/coding project, not necessarily with the intention of always finishing it, but I always end up learning a lot in the process. So pick something you enjoy and do it for fun, not just because you think you “should”. As much as I loved writing code for solving challenges, there were definitely times when it became stressful, and if you find that happening, it’s usually a sign you should switch things up for a bit. Sometimes that means working on a different problem, and sometimes it means doing something completely different. At one point I picked up crocheting, and I vividly remember crocheting while debugging my A-Level code because I was getting so frustrated with a program that refused to run. Weirdly, that kind of break actually helped more than staring at the screen ever did.
There are plenty of good books and resources which the far more experienced here will be happy to recommend, but I’ve mostly relied on learning by searching things as I go, because I personally find that dense books can be overwhelming when you don’t yet know what’s relevant. There’s a very high chance that whatever problem you’re stuck on has been hit by someone before (funnily enough this is true in both programming and life…). I’ve also been grateful to have friends and people around me who were there to help, so I’d suggest finding a similar community for yourself. It makes a massive impact being around people who share a similar goal to you than doing everything by yourself. When I first started programming, I never imagined I’d be able to solve the kinds of problems I can today. It can be really daunting at first, especially when you’re looking at other people’s code and it all feels incomprehensible, but you have to keep things in perspective and trust the learning process, it genuinely does add up over time!
Hope that helps!
P.S – I’ll be kind and explain what went in my thinking with the golfing of Madness’ initial solution, think of the below as the comments that were left as an exercise to the reader.
print((lambda c: "".join(("SHADOWBCEFGIKLMNPQRTUVXY"[(("A23456789XJQK".index(c[i]) + 13*"CDHS".index(c[i+1]))%6)+6*((("A23456789XJQK".index(c[i+2]) + 13*"CDHS".index(c[i+3]) - 36))//4)] + "FULHEARTBCDGIKMNOPQSVWXY"[((("A23456789XJQK".index(c[i+2]) + 13*"CDHS".index(c[i+3]) - 36))%4)+4*((("A23456789XJQK".index(c[i]) + 13*"CDHS".index(c[i+1]))//6))]) for i in range(0,len(c),4)))("7CXS3 H6S7C...".replace(" ", "")))
The key idea was first knowing what I wanted the code to do. So I knew how the decryption logic from the better readable version- i.e. I take the text, remove the spaces, process it in chunks of 4 chars, turn those into cards, convert those into numbers, recombine the coords, and look up the two letters in the grid.
Once I had that, the rest was just fancy implementation. I knew I was wanted to write in one line as a joke, and Python has thing called list comprehensions, which let you just build a list by doing X for every i in this rage. So my one line solution was basically to write a function (and use lambda so I call it immediately) which would take each block of 4 chars, compute the two output letters using the rule, and then join the all together in the string. It looks evil cuz all the intermediate steps are inlined instead of given nice variable names but it’s still exactly the same algorithm as the more readable version. If you have any specific questions about the code I’d happy to (try) and answer them.