pharo-copilot (Qwen2.5-Coder)
Collection
This is a collection for all the model trained and fine tuned on code completion tasks • 19 items • Updated • 1
pharo_task string | pharo_canonical_solution string | task_id string | pharo_tests string | task_name string |
|---|---|---|---|---|
luhn: aString
"Given a number determine whether or not it is valid per the Luhn formula.
The Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers.
The task is to check if a given string is valid.
S... | luhn: aString
"Given a number determine whether or not it is valid per the Luhn formula.
The Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers.
The task is to check if a given string is valid.
S... | 1 | testLuhn
self assert: (task luhn: '1') equals: false.
self assert: (task luhn: '0') equals: false.
self assert: (task luhn: '059') equals: true.
self assert: (task luhn: '59') equals: true.
self assert: (task luhn: '055 444 285') equals: true.
self assert: (task luhn: '055 444 286') equals: false.
self asse... | Luhn |
wordSearch: words grid: grid
"In word search puzzles you get a square of letters and have to find specific words in them.
Words can be hidden in all kinds of directions: left-to-right, right-to-left, vertical and diagonal.
Given a puzzle and a list of words return the location of the first and last letter of ea... | wordSearch: words grid: grid
"In word search puzzles you get a square of letters and have to find specific words in them.
Words can be hidden in all kinds of directions: left-to-right, right-to-left, vertical and diagonal.
Given a puzzle and a list of words return the location of the first and last letter of ea... | 2 | testWordSearch
| result |
"01 Should accept an initial game grid and a target search word"
result := task wordSearch: #('clojure') grid: #('jefblpepre').
self assert: (result at: 'clojure' ifAbsent: [ nil ]) isNil.
"02 Should locate one word written left to right"
result := task wordSearch: #('clojure') gri... | WordSearch |
twelveDays: start endVerse: end
"Your task in this exercise is to write code that returns the lyrics of the song: `The Twelve Days of Christmas.`
The Twelve Days of Christmas is a common English Christmas carol.
Each subsequent verse of the song builds on the previous verse.
The lyrics your code returns sho... | twelveDays: start endVerse: end
"Your task in this exercise is to write code that returns the lyrics of the song: `The Twelve Days of Christmas.`
The Twelve Days of Christmas is a common English Christmas carol.
Each subsequent verse of the song builds on the previous verse.
The lyrics your code returns sho... | 3 | testTwelveDays
self assert: (task twelveDays: 1 endVerse: 1) equals: #('On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.').
self assert: (task twelveDays: 2 endVerse: 2) equals: #('On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tre... | TwelveDays |
acronym: aString
"Convert a phrase to its acronym.
Techies love their TLA (Three Letter Acronyms)!
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other ... | acronym: aString
"Convert a phrase to its acronym.
Techies love their TLA (Three Letter Acronyms)!
Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).
Punctuation is handled as follows: hyphens are word separators (like whitespace); all other ... | 4 | testAcronym
self assert: (task acronym: 'Portable Network Graphics') equals: 'PNG'.
self assert: (task acronym: 'Ruby on Rails') equals: 'ROR'.
self assert: (task acronym: 'First In, First Out') equals: 'FIFO'.
self assert: (task acronym: 'GNU Image Manipulation Program') equals: 'GIMP'.
self assert: (task acro... | Acronym |
clockHour: hourInteger minute: minuteInteger
"Implement a clock that handles times without dates."
"(self new clockHour: 8 minute: 0) >>> '08:00'"
"(self new clockHour: 11 minute: 9) >>> '11:09'"
"(self new clockHour: -1 minute: 15) >>> '23:15'"
| clockHour: hourInteger minute: minuteInteger
"Implement a clock that handles times without dates."
"(self new clockHour: 8 minute: 0) >>> '08:00'"
"(self new clockHour: 11 minute: 9) >>> '11:09'"
"(self new clockHour: -1 minute: 15) >>> '23:15'"
| totalMinutes hour minute |
totalMinutes := (hourInteger * 60 + minu... | 5 | testClock
"Create a new clock with an initial time - on the hour"
self assert: (task clockHour: 8 minute: 0) equals: '08:00'.
"Create a new clock with an initial time - past the hour"
self assert: (task clockHour: 11 minute: 9) equals: '11:09'.
"Create a new clock with an initial time - midnight is zero hours"
... | ClockHour |
isbnVerifier: aString
"Given a string the program should check if the provided string is a valid ISBN-10.
The ISBN-10 verification process is used to validate book identification numbers.
These normally contain dashes and look like: 3-598-21508-8
The ISBN-10 format is 9 digits (0 to 9) plus one check charac... | isbnVerifier: aString
"Given a string the program should check if the provided string is a valid ISBN-10.
The ISBN-10 verification process is used to validate book identification numbers.
These normally contain dashes and look like: 3-598-21508-8
The ISBN-10 format is 9 digits (0 to 9) plus one check charac... | 6 | testIsbnVerifier
self assert: (task isbnVerifier: '3-598-21508-8') equals: true.
self assert: (task isbnVerifier: '3-598-21508-9') equals: false.
self assert: (task isbnVerifier: '3-598-21507-X') equals: true.
self assert: (task isbnVerifier: '3-598-21507-A') equals: false.
self assert: (task isbnVerifier: '3-5... | IsbnVerifier |
circularBuffer
"A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
A circular buffer first starts empty and of some predefined length. For example, this is a 7-element buffer:
[ ][ ][ ][ ][ ][ ][ ]
Assume that a 1 is writte... | circularBuffer
"A circular buffer, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
A circular buffer first starts empty and of some predefined length. For example, this is a 7-element buffer:
[ ][ ][ ][ ][ ][ ][ ]
Assume that a 1 is writte... | 7 | testCircularBuffer
| buf result |
"reading empty buffer should fail"
buf := task circularBuffer.
(buf at: #capacity:) value: 1.
self should: [ (buf at: #read) value ] raise: Error.
"can read an item just written"
buf := task circularBuffer.
(buf at: #capacity:) value: 1.
(buf at: #write:) value: 1.
... | CircularBuffer |
flattenArray: aCollection
"Take a nested list and return a single flattened list with all values except nil.
The challenge is to write a function that accepts an arbitrarily-deep nested list-like structure and returns a flattened structure without any nil values."
"(self new flattenArray: #(1 #(2 3 nil 4) #(nil) 5)... | flattenArray: aCollection
"Take a nested list and return a single flattened list with all values except nil.
The challenge is to write a function that accepts an arbitrarily-deep nested list-like structure and returns a flattened structure without any nil values."
"(self new flattenArray: #(1 #(2 3 nil 4) #(nil) 5)... | 8 | testFlattenArray
self assert: (task flattenArray: #(0 1 2)) equals: #(0 1 2).
self assert: (task flattenArray: #(1 #(2 3 4 5 6 7) 8)) equals: #(1 2 3 4 5 6 7 8).
self assert: (task flattenArray: #(0 2 #(#(2 3) 8 100 4 #(#(#(50))) ) -2)) equals: #(0 2 2 3 8 100 4 50 -2).
self assert: (task flattenArray: #(1 #(2 #(... | FlattenArray |
allYourBaseInputBase: inputBase digits: digitsArray outputBase: outputBase
"Convert a sequence of digits in one base, representing a number, into a sequence of digits in another base, representing the same number.
Try to implement the conversion yourself.
Do not use something else to perform the conversion for ... | allYourBaseInputBase: inputBase digits: digitsArray outputBase: outputBase
"Convert a sequence of digits in one base, representing a number, into a sequence of digits in another base, representing the same number.
Try to implement the conversion yourself.
Do not use something else to perform the conversion for ... | 9 | testAllYourBase
| result |
result := (task allYourBaseInputBase: 2 digits: #(1) outputBase: 10).
self assert: result equals: #(1).
result := (task allYourBaseInputBase: 2 digits: #(1 0 1) outputBase: 10).
self assert: result equals: #(5).
result := (task allYourBaseInputBase: 10 digits: #(5) outputBase: 2).... | AllYourBaseInputBase |
anagram: aCollectionOfWords subject: aString
"Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target.
An anagram is a rearrangement of letters to form a new word. A word is not its own anagram.
The target and candidates are words ... | anagram: aCollectionOfWords subject: aString
"Your task is to, given a target word and a set of candidate words, to find the subset of the candidates that are anagrams of the target.
An anagram is a rearrangement of letters to form a new word. A word is not its own anagram.
The target and candidates are words ... | 10 | testAnagram
self assert: (task anagram: #('hello' 'world' 'zombies' 'pants') subject: 'diaper') equals: #().
self assert: (task anagram: #('stream' 'pigeon' 'maters') subject: 'master') equals: #('stream' 'maters').
self assert: (task anagram: #('dog' 'goody') subject: 'good') equals: #().
self assert: (task anag... | Anagram |
resistorColorDuo: colours
"If you want to build something using a Raspberry Pi, you'll probably use resistors.
For this exercise, you need to know two things about them:
- Each resistor has a resistance value.
- Resistors are small - so small in fact that if you printed the resistance value on them, it woul... | resistorColorDuo: colours
"If you want to build something using a Raspberry Pi, you'll probably use resistors.
For this exercise, you need to know two things about them:
- Each resistor has a resistance value.
- Resistors are small - so small in fact that if you printed the resistance value on them, it woul... | 11 | testResistorColorDuo
self assert: (task resistorColorDuo: #('brown' 'black')) equals: 10.
self assert: (task resistorColorDuo: #('blue' 'grey')) equals: 68.
self assert: (task resistorColorDuo: #('yellow' 'violet')) equals: 47.
self assert: (task resistorColorDuo: #('white' 'red')) equals: 92.
self assert: (tas... | ResistorColorDuo |
rectangles: lines
"Count the rectangles in an ASCII diagram.
You may assume that the input is always a proper rectangle (i.e. the length of every line equals the length of the first line)."
"(self new rectangles: #(' +--+' ' ++ |' '+-++--+' '| | |' '+--+--+')) >>> 6"
| rectangles: lines
"Count the rectangles in an ASCII diagram.
You may assume that the input is always a proper rectangle (i.e. the length of every line equals the length of the first line)."
"(self new rectangles: #(' +--+' ' ++ |' '+-++--+' '| | |' '+--+--+')) >>> 6"
| h w count plusColsByRow |
lines isEmpty... | 12 | testRectangles
self assert: (task rectangles: #()) equals: 0.
self assert: (task rectangles: #('')) equals: 0.
self assert: (task rectangles: #(' ')) equals: 0.
self assert: (task rectangles: #('+-+' '| |' '+-+')) equals: 1.
self assert: (task rectangles: #(' +-+' ' | |' '+-+-+' '| | ' '+-+ ')) equals: 2.
... | Rectangles |
robotSimulator: facing atPosition: aPoint instructions: instructionsString
"Write a robot simulator.
A robot factory's test facility needs a program to verify robot movements.
The robots have three possible movements:
- turn right
- turn left
- advance
Robots are placed on a hypothetical infinit... | robotSimulator: facing atPosition: aPoint instructions: instructionsString
"Write a robot simulator.
A robot factory's test facility needs a program to verify robot movements.
The robots have three possible movements:
- turn right
- turn left
- advance
Robots are placed on a hypothetical infinit... | 13 | testRobotSimulator
self
assert: (task
robotSimulator: 'north'
atPosition: 0 @ 0
instructions: '')
equals: (Dictionary new
add: 'direction' -> 'north';
add: 'position' -> (0 @ 0);
yourself).
self
assert: (task
robotSimulator: 'south'
atPosition: -1 @ -1
instructions: ... | RobotSimulator |
bowling: rolls
"Score a bowling game.
Bowling is a game where players roll a heavy ball to knock down pins arranged in a triangle.
Write code to keep track of the score of a game of bowling.
Scoring Bowling:
The game consists of 10 frames. A frame is composed of one or two ball throws with 10 pins stan... | bowling: rolls
"Score a bowling game.
Bowling is a game where players roll a heavy ball to knock down pins arranged in a triangle.
Write code to keep track of the score of a game of bowling.
Scoring Bowling:
The game consists of 10 frames. A frame is composed of one or two ball throws with 10 pins stan... | 14 | testBowling
"Scoring and validation tests for bowling"
"01 Should be able to score a game with all zeros"
self assert: (task bowling: #(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) equals: 0.
"02 Should be able to score a game with no strikes or spares"
self assert: (task bowling: #(3 6 3 6 3 6 3 6 3 6 3 6 3 6 3 6 3 ... | Bowling |
hamming: strand1 strand2: strand2
"Calculate the Hamming Distance between two DNA strands.
Your body is made up of cells that contain DNA.
Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells.
In fact, the average human body experiences about 10 quadrillion c... | hamming: strand1 strand2: strand2
"Calculate the Hamming Distance between two DNA strands.
Your body is made up of cells that contain DNA.
Those cells regularly wear out and need replacing, which they achieve by dividing into daughter cells.
In fact, the average human body experiences about 10 quadrillion c... | 15 | testHamming
self assert: (task hamming: '' strand2: '') equals: 0.
self assert: (task hamming: 'A' strand2: 'A') equals: 0.
self assert: (task hamming: 'G' strand2: 'T') equals: 1.
self assert: (task hamming: 'GGACTGAAATCTG' strand2: 'GGACTGAAATCTG') equals: 0.
self assert: (task hamming: 'GGACGGATTCTG' strand2... | Hamming |
matchingBrackets: aString
"Given a string containing brackets `[]`, braces `{}`, parentheses `()`, or any combination thereof, verify that any and all pairs are matched and nested correctly.
The string may also contain other characters, which for the purposes of this exercise should be ignored."
"(self new matchingBra... | matchingBrackets: aString
"Given a string containing brackets `[]`, braces `{}`, parentheses `()`, or any combination thereof, verify that any and all pairs are matched and nested correctly.
The string may also contain other characters, which for the purposes of this exercise should be ignored."
"(self new matchingBra... | 16 | testMatchingBrackets
self assert: (task matchingBrackets: '[]') equals: true.
self assert: (task matchingBrackets: '') equals: true.
self assert: (task matchingBrackets: '[[') equals: false.
self assert: (task matchingBrackets: '}{') equals: false.
self assert: (task matchingBrackets: '{]') equals: false.
sel... | MatchingBrackets |
highScores: anArray
"Manage a game player's High Score list.
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era.
Your task is to write a method that return the highest score from the list, the... | highScores: anArray
"Manage a game player's High Score list.
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era.
Your task is to write a method that return the highest score from the list, the... | 17 | testHighScores
| result topThree |
"List of scores"
result := task highScores: #(30 50 20 70).
"Latest score"
result := task highScores: #(100 0 90 30).
self assert: (result at: #latestScore) equals: 30.
"Personal best"
result := task highScores: #(40 100 70).
self assert: (result at: #bestScore) equ... | HighScores |
wordCount: aString
"Your task is to count how many times each word occurs in a subtitle of a drama.
The subtitles from these dramas use only ASCII characters.
The characters often speak in casual English, using contractions like they're or it's.
Though these contractions come from two words (e.g. we are), t... | wordCount: aString
"Your task is to count how many times each word occurs in a subtitle of a drama.
The subtitles from these dramas use only ASCII characters.
The characters often speak in casual English, using contractions like they're or it's.
Though these contractions come from two words (e.g. we are), t... | 18 | testWordCount
| result |
result := task wordCount: 'word'.
self assert: result equals: ((Dictionary new) add: ('word'->1); yourself).
result := task wordCount: 'one of each'.
self assert: result equals: ((Dictionary new) add: ('of'->1); add: ('each'->1); add: ('one'->1); yourself).
result := task wordCount... | WordCount |
minesweeper: aMinefield
"Your task is to add the mine counts to empty squares in a completed Minesweeper board.
The board itself is a rectangle composed of squares that are either empty (' ') or a mine ('*').
For each empty square, count the number of mines adjacent to it (horizontally, vertically, diagonally).... | minesweeper: aMinefield
"Your task is to add the mine counts to empty squares in a completed Minesweeper board.
The board itself is a rectangle composed of squares that are either empty (' ') or a mine ('*').
For each empty square, count the number of mines adjacent to it (horizontally, vertically, diagonally).... | 19 | testMinesweeper
self assert: (task minesweeper: #()) equals: #().
self assert: (task minesweeper: #('')) equals: #('').
self assert: (task minesweeper: #(' ' ' ' ' ')) equals: #(' ' ' ' ' ').
self assert: (task minesweeper: #('***' '***' '***')) equals: #('***' '***' '***').
self assert: (task mines... | Minesweeper |
armstrongNumbers: anInteger
"An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. Write some code to determine whether a number is an Armstrong number."
"(self new armstrongNumbers: 9) >>> true"
"(self new armstrongNumbers: 10) >>> false"
"(self new armstro... | armstrongNumbers: anInteger
"An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. Write some code to determine whether a number is an Armstrong number."
"(self new armstrongNumbers: 9) >>> true"
"(self new armstrongNumbers: 10) >>> false"
"(self new armstro... | 20 | testArmstrongNumbers
self assert: (task armstrongNumbers: 5) equals: true.
self assert: (task armstrongNumbers: 10) equals: false.
self assert: (task armstrongNumbers: 153) equals: true.
self assert: (task armstrongNumbers: 100) equals: false.
self assert: (task armstrongNumbers: 9474) equals: true.
self asse... | ArmstrongNumbers |
sieve: limit
"Your task is to create a program that implements the Sieve of Eratosthenes algorithm to find all prime numbers less than or equal to a given number.
A prime number is a number larger than 1 that is only divisible by 1 and itself.
To use the Sieve of Eratosthenes, you first create a list of all the... | sieve: limit
"Your task is to create a program that implements the Sieve of Eratosthenes algorithm to find all prime numbers less than or equal to a given number.
A prime number is a number larger than 1 that is only divisible by 1 and itself.
To use the Sieve of Eratosthenes, you first create a list of all the... | 22 | testSieve
self assert: (task sieve: 1) equals: #().
self assert: (task sieve: 2) equals: #(2).
self assert: (task sieve: 10) equals: #(2 3 5 7).
self assert: (task sieve: 13) equals: #(2 3 5 7 11 13).
self assert: (task sieve: 1000) equals: #(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 9... | Sieve |
ocrNumbers: rows
"Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
1. To begin with, convert a simple binary font to a string containing 0 or 1.
The binary font uses pipes and underscores, four rows high and three columns wide.
If... | ocrNumbers: rows
"Given a 3 x 4 grid of pipes, underscores, and spaces, determine which number is represented, or whether it is garbled.
1. To begin with, convert a simple binary font to a string containing 0 or 1.
The binary font uses pipes and underscores, four rows high and three columns wide.
If... | 23 | testOcrNumbers
| result |
result := (task ocrNumbers: #(' _ ' '| |' '|_|' ' ')).
self assert: result equals: '0'.
result := (task ocrNumbers: #(' ' ' |' ' |' ' ')).
self assert: result equals: '1'.
result := (task ocrNumbers: #(' ' ' _' ' |' ' ')).
self assert: result equals: '?'.
self
... | OcrNumbers |
etl: tileDictionary
"Your task is to change the data format of letters and their point values in the game.
Currently, letters are stored in groups based on their score, in a one-to-many mapping.
- 1 point: A, E, I, O, U, L, N, R, S, T,
- 2 points: D, G,
- 3 points: B, C, M, P,
- 4 points: F, H, V, W... | etl: tileDictionary
"Your task is to change the data format of letters and their point values in the game.
Currently, letters are stored in groups based on their score, in a one-to-many mapping.
- 1 point: A, E, I, O, U, L, N, R, S, T,
- 2 points: D, G,
- 3 points: B, C, M, P,
- 4 points: F, H, V, W... | 24 | testEtl
self assert: (task etl: ((Dictionary new) add: ('1'->#('A' )); yourself)) equals: ((Dictionary new) add: ('a'->1); yourself).
self assert: (task etl: ((Dictionary new) add: ('1'->#('A' 'E' 'I' 'O' 'U' )); yourself)) equals: ((Dictionary new) add: ('i'->1); add: ('e'->1); add: ('a'->1); add: ('u'->1); add: ('o... | Etl |
spaceAge: aPlanet at: aSeconds
"Given an age in seconds, calculate how old someone would be on:
- Mercury: orbital period 0.2408467 Earth years
- Venus: orbital period 0.61519726 Earth years
- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
- Mars: orbital period 1.8808158 ... | spaceAge: aPlanet at: aSeconds
"Given an age in seconds, calculate how old someone would be on:
- Mercury: orbital period 0.2408467 Earth years
- Venus: orbital period 0.61519726 Earth years
- Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds
- Mars: orbital period 1.8808158 ... | 25 | testSpaceAge
self assert: ((task spaceAge: 'Earth' at: 1000000000) roundTo: 1 / 100) asFloat equals: 31.69.
self assert: ((task spaceAge: 'Mercury' at: 2134835688) roundTo: 1 / 100) asFloat equals: 280.88.
self assert: ((task spaceAge: 'Venus' at: 189839836) roundTo: 1 / 100) asFloat equals: 9.78.
self assert: ((... | SpaceAge |
romanNumerals: anInteger
"Your task is to convert a number from Arabic numerals to Roman numerals.
For this exercise, we are only concerned about traditional Roman numerals, in which the largest number is MMMCMXCIX (or 3,999)."
"(self new romanNumerals: 1) >>> 'I'"
"(self new romanNumerals: 104) >>> 'CIV'"
"(self n... | romanNumerals: anInteger
"Your task is to convert a number from Arabic numerals to Roman numerals.
For this exercise, we are only concerned about traditional Roman numerals, in which the largest number is MMMCMXCIX (or 3,999)."
"(self new romanNumerals: 1) >>> 'I'"
"(self new romanNumerals: 104) >>> 'CIV'"
"(self n... | 26 | testRomanNumerals
self assert: (task romanNumerals: 1) equals: 'I'.
self assert: (task romanNumerals: 2) equals: 'II'.
self assert: (task romanNumerals: 3) equals: 'III'.
self assert: (task romanNumerals: 4) equals: 'IV'.
self assert: (task romanNumerals: 5) equals: 'V'.
self assert: (task romanNumerals: 6) e... | RomanNumerals |
forth: instructions
"Implement an evaluator for a very simple subset of Forth.
Forth is a stack-based programming language. Implement a very basic evaluator for a small subset of Forth.
Your evaluator has to support the following words:
- `+`, `-`, `*`, `/` (integer arithmetic)
- `DUP`, `DROP`, `SWAP`, ... | forth: instructions
"Implement an evaluator for a very simple subset of Forth.
Forth is a stack-based programming language. Implement a very basic evaluator for a small subset of Forth.
Your evaluator has to support the following words:
- `+`, `-`, `*`, `/` (integer arithmetic)
- `DUP`, `DROP`, `SWAP`, ... | 27 | testForth
| result |
result := task forth: #('1 2 3 4 5').
self assert: result equals: #(1 2 3 4 5).
result := task forth: #('1 2 +').
self assert: result equals: #(3).
self
should: [ result := task forth: #('+') ]
raise: Error.
self
should: [ result := task forth: #('1 +') ]
raise: Erro... | Forth |
reverseString: aString
"Your task is to reverse a given string."
"(self new reverseString: 'stressed') >>> 'desserts'"
"(self new reverseString: 'strops') >>> 'sports'"
"(self new reverseString: 'racecar') >>> 'racecar'"
| reverseString: aString
"Your task is to reverse a given string."
"(self new reverseString: 'stressed') >>> 'desserts'"
"(self new reverseString: 'strops') >>> 'sports'"
"(self new reverseString: 'racecar') >>> 'racecar'"
^ String streamContents: [:stream |
aString size to: 1 by: -1 do: [:i |
stream ... | 28 | testReverseString
self assert: (task reverseString: '') equals: ''.
self assert: (task reverseString: 'robot') equals: 'tobor'.
self assert: (task reverseString: 'Ramen') equals: 'nemaR'.
self assert: (task reverseString: 'I''m hungry!') equals: '!yrgnuh m''I'.
self assert: (task reverseString: 'racecar') equal... | ReverseString |
dartsX: x y: y
"Calculate the points scored in a single toss of a Darts game.
Darts is a game where players throw darts at a target.
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
- If the dart lands outside the target, player ear... | dartsX: x y: y
"Calculate the points scored in a single toss of a Darts game.
Darts is a game where players throw darts at a target.
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
- If the dart lands outside the target, player ear... | 29 | testDarts
self assert: (task dartsX: -9 y: 9) equals: 0.
self assert: (task dartsX: 0 y: 10) equals: 1.
self assert: (task dartsX: -5 y: 0) equals: 5.
self assert: (task dartsX: 0 y: -1) equals: 10.
self assert: (task dartsX: 0 y: 0) equals: 10.
self assert: (task dartsX: -0.1 y: -0.1) equals: 10.
self asse... | DartsX |
collatzConjecture: n
"The Collatz Conjecture or 3x+1 problem can be summarized as follows:
Take any positive integer n. If n is even, divide n by 2 to get n / 2.
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
Repeat the process indefinitely. The conjecture states that no matter which number you start... | collatzConjecture: n
"The Collatz Conjecture or 3x+1 problem can be summarized as follows:
Take any positive integer n. If n is even, divide n by 2 to get n / 2.
If n is odd, multiply n by 3 and add 1 to get 3n + 1.
Repeat the process indefinitely. The conjecture states that no matter which number you start... | 30 | testCollatzConjecture
self assert: (task collatzConjecture: 1) equals: 0.
self assert: (task collatzConjecture: 16) equals: 4.
self assert: (task collatzConjecture: 12) equals: 9.
self assert: (task collatzConjecture: 1000000) equals: 152.
self
should: [ task collatzConjecture: 0 ]
raise: Error.
self
... | CollatzConjecture |
leap: aYear
"Your task is to determine whether a given year is a leap year.
A leap year (in the Gregorian calendar) occurs:
- In every year that is evenly divisible by 4.
- Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400"
"(self new... | leap: aYear
"Your task is to determine whether a given year is a leap year.
A leap year (in the Gregorian calendar) occurs:
- In every year that is evenly divisible by 4.
- Unless the year is evenly divisible by 100, in which case it's only a leap year if the year is also evenly divisible by 400"
"(self new... | 33 | testLeap
self assert: (task leap: 2015) equals: false.
self assert: (task leap: 1970) equals: false.
self assert: (task leap: 1996) equals: true.
self assert: (task leap: 2100) equals: false.
self assert: (task leap: 2000) equals: true.
self assert: (task leap: 1800) equals: false.
| Leap |
pangram: aString
"Your task is to figure out if a sentence is a pangram.
A pangram is a sentence using every letter of the alphabet at least once.
It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. k) or upper-case (e.g. K).
For this exercise, a sentence is a pangram if it contains... | pangram: aString
"Your task is to figure out if a sentence is a pangram.
A pangram is a sentence using every letter of the alphabet at least once.
It is case insensitive, so it doesn't matter if a letter is lower-case (e.g. k) or upper-case (e.g. K).
For this exercise, a sentence is a pangram if it contains... | 34 | testPangram
self assert: (task pangram: '') equals: false.
self assert: (task pangram: 'abcdefghijklmnopqrstuvwxyz') equals: true.
self assert: (task pangram: 'the quick brown fox jumps over the lazy dog') equals: true.
self assert: (task pangram: 'a quick movement of the enemy will jeopardize five gunboats') equ... | Pangram |
raindrops: aNumber
"Your task is to convert a number into its corresponding raindrop sounds.
If a given number:
- is divisible by 3, add 'Pling' to the result.
- is divisible by 5, add 'Plang' to the result.
- is divisible by 7, add 'Plong' to the result.
- is not divisible by 3, 5, or 7, the result... | raindrops: aNumber
"Your task is to convert a number into its corresponding raindrop sounds.
If a given number:
- is divisible by 3, add 'Pling' to the result.
- is divisible by 5, add 'Plang' to the result.
- is divisible by 7, add 'Plong' to the result.
- is not divisible by 3, 5, or 7, the result... | 35 | testRaindrops
self assert: (task raindrops: 1) equals: '1'.
self assert: (task raindrops: 3) equals: 'Pling'.
self assert: (task raindrops: 5) equals: 'Plang'.
self assert: (task raindrops: 7) equals: 'Plong'.
self assert: (task raindrops: 6) equals: 'Pling'.
self assert: (task raindrops: 8) equals: '8'.
se... | Raindrops |
grains: arg
"Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would... | grains: arg
"Calculate the number of grains of wheat on a chessboard given that the number on each square doubles.
There once was a wise servant who saved the life of a prince.
The king promised to pay whatever the servant could dream up.
Knowing that the king loved chess, the servant told the king he would... | 36 | testGrains
self assert: (task grains: 1) equals: 1.
self assert: (task grains: 2) equals: 2.
self assert: (task grains: 3) equals: 4.
self assert: (task grains: 4) equals: 8.
self assert: (task grains: 16) equals: 32768.
self assert: (task grains: 32) equals: 2147483648.
self assert: (task grains: 64) equal... | Grains |
secretHandshake: anInteger
"Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake.
The sequence of actions is chosen by looking at the rightmost five digits of the number once it's been converted to binary. Start at the right-most digit and move left.
The actions for... | secretHandshake: anInteger
"Your task is to convert a number between 1 and 31 to a sequence of actions in the secret handshake.
The sequence of actions is chosen by looking at the rightmost five digits of the number once it's been converted to binary. Start at the right-most digit and move left.
The actions for... | 37 | testSecretHandshake
self assert: (task secretHandshake: 1) equals: #('wink').
self assert: (task secretHandshake: 2) equals: #('double blink').
self assert: (task secretHandshake: 4) equals: #('close your eyes').
self assert: (task secretHandshake: 8) equals: #('jump').
self assert: (task secretHandshake: 3) eq... | SecretHandshake |
sumOfMultiples: factors limit: level
"Your task is to write the code that calculates the energy points that get awarded to players when they complete a level.
The points awarded depend on two things:
- The level (a number) that the player completed.
- The base value of each magical item collected by the pla... | sumOfMultiples: factors limit: level
"Your task is to write the code that calculates the energy points that get awarded to players when they complete a level.
The points awarded depend on two things:
- The level (a number) that the player completed.
- The base value of each magical item collected by the pla... | 38 | testSumOfMultiples
self assert: (task sumOfMultiples: #(3 5) limit: 1) equals: 0.
self assert: (task sumOfMultiples: #(3 5) limit: 4) equals: 3.
self assert: (task sumOfMultiples: #(3) limit: 7) equals: 9.
self assert: (task sumOfMultiples: #(3 5) limit: 10) equals: 23.
self assert: (task sumOfMultiples: #(3 5)... | SumOfMultiples |
matrix: aString at: anIndex by: aSymbol
"Given a string representing a matrix of numbers, return the rows and columns of that matrix.
Your code should be able to spit out:
- A list of the rows, reading each row left-to-right while moving top-to-bottom across the rows,
- A list of the columns, reading each c... | matrix: aString at: anIndex by: aSymbol
"Given a string representing a matrix of numbers, return the rows and columns of that matrix.
Your code should be able to spit out:
- A list of the rows, reading each row left-to-right while moving top-to-bottom across the rows,
- A list of the columns, reading each c... | 39 | testMatrix
self assert: (task matrix: '1' at: 1 by: #row) equals: #(1).
self assert: (task matrix: '1 2
3 4' at: 2 by: #row) equals: #(3 4).
self assert: (task matrix: '1 2
10 20' at: 2 by: #row) equals: #(10 20).
self assert: (task matrix: '1 2 3
4 5 6
7 8 9
8 7 6' at: 3 by: #row) equals: #(7 8 9).
self assert... | Matrix |
allergies: score with: itemString
"Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).
The l... | allergies: score with: itemString
"Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
An allergy test produces a single numeric score which contains the information about all the allergies the person has (that they were tested for).
The l... | 40 | testAllergies
self assert: (task allergies: 0 with: 'peanuts') equals: false.
self assert: (task allergies: 0 with: 'cats') equals: false.
self assert: (task allergies: 0 with: 'strawberries') equals: false.
self assert: (task allergies: 1 with: 'eggs') equals: true.
self assert: (task allergies: 5 with: 'eggs'... | Allergies |
tournament: rowCollection
"Tally the results of a small football competition. Based on an input containing which team played against which and what the outcome was, return the table rows with the summary.
What do those abbreviations mean?
- MP: Matches Played
- W: Matches Won
- D: Matches Drawn (Tied)
... | tournament: rowCollection
"Tally the results of a small football competition. Based on an input containing which team played against which and what the outcome was, return the table rows with the summary.
What do those abbreviations mean?
- MP: Matches Played
- W: Matches Won
- D: Matches Drawn (Tied)
... | 41 | testTournament
| header |
header := 'Team | MP | W | D | L | P'.
self assert: (task tournament: #()) equals: #( 'Team | MP | W | D | L | P' ).
self assert: (task tournament: #('Allegoric Alaskans;Blithering Badgers;win')) equals: #( 'Team ... | Tournament |
twoFer: aName
"Your task is to determine what you will say as you give away the extra cookie.
If you know the person's name (e.g. if they're named Do-yun), then you will say: `One for Do-yun, one for me.`
If you don't know the person's name, you will say you instead: `One for you, one for me.`"
"(self new twoFe... | twoFer: aName
"Your task is to determine what you will say as you give away the extra cookie.
If you know the person's name (e.g. if they're named Do-yun), then you will say: `One for Do-yun, one for me.`
If you don't know the person's name, you will say you instead: `One for you, one for me.`"
"(self new twoFe... | 42 | testTwoFer
self assert: (task twoFer: 'Alice') equals: 'One for Alice, one for me.'.
self assert: (task twoFer: 'Bob') equals: 'One for Bob, one for me.'.
self assert: (task twoFer: nil) equals: 'One for you, one for me.'
| TwoFer |
atbashCipher: aString decode: isDecoding
"Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards. The first lett... | atbashCipher: aString decode: isDecoding
"Create an implementation of the atbash cipher, an ancient encryption system created in the Middle East.
The Atbash cipher is a simple substitution cipher that relies on transposing all the letters in the alphabet such that the resulting alphabet is backwards. The first lett... | 43 | testAtbashCipher
| result |
"Encode tests"
result := task atbashCipher: 'yes' decode: false.
self assert: result equals: 'bvh'.
result := task atbashCipher: 'no' decode: false.
self assert: result equals: 'ml'.
result := task atbashCipher: 'OMG' decode: false.
self assert: result equals: 'lnt'.
resu... | AtbashCipher |
binary: aString
"Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.
Implement binary to decimal conversion.
Given a binary input string, your program should produce a decimal output.
The program should handle invalid inputs.
Implement the ... | binary: aString
"Convert a binary number, represented as a string (e.g. '101010'), to its decimal equivalent using first principles.
Implement binary to decimal conversion.
Given a binary input string, your program should produce a decimal output.
The program should handle invalid inputs.
Implement the ... | 44 | testBinary
self assert: (task binary: '0') equals: 0.
self assert: (task binary: '1') equals: 1.
self assert: (task binary: '10') equals: 2.
self assert: (task binary: '11') equals: 3.
self assert: (task binary: '100') equals: 4.
self assert: (task binary: '1001') equals: 9.
self assert: (task binary: '1101... | Binary |
proverb: wordCollection
"For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
Given a list of inputs, generate the relevant proverb.
Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content.
No line of the output text should be a... | proverb: wordCollection
"For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
Given a list of inputs, generate the relevant proverb.
Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content.
No line of the output text should be a... | 45 | testProverb
self assert: (task proverb: #()) equals: #().
self assert: (task proverb: #('nail')) equals: #('And all for the want of a nail.').
self assert: (task proverb: #('nail' 'shoe')) equals: #('For want of a nail the shoe was lost.' 'And all for the want of a nail.').
self assert: (task proverb: #('nail' 's... | Proverb |