« first day (316 days earlier)      last day (3702 days later) » 

5:00 PM
The example code I put above is run in parallel
 
Ok... so there's a wrong assumption then
Would you mind reposting it?
 
3 hours ago, by rolfl
public static void main(String[] args) {
    final int sz = 1000000;
    List<Integer> input = new ArrayList<>(sz);
    for (int i = 0; i < sz; i++) {
        input.add(i);
    }

    final AtomicInteger idgen = new AtomicInteger();

    List<Integer> output = input.parallelStream().collect(Collector.of(
            ArrayList<Integer>::new,
            (acc, t) -> acc.add(t),
            (left, right) -> {System.out.println("Combine " + idgen.incrementAndGet()); ArrayList<Integer> comb = new ArrayList<Integer>(); comb.addAll(left); comb.addAll(right); return comb;}));
 
Have you verified that it gets called in parallel?
 
Yes...
 
May I ask how? I'm nsure of how I would verify it personally, maybe watch the threads?
 
5:02 PM
two machines. One with 4 cores/8HT and it runs on 16 threads, the other with ....
2 cores, 4HT, and it runs on 8 threads.
 
Fair enough
 
When I set both UNIRDERED and CONCURRENT, I get concurrent-modification problems (array-index-out-of-bounds).
It uses the ForkJoin pool threads.... BTW
 
strange.... Is there any way to explain this code then?
@Override
@SuppressWarnings("unchecked")
public final <R, A> R collect(Collector<? super P_OUT, A, R> collector) {
    A container;
    if (isParallel()
            && (collector.characteristics().contains(Collector.Characteristics.CONCURRENT))
            && (!isOrdered() || collector.characteristics().contains(Collector.Characteristics.UNORDERED))) {
        container = collector.supplier().get();
        BiConsumer<A, ? super P_OUT> accumulator = collector.accumulator();
        forEach(u -> accumulator.accept(container, u));
I'm bad with using a proper debugger, but setting breakpoints could work I guess
 
Let me post some code here too:
public static void main(String[] args) {
    final int sz = 1000000;
    List<Integer> input = new ArrayList<>(sz);
    for (int i = 0; i < sz; i++) {
        input.add(i);
    }

    final AtomicInteger idgen = new AtomicInteger();

    System.out.println("Mapping");

    Map<Integer,Integer> output = input.parallelStream().collect(Collector.of(
            HashMap<Integer,Integer>::new,
            (acc, t) -> acc.put(acc.size(), t),
            (left, right) -> {
                int id = idgen.incrementAndGet();
That code produces:
Mapping
main Combined 3
ForkJoinPool.commonPool-worker-7 Combined 1
ForkJoinPool.commonPool-worker-1 Combined 2
ForkJoinPool.commonPool-worker-2 Combined 4
ForkJoinPool.commonPool-worker-3 Combined 5
ForkJoinPool.commonPool-worker-4 Combined 7
ForkJoinPool.commonPool-worker-5 Combined 6
main Combined 9
ForkJoinPool.commonPool-worker-7 Combined 12
ForkJoinPool.commonPool-worker-1 Combined 10
ForkJoinPool.commonPool-worker-4 Combined 13
ForkJoinPool.commonPool-worker-3 Combined 14
ForkJoinPool.commonPool-worker-2 Combined 11
Without the CONCURRENT
it produces:
Mapping
ForkJoinPool.commonPool-worker-7 Combined 1
ForkJoinPool.commonPool-worker-4 Combined 4
ForkJoinPool.commonPool-worker-2 Combined 6
ForkJoinPool.commonPool-worker-6 Combined 2
ForkJoinPool.commonPool-worker-5 Combined 3
ForkJoinPool.commonPool-worker-3 Combined 7
ForkJoinPool.commonPool-worker-7 Combined 9
main Combined 8
ForkJoinPool.commonPool-worker-2 Combined 11
ForkJoinPool.commonPool-worker-3 Combined 15
ForkJoinPool.commonPool-worker-2 Combined 17
ForkJoinPool.commonPool-worker-6 Combined 13
From the JavaDoc for Collector.Characteristics.CONCURRENT:
> Indicates that this collector is concurrent, meaning that the result container can support the accumulator function being called concurrently with the same result container from multiple threads.
> the accumulator function being called concurrently with the same result container from multiple threads.
 
following it...
 
5:11 PM
There is no difference in the effective output for with, and without the CONCURRENT Characteristic.
 
And only when you put unordered on it aswell, then it actually goes into that branch
 
Okay, that is exactly how the code does it (how unsurprising)
 
The big thing I have discovered though, is the order of reducing is strictly in relative-order
 
Then to find out where the paralleization actually matters
How do you mean exactly?
relative-order = "from left to right"?
 
5:14 PM
in otherwords, combine(a,b) will never be combine(b,a)
Yes, it splits the input in segments, say a, b, c, d
 
Okay, that was my point since the start, but how did you exactly discover it?
 
Then it will combine in that order....
By experimentation ;-)(
 
:p
 
Now, it is lunch time for me.
 
now this line container = evaluate(ReduceOps.makeRef(collector)); is going to be interesting
which comes down to
    return isParallel()
           ? terminalOp.evaluateParallel(this, sourceSpliterator(terminalOp.getOpFlags()))
           : terminalOp.evaluateSequential(this, sourceSpliterator(terminalOp.getOpFlags()));
Where terminalOp is ReduceOps.makeRef(collector)
(have a nice lunch btw)
And thus evaluateParallel defaults to:
   @Override
    public <P_IN> R evaluateParallel(PipelineHelper<T> helper,
                                     Spliterator<P_IN> spliterator) {
        return new ReduceTask<>(this, helper, spliterator).invoke().get();
    }
And then suddenly... magic happens.
This declaration...
private static final class ReduceTask<P_IN, P_OUT, R,
                                      S extends AccumulatingSink<P_OUT, R, S>>
        extends AbstractTask<P_IN, P_OUT, S, ReduceTask<P_IN, P_OUT, R, S>> {
Netbeans should support matching the < and > type parameters
We should make a Coding Challenge to implement the Java 8 Streams API... ...
 
5:27 PM
Or a coding challenge to implement export into g++. It should take some years and a full team of engineers. And also probably rewriting g++ from scratch.
 
haha
 
@skiwi I thought the general idea was supposed to be to increase participation with challenges that were interesting and fun, not to kill the site outright. :-)
 
What happened to the fun part :( just kidding
 
@Morwenn Hmm....why would anybody even want to do that, given that export has been removed from the language?
 
@JerryCoffin No reason at all. It would just be an overly difficult code challenge.
 
5:30 PM
@Morwenn It would certainly qualify for that.
@skiwi Java happened.
 
Hmm, @200's code in this review is confusing me.
2
A: Stack Exchange chat bot for posting recent answers

200_successFor starters, indent your code consistently — the standard in Ruby is two spaces. That includes indenting the contents of your begin-rescue-end blocks. Normally, I don't like to make such a huge fuss about indentation, but in this case I think it's highly important, because: Your program has ...

He got rid of some stuff, and I can't figure out why.
Maybe he just forgot to add it in...
 
I think this is off-topic:
1
Q: Magic 8 ball game

srikanthI'm trying to implement a magic 8 ball game which produces random answers without any GUI. Since I'm a newbie to VB.NET, I might have not written the program up to the coding standards. Module Module1 Private recognizer As SpeechRecognizer Sub Main() While (True) re...

Select Case e.Result.Text.ToUpper
    Case Is = "Application Close"
        End
    Case Else
        generateRandomSpeech()
End Select
 
@skiwi - the answer is updated.
 
^^^^ can't be working code
...or, it's asking for code to be written?
> How to modify in such a way that it produces random voice for every speech detected?
 
Let's see @rolfl if I can read it before dinner
 
5:43 PM
I don't like 1-liner streams.... ;-)
Especially with intermediate collections.
 
Ah it wasn't too much of a read
 
Not really, just a summary of what whe have talked about in here.
But, if someone should read it later, I will stand by what is in there ;-)
 
Now onto dinner
And playing Diablo III for 6 hours kind of straight is more tiresome than I thought
 
We're about to have another 4K user!
4
 
DVLR
Welcome to some new 4K and 8K users ;)
 
6:16 PM
We have no users between 12K and 18K, but we have three users at 18.4K with just 30 reputation between them...
5
 
Logging into chat with my sockpuppet is impossible!
 
Why?
 
It also looks like ChrisW is going to pass me soon, rep-wise.
 
Hrm, I wonder if this is rude:
in NSChat on Stack Overflow Chat, 1 min ago, by nhgrif
As a policy, I don't answer questions regarding other people's libraries...
 
6:19 PM
@rolfl I don't know, you tell me. Maybe you don't vote enough on us? :)
4
 
Thing is, I pretty much vote on anything that is half-decent...
 
Ditto ^
 
I think you don't answer enough .....
There are perhaps 10 people who are regular voters here.... in order to get decent rep, you have to:

1. get on the Hot List with a good answer
2. answer at least 2 questions per day
3. ...?
 
True. I haven't answered in days
What is a "regular voter"?
 
Even if the answers supply a small increment in value, it gets an upvote....
14 people have case more than 10 votes a day, this month
 
6:24 PM
on average, or every day?
 
on average
more than 160 votes this month
 
This is a good answer:
1
A: Stack Exchange chat bot for posting recent answers

Wayne ConradBlock syntax This: loop { ... } Causes a syntax error in MRI 2.1. This would get fix the syntax error: loop { ... } However, the use of {...} is normally reserved for single-line blocks. Prefer: loop do .. end Methods Use many more methods. It should be possible to figure out ...

 
DVLR ... ;-)
 
That question was so napalm'd
@syb0rg won't work with the puppet?
 
@Mat'sMug No. I think I'll somehow have to join programmatically. But I don't know how to do that.
 
6:31 PM
0
Q: ActiveRecord extension to find next / previous record(s) in one query

glebmI just wrote this gem order_query to find next / previous records relative to the record assuming a (possibly complex) ORDER BY over the records. Readme: Usage (excerpt) class Issue < ActiveRecord::Base include OrderQuery order_query :order_display, [ [:priority, %w(high medium low)]...

0
Q: Map color problem: Optimize using a heap?

gjdanisI've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and MapColor objects: class Territory: def __init__(self, name, neighbors, color = None): self.name = name self.neighbors = neighbors self.color...

 
@syb0rg
20
Q: RebolBot - a chat bot for the chat rooms

Graham Chiu RebolBot is a chat bot with a natural English dialect interface, specifically targeting the StackOverflow chat rooms. Yet it has a modular design, can post tweets to Twitter, and could be modified with only a little effort to work with other chat systems. An instance of the bot hangs out...

> An instance of the bot hangs out in the [Rebol and Red] room, where it runs under its own account.
 
Anyone have interaction with Flambino ?
 
not recently
 
@Mat'sMug I'll see what I can figure out.
 
6:33 PM
 
6:56 PM
user image
7
 
LOL ..... <--- go ahead and star ,.....
2
 
827
Q: What is your best programmer joke?

hmasonWhen I teach introductory computer science courses, I like to lighten the mood with some humor. Having a sense of fun about the material makes it less frustrating and more memorable, and it's even motivating if the joke requires some technical understanding to 'get it'! I'll start off with a cou...

 
@syb0rg found this:
Default API daily limits:

Key: 10,000
No Key: 300
 
I have a key.
$ ruby bot.rb
logged in with SE openid
logged in to root
logged in to chat
found fkey
Bot initialized.
9997/10000 quota remaining
Answer posted.
9537/10000 quota remaining
9996/10000 quota remaining
9536/10000 quota remaining
9535/10000 quota remaining
9995/10000 quota remaining
 
> PM Install-Package StacMan ..and I have a "it just works" .net wrapper :)
should I get a key now, or wait until I actually have an app?
 
7:10 PM
You can get it now, it doesn't matter too much.
 
> When should I use a key?
The No Key limit is meant for light experimentation and simple development work. The instant you need the higher limit, it is acceptable to register for a key. Your application does not need to be in a releasable — even an alpha — state. Remember to update your application registration when you do release your app.
I'll fiddle with 300 for now ;)
 
Hmm, I might need to update my application registration soon.
:P
 
7:28 PM
Nothing in any of the .m files yet--just trying to get an outline of what needs to be implemented from a user perspective.
 
Heh, just been a massive change in the user board --- hey @palacsint, new #3 ;-) codereview.stackexchange.com/…
2
 
7:44 PM
0
Q: Python Code Advice

user3321145I'm new to Python and want to make sure I'm not developing bad habits. If you could please review this code below and give me any tips, practice ideas or critiques you might have. Any ideas on which aspects of the language I should focus on early would also be appreciated. Thank you! #!usr/env/...

 
7:54 PM
Perhaps soon incoming from SO:
This question appears to be off-topic because it is about reviewing code, which is on topic at Code ReviewSimon André Forsberg 23 secs ago
 
0
Q: Passing function with parameters as parameter, not working with loop inside function

TaraIf I explicitly specify a function & parameters inside a function it will print out the answer of each iteration of the loop that's inside my function, but when I replace the explicit function & parameters with a variable it will print out the first iteration only. In my example_function_1 attem...

 
@syb0rg chat.stackoverflow.com/faq implies you should stay in chat as long as the chat is open in a browser window. Was it your bot that was kicked out? Perhaps the bot needs to do/simulate something Ajax-like as a keep-alive.
 
@ChrisW Some sort of keep-alive request?
 
8:14 PM
0
Q: Lua Formula Code

KnightOfNiA friend of mine dabbles in lua, and he recently sent me a code which applies an equation we were discussing. I personally am very mediocre with lua, but my Python instincts are tingling - I feel as though this code could almost certainly be shortened. Any thoughts? print("Choose what you want t...

 
@StackExchange Code isn't written by OP, off-topic?
 
Yep, it's off-topic.
 
@StackExchange I shouldn't have asked a question to which OP can answer “yes”:
@amon Thanks for your concern! I asked him before I posted and he was all right with it. — KnightOfNi 1 min ago
This is still too far in a grey area for me to be comfortable with :/ What now?
 
0
Q: Django on virtual machine - watching changes in static files and autocompiling LESS without inotify. Does this solution make any sense?

WaiskiI'm setting up a Django development environment using Vagrant to run an Ubuntu virtual machine on VirtualBox. As this is a student project run mostly be very amateur coders and I want everyone to be able to contribute, I want the environment to be as convenient as possible. What I'm trying to ac...

0
Q: JavaScript: forEach and NodeList

PM 77-1This is loosely based on one of W3_School samples: <!DOCTYPE html> <html> <body> <p>Hello World!</p> <p>The DOM is very useful!</p> <p>This example demonstrates forEach() function</p> <script> var x=Array.prototype.slice.call(document.getElementsByTagName("p")); x.forEach(function(value, index...

 
@amon If he says he's got permission, who are we to say "No you don't"?
I think it's OK
I see no reason to close it.
 
8:30 PM
Argh
 
@rolfl You know my bot works when you kill a zombie and it almost immediately gets an upvote.
 
I was wondering that!
 
That 512 surrounded by three 256's...
 
@SimonAndréForsberg technically, CC-BY-SA requires attribution of the copyright holder, which this question doesn't provide. Also, there is an argument to disallow questions about code not written by OP for reasons that go beyond copyright
 
I think someone has been upvoting Winston to keep me off the top-row a little longer ;-) That's OK, all for 20K users ;-)
 
8:33 PM
@amon Sure, I am aware of those beyond-copyright reasons, but I don't think they apply here. No one is at risk of getting fired.
@skiwi Now there's a game that would be interesting in writing an AI too!
 
:D
 
That game is interesting ... I made one 512 yesterday, the rest was too hard.
 
Pressing up, left, right, down works quite well at the start... was just checking out some comment that it was possible that way
but nope it is not, nless youa re extremely lucky
 
@skiwi how dare you have notepad.exe open! That's bad programmer's luck ;-)
3
 
I always play it tetris-like style
@amon Actually it is a reminder for when I close the PC down tonight, that I still need to do one thing by the end of today
 
8:38 PM
install notepad++ ?
 
use Sticky Notes?
 
notepad++ is only for serious stuff
sticky notes do not pop up when I close down my PC
Literally the only thing I use Notepad for is for things that I do not need to save
 
Why should anything pop up when you close your PC?
 
So that I do not forget it :D
 
What's that Android-looking icon to the left of Diablo 3?
Ah, you mean a pop up dialog to remind you to save :)
 
8:41 PM
No
I mean like, log in to this game to do a stupid daily thing
and if you forget it, then you lose progress on something, like consecutive login that coudl be running for weeks
And android-thingie is Android Studio
 
@syb0rg That's what I guessed. I don't know the chat protocol. It (downloading real-time updates) seems to be Websockets rather than HTTP.
 
9:00 PM
@rolfl "Why the big gap?" -- Perhaps ... Java?
 
@ChrisW you will be the gap-filler soon.
You are a two, maybe 3 weeks away from 10K at your current rate
I am not sure if other people have the same competitive streak as me, but, I look at your rate of rep gain and see you in the top 6 with konijn in a month
@SimonAndréForsberg is a slacker at the moment.... and half of the top6 currenly are idle.
 
@skiwi what stupid daily thing games?
I'm not a slacker, I'm just.... tired!
 
Well I was playing Neverwinter (MMORPG) and still have not completely decided whether I should stop or not, but haven't been playing actively in the last 3 weeks
 
Sounds like you've almost stopped already
I've only played three Hearthstone games today. So I've almost stopped already :P
 
9:16 PM
@syb0rg My browser is doing an occasional POST:

POST /user/info HTTP/1.1
Host: chat.stackexchange.com
Connection: keep-alive
Content-Length: 21
Accept: */*
Origin: http://chat.stackexchange.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Referer: http://chat.stackexchange.com/rooms/8595/the-2nd-monitor
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-CA,en;q=0.8,en-US;q=0.6,en-GB;q=0.4,fr-FR;q=0.2,fr;q=0.2
Note the "Referer". Maybe that's a keep-alive?
 
@ChrisW Is that output from WireShark?
 
Chrome Inspector
 
9:28 PM
night
 
@SimonAndréForsberg Good night!
 
gn @SimonAndréForsberg
 
@rolfl Sorry to contradict, but at 4K/month it would take another 3 months to squeeze into the "top 6", assuming Winston remains "idle". But simply exceeding 10k could be a useful milestone (for post-graduation privileges).
 
9:55 PM
Whover gets ahead of svick first will be 6, right? That's only 11.xK
 
@rolf
first time on chat website, thanks for invitation and apologize if i violate any conventions inadvertanly
@rolf I wanted to discuss your solution over primes.
 
Hello @JavaDeveloper
 
Sure, I understand, and no problem and welcome;-)
 
Hello @sybOrg
 
So, you want to know how I 'incrementally' re-start the sieve part way through?
 
10:02 PM
@rolfl thanks for so many brilliant feedback and learning because of you
Actually let me help save your time (i hope) by asking you from where I stopped.
 
You're welcome... remember to vote for answers that help.... (and I hope you vote for other questions/answers, not just your own ;-)
 
I have been so far very selfish only taking input and not contributing anything, but I have my own targets to commit and once done, maybe in a year, I might start returning back to community
Anyways let me ask my doubt
 
Your timing is pretty bad though ..... ;-) .... I have to go carve up some dinner... will be back in 40 minutes or so.
 
Sure absolutely
I will be there
 
Chat is a friendly place, and while you wait, you should check out the 100 days and the CodeReview review on Meta
 
10:06 PM
sure thanks
 
Hello, @JavaDeveloper. It's nice to see you here. I look forward to seeing your contributions on this site, whenever time permits. Many of your questions so far have been quite good in terms of scope and interest, and the feedback from them should help you give strong answers someday. As always, continue to vote on useful posts, which is another great way to give back.
 
Hi @Jamal, thanks for editing so many of my answers. In near future, it would definately put contributing back to community in my agenda.
 
10:31 PM
Right, hunger dealt with.... prime numbers now.,
@JavaDeveloper still with us?
            int first = (prime - (startfrom % prime)) % prime;
            if (((first + startfrom) & 1) == 0) {
                first += prime;
            }
            for (int j = first; j < sieve.length; j += prime + prime) {
                sieve[j] = NOTPRIME;
            }
 
@rolfl
just entered
 
So you were wonderin about that code?
 
yes this my doubt, lets take the number nth to be getNthPrime(6);
 
The pre-conditions for that code are:
- you want to find the primes from integer value X to integer value Y
- you already know all the primes from 2 to X - 1
 
now its something like this, 13 + 4 is prime
but 13 + 8 is not prime
looking at code 2 + 3 + 3 = 8
which gets marked as NOTPRIME
 
10:36 PM
I think you are ahead of yourself here....
 
It is more basic than that....
You know how the sieve works, right?
 
You have all the numbers, and you cross out what's a multiple of a prime.
What's left are prime numbers
 
10:36 PM
OK, so that's all we are doing here.... believe it or not.
 
sure so let me understand my first doubt
 
So, lets say we want to identify the primes from 0 through 10.....
 
int first = (prime - (startfrom % prime)) % prime;
 
we treat 0, 1, and 2 as special cases.
 
10:37 PM
Then we identify 2, 3, 5, and 7 as prime.
OK, mow we get to this new code.
We know 2, 3, 5, and 7 are prime, but we want to build a new sieve from 10 to 20.
 
sure go on i am following
 
We want to 'cross out' all the prime multiples in that range 10 to 20.
So, the code has special handling for even numbers, so we forget about 2.... and all even numbers.
 
followed
 
We start from 3.... and we need to find the first odd multiple of 3 >= 10
We know the even multiples are not prime because they are even
So, the code....:
            int first = (prime - (startfrom % prime)) % prime;
            if (((first + startfrom) & 1) == 0) {
                first += prime;
            }
            for (int j = first; j < sieve.length; j += prime + prime) {
                sieve[j] = NOTPRIME;
            }
int first = (prime - (startfrom % prime)) % prime;
That line says 'what's the first multiple of 3 >= 10'
Well, not quite, it is actually the (first multiple >= 10) - 10
consider 10%3 is 1
3 - 1 is 2
10 + 2 is 12, which is the first multiple of 3 >= 10
This making sense?
 
10:44 PM
But, 12 is an even number and it is not much use for us, so, the next thre lines are:
        if (((first + startfrom) & 1) == 0) {
            first += prime;
        }
That says that if 10 + 2 is even, add 3 to it to make 15.
15 is thus the first odd multiple of 3 in the range 10 -> 20
 
hmm... now things are clearer
 
The loop then marks 15 as NOTPRIME, and then keeps adding 6 (3 + 3) to cross out the multiples from the sieve
 
why not just 3 ? is it because even numbers are taken into account ?
i mean is 3 + 3 solely for keeping numbers odd ?
 
correct.
saves half the comparisons
 
ok I think thats good enof. some of you answers are just super smart :)
 
10:49 PM
By treating 2 as a special case for primes you can then completely ignore all other even numbers
 
Then, you just have to keep yourself in the odd 'domain', and it works out OK.
 
yup, i figured this part out
 
It has been pointed out that using a sieve like that is not the most efficient though ... I should perhaps be using a BitSet .... but that makes the logic even more obscure.
 
hmm.. yup.
 
10:51 PM
Your interest in primes, as well as some othe questions here, inspired me to put together a prime-number generator..... have a look at: codereview.stackexchange.com/questions/42636/…
The code may interest you, but also the reviews of the code.
 
Oh sweet. thats very helpful. There are junk answers all over the internet, only if people could be redirected to your answers
 
That's flattering, but I am not a very text-book sort of problem solver.... my solutins take a lot of work to make them 'presentable'.
 
Anyways just curious - there is another question - "given an excel sheet column translate it to numeric value". I have not seen a single good answer, have you happened to solve or review such an answer before
 
For example, the fact that the code above was confusing, means it is crappy code;-)
What is the actual link to the question (the share link)?
 
Sure.
looking
 
10:56 PM
I could not find anything like that in the search for CodeReview .. ;-)
 
28
Q: Programming Riddle: How might you translate an Excel column name to a number?

Pablo FernandezI was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It's about translating Excel column letters to actual numbers, if you recall, Excel names its columns with letters from A to Z, and then the sequence goes AA, AB, AC... AZ, BA,...

 
Ahh, stack overflow, not code review
 
Its related to another question I asked on math exchange
1
Q: Whats the function to translate between two number series with and without zero

JavaDeveloperThere are two number series series 1 : 0 1 2 3 4 5 6 7 8 9 10 11 ... And the second number series is stripped by zero's series 2 : 1 2 3 4 5 6 7 8 9 11 12 Thus we can see that 12 of series 2 maps to 10 of series 1 I am looking for a formulae that can do such translations for me.

But got no answer so far
This was asked to me by microsoft a year ago
 
Are you missing the 10 in the second series for any reason?
 
yes, 0's should not be part of number series
 
11:01 PM
Ahh, you should be more clear with your questions. That is not obvious from the way you describe the problem....
So, would 101 be part of the second series ? (I presume 'no')?
 
no
I agree with your point
Also in my best guess both questions (excell ) and (number series) are related
 
Interesting problem. It would be easier to map from the second series to the first, rather than the other way around.....
No, I don't see a pattern between mapping the excel columns back to column numbers, and the zero problem.
 
excel sheet does not have concept of 0's
 
Sorry I can't help but asking.. why not just use R1C1 references?
(hi!)
 
Hi...
the question is really, I have column AU in an excel sheet, what is it's column number (it is the x'th column)
 
11:05 PM
well let me try to explain what i understand
 
These are all interview-type questions.
 
AB..XYZ and then the next one is AA
 
It's column number AU.
 
Yeah, I'd create a Range object selecting that column, and then get the R1C1 address for the selection - the number you want is next to the "C"..
 
I am what you mean by 'get R1C1 address'
 
11:08 PM
Excel addresses are either "A1" or "R1C1" style
Columns in "A1" references go A, B, C, ..AA, AB, AC, ..
"R1C1" reads "row 1", "column 1"
 
I am not supposed to use an predefined API
 
So, it's for Excel but you can't use the Excel object model?
 
This is an interview question ( not for real life project )
 
ah!
 
They are trying to test a function / method / prodedure
to translate A - 1 Z - 26 and AA- 27
which in my opinion is similar to a number series with 0's stripped
 
11:11 PM
ok I must have missed that part
 
ok
no probs
then AA -> 11
and since we dont have any char that maps to 0
if A -> 1
we dont have 10
ie a 26 base number series without a single 0
 
that sounds like it would make a good Code Golf / Programming Puzzles question
 
@JavaDeveloper there are still 0 digits in the results,
There is still column 10, it is just called 'J'.
 
Yeah but i meant no zero digits for base 26
 
A == 0
if you treat A as 0, then add 1 to the result, you have the answer
Oh, actuall, I see what you mean.
 
11:14 PM
yeah but AA is 00
which is getting me confused
yeah but AA is 00
which is getting me confused
 
yeah but AA is 00
which is getting me confused
 
lol
2
 
OK, I see the correlation between the excel and the zero problem now ;-)
 
Converting from excel to decimal is easier than the other way around.
With a loop, not a straight formula
 
11:21 PM
I cannot see through what you mean
you mean simply ctr in a loop at the very low level of understanding
 
public static int getExcelColumnNumber(String descriptor) {
    char[] chars = descriptor.toLowerCase().toCharArray();
    int result = 0;
    for (char c : chars) {
        result *= 26;
        result += c - 'a' + 1;
    }
    return result;
}
 
interesting
 
The reverse would be a modulo operation, getting the data in reverse order.
 
ok I will solve this - do you mind i post final answer on code review ?
for both char -> number and number -> char
I can put on the note - (rolfl) suggestions - it would be useful to many
 
Sure, feel fee....
no need to credit me ;-)
 
11:33 PM
Awesome thanks this question, had hung me for quite a while. Np ! but thanks anyways
 
@Malachi hey man, whats this you want me to see. I'm just working on making my games. Gunna put it up on greenlight this week.
 
@BenVlodgi Greenlight? Do you have a version I could see?
 
0
Q: Switch-case Monstrosity for CPU Emulator

Lee AllanI am still working on A Z80 CPU emulator and I have decided to prototype it in javascript and then translate it into a faster language, It might be ported to C but more likely is Java - this means I cannot use pointers or jump-tables. It both compiles assembly and interprets it however both are g...

 
11:51 PM
@syb0rg darn, I can get everything I want from the SE API, ...except the chat.
got a link to some doc?
 

« first day (316 days earlier)      last day (3702 days later) »