Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Hello ladies and gentlemen!

It was a rather long time ago that Code Golf - The Reboot was active, and I enjoyed it so much, that I decided it would be fun to pick that up again. So here I am with a new task. Don't know what Code Golf is? Check some old topics. You have one week to complete this task, and entries should be submitted by sending a PM to me. Without any further ado, here is your task:

Write a program that inputs a positive integer and outputs the Belgium k-number of the input. Of course, you have no idea what a Belgium k-number is, so let me explain that first. Let k be one of the integers 0-9. The input N has the Belgium k-number, if N occurs in the increasing sequence which starts with k, and the difference between 2 consecutive numbers in the sequence are the same as the digits of N. See this for a better explanation. Let me give an example.


Code:
k = 7, N = 85
Sequence starts with 7
7  + 8 = 15
15 + 5 = 20
20 + 8 = 28
28 + 5 = 33
33 + 8 = 41
41 + 5 = 46
46 + 8 = 54
54 + 5 = 59
59 + 8 = 67
67 + 5 = 72
72 + 8 = 80
80 + 5 = 85
STOP

As you can see, 85 is in the sequence (7, 15, 20, 28, 33..), which means 85 as Belgium k-number 7.

Other example:

Code:
k = 7, N = 152
Sequence starts with 7
7  + 1 = 8
8  + 5 = 13
13 + 2 = 15
15 + 1 = 16
16 + 5 = 21
21 + 2 = 23
23 + 1 = 24
...


Providing that ANY input N>9 has at least 1 Belgium k-number, find one of the Belgium k-numbers with any input.

Good luck! Smile

I've no idea if this is a simple or a hard task, we will see later!
I'm at 51 bytes, and I don't think it is possible to optimize further, but I've been wrong before.

Edit: PT_ is at 48, and somehow found an optimization in mine?!
My O(n) version is also 48 bytes, but my O(log(n)) version is 42 bytes, which takes 1/3 of a second to compute that 999999999999 is a Belgian-9 number Very Happy

Edit: I just optimized the O(n) version to 41 40 bytes. Sad
Entry submitted. I think I've optimized it as much as I can.
Sorry if I was not clear, but your program should input the variable, you can't assume N (or any other variable) is set before the program runs. In TI-BASIC, it looks like
Code:
Input N
or something similar. With Assembly, you are allowed to fetch the input from Ans. It should display/set in Ans at least one k-number.
Wait, how are we counting the size of a program? Bytes of code, or size in the menu (code + 9 + name length)?
Bytes of code, minus the header.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement