Posts tagged racket

Advent of Code 2022 - Day 1: Calorie Counting

:: programming, puzzle, racket

Each day will have some preliminary setup code:

1
2
3
#lang iracket/lang #:require racket
(require "../advent.rkt")
(require threading)

Day 1 - Part 1

We’re given the following sample data:

1000
2000
3000

4000

5000
6000

7000
8000
9000

10000

This list represents the Calories of the food carried by five Elves:

  • The first Elf is carrying food with 1000, 2000, and 3000 Calories, a total of 6000 Calories.
  • The second Elf is carrying one food item with 4000 Calories.
  • The third Elf is carrying food with 5000 and 6000 Calories, a total of 11000 Calories.
  • The fourth Elf is carrying food with 7000, 8000, and 9000 Calories, a total of 24000 Calories.
  • The fifth Elf is carrying one food item with 10000 Calories.

Find the Elf carrying the most Calories. How many total Calories is that Elf carrying?

Plotting in a Racket Notebook

:: programming, racket

I recently started experimenting with the Racket notebook package, IRacket. Notebooks are handy for experimentation and visualization, so I wanted to be able to display a plot. I discovered that (require plot) did not work, but if I changed that slightly to (require plot/pict), I was able to display a plot in the notebook.

Advent of Code 2022 - Day 0 - Preparation

:: programming, racket, puzzle

Table of Contents

Now that I have a couple years experience with Advent of Code, I’d like to get a little more organized prior to the contest. I’m hoping to create a blog post for most of the days, and I think I’ll make use of Ryan Culpepper’s IRacket package this year. IRacket allows creating Jupyter notebooks, and by exporting them as markdown files, they can be copy/pasted directly into a Frog static site generator file for a blog post. I thought about using only a notebook this year, but I think I would miss having a clutter-free version of just the code.

Advent of Code 2022

:: programming, racket, python, javascript, puzzle

Advent of Code 2022 will start on December 1. This will be my third year, after participating in 2021 and 2020.

I hope to have time to code all of the solutions in Racket, my favorite programming language, and I should be able to translate some of them into Python and/or Javascript as a learning exercise.

My primary goal is to create an elegant Racket solution for each day’s puzzle that is clear, commented and tested. For some of the days, I may also create variants that emphasize performance or conciseness.

Programming Language Popularity - Part Thirteen

:: programming, c, clojure, common lisp, elixir, haskell, julia, lisp, ocaml, prolog, racket, ruby, rust, scheme

I occasionally compile some statistics on programming language popularity by running a bunch of Google searches to rank programming languages according to the number of results. I wouldn’t read too much into these stats, but they are not without value.

This time, I’ve included the code I use (written in Racket) and the raw data.

I made the following Google searches and summed the results:

"implemented in <lang>"
"written in <lang>"
"developed in <lang>"
"programmed in <lang>"

How to Write a Spelling Corrector in Racket

:: programming, racket

In September, 2008, I translated Peter Norvig’s spelling corrector into Ruby. My current favorite language is Racket, so I thought it would be a good exercise to port it to Racket. After some helpful tips by Vincent St-Amour and Sam Tobin-Hochstadt in the #racket IRC channel, I came up with the following. I’ll show it two different ways, the first minimizes the line count (without sacrificing too much stylistically) to 27 lines, and the second is closer to how I’d normally format it: