pharo-llm/pharo-exercism-benchmark huggingface dataset:
"Exercise: Matrix"

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 column top-to-bottom while moving from left-to-right."
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 1 by: #row) >>> #(9 8 7)"
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 2 by: #row) >>> #(5 3 2)"
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 3 by: #row) >>> #(6 6 7)"
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 1 by: #column) >>> #(9 5 6)"
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 2 by: #column) >>> #(8 3 6)"
"(self new matrix: '9 8 7', String lf, '5 3 2', String lf, '6 6 7' at: 3 by: #column) >>> #(7 2 7)"
| rows |
	rows := aString lines collect: [ :line | line parseLiterals ].
	(#( row column ) includes: aSymbol) ifFalse: [ ^ nil ].
	^ aSymbol = #column
		  ifTrue: [ (rows collect: [ :r | r at: anIndex ]) asArray ]
		  ifFalse: [ rows at: anIndex ]


"Tests"
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: (task matrix: '1' at: 1 by: #column) equals: #(1).
  self assert: (task matrix: '1 2 3
4 5 6
7 8 9' at: 3 by: #column) equals: #(3 6 9).
  self assert: (task matrix: '1 2 3
4 5 6
7 8 9
8 7 6' at: 3 by: #column) equals: #(3 6 9 6).
  self assert: (task matrix: '89 1903 3
18 3 1
9 4 800' at: 2 by: #column) equals: #(1903 3 4)
"Exercise: Allergies"

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 list of items (and their value) that were tested are:
    - eggs (1)
    - peanuts (2)
    - shellfish (4)
    - strawberries (8)
    - tomatoes (16)
    - chocolate (32)
    - pollen (64)
    - cats (128)
    Now, given just that score, your program should be able to say:
    - Whether the person is allergic to any one of those allergens listed above.
    - All the allergens the person is allergic to.
    Note: a given score may include allergens not listed above (i.e. allergens that score 256, 512, 1024, etc.). Your program should ignore those components of the score."
"(self new allergies: 2 with: 'peanuts') >>> true"
"(self new allergies: 34 with: nil) >>> #('peanuts' 'chocolate')"
"(self new allergies: 257 with: nil) >>> #('eggs')"
| items |
    items := #('eggs' 'peanuts' 'shellfish' 'strawberries'
               'tomatoes' 'chocolate' 'pollen' 'cats').

    itemString ifNil: [
        ^ items select: [:item | (score bitAt: (items indexOf: item)) = 1 ] ].

    (items includes: itemString) ifFalse: [
        ^ Error signal: 'Invalid food item: ', itemString ].

    ^ (score bitAt: (items indexOf: itemString)) = 1


"Tests"
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') equals: true.
  self assert: (task allergies: 5 with: 'shellfish') equals: true.
  self assert: (task allergies: 5 with: 'strawberries') equals: false.
  self assert: (task allergies: 9 with: 'peanuts') equals: false.
  self assert: (task allergies: 9 with: 'shellfish') equals: false.
  self assert: (task allergies: 9 with: 'eggs') equals: true.
  self assert: (task allergies: 9 with: 'strawberries') equals: true.

  self assert: (task allergies: 0 with: nil) equals: #().
  self assert: (task allergies: 1 with: nil) equals: #('eggs').
  self assert: (task allergies: 2 with: nil) equals: #('peanuts').
  self assert: (task allergies: 8 with: nil) equals: #('strawberries').
  self assert: (task allergies: 3 with: nil) equals: #('eggs' 'peanuts').
  self assert: (task allergies: 5 with: nil) equals: #('eggs' 'shellfish').
  self assert: (task allergies: 248 with: nil) equals: #('strawberries' 'tomatoes' 'chocolate' 'pollen' 'cats').
  self assert: (task allergies: 255 with: nil) equals: #('eggs' 'peanuts' 'shellfish' 'strawberries' 'tomatoes' 'chocolate' 'pollen' 'cats').
  self assert: (task allergies: 509 with: nil) equals: #('eggs' 'shellfish' 'strawberries' 'tomatoes' 'chocolate' 'pollen' 'cats')
"Exercise: TwoFer"

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 twoFer: 'Do-yun') >>> 'One for Do-yun, one for me.'"
"(self new twoFer: 'Alice') >>> 'One for Alice, one for me.'"
"(self new twoFer: 'Bohdan') >>> 'One for Bohdan, one for me.'"
"(self new twoFer: nil) >>> 'One for you, one for me.'"
"(self new twoFer: 'Zaphod') >>> 'One for Zaphod, one for me.'"
| name |
    name := aName ifNil: [ 'you' ] ifNotNil: [ aName ].
    ^ 'One for ', name, ', one for me.'


"Tests"
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.'
"Exercise: Binary"

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 conversion yourself.
    Do not use something else to perform the conversion for you."
"(self new binary: '0') >>> 0"
"(self new binary: '101') >>> 5"
((aString reject: [:c | ($0 to: $1) includes: c]) isEmpty) ifFalse: [ ^ nil ].

    ^ (aString reverse asArray
        withIndexCollect: [:digit :i | digit digitValue * (2 raisedTo: i - 1)])
        sumNumbers


"Tests"
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: '11010') equals: 26.
  self assert: (task binary: '10001101000') equals: 1128.
  self assert: (task binary: '000011111') equals: 31.
  self assert: (task binary: '2') equals: nil.
  self assert: (task binary: '01201') equals: nil.
  self assert: (task binary: '10nope') equals: nil.
  self assert: (task binary: 'nope10') equals: nil.
  self assert: (task binary: '10nope10') equals: nil.
  self assert: (task binary: '001 nope') equals: nil
"Exercise: Proverb"

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 static, unchanging string; all should vary according to the input given."
"(self new proverb: #('nail' 'shoe' 'horse' 'rider' 'message' 'battle' 'kingdom')) >>> #('For want of a nail the shoe was lost.' 'For want of a shoe the horse was lost.' 'For want of a horse the rider was lost.' 'For want of a rider the message was lost.' 'For want of a message the battle was lost.' 'For want of a battle the kingdom was lost.' 'And all for the want of a nail.')"
| phrases |
    wordCollection ifEmpty: [ ^ #() ].
    phrases := OrderedCollection new.
    wordCollection overlappingPairsDo: [:w1 :w2 |
        phrases add: ('For want of a {1} the {2} was lost.' format: { w1. w2 }) ].
    phrases add: ('And all for the want of a {1}.' format: { wordCollection first }).
    ^ phrases asArray


"Tests"
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' 'shoe' 'horse')) equals: #('For want of a nail the shoe was lost.' 'For want of a shoe the horse was lost.' 'And all for the want of a nail.').
  self assert: (task proverb: #('nail' 'shoe' 'horse' 'rider' 'message' 'battle' 'kingdom')) equals: #('For want of a nail the shoe was lost.' 'For want of a shoe the horse was lost.' 'For want of a horse the rider was lost.' 'For want of a rider the message was lost.' 'For want of a message the battle was lost.' 'For want of a battle the kingdom was lost.' 'And all for the want of a nail.').
  self assert: (task proverb: #('pin' 'gun' 'soldier' 'battle')) equals: #('For want of a pin the gun was lost.' 'For want of a gun the soldier was lost.' 'For want of a soldier the battle was lost.' 'And all for the want of a pin.')
"Exercise: Isogram"

isogram: aString
"Determine if a word or phrase is an isogram.
    An isogram (also known as a non-pattern word) is a word or phrase without a repeating letter (case-insensitive), however spaces and hyphens are allowed to appear multiple times."
"(self new isogram: 'lumberjacks') >>> true"
"(self new isogram: 'background') >>> true"
"(self new isogram: 'downstream') >>> true"
"(self new isogram: 'six-year-old') >>> true"
"(self new isogram: 'isograms') >>> false"
| significantString |
	significantString := (aString copyWithoutAll: '- ') asLowercase.
	^ significantString size = significantString asSet size


"Tests"
testIsogram
self assert: (task isogram: '') equals: true.
  self assert: (task isogram: 'isogram') equals: true.
  self assert: (task isogram: 'eleven') equals: false.
  self assert: (task isogram: 'zzyzx') equals: false.
  self assert: (task isogram: 'subdermatoglyphic') equals: true.
  self assert: (task isogram: 'Alphabet') equals: false.
  self assert: (task isogram: 'alphAbet') equals: false.
  self assert: (task isogram: 'thumbscrew-japingly') equals: true.
  self assert: (task isogram: 'thumbscrew-jappingly') equals: false.
  self assert: (task isogram: 'six-year-old') equals: true.
  self assert: (task isogram: 'Emily Jung Schwartzkopf') equals: true.
  self assert: (task isogram: 'accentor') equals: false.
  self assert: (task isogram: 'angola') equals: false
"Exercise: Gigasecond"

gigasecond: aString
"Your task is to determine the date and time one gigasecond after a certain date.
    A gigasecond is one thousand million seconds. That is a one with nine zeros after it."
"(self new gigasecond: '2015-01-24T22:00:00') >>> '2046-10-02T23:46:40'"
| moment |
    moment := aString asDateAndTime + (1000000000 asSeconds).
    ^ String streamContents: [:stream |
        stream
            nextPutAll: moment asDate yyyymmdd;
            nextPut: $T;
            nextPutAll: moment asTime print24]


"Tests"
testGigasecond
self assert: (task gigasecond: '2011-04-25') equals: '2043-01-01T01:46:40'.
  self assert: (task gigasecond: '1977-06-13') equals: '2009-02-19T01:46:40'.
  self assert: (task gigasecond: '1959-07-19') equals: '1991-03-27T01:46:40'.
  self assert: (task gigasecond: '2015-01-24T22:00:00') equals: '2046-10-02T23:46:40'.
  self assert: (task gigasecond: '2015-01-24T23:59:59') equals: '2046-10-03T01:46:39'