kata

Welcome to Scienxlab's kata coding challenges for subsurface scientists and engineers.

Want practice coding on familiar data? You can solve these geoscience-flavoured challenges in any language, and learn how to use a web API in the process. To find out how, read on.

🤓 Go to the list of challenges.

🚀 Launch Google Colab and get stuck in right now!

What are these things?

kata (形) is a Japanese word meaning 'form'. In martial arts like karate, kata are training exercises. Software engineers have adapted the idea into coding challenges. We have written some geocomputing-flavoured kata for you to try.

Kata also happens to mean 'down' in Greek (e.g. as in 'katabatic wind'), so it's especially appropriate for geoscience :)

Getting an exercise

To receive the challenge, get your input data, and give your responses, you will be communicating with a web API. It's just like using a website, except you can access it via code as well as a browser. The API is being served at the URL https://kata.scienxlab.org

We can read this week's question from the challenge 'endpoint' at https://kata.scienxlab.org/challenge. This is expecting you to ask for a resource, which is the challenge name. The first challenge is called sequence so let's go to https://kata.scienxlab.org/challenge/sequence (note the name of the challenge at the end).

You can paste that URL into a browser to read the challange, but we can do it right from Python:

import requests
url = 'https://kata.scienxlab.org/challenge/sequence'  # <- In week 2, you'll change the name
r = requests.get(url)
r.status_code

What comes back is a string:

r.text

The text is written in Markdown, a markup language for formatting plain text. We can use IPython's display module to render it:

from IPython.display import Markdown
Markdown(r.text)

About those questions

In general, question 1 should be pretty approachable for all learners. It shouldn't take more than a few lines of code to solve — and you might be able to do it in one!

Question 2 should be solvable by most beginners, but it will take a bit more work. It probably needs at least a few lines of code. It will probably involve more than one data structure. You might need loops or NumPy, depending on the type of problem.

Question 3 is supposed to be a bit tricky. It should be solvable by beginners, but it might take you an hour or two.

If there is a question 4, it will be about the same difficulty as Question 3.

Getting your input

When you think you've figured out how to solve the problem, or at least have a go at Question 1, you'll need some unique input that's only for you, so we need to pass some information to the server.

Choose a value for 'key' — it can be any string, like your name, or your favourite word. It is not stored on the server or interpreted in any way, it's just a string that acts as a unique identifier. It ensures that you will probably get your own input, unlike anyone else's.

my_key = "honey badger"
params = {'key': my_key}
r = requests.get(url, params)
r.text

This input will be the same for all of the questions.

You can now attempt to answer the questions.

Giving your answer

Running your solution on your unique input gives you an answer. You can give this answer to the server and it will tell you if you are correct or not:

params = {'key': my_key,   # <- must be the same key as before
          'question': 1,   # <- which question you're answering
          'answer': 1234,  # <- your answer to that question
          }
r = requests.get(url, params)
r.text

💡 Tips

Want to contribute?

If you'd like to have a go at writing a challenge, we'd love to add it to the collection! Take a look at the kata-dev repo, which contains everything you need to know about how to make a challenge for the community. You can also post issues there, since there is no public repo for the app itself.

We also appreciate all feedback, especially if you have undue trouble, find an error, or can't understand a challenge. The Software Underground's Mattermost is the best place: look for the kata channel.