Mercurial > repos > other > SevenLanguagesInSevenWeeks
view 2-Io/day1-collections.io @ 101:1fae0cca1ef8
Reduce large maze to single width corridors
This reduces the permutations for
a x
x x
b x
To one (two steps north) from four (two steps north; one east, two north, one west; one east, one north, one west, one north; and one north, one east, one north, one west). Longer corridors were worse!
We would filter this in the "been here before via another path" but that's still a lot of lookups in lists, which is inefficient.
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 14 Jul 2019 13:42:24 +0100 |
parents | 4e1a659f8383 |
children |
line wrap: on
line source
# Io has Lists and Maps as collections toDos := list("Task 1", "Task 2") toDos size println # Calling a method with arguments is like most other languages toDos append("Task 3") toDos size println # Lists are like arrays and are zero-indexed list(1, 2, 3) at(1) println # Lists can act like stacks and queues list(1, 2, 3) prepend(0) println list(1, 2, 3) append(4) println list(1, 2, 3) push(4) println list(1, 2, 3) pop println list() isEmpty println # Lists can also do some basic maths list(1, 2, 3, 4) average println list(1, 2, 3, 4) sum println # Map is a prototype to be cloned rincewind := Map clone rincewind atPut("home", "Unseen University, Ankh Morpork") rincewind at("home") println rincewind atPut("job", "Wizzard") rincewind at("job") println # Maps can be turned in to objects with slots and lists (of (two-element) lists) rincewind asObject println rincewind asObject home println rincewind asList println # You can also pull keys from a map rincewind keys println