Skip to content

Instantly share code, notes, and snippets.

View les-peters's full-sized avatar

Les Peters les-peters

View GitHub Profile
@les-peters
les-peters / 2023-05-08.py
Created May 12, 2023 20:53
Sum Odd Squares
question = """
Sum the odd-square numbers less than a given integer n.
Example:
> oddSquareSum(1)
> 0
> oddSquareSum(2)
> 1
> oddSquareSum(9)
@les-peters
les-peters / 2023-02-06.py
Created February 6, 2023 21:17
Excel columns
question = """
Spreadsheet programs often use the A1 Reference Style to refer
to columns. Given a column name in this style, return its column number.
Eexcel_columnamples of column names to their numbers:
A -> 1
B -> 2
C -> 3
// etc
@les-peters
les-peters / 2023-01-23.py
Created January 29, 2023 18:30
Fill in the Gaps
question = """
You are given a list of positive integers which represents some range of
integers which has been truncated. Find the missing bits, insert ellipses
to show that that part has been truncated, and print it.
If the consecutive values differ by exactly two, then insert
the missing value.
Examples:
> missingBits([1,2,3,4,20,21,22,23])
@les-peters
les-peters / 2023-01-02.py
Created January 2, 2023 17:41
Max Sub Array
question = """
Given an array of integers arr and an integer n, return a
subarray of arr of length n where the sum is the largest.
Make sure you maintain the order of the original array, and
if n is greater than arr.length, you can choose what you
want to return.
Example:
> maxSubarray([-4,2,-5,1,2,3,6,-5,1], 4)
@les-peters
les-peters / 2022-12-26.pl
Created December 27, 2022 21:03
String of Zeros
sub replaceZeros($) {
$out_str = $_[0];
$out_str =~ s/(0+)/length($1)/ge;
printf("$out_str\n");
}
replaceZeros("1234500");
replaceZeros('1234500362000440');
replaceZeros('123450036200044');
replaceZeros('000000000000');
@les-peters
les-peters / 2022-12-26.py
Created December 27, 2022 20:56
Strings of Zeros
question = """
Given a string of any length which contains only digits from 0 to 9,
replace each consecutive run of the digit 0 with its length.
Example:
> replaceZeros('1234500362000440')
> 1234523623441
> replaceZeros('123450036200044')
@les-peters
les-peters / 2022-12-19.asm
Created December 19, 2022 17:48
Capital after Vowel, ASM version
START: LDY #00 ; start loop at 0
LOOP: LDA $0800,Y ; load Y-th character
BEQ _END ; stop loop if NULL found
TRY_A: CMP #61 ; compare to 'a'
BNE _TRY_E
JSR _VOWEL ; found a vowel
INY ; next character
JMP _LOOP
TRY_E: CMP #65 ; compare to 'e'
BNE _TRY_I
@les-peters
les-peters / 2022-12-19.py
Created December 19, 2022 17:24
Capital After Vowel
question = """
Given a string, make every consonant after a vowel
uppercase. Can you do this with and without regex?
Example:
> capitalAfterVowel("hello world")
> "heLlo WoRld"
> capitalAfterVowel("xaabeuekadii")
@les-peters
les-peters / 2022-11-14.py
Created November 17, 2022 21:06
combine strings
question = """
Given a list of strings arr, and a max size n, return a new list where the
strings (from left to right) are joined together with a space, so that each
new string is less than or equal to the max size.
Examples:
> combineStrings(["a", "b", "c", "d", "e", "f", "g"], 5)
> ["a b c", "d e f", "g"]
@les-peters
les-peters / 2022-10-17.py
Created October 17, 2022 16:44
Open Doors
question = """
Let's say you have n doors that start out as closed. With the
first pass across the doors, you toggle every door open. With
the second pass, you toggle every second door. With the third,
every third door, and so on. Write a function that takes in an
integer numberOfPasses, and returns how many doors are open after
the number of passes. Thanks Max for inspiring this question!
Example: