All Questions
18 questions
2votes
2answers
130views
Project sequence to multiple sequences using LINQ (or extension methods)
I'm creating a method that expands a sequence. This is a sample of how it works: Input: {1, 2, 3} Output: {1}, {1, 2}, {1,2,3} So far, I've been able to solve the ...
1vote
1answer
152views
Eliminating repetitions of subsequent items in a list
I would like to convert a list AA = {1, 12, 3, 3, 3, 8, 5, 5 } into list B ...
0votes
1answer
195views
Simplifying for loops that includes conditions with better linq queries
The code below selects all items that are locked. How can I optimise it? ShopItemData doesn't contain a field for locked/unlocked. ...
4votes
2answers
196views
Finding which items have at least one common value with other items
I have the following collection : ...
3votes
1answer
966views
Non brute force algorithm for Birthday Chocolate
Problem: https://www.hackerrank.com/challenges/the-birthday-bar/problem Lily has a chocolate bar that she wants to share it with Ron for his birthday. Each of the squares has an integer on it. She ...
5votes
1answer
95views
Representing relations between devices when presented with only one-to-many mappings
There are devices that communicate between each other. Already existing in the Legacy codebase is a list of one-to-many mappings between the devices. I have written a function in my backend that ...
9votes
3answers
783views
LINQ-ifying Colour Generation from Strings
Recently I was thinking about how Google, Microsoft Outlook on Windows Phone (and now many others) method of giving you a coloured icon with a letter in the centre of it works. Essentially, given ...
2votes
2answers
896views
Get first DateTime by given weekdays and a starttime
At work there is an input-system where customers are able to specify weekdays and a starting time for an event. The weekdays are integers in the range from 1 (Monday) to 7 (Sunday). After the customer ...
3votes
1answer
175views
Rolling up Invoice Items Matching Certain Criteria
I have a listing of invoice line items that I need to apply some convoluted business logic to. We have another listing of items that I compare the invoice items to and if I find matches, I then need ...
3votes
2answers
117views
How to find contradiction in order of items in multiple sequences
Suppose you have several sequences: A: 1 2 3 4 5 B: 2 4 5 C: 2 1 3 4 5 D: 3 2 Here, some pairs of list contradicts each other, because they ...
0votes
1answer
535views
Select values from two collections
I have a model: ...
23votes
5answers
4kviews
Linq me a FizzBuzz
I got this requirement recently: Write some code that prints out the following for a contiguous range of numbers: the number 'fizz' for numbers that are multiples of 3 'buzz' for numbers that are ...
0votes
1answer
229views
Approximate integral in one line of code
This is what I came up with: Version 1: ...
7votes
3answers
8kviews
Searching all diagonals of a 2D M x M array
I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array. Though the code works, I'd like to know if there is a way I can ...
6votes
2answers
5kviews
Determining expiration date based on list of months in which to refresh
I have a list of months in which users are required to update some data. I want to determine at what date they should have updated their data. They must update in March, May and August. If today is ...