Python Challenge - Level 0

Problem

Hint: try to change the URL address.

The image shows 2^38 on a calculator screen. The goal is to compute 2^38 and replace 0 in the URL with the result.

Solution

Python

Python handles arbitrarily large integers seamlessly in its standard integer type:

result = 2 ** 38
print(result)
# 274877906944

Alternatively, bit-shifting or pow():

print(1 << 38)
print(pow(2, 38))

Go

Go integers have fixed width (int is 32 or 64 bits depending on the architecture). 2^38 ≈ 2.74 × 10¹¹, which exceeds 32 bits (2^31 - 1 ≈ 2.14 × 10⁹) but fits comfortably within a signed 64-bit integer (int64 max ≈ 9.22 × 10¹⁸):

package main

import (
	"fmt"
	"math/big"
)

func main() {
	// 1. Bit shift with explicit 64-bit integer
	fmt.Println(int64(1) << 38)

	// 2. Arbitrary-precision with math/big (equivalent to Python's int behavior)
	bigVal := new(big.Int).Exp(big.NewInt(2), big.NewInt(38), nil)
	fmt.Println(bigVal)
}

Rust

Rust provides explicit fixed-size primitive types. Attempting 1 << 38 on a 32-bit integer would fail to compile or panic on overflow:

fn main() {
	// 1. Explicit 64-bit integer exponentiation
	let val = 2u64.pow(38);
	println!("{val}");

	// 2. Bit shift with typed literal
	let shifted = 1u64 << 38;
	println!("{shifted}");
}

Language Comparison

Feature Python Go Rust
Large Integers Transparent arbitrary precision (int grows automatically) Fixed-width types (int32, int64); math/big in stdlib for arbitrary precision Fixed-width types (i32, u64, u128); num-bigint crate for arbitrary precision
Power Operator / Method 2 ** 38 or pow(2, 38) math.Pow(2, 38) (floats) or big.Int.Exp 2u64.pow(38)
Bit Shift Safety 1 << 38 automatically allocates larger limbs 1 << 38 defaults to untyped int (evaluated at compile time); int32(1) << 38 overflows Typed: 1u32 << 38 is a compile error; 1u64 << 38 is valid
REPL / Scripting Instant evaluation in Python REPL Requires go run or playground Requires cargo run or evcxr REPL

Key insight: Python's unified int type (which merged int and long in Python 3) abstracts away word boundaries and integer overflows completely. Systems languages like Go and Rust require the developer to make deliberate choices about integer width (int64/u64) or explicitly opt into heap-allocated big integers.

Next Level

Replace 0 with 274877906944 in the URL:

http://www.pythonchallenge.com/pc/def/274877906944.html

Which redirects to:

http://www.pythonchallenge.com/pc/def/map.html