Monthly Coding Challenges

Please have complete examples and make sure all submissions are fully runnable in some manner under a linux or an emulation system (ie c code works with gcc, c# with mono, javascript with node, asm is x86, etc…)

A pastebin service is in the works for next month’s challenge. For now, links to github gist/pastebin/insert favorite code pasting site… are allowed.

The winner will be picked the weekend before the next XM Core Conference Line Dial in/VCC Meetup towards the end of the month and announced doing the meetup. Prizes are always awarded at the end of the Meetup event.

Is this a valid answer?
;\code in mpasm 8bit
greaterthan ;\function label
;\given the random number is in register w
;\given label LIMIT represent a register address
;\containing a valid limiting value in bank0…
banksel LIMIT;\ macro for bank selection
subwf LIMIT, w;\ LIMIT-W->W
skpc; \ skip if carry bit is one
;\ if the subtraction caused a carry then random
;\number is bigger than the limit.
retlw 0;\ return false in register w
retlw 1;\ return true in w register random number
;\is greater than limit

No, as MPASM can’t assemble HTML-escaped code. :slight_smile:

Try using <code> and </code> blocks to protect your code. It should look like this:

int foo = 5;

So what assembly language is correct to use.

I think you missed my point: You pasted in your program, which was then mashed into web gobbledygook (technical term there) that would not be appropriate for an assembler.

Please edit your post and use the two tags I mentioned before and after the code, respectively. This will avoid the forum, your web browser, or whatever from pureé-ing your code.

You might also consider <pre>, instead of <code>, as it will preserve spacing:

   addlw  TABLE_START
   movwf  temp
   rlf    known_zero,w
   addlw  high(TABLE_START)
   movwf  pclath
   movf   temp,w
   movwf  pcl
TABLE_START
   retlw ...

Posting code before OP declares the challenge over seems bad form…

Please use x86 instruction set in either Intel or at&t notation as I’ll have to run the code through the testing program to accurately score entities.

Ok ladies and gents, lets see some code! Sept 30 is just around the corner.

Well… I just found out about this today and I thought I would give it a shot …

#include <stdio.h>

int equals_zero(_Bool in) {
	return (int)!in;
}

int greater_than_zero(int in) {
	return equals_zero(in - 1) + equals_zero(in - 2);
}

int less_than_zero(int in) {
	return equals_zero(in + 1) + equals_zero(in + 2);
}

int main(int argc, char**argv) {
	int i;
	
	printf("Greater than zero --\n");
	for(i=-2; i<=2; i++) 
		printf("%d: %d\n", i, greater_than_zero(i));
	printf("\n\n");
	
	printf("Equal to zero --\n");
	for(i=-2; i<=2; i++) 
		printf("%d: %d\n", i, equals_zero(i));
	printf("\n\n");
	
	printf("Less than zero --\n");
	for(i=-2; i<=2; i++) 
		printf("%d: %d\n", i, less_than_zero(i));
	printf("\n\n");
	
	return 0;
}
2 Likes

I found a way to get rid of the not (!) …

int equals_zero(int in) {
	return (_Bool)((_Bool)(in)-1);
}

I would have liked to work on this problem, but found it unclear.

What do you mean by arithmetic? Multiplication is arithmetic; was it allowed? The less-than operator is also arithmetic, but obviously you don’t mean for that to be allowed. But it gets fuzzy: what about the conditional expression operator? What about the not operator? Bit shifts? Casts? Array subscripting? Parentheses? Those are all operators. Which are allowed?

http://en.cppreference.com/w/c/language/operator_precedence

This problem was less a technical problem and more a “guess what the author had in mind” problem. I will point out that addition and subtraction modulo powers of two are closed under composition, which amounts to saying (crudely and a bit ambiguously) that + and - are insufficient by themselves.

1 Like

Likewise.

A comparison in assembly language is nothing but a subtraction but the difference is not stored anywhere.

1 Like

@denzuko … Dwight, are you ever up at the space? I most hang out in the Digital Media area if you ever want to stop by.

I’m there usually on the weekends and a day or two through out the week, depends on the schedule. I’ll also be swinging by later tonight after work around 20:00.

We now have an official wiki page. https://dallasmakerspace.org/wiki/Coding_Challenges

2 Likes

Do you mind if I format the wiki a bit and make it more clear?

Also, I have a question about the September challenge and arithmetic…
When you say arithmetic, are you talking about just using math functions in general or just the math functions you specified (Addition, Subtraction and inverting the sign)?

Also, I have an idea. Could we each month have perhaps two or three coding challenges? A beginner, intermediate and advanced? This way people that are just learning might have fun as well.

Also, a general question for the challenges. Why do have a default range that is not a multiple of 2? I would have thought that a full 16 bit signed integer (short) might be closer to what we might want. For example -32768 to 32767.

1 Like

Just do it.
If @denzuko objects, it can be reverted. That’s the beauty of wiki history… If the two of you can’t see eye to eye, discuss, but usually people like the assistance with the wiki.

2 Likes

@jast is right on that. I appreciate the volunteering for assistance with all this as its more than welcome. Obviously @draco you and I did get to talk a bit on all this the other night in person and if there’s a few extra challenge ideas you’ll like to submit then I welcome it for upcoming months.

However, since you’re competing in the september challenge and in the sake of fairness we’ll explore those challenges your proposing for after the September XM Core dial-in event.

As for any conflicting ideas on the wiki or challenge ideas, we can discuss those in talk, on the bbs, irl at the space, or at the XM Core dial-in events to come towards a resolution.

This also extends to anyone else interested in contributing to the coding challenges.

1 Like

Spoiler alert

DEFINE JudgesMind $0x081983
POKE JudgesMind, 12360.1

ERROR… ERR.RO…ERO
beep
TIS-100 ©1985-2015 Zachtronics Industries
BOOT: |

1 Like

In honor of the month of October, “Guru Meditation”

1 Like