« first day (3425 days earlier)      last day (1433 days later) » 

12:15 AM
Any feedback for this and this?
 
 
8 hours later…
8:29 AM
0
A: Sandbox for Proposed Challenges

l4m2What day is it today? code-challenge Given a date y4y3y2y1-m2m1-d2d1, output the day in the week w. 0 as Sunday, 1 as Monday, and so on. You can assume the date is valid, and every year has 12 month, every Jan,Mar,May,Jul,Aug,Oct,Dec have 31 days, every Apr,Jun,Sep,Nov have 30 days, Feb have 29 ...

 
8:40 AM
-2
Q: input ten numbers and construct a max heap. After constructing max heap, consider all the numbers that are at the leaf nodes of the heap

hamza ahsanWAP in Java to input ten numbers and construct a max heap. After constructing max heap, consider all the numbers that are at the leaf nodes of the heap. Input frequency of search of all those numbers and create an optimal binary search tree using those numbers and their frequency of search. Compu...

 
9:27 AM
1
Q: Toroidally magnify-blur a matrix

BubblerTask Given a matrix of numbers \$M\$ with \$r\$ rows and \$c\$ columns, and the magnification factor \$n\$, build the matrix with \$rn\$ rows and \$cn\$ columns where the original elements are spaced \$n\$ units apart and the gaps are filled by piecewise linear interpolation: $$ \begin{bmat...

 
 
1 hour later…
10:42 AM
hello!
 
11:38 AM
Anyone here familiar with EBNF and railroad diagrams?
 
Greets! I'm working on Roger Hui's sorting task (sort a vector of n indices, where each is one byte big)
 
Having fun?
 
the task forbids SSE, loop unrolling, and other helpful stuff so I just decided to compile portable C code with -Os
so far I completed the challenge
I could post my solution, because I'm finding a better one
if such exists
idk how to post code snippets
 
What is the challenge though?
 
uint8_t m1(v,n,q,i)uint8_t*v;{uint8_t
m,s,b;if(n&1)m=*v,q=1;else m=(*v<v[1]
)?v[1]:*v,q=2;for(i=q;i<n-1;i+=2){if(
v[i]<v[i+1])s=v[i],b=v[i+1];else s=v[
i+1],b=v[i];m=m<b?b:m;}return m;}
done
@mypronounismonicareinstate its above, in brackets
* sorry, not a sorting task, finding the maximum
 
11:46 AM
Where did you find the challenge?
 
Roger Hui gives the following C code and some APL below I can't understand
unsigned char max2(unsigned char * x, int n) {
    unsigned char m = *x++;
    for(int i = 0; i < n; i++, x++)
        if(m < *x)
            m = *x;
    return m;
}
 
And the APL code?
 
I still understand nothing. What do we have to do?
 
this is it
  x←?1e6⍴1000
  a. ¯1+{≢⍵}⌸(⍳1000),x     1.00       (_1+#/.~(i.1000),x  )
  b. ¯1+{≢⍵}⌸(⍳1+⌈/x),x    1.62       (_1+#/.~(i.1+>./x),x)
that's the hint
@mypronounismonicareinstate Find the maximum of a vector of 1-byte ints without using multicore, vector instructions, loop unrolling, etc.
Can you do it faster in C than the following?
 
That's APL on the left and the equivalent J on the right.
 
11:48 AM
fair point, I guess its distinct occurences 1st and max 2nd.
Szewczyk: 8228, 255 Hui: 12644, 255
Szewczyk: 6836, 255 Hui: 11776, 255
Szewczyk: 5524, 255 Hui: 6692, 255
Szewczyk: 6836, 255 Hui: 11776, 255
 
a. is the occurrences of all numbers in the allowed range, while b. is the occurrences of all numbers up to the maximum.
 
some benchmarks in cycles, on random data aligned to the page size
so far my code seems superior, but I wonder can it be made better.
 
no loop unrolling seems to be an unobservable requirement :( How much data was used to benchmark?
 
random data aligned to the page size
4096 bytes
because a page, obviously, on my PC is 4K big
 
perhaps a good idea would be to compute the OR of chars in blocks and if it's a subset of the current number to skip the entire block? (presumably, of 8 chars as an int64_t) (I guess I'll try that later) (I assume quitting once 255 was found is not fair, though) What unit of time is used in the benchmarks? (CPU cycles?)
 
11:56 AM
@mypronounismonicareinstate Why is quitting once 255 is found not fair? That has to be the max.
 
12:08 PM
yes, CPU cycles.
@mypronounismonicareinstate that doesn't seem bad, but it smells of unrolling and this is mildly banned
 
your approach also has i += 2, I guess it also smells of unrolling in the same way; loop unrolling is unobservable :(
 
it's doing stuff in pairs for smaller amount of comparisons
 
12:38 PM
I've had some time on my hands so I implemented your approach:
uint8_t m1(v,n)uint8_t*v;{uint8_t m=0;if(n&1){m=*v;v++;n--;}for(int i=0;i<n;i+=2){if((v[i]|v[i+1])>m){m=(v[i]>m)?v[i]:v[i+1];}}return m;}
the performance is comparable to Hui's miniature and significantly slower than my algo
 
How to invoke your solution? (I implemented my idea with int64_ts; it indeed sounds like it will be slower)
 
ret = m1(vec, size, 0, 0)
uint8_t m1(v,n,q,i)uint8_t*v;{uint8_t m
,b;if(n&1)m=*v,q=1;else m=(*v<v[1])?v[1
]:*v,q=2;for(i=q;i<n-1;i+=2){b=v[i]<v[i
+1]?v[i+1]:v[i];m=m<b?b:m;}return m;}
this is an improved version
with a bit less fluff inbetween
 
I (and my compiler) am worried by how your code has both implicitly-int-typed variables and uint8_t
 
reason is simple
uint8_t is shorter than unsigned char
and implicit int is shorter than int
 
I seem to be getting 175ms vs 202ms with `g++ -Os` (assuming -Os doesn't do cheating like unrolling; it probably shouldn't. but it seems to; this shouldn't happen), my code is `byte bmax(const unsigned char* u8x, int n) { const uint64_t* u64x = reinterpret_cast<const uint64_t*>(u8x); int i, j; byte max = 0; for(i = 0, j = 0; i < n; i += 8, j++) { /*"or" and "bitor" are keywords, of course */ uint64_t oR = u64x[j]; oR |= oR >> 32; oR |= oR >> 16; oR |= oR >> 8; if(byte(oR) > max) { for(int off = 0; off < 8; off++) max = std::max(max, u8x[i + off]); } } i -= 8; for(; i < n; i++) max = std::ma
byte bmax(const unsigned char* u8x, int n)
{
	const uint64_t* u64x = reinterpret_cast<const uint64_t*>(u8x);
	int i, j;
	byte max = 0;
	for(i = 0, j = 0; i < n; i += 8, j++)
	{
		//"or" and "bitor" are keywords, of course
		uint64_t oR = u64x[j];
		oR |= oR >> 32;
		oR |= oR >> 16;
		oR |= oR >> 8;
		if(byte(oR) > max)
		{
			for(int off = 0; off < 8; off++)
				max = std::max(max, u8x[i + off]);
		}
	}
	i -= 8;
	for(; i < n; i++)
		max = std::max(max, u8x[i]);
	return max;
}
 
1:09 PM
that's not C
but it's eaisly translatable to c
 
0
A: Sandbox for Proposed Challenges

nopeBot Duels KOTH king-of-the-hill Submissions Submissions should be a JS function that takes the following parameters: curr_x - the current x coordinate of your bot curr_y - the current y coordinate of your bot enemy_x - the current x coordinate of your opponent's bot enemy_y - the current y co...

 
you: 14116 Hui: 9238
you: 16466 Hui: 11972
two random results
verdict: 4 is too much, 2 is just fine
 
this result makes much more sense than mine; I have no idea where is my benchmarking wrong
 
I consider my solution above acceptable
a few questions to tick off: did you use the return value?
did you use __rdtsc, or maybe clock or time?
how big is your input?
4K input favors your solution, because reasons.
 
Yes; as I usually do in such cases, I xor all return values and printf the result. I was testing on 100000 test cases with 4096 random bytes. I think you missed a truncating cast in your code in the if(byte(oR) > max) line.
 
1:20 PM
hmm yes, and what is suprising, it actually works well with -O0
but I believe it's due to the fact that the loop is unrolled
 
My only guess to explain how 6 uint64_t operations are better than 8 uint8_t operations is that maybe reading a single byte from memory is slow.
 
5
Q: Lucky dice rolls

Gábor FeketeLucky dice rolls In pen and paper roleplaying games dice are used for various chance calculations. The usual way to describe a roll is \$n\textbf{d}k\$ where \$n\$ is the number of dice and \$k\$ is the number of faces on a die. For example \$3d6\$ means that you need to roll the classical 6-sid...

 
operations on larger numbers in terms of size has always been faster
than continuous operations on smaller numbers
I believe a lot comes into play. At first, I'd suspect partial register stalls, but I can't believe a compiler would make this mistake
maybe caching comes into play /shrug
and maybe the CPU pipeline is just optimized for computations on large numbers, this seems logical
that's a bit like how SIMD works, isn't it - larger vectors, the processor can do its job while the program isn't occupying other parts of the pipeline
 
anyway, why can't they use loop unrolling? (I can imagine some kind of special CPUs without SIMD, but can't imagine anything that can't use unrolled loops)
 
that's the challenge, I think it would be a good idea to ask Roger Hui why did he ban it
 
1:34 PM
@KrzysztofSzewczyk Go ahead and ask!
 
although I like Roger for his work on J and APL in general, I've got other things to do currently :p
 
I can ask him if you want.
 
sure thing
this thing has been bugging me since 1pm today
and it's 5pm already
I've been doing other things inbetween, but yeah, I bet solid 2 hours went into fiddling with it
 
Is your code always obfuscated like that, or did you do that before sending it here?
 
depends, sometimes I write concise C code when I'm feeling lazy
and in such cases, I never test my code
the smallest amount of keystrokes the better
that's mainly why I like J :p
but for real stuff that I'd like to maintain that isn't a fun puzzle, I'm writing normal code
 
1:40 PM
@KrzysztofSzewczyk OK, email sent.
 
nice
lmk when Roger responds
 
For sure. I've linked him this discussion, though I don't think he has a SE account.
 
for some reason my runtime halves when I manually unroll the inner loop; now I suspect that my benchmark is wrong even more
 
hahaha no
-Os and -O0 do literally zero unrolling
so if you unroll it yourself, chances are your compiler will either roll it again or leave it be
that's the main reason I don't consider optimization other than -Ofast or -O3 (or in some edge cases -Os) for anything else than debugging.
also, since when is byte a C++ keyword
I've seen it in Arduino code, but not in regular C++ code
 
it's a typedef unsigned char byte;, a typedef I often (inconsistently) use because I'm coming from C# (over time, I started getting annoyed at its slowness)
 
1:47 PM
ah, interesting
so you're not doing typical C#-things aren't you
 
@mypronounismonicareinstate to me it seems the requirements were there purely for the fun of the challenge (i.e. probably to prevent what yall're doing with oring :p)
 
what's oring?
also, it doesn't seem like a real challenge to me, more like a toy
you may say - there's nothing wrong with it
 
@KrzysztofSzewczyk OR-ing :p
 
ah, fine
I'd agree if only Roger didn't take it seriously
 
in any case, would it be a good idea to post something like that (with the [fastest-code] tag) to the site?
 
1:56 PM
@dzaima then the challenge looks like "golf me a fast fourier transform, but in Malbolge, to prove that ebe ebe"
for a long time I wanted to post a fastest-code Malbolge Unshackled interpreter hoping that someone will post an interpreter that will run my programs without taking exabytes of RAM and more processor cycles than the amount of particles observable universe squared :p
 
i'm more interested in what exactly was used for timing. if it's purely CPU cycles there are a couple things i'd try (depending on the platform, achieving 3 ops/item (including the jump to start) + O(1) wouldn't be hard, but it'd be slow otherwise), if it's time then the compiler using correct operations is pretty much all that matters
 
I'd happily hear how do you process an entire vector of size N using a O(1) algorithm.
 
I was timing in time because most of the time the time matters. (what a repetitive sentence). Isn't that O(1) for initialization/exit?
 
Infinite code banned
well then, maybe I misunderstood it :p
 
@KrzysztofSzewczyk i meant more like O(3 ops*N + N ops)
 
2:00 PM
interesting
 
A list of random data will be an amortized O(1) if you exit after the first 255, I think :)
 
there's no guarantee that the distribution of PRNG powering the /dev/urandom device is uniform
rather, a better idea is to just exit after you spot a 255
 
@dzaima i may have forgotten a couple of ops, it's 5 ops/item :/
.oO(x86's LOOP instruction)
 
> Loop unrolling is a distasteful way to get speed-ups, and does not require much insight or skill. This view is of course depends on your point of view. Since I am posing the puzzle I get to make the rules. :-)

The context in which the puzzle is posed is a hint in itself. The "expert C programmers" to whom I posed the puzzle did not have the benefit of this hint.
 
anyway this is that stupid solution :p
 
2:14 PM
I tried it before
it's not great not terrible I'd say
 
@KrzysztofSzewczyk exactly, but it is less x86 instructions per item
 
.. but it doesn't change anything, because it's not faster
been there, done that
 
@KrzysztofSzewczyk that's why i said the timing method and system configuration matters a lot (is constant memory bombarding a big issue, is the processor good at evaluating these types of instructions, etc), and otherwise it seems relatively related to the task at hand
 
yep
but I think the general idea suggested above is better than this
albeit it seems quite hairy because loop unrolling is banned
and arguably, the code may or may not unroll a bigger loop
 
@KrzysztofSzewczyk obviously there are many things better, but i'd call it hitting the unrolling rule and therefore non-competitive
 
2:19 PM
well then
if you come up with something
feel free to ping me
 
2:35 PM
hi all!
 
2:49 PM
query: Imagine you have two spots on planet earth and you try to shine a light from one to the other by reflecting it off an object 500km up,
how do you map the angle you would shine the light at to the distance between the two spots?
(definitely a coding question :) )
 
3:18 PM
hint: the mirror will evenly split the light path
 
I can see there is an isosceles triangle . But the height of the triangle depends on how far about the spots are
so I am confused now :)
@JohnDvorak can you see how to solve it?
 
yes.
 
ah.. please tell me!
 
Actually, that would be the case if the mirror was known to be horizontal. As is, the situation is underdefined.
 
3:33 PM
@JohnDvorak Not only that, it also doesn't specify if the object is equidistant from the spots, and if if it is, whether it is directly above the great circle that connects the spots.
 
Right. It could be 3D.
 
if I wanted to post a challenge regarding emulation of a certain automata, should I specify that a single storage cell should be unbounded? or leave it bounded and up to choice of the golfer?
 
Heh, it might not even be possible to shine the light, even if the spots are immediately adjacent.
 
You can calculate: the shortest path angle (planar equidistant case), longest path angle (planar case tangent at receiver), or the 3D case with both transmitter and receiver tangent
 
"certain automata" that doesn't tell me a lot about the challenge...
 
3:35 PM
Case: both spots are at the north pole, and the object 500 km above the south pole.
 
it's a minsky machine
 
For the last one, the path length is actually independent on how far the points are.
The maximum range is actually pretty low - 4773 kilometers and a change when both transmitter and receiver are horizontal and coplanar.
Actually, keep it at 4774 km. Easier to remember and a tad more accurate :)
Another update, 4774 to the dot is possible even without atmospheric refraction, you just need to aim just below 12 arc-seconds above the horizon.
 
4:08 PM
0
Q: What calculator is this datafile for?

Krzysztof SzewczykThe challenge today is very simple. The task is to determine the TI calculator, for which the submitted datafile was made for. The datafiles always start with a string **TI, the version (described below) and other data you can ignore. Now, the versions you need to recognize are: 95* => TI-95 9...

 
@JohnDvorak The mirror is horizontal
@Adám Let's assume the angle of incidence equals the angle of reflection
 
 
1 hour later…
5:32 PM
the index-of challenge seems to be a nice project to do/
also you can still meet the requirements compiling with -O2, just add -fno-vectorize and -fno-unroll-loops, flags might be a bit different depending on compiler
iirc gcc doesnt enable vectorization until O3 but clang has it enabled at O1
 
6:29 PM
0
Q: What is the fastest but safest way down a mountain?

SqepiaIntro Help! I'm stuck on a snow-covered mountain and I need to get down as fast as possible, preferably without dying. I have a map showing how high each part of the mountain is above the normal ground. I am a novice skier, which means I like to stick to slopes that aren't too steep. I'm willin...

 
6:40 PM
two of my Charcoal answers were downvoted recently, but not my Retina answers on the same questions... what's wrong with Charcoal?
 
 
4 hours later…
10:54 PM
made that range-finding puzzle into a small repo with a simple benchmark
 

« first day (3425 days earlier)      last day (1433 days later) »