Python Challenge - Level 30

Problem

The page says:

The picture is only meant to help you relax

In the page directory, downloading yankeedoodle.csv provides a list of 7,367 floating-point numbers separated by commas.

Solution

Factorizing 7,367:

7367 = 53 × 139

Plotting these float values as a 53 × 139 grayscale image (after rotating and transposing) reveals an equation:

n = str(x)[5] + str(y)[5] + str(z)[6]

Taking the numbers in successive triplets (a, b, c):

  • Take the 5th digit (index 5) of the string representation of a.
  • Take the 5th digit (index 5) of the string representation of b.
  • Take the 6th digit (index 6) of the string representation of c.
  • Combine them into a 3-digit decimal number and convert to ASCII byte: int(a[5] + b[5] + c[6]).

Decoding the resulting bytes gives:

So, you found the hidden message.
There is lots of room here for a long message, but we only need very little space to say "look at grandpa", so the rest is just garbage.

The keyword is grandpa.

Python

with open("yankeedoodle.csv") as f:
    raw = f.read().replace("\n", "").split(",")
    numbers = [x.strip() for x in raw if x.strip()]

# Process in triplets
result = []
for i in range(0, len(numbers) - 2, 3):
    a, b, c = numbers[i], numbers[i + 1], numbers[i + 2]
    val = int(a[5] + b[5] + c[6])
    result.append(val)

msg = bytes(result).decode(errors="ignore")
print(msg[:150])
# 'So, you found the hidden message.\nThere is lots of room here for a long message, but we only need very little space to say "look at grandpa"...'

Go

package main

import (
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	content, err := os.ReadFile("yankeedoodle.csv")
	if err != nil {
		panic(err)
	}

	raw := strings.ReplaceAll(string(content), "\n", "")
	tokens := strings.Split(raw, ",")

	var numbers []string
	for _, t := range tokens {
		trimmed := strings.TrimSpace(t)
		if trimmed != "" {
			numbers = append(numbers, trimmed)
		}
	}

	var message []byte
	for i := 0; i+2 < len(numbers); i += 3 {
		a, b, c := numbers[i], numbers[i+1], numbers[i+2]
		if len(a) > 5 && len(b) > 5 && len(c) > 6 {
			d1 := a[5] - '0'
			d2 := b[5] - '0'
			d3 := c[6] - '0'
			val := int(d1)*100 + int(d2)*10 + int(d3)
			if val < 256 {
				message = append(message, byte(val))
			}
		}
	}

	fmt.Printf("Message: %.120s...\n", string(message))
}

Rust

use std::fs;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let content = fs::read_to_string("yankeedoodle.csv")?;
    let numbers: Vec<&str> = content
        .split(|c| c == ',' || c == '\n' || c == '\r')
        .map(|s| s.trim())
        .filter(|s| !s.is_empty())
        .collect();

    let mut message = Vec::new();

    for chunk in numbers.chunks_exact(3) {
        let (a, b, c) = (chunk[0].as_bytes(), chunk[1].as_bytes(), chunk[2].as_bytes());
        if a.len() > 5 && b.len() > 5 && c.len() > 6 {
            let d1 = a[5] - b'0';
            let d2 = b[5] - b'0';
            let d3 = c[6] - b'0';
            let val = (d1 as u16) * 100 + (d2 as u16) * 10 + (d3 as u16);
            if val < 256 {
                message.push(val as u8);
            }
        }
    }

    let text = String::from_utf8_lossy(&message);
    println!("Message: {:.120}...", text);
    Ok(())
}

Language Comparison

Feature Python Go Rust
CSV / String Parsing split(',') with list comprehension strings.Split + strings.TrimSpace Split pattern iterator .split(|c| ...)
Character Arithmetic String slicing int(a[5] + b[5] + c[6]) parses via string conversion Byte arithmetic (a[5]-'0')*100 + ... avoids string allocations Direct ASCII byte arithmetic with as_bytes()
Triplet Chunking Step by 3 slice: range(0, len, 3) Loop step: i += 3 chunks_exact(3) iterator

Key insight: In Go and Rust, avoiding string conversions by computing the decimal value directly from ASCII digit bytes ((b - '0')) is both clean and orders of magnitude faster than string slicing and strconv.Atoi.

Next Level

The message says "look at grandpa":

http://www.pythonchallenge.com/pc/ring/grandpa.html