« first day (693 days earlier)      last day (3622 days later) » 

uh
@Duga
Looks like SEDE is getting an update :)
@Duga - nice
Ohh, #61 was my bug
7
Q: Unable to select values from Data Explorer results (firefox bug only)

rolflAfter the recent release of the new Data Explorer code drop, I believe it's become impossible, to copy/paste values from the results. This has been confirmed to fail on multipe user's Firefox browsers, but is confirmed to work on Chrome. For example, I recently created this SEDE query, which pr...

00:16
@Duga -5 from yesterday I think. At least a little hope.
0
Q: C++ Console based password generator

AMartinNo1I am currently developing a password generator and just finished my first version. I know there is a lot to do but before I proceed with the next version I would like to have a feedback on my current source code. The source code can be viewed at github: https://github.com/AMartinNo1/passwordgene...

@rolfl Congratulations on getting "your" bug fixed :)
although that redeploy took quite a while... almost two months.
00:33
Gotta love SO comments...
in Duga's Playground, yesterday, by Duga
SO is not for opinions ; programmers.stackexchange.com is. — cosmo0 1 min ago
2
Q: Creating an iOS form with many similar text field cells

MaKoI'm using multiple instances of an object creating a form: {... BPFormInputTextFieldCell *nameCell = [[inputTextFieldClass alloc] init]; nameCell.backgroundColor = cellBgnd; nameCell.textField.placeholder = @"business_name"; nameCell.mandatory = YES; nameCell.textField.delegate =...

01:29
ACTIVITY
Happy 10k, @Edward
Hi, @SirPython
Hello, @Hosch250
My sisters said I couldn't find one of their boy friend's email addresses without making a FB account, which I don't want to do.
I found his LinkedIn account.
I haven't made one yet, but I'm considering it.
Then, I'll email it to my sisters and see what they say ;)
Are your sisters older or younger?
Both.
She is an adult too...
01:36
Sorry about that.
NP.
Anyway, her boy friend is over in Europe - they've never met.
Was Amazon well known when they developed the Kindle?
I believe so.
Amazon is older than me.
Kindle is about 7-8 years old, so I guess so.
Amazon was founded 19 years ago.
I actually only heard of the kindle a few years ago.
No, Amazon is almost 21.
I'm 19, going on 20 - our birthdays are actually kind of close.
01:43
You're right. I made a an error.
Only they are a year older.
I bumped someone today.
Used to do that on a daily basis, but I've slowed down a bit, and people are farther apart now.
"bump"?
With rep.
Do you play chess?
Want to play?

 SE Chess

Let's play chess! Everyone is welcome. Winning is only optiona...
01:47
Sure
I play through lichess because I don't need an account.
02:43
So, I answered a question.... a long time ago, and it is a messy answer....
today someone tries to fix the code, which is obviously broken...
but I look at it now, and don't know how to fix it. codereview.stackexchange.com/posts/36804/revisions
I usually skip (approving) the edits, when it comes to code modification.
I approved the edits
including the ones that says they are wrong
hmm, nvm
I have seen you teach many people many stuff, Time I get some of that knowledge.
Oh, Here is a good question, How is your at home servers are set-up ?
I would actually be happy to go through it, but not now.... I have alcohol, and a movie.... and a bed afterwards... it's Friday. Catch me and remind me at another point though
I'm not even going to look at that code that's broken until tomorrow
2
02:53
Ah, K. Have fun
0
Q: Adding elements in two lists as numbers in prolog

YonChothe problem is adding two list as numbers L1 = [1,9,9] and L2 = [0,9,9] ?- sum([1,9,9],[0,9,9], Lo). Lo = [2,9,8] but I also wanted to add this ?- sum([8,1,9],[1,8,2],Lo). Lo = [1, 0, 0, 1]. This is my code, I used the backtracking method I've learned : link([],L,L). link([Head|Tale],L...

 
5 hours later…
07:45
0
Q: Game of Life in Python: surrounding Count function not working?

leehHere is my very rough implementation of Conway's Game of Life simulation. LIVE = 1 DEAD = 0 def board(canvas, width, height, n): for row in range(n+1): for col in range(n+1): canvas.create_rectangle(row*height/n,col*width/n,(row+1)*height/n,(col+1)*width/n,width=1,fill='...

 
2 hours later…
10:01
Ahhhhh I love the smell of coffee and squished bugs in the morning.
10:23
Coffee and croissants. Best thing in the morning.
om nom
I am just waiting for my father and/or my brother to come back before drinking/eating.
Enjoy.
11:04
Monking
I have a feeling I've been doing C# events all wrong. When I clicked the "implement interface" button, I go this.
        public event EventHandler<EventArgs> Confirm;

        event EventHandler<EventArgs> ICreateBranchView.Cancel
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }
This is not how I've been doing it....
Is event a special keyword in C#?
yeah.
I've been doing something like this though
    public event EventHandler<EventArgs> CreateBranch;
    public void OnCreateBranch(object sender, EventArgs e)
    {
        RaiseGenericEvent(CreateBranch, e);
    }
Uh, that's quite a difference
    private void RaiseGenericEvent(EventHandler<EventArgs> handler, EventArgs e)
    {
        if (handler != null)
        {
            handler(this, e);
        }
    }
Yeah..... I smell a CR coming.
11:10
Calling functions directly still looks weird to me
in VBA, 37 secs ago, by skiwi
Ah right, I forgot it's 12:10 here
Yeah. I've been at it for a while. Bit of a morning duck.
I was really thinking it was like 8am, and that you were a night lurker
Ohhhhhh. The form already has a Cancel event so I have a conflict....
That's what's going on.
Was up earlier to see Formula 1 qualifying :)
11:16
Wondering what to do in like some spare time before I can really do something... I can try to clear some of my backlog of 870 tabs of interesting articles/questions/etc.
In Cities: Skylines I think this is not how trains are supposed to work: gfycat.com/DarlingGaseousBird
11:30
I'd really love to work on such games, programming graphics and AI should be immensive fun
11:43
10 tabs down... progress
Yeah. Progress here too. I think I'm about half done with the Branches view now.
Just reading my "what brings you here today" post of almost a year ago...
> Sometimes questions appear in the Hot Questions tracker when I'm browsing on SO's java-8 tag.
Browsing SO... what a joke! :D
Eh... I guess if you're bored. I certainly browse CR.
12:16
Morning, all.
@skiwi Don't tell me anything about F1 quali. I haven't seen it yet.
@Edward All I can tell is that I've watched it
I'll go play a race on GRID: Autosport at Sepang ;)
@Edward Hey :)
@SirPython Thanks, if you're still in the room.
With XBox controller... I hope in a few years I'll be able to buy a proper Raceseat or at least a Steering wheel + pedals and Oculus Rift CV ;)
@skiwi Even more fun is an actual racecar. :)
12:20
@Edward Yeah, that's definitely on my list too! Not sure if I'm allowed to without a driver's license though
Not in most series, no.
I'm on my way to getting my license though
This is what I've been doing lately: chumpcar.com
A wee bit cheaper than F1
Looks incredible fun
@Morwenn Hi! Long time no see.
@skiwi Absolutely!!!
12:22
@Edward You made more points than me while I was away ç___ç
Too bad the hardest I'll drive with my driving lessons car will be 135 km/h probably
I figured my 1 year anniversary on CR was coming up so I made the push to cross 10k
Well, congratulations then :)
I'm sure that Mercedes C220 TDI would be able to read 200 ;)
@skiwi That's fast enough to learn a lot. As you know, most passing is done under braking.
C220? I love those old tanks!
12:25
Only a bit sad that I won't see such a car for a long while until I get a well-paid job
@skiwi You should have seen the rusty old thing I was driving in college! I eventually sold it to my brother for $75 and half a pizza.
2
I probably overcharged him.
@Morwenn: In your studies of Gray codes, have you studied much number theory?
@Edward wow... lol, that must've been an interesting ride!
@Edward Not really. I happened to read some number theory-related things meanwhile but that wasn't related to my Gray code stuff.
Why the question? :)
The reason I ask is that I know there must be a better algorithm for this question:
11
Q: Checking if a number is divisible by 9

kapil.thakarI tried to develop a new way to check if a number is divisible by 9. I have written my code and it is working fine. I'm not allowed to use *,/ and %. int isDivby9(int x) { int status = 0; int divby8 = 0; int orgx = x; if(x>=9) { divby8 = x >> 3; ...

@Edward Transform to strings, add digits, check if the result is divisible by 9.
Could probably be user for big numbers. But pretty inefficient otherwise.
12:35
Yes, that's the way we would do it in decimal, but I know it should be possible in binary as well.
Just looking for my number theory book...
A divisibility rule is a shorthand way of determining whether a given number is divisible by a fixed divisor without performing the division, usually by examining its digits. Although there are divisibility tests for numbers in any radix, and they are all different, this article presents rules and examples only for decimal numbers. == Divisibility rules for numbers 1–20 == The rules given below transform a given number into a generally smaller number, while preserving divisibility by the divisor of interest. Therefore, unless otherwise noted, the resulting number should be evaluated for d...
I don't think you can do really better than this :/
Ah, but you can!
10
Q: Design DFA accepting binary strings divisible by a number 'n'

NaveenI need to learn how to design a DFA such that given any number 'n', it accepts binary strings { 0 ,1 } whose decimal equivalent number is divisible by 'n'. There will be different DFAs for different 'n', but can somebody give a basic approach i should follow to proceed with any number 0 < n <10 .

@Edward You could use __builtin_ctz on GCC and Clang instead of the first loop to compute the number of digits to shift.
@Edward The algorithm for the question is: num % 9
And I've downvoted the question actually for silly requirements.
Yes, both of those would improve speed but don't meet the silly requirements.
12:44
Which is why I downvoted the question, voted to undelete the answer which suggests num % 9, and have been contemplating casting a close vote on the question or perhaps opening a meta about it.
The requirements seem silly in C, but they are absolutely relevant for something like Verilog or VHDL
What are those things?
Hardware design languages
I see.
@nhgrif You could as well consider that the requirements for my Gray code addition question are silly.
12:46
link to question?
15
Q: Gray codes addition

MorwennAs some of you know, I have been working with Gray codes and am trying to design a good gray_code class in modern C++. I will end up posting several parts of the implementation, but what I want to be reviewed is mostly the addition function. Anyway, here is the code of the class essentials: temp...

I don't like the idea that it's okay to say very fundamental things to the language you're writing in are off-limits without giving a very good reason why they're off limits.
The goal is to perform an addition without converting the Gray codes to integers, using a regular integer addition and converting the result back to a Gray code.
In that case, @Morwenn it sounds like your "silly" requirements might actually make the code more efficient?
Which could be considered silly. On the other, while it's implemented in C++, I may have improved some things if somebody tries to implement it in hardware.
12:48
> One of my goals is to provide operations specialized for gray_code only if the operation can be faster than converting the Gray code to the corresponding integer, performing the operation on the integer and converting the integer back to a Gray code.
@nhgrif Not at all, the conversions are fast as light. My algorithm is an order of magnitude slower than the naive double convrsion once optimized.
In other words, I didn't reach my goal.
"only if the operation can be faster"
But you had a meaningful goal behind your "silly" requirements.
I think that algorithm exploration is useful, in whatever language.
@Edward I tend to agree with that :)
In this modulo 9 question, there's not a meaningful goal behind "can't use *, /, or %"
12:49
0
Q: monitors few servers / API endpoints etc

Abhinav GauniyalI am trying to create a simple nodejs program that monitors few provided servers or machines and provides output in JSON. Here is relevant code : // @file name : watch.js // author : Abhinav Gauniyal // requires var os = require('os'); var http = require('http'); var net = require('net')...

And I'm not saying that algorithm exploration isn't useful.
I just don't think that algorithm exploration with silly requirements without meaningful goals behind those requirements really feels outside the scope of code review.
@nhgrif One meaningful purpose might be "this is a first step in prototyping before i convert it to a hardware implementation"
And it's a lot more interesting than all FizzBuzz implementations put together.
I disagree.
FizzBuzz is a way of exploring a language. If you don't put silly requirements, you can learn a lot about the language actually.
Consider this FizzBuzz answer:
23
A: Is this FizzBuzz Swift-y?

syb0rg Is this FizzBuzz Swift-y? Kinda, but it could be a lot better. Here's what I would do to fix it: Extrapolate this code into a method, then call the method from the for loop. func fizzbuzz(i: Int) -> String { // ... } There is a handy Swift feature called "Tuples". Tuples are grouping...

Silly requirements are a way of exploring other tools.
@Morwenn I agree.
12:52
I'm also not saying you shouldn't put silly requirements on yourself when you're trying to explore other tools.
We have a lot of accepted questions that have seemingly arbitrary restrictions.
What I'm saying is that silly requirements on a Code Review question without meaningful reasons behind those questions seems outside of Code Review's scope.
Actually, the problem is that people should give a meaning to requirements.
Here's why... let's make this more like a real-world scenario, @Edward
Let's say I'm your project manager, and I assign you to come up with the fastest algorithm for doing X operation. I give you 3 months to do it.
@Morwenn :) You have obviously worked with product development!
12:54
In those 3 months, I want you to explore every possible approach and come up with the fastest possible algorithm.
@Edward Er, not really.
But at the end of those 3 months, your colleagues that are code reviewing you shouldn't care about any meaningless requirements you may have put on any implementation you put together.
Only the meaningful requirements.
@Edward How come __builtin_ctz does not meet the requirements by the way?
Sorting meaningful requirements from the rest is easier said than done.
As a base, any Code Review question should describe the basic requirements: "Given X input, deliver Y output." and then a pile of code which does this.
12:56
@Morwenn Perhaps it doesn.t
Any requirements on top of those (such as restrictions on why you can't do it in the most obvious way) need to have reasons behind them.
@nhgrif Here's a real world example. Many years ago, I was working on a series of products that had European and North American variations.
"Given X input, deliver Y output. Algorithm Q cannot be used because of reasons R, S, and T."
@Edward Does reimplementing the modulo algorithm by hand meet the requirements? x)
I was working on the Euro version.
I heard that a North American customer wanted the Euro version and was excited about the implicit endorsement of my work.
So I asked what feature compelled the choice.
"It fits better in the box they had already chosen."
:/
12:58
Okay
It seems silly, but it at least has a reason behind it.
Yes, but the reasons are not always transparent to developers.
> "Given X input, deliver Y output. Algorithm Q cannot be used because of reasons R, S, and T."
@nhgrif Deserves a meta post? Requirements vs reason?
@Edward Reasons may not always be transparent to developers, but a restriction as silly as "You can't use 3 of the 5 most basic math operators" is never going to be a real reason...
@nhgrif As I mentioned, it's very real in hardware.
13:00
Not in C.
Ever try C on an 8-bit processor with no multiply or divide instructions?
I have.
@nhgrif Depends on the compiler and the platform. Sometimes, you can still implement a better modulo than the buit-in one.
Well, I will stat the meta post about requirements and stuff.
@Morwenn Is that what the user is asking for? To implement a better modulo?
@Morwenn I think it's a good idea for a meta post.
If so, shouldn't it be ABSOLUTELY CRUCIAL for the compiler, OS, version of C to all be specified?
13:01
Meh, reinventing the wheel is a very common exerise.
6
"Seemingly arbitrary requirements": does it sound like a good discussion title?
more than that, often, hard problems have been solved with language-levele infrastructure, like regex.
@Morwenn I think so.
I want to be clear, I haven't even cast a close vote on this question...
but, for educational levels, you have to remove the now-easy-t-use implementation as a solution in order to understand why the problem is hard
13:03
But I have cast a down vote because I find the question very uninsteresting.
@nhgrif Doesn't matter -- it's an interesting discussion and will probably come up again.
Because a similar scenario I can imagine would be someone placing the requirement of "Without using OOP techniques, solve problem X in OOP language Y."
I think it's okay-ish as an exercise, but to be the requirement that answers you receive must be non-OOP despite you implementing in a OOP language?
I think that's against the spirit of Code Review, to be honest.
How about this one?
6
Q: Removing duplicates without using a temporary buffer

saurabh kapoorThis question is from Cracking the Coding Interview and in this question they have asked to solve without using temporary buffer. I have used Iterator interface. Can I use it or need to re-implement it? import java.util.Collection; import java.util.Collections; import java.util.Iterator; import...

Because "use a different language" can never be an acceptable answer (even if it's a comment sometimes).
That divisible-by-9 needs a different answer.....
13:06
An interesting answer to "divisible-by-9" would be one that actually fully re-implements modulo.
And if the question were a full re-implementation of the operator, then I think the requirement of not using it is not silly at all.
@nhgrif Yes that would be an interesting answer.
Or if the question were to determine "isOdd" because "isOdd" is probably a lot more common question than whether it's divisible by some random magic number.
0
Q: Seemingly arbitrary requirements

MorwennThis meta question is actually a follow-up of a discussion started on The 2nd Monitor about the following question: Checking if a number is divisible by 9. To put it bluntly, the objects of interest are the requirements in the question: I tried to develop a new way to check if a number is di...

@nhgrif In many cryptographic algorithms, whether a number is divisible by some random magic number is exactly the crux of the problem.
Feel free to edit and adapt the question so that it fits the debate :)
13:10
@Edward Perhaps, but that's certainly a less common problem than isOdd and I imagine this cryptographic algorithms look at different numbers, not just 9.
Think of what the OP was doing, though. They were thinking about a problem, trying a new solution and then coming here to ask if there's a better algorithm. Isn't that exactly what we do here?
I'd like to think we do more than just nitpick about variable names and formatting!
@Edward That's not what they're doing though.
How do you see it?
Haha, I just wrote a jazzy recorder melody on one of my band's blackened folk metal songs x)
They're saying "Here is my algorithm. Is there a better algorithm except for algorithm X"
It's the "except for algorithm X" without "because of reasons R, S, T" that I don't like.
13:15
1
Q: Seemingly arbitrary requirements

MorwennThis meta question is actually a follow-up of a discussion started on The 2nd Monitor about the following question: Checking if a number is divisible by 9. To put it bluntly, the objects of interest are the requirements in the question: I tried to develop a new way to check if a number is di...

unless their implementation is a complete rewrite of algorithm X (so if this was complete rewrite of modulo, not just a true/false is divisible by one magic number)
@nhgrif But then that would be your arbitrary requirement.
What would?
Maybe it's my hardware background, but this sort of thing (divisibility by one fixed number) is actually extremely common.
Okay, then put the reason in the question.
Here's why, Edward.... here's why...
13:17
I'm thinking I might add it to my answer.
If I'm reviewing someone's code at work, and I run across a situation where the colleague wrote this algorithm instead of using some well-known existing thing that's a 1-line call to something
My first question is "Why?"
I can't know whether the colleague has unnecessarily or necessarily re-invented the wheel if I can't understand why they did so.
Sure, and that's perfectly valid.
I need to know what's wrong with the other implementation that has been tried and tested for a long time.
@Edward That's all that I'm asking for... that's what this divisible by 9 question lacks.
Is modulo to slow? If so, answers need to compare the speed of their answer to modulo (and we need to know specifics about compiler, language version, hardware, etc)
Are there hardware requirements (which likely mean I need to set up specific compiler settings, right)?
We seem generally to make an exception for "interview questions."
If I were asked to do something like this in an Interview, the first word out of my mouth would be "Why?" followed by "What's wrong with modulo?"
13:21
Sure, me too.
Until the interviewer has answered these questions, I can't be entirely certain how I should be approaching the problem.
Which means... without these reasons, any code reviewer can't be entirely certain how to answer a code review question with these reasons.
What if the interviewer says, "just assume you can't use them. Show us how you would approach the problem."
Forfeit the job?
It's certainly valid to ask the question, as you have, but it's also valid to not have a good reason, it seems to me.
Depends.
In the context of an interview, it might be to try to get the candidate to think of alternative solutions.
I think that's valid here, too.
If the interviewer were specify some high level language method call, I might re-implement it. It's possible that I know a one-line method to do it in Objective-C, and although the interviewer is asking me to do it in my most comfortable language, they also know there's not a one-line solution for it in the language they're interviewing me for.
But if I'm being asked in an interview to not use modulo, multiplication, or division, and the interviewer doesn't have a good reason, and the company isn't Google, Microsoft, or Apple, then I'll probably walk out...
"Implement strlen() in C" is a very common interview question.
@Morwenn I love it!
@Edward Can't be used for anything but I love the concept too :)
The list might be slightly longer than those 3 companies... but if I'm being asked to do that, then I'm interviewing for a job were likely I'll have silly restrictions placed on me for no understandable reason on a regular basis
So yes, I'd walk out if it weren't an absolutely amazing opportunity with a mega name company.
It'd be a sign I'm interviewing at a place I don't want to work out.
I'm interviewing the company just as much as they are interviewing me.
@Morwenn There is actually some practical use for that mode of thought though. Making robust code requires one to think, "does this work even if hardware fails" is sometimes useful.
See the recent Mars rover for when that might be useful...
> Take one down, pass it around, 93.77862 bottles of beer on the wall.
93.6543 bputlfs of!bedr nn tie walj, 93.65845 bottles of beer.
13:29
@skiwi Hey, they stole my code! :)
@Edward And before I answered this interview question, I'd ask "Why? What's wrong with strlen()? Am I being hired to develop a new programming language?"
@nhgrif "No, we just want to see how you think."
@nhgrif What's wrong with strlen? Well, probably its O(n) complexity.
And provided that answer, I'd probably proceed to answer it. But I'd answer it on the assumption that I'll never be given the answer "We just want to see how you think" when I'm working on real code.
And the first day I heard that, I'd start emailing out resumes.
I'm trying to imagine what it would be like to work somewhere where all requirements were fully rationally explained.
I don't think I've even heard of such a place...
13:33
I'm not placing the restriction of "fully rational"
But "because" is never an answer I'd put up with.
@Edward Maybe the NASA comes close
Yet that's the reason the "divisible by 9" question gives us.
What are we even arguing about here?
If there's a valid question with valid restrictions and valid answers, what's the problem?
@skiwi Having had friends working for NASA and JPL, you'd be surprised...
@Edward Are you saying you'd be perfectly happy re-implementing modulo just because your boss said so, and you'd be okay if he gave you no explanation for why? Just because.
If you don't know why, then you have no clue about what the actual things to look out for are. Am I under some hardware restriction? Am I supposed to make this faster?
13:36
@nhgrif Not "perfectly happy" but on the other hand, if every developer insisted that every requirement was fully justified to them, we wouldn't get a lot of work done.
And if you don't know those reasons, you tinker away, get it done, and then your boss says "Well, this doesn't work."
I'M NOT ASKING FOR FULLY JUSTIFIED!!!!
I'm asking for any justification.
The divisible by 9 question offers NONE.
Really, what is your problem with the question?
OK, I suppose we simply have a different outlook.
I think that "intellectually interesting" is sufficient.
My outlook used to be express.
There are no explanations behind the requirement. We can't know if we're supposed to be speed testing against modulo (and if so, what compiler, what OS, what hardware), or if we're under some sort of hardware requirement that prevents some sort of operation, etc.
13:38
@nhgrif All I can see is that the OP tried to come up with a way to check for divisibility by 9 that differs from well-known implementations, his requirements are that it should work and he wants the code to be as readable as possible
That's al there is to it
@skiwi No, his requirement also includes the abitrary exclusion of /, *, and %.
So num % 9 is an unacceptable albeit best answer.
If it doesn't meet requirements it's not best.
2
@nhgrif It depends, some other guy just answered with an algorithm that can perform better.
1
Q: Filling a cumulative array in Swift

MazyodI have a "cumulative" lookup array for a custom collection view layout. The idea is that I have an array of rectangles, each with an index. The index is not unique, and is monotonically increasing. I need to create a lookup table, such that given a cell index, it returns the accumulated height ...

Consider that question
And look at the comments.
I have no intentions of answering that question (and fortunately none of you guys can as far as I know) without receiving a good explanation for why the existing methods that UIKit provides isn't an option.
@Morwenn And that's how we all benefit.
13:45
@nhgrif It's not an answer, it doesn't meet his requirements
If I post a CR question using Java and say I cannot use additional libraries, then I won't allow an answer that suggests me to use an Apache library
Additional libraries is a much different requirement... I'm okay with the requirement of not using external libraries without any reasoning... I can make an exception for that.
That's VERY different from not using an existing operator, function, method, class, etc., that's built in to what you're already using without any good reason.
The library exception, haha :D
@Edward ->
int main() {
    for (int i=-10000; i < 1000000; ++i) {
        if (isDivBy9(i) != (i%9 == 0)) {
            return 1;
        }
    }
    return 0;
}
 time ./div9
0.117u 0.000s 0:00.11 100.0%    0+0k 0+0io 0pf+0w
panabox:~/xxx/crev>
Some libraries are non-free. Open-source ones are subject to various licenses that may or may not match up with your project's licenses. It seems more likely that the library won't meet your project requirements than will.
@rolfl Nice. Which implementation?
13:50
Mine ... ;-)
int nextUnit(int u) {
    // implement u * 10 using addition.
    int unit = u + u + u;
    return unit + unit + unit + u;
}

int digitSum(int x) {
    int units[24] = {0};
    units[0] = 1;
    int column = 0;

    while (units[column] < x) {
        column++;
        units[column] = nextUnit(units[column - 1]);
    }

    int sum = 0;
    while (x > 0) {
        if (x >= units[column]) {
            x -= units[column];
            sum++;
        } else {
            column--;
        }
    }
    return sum;
@rolfl Wouldn't multiply by ten be faster with shift and add?
@200_success In your answer this condition may not be required, am I correct?
@rolfl I hope you're planning on posting it.
this.rest() == null is not required in else if (position < 1 || this.rest() == null) {
13:52
0
Q: Longest palindrome in a given string using LINQ

callee.argsCan someone point it out if there are any problems with below code? I was solving some problems on online coding test website and some test cases failed for this code. I'm not sure what I'm missing. public static void GetLongestPalindromeLength() { var input = Console.ReadLine().ToC...

@overexchange Why don't you leave a comment on the answer itself?
@Edward Well, I knew about the algorithm, but did not know about the comment on the question until afterwards....
Is it possible to count and sum digits easily in C? I don't know C, but I do know that a number is divisible by 9 if the sum of its digits is divisible by 9. That little factoid is likely what this problem is hoping you know, given the constraints. The resulting function would be simple then, using recursion; in psuedocode: if (numDigits ==1) then return 9==x; else, return isDivBy9(sumOfDigits(x)); — Willem Renzema 21 hours ago
That's essentially what my answer does, and, it's not a review, just a code-dump ;-)
I even used the same function name.... (which I edited from your code because I wanted a capital B
Fair enough, but still interesting enough. Maybe you could post a comment with a link to the code?
13:56
I like that idea!
@rolfl You probably got a little bit of perforance thanks to tail recursion.
It runs a bunch faster with O3 than O2 ... maybe...
panabox:~/xxx/crev> gcc -std=c99 -o div9 -Wall  div9.c
panabox:~/xxx/crev> time ./div9
0.282u 0.000s 0:00.28 100.0%    0+0k 0+0io 0pf+0w
panabox:~/xxx/crev> gcc -std=c99 -o div9 -Wall -O1 div9.c
panabox:~/xxx/crev> time ./div9
0.151u 0.000s 0:00.15 100.0%    0+0k 0+0io 0pf+0w
panabox:~/xxx/crev> gcc -std=c99 -o div9 -Wall -O2 div9.c
panabox:~/xxx/crev> time ./div9
0.121u 0.000s 0:00.12 100.0%    0+0k 0+0io 0pf+0w
panabox:~/xxx/crev> gcc -std=c99 -o div9 -Wall -O3 div9.c
panabox:~/xxx/crev> time ./div9
You could try your algorithm with @Edward's powers of two optimization. It should work as well to reduce the number of digits to add.

« first day (693 days earlier)      last day (3622 days later) »