|
Hi, Super Lloyd,
Yeah, been using this a long while.
The code example by Icaza is kind of "scary," though. Over twenty aliases for System.IntPtr. Clearly, he doesn't like to declare variables the "usual" way; I also find his use of lower-case aliases for Types that would usually have an initial upper-case letter (or use camel-casing) ... strange.
However, looking at that code, it does appear "consistent," and I assume part of his motivation for writing in this format has to with the multi-platform aspect of it.
cheers, Bill
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
IntPtr is just a .. void* really.. doesn't tell you much... a bit like those windows HANDLE.
I guess he did that to introduce an helpful illusion of typing!
|
|
|
|
|
So instead of:
using System;
Guid g = Guid.NewGuid();
you use:
using guid = System.Guid;
guid g = guid.NewGuid();
Genius. 
|
|
|
|
|
We had no air conditioning as the system actually hadn't been finished at the time the rest of the house was, and we weren't told that (which I believe is a Fort Wayne Construction Code Violation). We just got it fixed, and now there is no power to the outlets in the garage, where our modem is.
I checked each outlet, and found a single outlet next to the Water Heater and Furnace that had power, and jerry rigged a system to power the modem with an extension cord and a power strip. And yes, it works.
We have an electrician coming tomorrow to figure out the power issue, so this is only a temporary measure (it's probably not code compliant, anyways )
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
I know there is not a lot going on in the Lounge at the moment but this should really be posted on facebook!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: but this should really be posted on facebook!
Yes, and I want to see a picture of this rats nest of an extension cord and power strip that violates code!
Marc
|
|
|
|
|
Brisingr Aerowing wrote: Do questions with multiple question marks annoy you???
Not as much as multiple exclamation points!!!!
|
|
|
|
|
Super Lloyd wrote: Not as much as multiple exclamation points!!!!
Please leave Australia now.
It is not, and has never been anything other than an Exclamation Mark!
Your vocabulary and spelling leaves you Merka as the only place that will take you.
Michael Martin
Australia
"I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible."
- Mr.Prakash One Fine Saturday. 24/04/2004
|
|
|
|
|
So...you'll keep all the poisonous snakes, poisonous spiders, poisonous birds, poisonous marsupials, poisonous rabbits (for all I know), poisonous sharks, and drop bears - but you won't keep a bloke who calls 'em "exclamation points"?
Rough country you got there sport!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You ought to hear me rip in to the kids and their friends who can't pronounce like an Australian.
Say Forehead and Template.
You said them wrong and can go live with Geraint the Welsh bloke I sent home to Abergwynfi Cape cause he spoke wrong too.
Michael Martin
Australia
"I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible."
- Mr.Prakash One Fine Saturday. 24/04/2004
|
|
|
|
|
It
Michael Martin wrote: Say Forehead and Template.
Fore-o and Temp-o
veni bibi saltavi
|
|
|
|
|
Apparently an electrical design pattern has not been followed
You always obtain more by being rather polite and armed than polite only.
|
|
|
|
|
It turns out that a GFCI outlet protecting the garage tripped, and I mixed up which button was which. Now it works.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
But is the extension cord solution compliant with federal regulations regarding trans-gender access?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I had a requirement which looked like a coding puzzle. Something so intuitive to us humans is hard to express in programming term. Well not so hard but something that makes you think.
So here is the deal. Given a list of integers split list into series of sub lists.Each sub list contains consecutive digits until digit in input list is not equal to previous digit plus one. At that point start new sub list.
List<int> lstInput = new List<int>(){1,2,3,5,6,7,22};
Sub lists should be {1,2,3} {5,6,7} {22}
Here is my not so elegant solution My Not So Elegant Solution [^]
Smart minds of CP it is your opportunity to show your genius. I know you can make it more elegant.
Zen and the art of software maintenance : rm -rf *
Maths is like love : a simple idea but it can get complicated.
|
|
|
|
|
Ah, so the Friday Programming Challenge is being revived, but on Wednesday?
I'd start with a List<List<int>>
Initialize list
Set index to 0
Iterate input values
If test fails
Add a new List
Increment index
List [ index ].Add ( value )
Maybe I'll write it later, maybe I won't. Now I'll have a look at yours...
Here's mine:
private static System.Collections.Generic.List<System.Collections.Generic.List<int>>
Split
(
System.Collections.Generic.IList<int> values
)
{
System.Collections.Generic.List<System.Collections.Generic.List<int>> result =
new System.Collections.Generic.List<System.Collections.Generic.List<int>>() ;
if ( ( values != null ) && ( values.Count > 0 ) )
{
result.Add ( new System.Collections.Generic.List<int>() ) ;
int l = 0 ;
result [ l ].Add ( values [ 0 ] ) ;
for ( int i = 1 ; i < values.Count ; i++ )
{
if ( values [ i ] - values [ i - 1 ] != 1 )
{
result.Add ( new System.Collections.Generic.List<int>() ) ;
l++ ;
}
result [ l ].Add ( values [ i ] ) ;
}
}
return ( result ) ;
}
modified 25-May-16 23:38pm.
|
|
|
|
|
I'm learning ES6:
function* consec(array) {
let arr = array.splice(0);
while (arr.length > 0) {
let nextSeqIndex = arr.findIndex((v, i, a) => v != a[0] + i);
if (nextSeqIndex === -1) return yield arr;
yield arr.splice(0, nextSeqIndex);
}
}
let array = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 22];
for (let sub of consec(array)) {
console.log(sub);
}
code@repl.it[^]
|
|
|
|
|
Use Linq:
using System.Linq;
List<List<int>> output = lstInput
.Select((n,ix)=>new {n, ix})
.GroupBy(p=>p.ix / 3, p=>p.n)
.Select(g=>g.ToList())
.ToList();
Never mind, I didn't read the post completely, sorry. 
modified 26-May-16 1:59am.
|
|
|
|
|
OK here is my improved solution, using Linq:
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<int> lstInput = new List<int>(){1,2,3,4,5,6,7,9,10,11,22};
var aggResult = lstInput
.Aggregate(new
{
last = lstInput.First()-1,
result = new List<List<int>>(),
current = new List<int>()
},
(agg, n)=>
{
List<int> current = agg.current;
if(n != agg.last + 1)
{
agg.result.Add(current);
current = new List<int>();
}
current.Add(n);
return new {last = n, result = agg.result, current};
});
if(aggResult.current.Count > 0)
{
aggResult.result.Add(aggResult.current);
}
Console.Out.WriteLine(
"{{{0}}}",
string.Join(
"},{",
aggResult.result.Select(o=>string.Join(",", o.Select(e=>e.ToString())))
)
);
}
}
Not sure it's any more elegant, though... 
|
|
|
|
|
Staffan Bruun wrote: Not sure it's any more elegant, though Comparing this dogs breakfast to kenneths I know which one I would want to support. I use Linq quite a bit but only for the simplest things. Once you get into aggregates I start looking for other options.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah, it kind of blew up in my face as I wrote it.
The problem with coding is that it is hard to pick the simple, correct and maintainable solution when it just seems so... ordinary sometimes, compared to a conceptually elegant solution where the true devil hides in the details.
|
|
|
|
|
Perhaps come old fashioned coding like this:
private List<List<int>> GetList(List<int> Input)
{
List<List<int>> Result = new List<List<int>>();
List<int> CurrentList = new List<int>();
CurrentList.Add(Input[0]);
for (int i = 1; i < Input.Count; i++)
{
if (Input[i] == (Input[i - 1] + 1))
CurrentList.Add(Input[i]);
else
{
Result.Add(CurrentList);
CurrentList = new List<int>();
CurrentList.Add(Input[i]);
}
}
if (CurrentList.Count != 0)
Result.Add(CurrentList);
return Result;
}
|
|
|
|
|
You could also use the GetRange function on the list to do the actual work of making the sub lists, and then you don't need to keep track of so many things.
List<List<int>> GetSubLists(List<int> lstInput)
{
List<List<int>> lstSubLists = new List<List<int>>();
if (lstInput.Count == 0)
return lstSubLists;
int subListStartIndex = 0;
for (int i = 1; i < lstInput.Count; ++i)
{
if (lstInput[i] - lstInput[i-1] != 1)
{
lstSubLists.Add(lstInput.GetRange(subListStartIndex, i - subListStartIndex));
subListStartIndex = i;
}
}
lstSubLists.Add(lstInput.GetRange(subListStartIndex, lstInput.Count - subListStartIndex));
return lstSubLists;
}
|
|
|
|
|
Now that is simple and beautiful
Zen and the art of software maintenance : rm -rf *
Maths is like love : a simple idea but it can get complicated.
|
|
|
|
|
technical ? => QA forum
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|