CodeWalrus Website > Contests

Code Golf Belgium Numbers

(1/2) > >>

PT_:

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
--- End code ---
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
...
--- End code ---

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

Good luck! :)

I've no idea if this is a simple or a hard task, we will see later!

Sorry, didn't realize there are already 2 open contests at CW :(

c4ooo:
You should change the name of the thread to "code golf - the reboot - the reboot #1" :P

Anyways, I don't remember you participating in codegolf on omninaga? Lol  9_9  :P

Juju:
And I rebooted the concept just yesterday, what a coincidence? Eh, I dunno, you should had seen it. Anyway. Good to have some contests here. I'll try to do something.

EDIT: What about Code Golf: The CWreboot #2? (#1 is mine, hehe)

_iPhoenix_:
I'm at 51 bytes, which I suspect is the absolute minimum.

(This is TI-BASIC only, btw)

Juju:
Okay, so if I understand, for any input N, find the k number(s), if there's any?

Edit: I'm at 95 bytes in Ruby (or 87 in Ruby 2.4). Cool and good.