The Nine Pattern

9

Introduction

I stumbled across this (useless) pattern the other day while I was watching TV. I named it "the 9 pattern" because the first number to use it was 9. The gist of it is, you enter a number (let's say x), and then you get back:

  • x
  • x + (x / 3) [let's call this y]
  • two-thirds of y [let's call this z]
  • z + 1

So, if I put inside this pattern the number 9 as x, this is what would come out:

  • 9 (9)
  • 12 (9 + 9 / 3) [9 over 3 is 3, and 9 + 3 is 12]
  • 8 (12 times two-thirds) [a third of 12 is 4, and 4 * 2 is 8]
  • 9 (8 + 1 is 9)

Challenge

Write me a function (in any programming language) that takes in a number, and outputs an integer array using the pattern.
Somewhat like this psuedo-code:

function ninePattern(int myInt) returns IntegerArray {  
    int iterationA = myInt + (myInt / 3);  
    int iterationB = iterationA * (2 / 3); 
    int iterationC = iterationB + 1;  
    IntegerArray x = [myInt, iterationA, iterationB, iterationC];  
    return x;  
}

Clarifications

Discussions have been arousing in comments regarding the specifications of the question. This section is meant to clarify some of those.

"better to count in bytes than characters"

I picked characters because (for me, at least) it would be easier to judge. Of course, I can't change that now. (lots of answers are already posted)

"rounding"

Rounding follows this rhyme:

If it's 5 or more, raise the score
If it's 4 or less, let it rest

Simply, put, if it is something like 4.7 or 3.85, round them to 5 and 4 respectively.

Examples

Input => Result
9 => [9, 12, 8, 9]
8 => [8, 11, 7, 8]
6 => [6, 8, 5, 6]
23 => [23, 31, 21, 22]
159 => [159, 212, 141, 142]

If, however, the numbers are something like 2.3 or 10.435446, round them to 2 and 10 respectively.

"language support"

You are free to not use functions and/or arrays IF AND ONLY IF the language of your choice does not support them. If it does (even if it will increase your characters count), you must use them.

InitializeSahib

Posted 2016-05-24T00:19:12.097

Reputation: 491

1Must the output be an array, or are the numbers by themselves enough (like the Pyth answer)? – David – 2016-05-24T00:46:11.697

@David must be an array – InitializeSahib – 2016-05-24T00:47:19.850

2

You are free to restrict to just full programs, or just functions, but there is discussion on meta of the defaults, which gives some useful background in case it affects your decision for future challenges. By default challenges accept both, to allow more languages to compete.

– trichoplax – 2016-05-24T01:38:51.563

1

There are defaults for input and output too. Again, you don't have to follow them, this is just to let you know.

– trichoplax – 2016-05-24T01:46:15.447

I took a shot at it in brainfuck but I don't think it's possible for it to work with all numbers since brainfuck can't do floating point division. This code will work for all multiples of 9 as input (9,18,27,36,etc). Link: http://bit.ly/1Wen2Cl. (Had to shorten link because it's 1783 characters)

– Keatinge – 2016-05-24T03:13:30.557

3-1 for the arbitrary array and function requirements, which prevents languages without an array/list type or functions from competing. – Mego – 2016-05-24T04:15:30.197

4

Also, you should score the contestants in bytes, not in characters. We have a Sandbox, where you can get feedback on your post before it goes live.

– Loovjo – 2016-05-24T05:21:08.270

1Is y = round(x + x/3); z = round(⅔ y), or does the rounding happen only in the final step of printing the results? – Lynn – 2016-05-24T10:59:15.500

1What if the language does not have array? Can we use delimiters to separate them? – Leaky Nun – 2016-05-24T11:13:29.660

Another thing, counting in characters is often uninteresting, as it encourages boring base encoding of answers. In addition, you don't specify how rounding needs to be performed. Does 6.5 round to 6 or 7? What about 7.5? What about "near misses" due to floating point precision? – FryAmTheEggman – 2016-05-24T18:06:06.653

"Write me a function" Does this mean it's OK to write int[] aJavaMethodOrFunctionOrWhateverThatIsNotInsideAClassOrAnEnum(int i)? – user8397947 – 2016-05-24T19:10:58.050

@dorukayhan That's acceptable by default. – Mego – 2016-05-24T19:51:18.393

@FryAmTheEggman The usual meaning of rounding is half-up. – Mego – 2016-05-24T19:51:48.460

@Mego Many languages actually use banker's rounding by default, where if the digit before the 5 in the decimal representation of the number is even, you round down, but if it is odd you round up. In any case, I don't think it is a default that can be assumed (I've never seen anything on meta about it, anyway). – FryAmTheEggman – 2016-05-24T19:55:21.583

I recommend adding more examples as some of the answers indeed work with the example 9 but fail with other inputs. – Frozn – 2016-05-24T20:54:59.847

I've explained some of the complaints in a new "Clarifications" section. – InitializeSahib – 2016-05-24T23:18:54.487

I'm sure you meant round to 5 and 4 instead of 4 and 3 in the clarification. Else I misunderstood maths. – Frozn – 2016-05-24T23:24:40.240

@Frozn Oh, yes I did mean that! Editing now – InitializeSahib – 2016-05-24T23:25:52.723

Answers

11

MarioLANG, 659 621 591 582 556 543 516 458 418 401 352 308 369 bytes

rounding is quite expensive :/

Try it online

;>>[![( [( [( [( [( [<(([!)))!+(((-<>( >((+
:"==#================"===#== #=====""[ "==
)(  -[!)>>[![)  [)[<(!>)[<)) >))) [!!-[!((
 (  )"#="==#======="=#==="=<="=====##==#==<
 +  +>) )-+<>+)[!)+! +))![-[)>[ [([-[![<<:
 +  )-+ )(=""===#==#  ==#===)"=======#=====
 +  >!>)!>  !(- < !:+:))<  ))!((++)))< 
 )  "#"=#===#===" ======" ===#======="
 !
=#========================

Well this was more fun than expected, this is probably not optimal but I guess i'm getting there.

Explanation time:

(for the 352 bytes version)

first we get the argument and print it :

;
:

simple enough

we then move to the bulk of the program : the division input / 3

;>>[![              [( [( [<result
:"==#======================"======
)   -[!)>>[![        [<((((!   
)   )"#="==#=========="====#
+(  +>) )  +>(+)[!)+))!
+(  )-+ )  -"====#====#
+   >!>)!  >! -  <
    "#"=#  "#===="
 !
=#

which is a slightly modified conversion of the brainfuck division

[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]

which take for input

n 0 d 0 0 

and give you back

0 n d-n%d n%d n/d 

once we got the division we use it to get the sum of n and n/d and print it

;>>[![              [( [( [<    !+(((-<
:"==#======================"===)#====="
)   -[!)>>[![        [<((((!    >))) [!(((
)   )"#="==#=========="====#   ="=====#==:
+(  +>) )  +>(+)[!)+))!
+(  )-+ )  -"====#====#
+   >!>)!  >! -  <
    "#"=#  "#===="
 !
=#

we then need to do another division : ( 2 * ( n + n / d ) ) / 3

so we get ( 2 * ( n + n / d )

;>>[![              [( [( [<    !+(((-<
:"==#======================"===)#====="
)   -[!)>>[![        [<((((!    >))) [!(((
)   )"#="==#=========="====#   ="=====#==:
+(  +>) )  +>(+)[!)+))! 2*2n/d>[   -[![  <
+(  )-+ )  -"====#====# ======"======#====
+   >!>)!  >! -  <            !((++))<
    "#"=#  "#===="            #======"
 !
=#

and put it with 3 back into the division

;>>[![              [( [( [<    !+(((-<
:"==#======================"===)#====="
)   -[!)>>[![        [<((((!    >))) [!(((
)   )"#="==#=========="====#   ="=====#==:
+(  +>) )  +>(+)[!)+))!      )>[   -[![  <
+(  )-+ )  -"====#====#      )"======#====
+   >!>)!  >! -  <       +++))!((++))<
    "#"=#  "#====" ===========#======"
 !
=#=================

at that point everything explose, mario is stuck in an infinite loop doing division on bigger and bigger number, forever.

and to fix that we need a way to diferenciate between the first and the second division, it end up that, oh joy, we do have a way

;>>[![              [( [( [<([!)!+(((-<
:"==#======================"==#)#====="
)   -[!)>>[![        [<((((!))< >))) [!(((
)   )"#="==#=========="====#)="="=====#==:
+(  +>) )  +>(+)[!)+))!!:+:)))>[   -[![  <
+(  )-+ )  -"====#====#======)"======#====
+   >!>)!  >! -  <       +++))!((++))<
    "#"=#  "#====" ===========#======"
 !
=#=================

basically we look if the x in

x 0 n d-n%d n%d n/d 

is 0, if it is it mean we are on the first division

else we are on the second division, and we just print the result of the division, add 1 then print it again

and voilà easy as pie.

Ether Frog

Posted 2016-05-24T00:19:12.097

Reputation: 343

Welcome to PPCG! – Erik the Outgolfer – 2016-05-24T12:17:16.863

Doesn't round to the specs provided by the question (of course, I did update it after you posted your answer, but you should at least update your answer to fit the new specs) – InitializeSahib – 2016-05-27T23:39:50.287

Done. while we are talking about test case you should add 10 to have a number that you round down on the fist operation. – Ether Frog – 2016-05-28T23:56:37.913

9

Emotinomicon 99 bytes, 33 characters

,⏬➗➕⏬✖➗⏬➕

Explanation:

                                 clear output
                                 begin quote string
  ,                               
                                 end quote string
                                 duplicate top of stack
                                 duplicate top of stack
                                 take numeric input
                                 duplicate top of stack
                                 pop N and output as a number
                                 reverse stack
          ⏬                       pops and outputs top of stack as character
                                 reverse stack
                                 duplicate top of stack
                                 push 3 to the stack
              ➗                   divide top two elements on stack
               ➕                  add top two elements on stack
                                 duplicate top of stack
                                 pop N and output as a number
                                 reverse stack
                   ⏬              pops and outputs top of stack as character
                                 reverse stack
                                 push 2 to the stack
                      ✖           multiply top two elements on stack
                                 push 3 to the stack
                        ➗         divide top two elements on stack
                                 duplicate top of stack
                                 pop N and output as a number
                                 reverse stack
                            ⏬     pops and outputs top of stack as character
                                 reverse stack
                                 push 1 to the stack
                               ➕  add top two elements on stack
                                 pop N and output as a number

Bálint

Posted 2016-05-24T00:19:12.097

Reputation: 1 847

3Yay for unconventional languages! :P – user48538 – 2016-05-26T19:19:17.603

4

MATL, 14 bytes

Xot4*3/tE3/tQv

Try it Online

Pretty simple, v concatenates the stack into an array. Xo converts to an integer data-type, and all operations thereafter are integer operations.

David

Posted 2016-05-24T00:19:12.097

Reputation: 1 316

3The spec is to return an array, not the final result only. – Value Ink – 2016-05-24T00:27:47.203

3Also lol at those flagging for deletion in <2 minutes :D – David – 2016-05-24T00:36:49.853

@David D: I don't think I can retract deletion votes – Downgoat – 2016-05-24T00:39:07.677

@David upvoted your answer as my condolences :) – InitializeSahib – 2016-05-24T00:48:05.277

Haha I don't really mind, just found it amusing – David – 2016-05-24T00:51:56.320

1I'm pretty sure this isn't a function either, correct me if I'm wrong. – Maltysen – 2016-05-24T01:03:43.943

@Maltysen Maybe you're right, but I can't test it rn. Maybe the OP will give us some info? – InitializeSahib – 2016-05-24T01:05:19.613

@David it's fine then, and your program seems to pass all my checks – InitializeSahib – 2016-05-24T01:06:48.337

4

Cheddar, 27 bytes

b=8/9*$0
[$0,$0+$0/3,b,b+1]

$0 is variable with input. Cheddar just isn't a golfy language ¯\_(ツ)_/¯ , also this is non-competing because Cheddar's input functionality was made after this challenge.

Ungolfed:

IterationB := 8 / 9 * $0  // 8/9ths of the Input
[ $0,                     // The input
  $0 + $0 / 3,            // Input + (Input/3)
  IterationB,             // (see above)
  IterationB + 1          // above + 1
]

Downgoat

Posted 2016-05-24T00:19:12.097

Reputation: 27 116

1Tears of joy! It's gone so far! :D – Conor O'Brien – 2016-05-24T15:44:05.647

3

Java, 86 82 84 85 characters

class c{int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}}

The letter d placed right after an integer makes the integer a double.

Ungolfed:

class c{
    int[] i(int I) {
        int a = I + (I / 3),
            b = (int)(a * (2d / 3d));
        return new int[]{I, a, b, b + 1};
    }
}

Without the class (class c{} is 8 chars long), it downsizes to 76 characters:

int[]i(int I){int a=I+(I/3),b=(int)(a*(2d/3d));return new int[]{I,a,b,b+1};}

More accurate version in 110 chars (118 with the enum) - it uses floats because ain't nobody got space for casting Math#round(double):

int[]i(int I){float a=I+(I/3f),b=(a*(2f/3f));return new int[]{I,Math.round(a),Math.round(b),Math.round(b+1)};}

user8397947

Posted 2016-05-24T00:19:12.097

Reputation: 1 242

I think I should learn Pyth. – user8397947 – 2016-05-24T01:26:49.093

5

+1, because ya know, java

– James – 2016-05-24T01:29:29.167

Since the code is required to be a function, is the enum really necessary? – Mego – 2016-05-24T04:16:36.227

you can remove enum keyword, as requirement is to write a function, and you could remove space between function name and type – user902383 – 2016-05-24T12:49:55.407

What version of Java is this? – Loovjo – 2016-05-24T15:36:53.920

Java has double declarations, right? So you should be able to do 3d, 2d, 3d, etc. Also, I think you can save another 3 bytes by doing a=I*4d/3d right? – Nate Diamond – 2016-05-24T17:05:51.900

@Loovjo Java 5.0 is the oldest release that can compile this. – user8397947 – 2016-05-24T19:25:56.923

1@dorukayhan Weird, I seem to get an error when I'm trying to run this in Eclipse, it can't convert from double to int. I'll see if I can figure out what the problem is tomorrow. – Loovjo – 2016-05-24T19:29:00.423

@Loovjo is right, this code doesn't even compile as you have to cast the doubles to ints. – Frozn – 2016-05-24T20:51:13.050

1I just fixed the code – user8397947 – 2016-05-24T21:09:01.103

1I see but it doesn't give correct results for inputs like 8 or 10. The first addition isn't working properly as I + (I / 3) is using an integer division, meaning that fractions are discarded and thus the result isn't rounded properly. – Frozn – 2016-05-24T22:36:52.003

The error happens because the numbers are ints. If they were doubles, everything would be fine. Also note that I+(I/3) == I+(int)(I/3d) == (int)(I + (I/3d) (because I is an integer, and casting a double to an int or a long simply discards the decimal places (e.g (int) 9.9 is 9, not 10)) - oh wait, I can post an longer but more accurate implementation – user8397947 – 2016-05-24T22:55:49.397

>

  • figures out the accurate implementation in a few minutes*
  • < – user8397947 – 2016-05-24T23:09:26.783

    Yes that's all right but there would be no correct rounding as e.g. (int) (8 + 8 / 3d) == (int) (8 + 2.666) == 10 where as the correct solution would be to round 8+2.6666 to 11. The solution with floats looks correct, but I'm sure that you can shorten it. (I think if we go into more detail we should move that to chat) – Frozn – 2016-05-24T23:11:42.113

    3

    Java, 56 80 Bytes

    As some users pointed out, this solution (as some others in java) does not round data properly. So now I'm presenting slightly longer solution which should return correct result

    int[]h(int a){int[]b={a,Math.round(a+a/3f),a=Math.round(a*8f/9),++a};return b;}
    

    or 60 bytes lamda version

    a->new int[]{a,Math.round(a+a/3f),a=Math.round(a*8f/9),++a}
    

    Golfed version

    int[]g(int a){int[]b={a,a+a/3,a*8/9,a*8/9+1};return b;}
    

    and ungolfed

    int[] g(int a) {
            int[] b = { a, a + a / 3, a * 8 / 9, a * 8 / 9 + 1 };
            return b;
        }
    

    or 36 bytes defined as lambda

    a->new int[]{a,a+a/3,a*8/9,a*8/9+1}
    

    user902383

    Posted 2016-05-24T00:19:12.097

    Reputation: 1 360

    Does not have the rounding required by the Question. – Marv – 2016-05-24T14:47:19.460

    1As @Marv mentioned this question doesn't work correcty, e.g. for input 8 the expected result would be [8,11,7,8] but it is [8,10,7,8] – Frozn – 2016-05-24T20:48:08.363

    why downvote? i fixed it and it working correctly now? – user902383 – 2016-05-25T19:27:30.763

    Sorry for the downvote after you fixed it. The downvote is locked now, so I cannot remove it unless you make some change to your answer (any trivial change is enough) – edc65 – 2016-05-29T20:25:52.283

    @edc65 ok, done – user902383 – 2016-05-29T21:59:27.317

    2

    Java 8 lambda, 109 81 79 75 characters

    Because... you know... even Java can be golfed...

    a->{int b=(int)(.5+a*4./3),c=(int)(.5+b*2./3);return new int[]{a,b,c,++c};}
    

    Lambda ungolfed into class:

    class C {  
       static int[] a(int a) {
            int b = (int) (.5 + a * 4. / 3),
                c = (int) (.5 + b * 2. / 3);
            return new int[]{a, b, c, ++c};
        }
    }
    

    I assume I'm allowed to use longs as they are also an integer type. Sadly one needs to correctly round integers and thus a "short" cast doesn't work. By using longs we don't need to cast the rounding results back to ints.

    Update

    Using the nice little + 0.5 and casting afterwards trick we keep the correct rounding and save 2 chars!

    Also this trick doesn't require the use of long any longer thus we can switch back to ints shaving of 4 more chars.

    Frozn

    Posted 2016-05-24T00:19:12.097

    Reputation: 381

    Welcome to PPCG! – Erik the Outgolfer – 2016-05-24T11:50:47.293

    Thanks :) I followed the questions around here for a while now and I figured that this may be a question which I could participate in though the answer is longer than I expected it to be. – Frozn – 2016-05-24T11:53:48.990

    I'll "+1", hoping you'll add the mandatory "because... you know... Java!" – Olivier Dulac – 2016-05-24T11:59:32.517

    @Frozn I'm not sure if you can remove the a->{ and the final } for -5 bytes. – Erik the Outgolfer – 2016-05-24T12:13:54.457

    @OlivierDulac Not yet :) – Erik the Outgolfer – 2016-05-24T12:14:17.363

    @OlivierDulac added in a slightly different version because I think it fits very good. If I should switch to the standard edition I can do that too. – Frozn – 2016-05-24T12:18:37.040

    @ΈρικΚωνσταντόπουλος I had a look at some other Java answers and they all included the 'lambda definition' thus I think I have to let it there. – Frozn – 2016-05-24T12:20:12.867

    2

    Java, 64 bytes

    int[]f(int i){return new int[]{i,i+=i/3+0.5,i-=i/3-0.5,i+=1.5};}
    

    Notes

    • This has the required rounding build in, not sure if you can do it shorter if mixed with @user902383's solution.

    Ungolfed

    int[] f(int i) {
        return new int[]{
                i, 
                i += i / 3 + 0.5, 
                i -= i / 3 - 0.5, 
                i += 1.5};
    }
    

    Output with i=9

    [9, 12, 8, 9]
    

    Marv

    Posted 2016-05-24T00:19:12.097

    Reputation: 839

    1

    +1. Cuz, ya know, Java

    – user48538 – 2016-05-24T15:04:36.057

    Same as in user902383's solution, this doesn't work correctly, e.g. for 8 expected [8,11,7,8] but is [8,10,7,8], for 6 expected [6,8,5,6] but is [6,8,6,7] – Frozn – 2016-05-24T20:50:03.083

    3

    @Frozn this solution is not working properly as well, and for test cases which you gave return same result as my old solution https://ideone.com/LVK8FU

    – user902383 – 2016-05-25T08:31:40.980

    2

    Scratch, 33 bytes

    Script
    Asks for input, sets a to input rounded, sets b and c to their respective changes, then says all four numbers, seperated by commas.

    weatherman115

    Posted 2016-05-24T00:19:12.097

    Reputation: 605

    1

    Mathematica - 21 bytes

    Just got Mathematica from my brothers RPi, so trying it out for fun, and what better way than a PPCG challenge.

    {#,4#/3,8#/9,8#/9+1}&
    

    Defines an anonymous function. Try it out like:

    In[26]:= x:={#,4#/3,8#/9,8#/9+1}&                                             
    
    In[27]:= x[9]                                                                 
    
    Out[27]= {9, 12, 8, 9}
    

    Maltysen

    Posted 2016-05-24T00:19:12.097

    Reputation: 25 023

    Will this give integers as a result, or fractions? – David – 2016-05-24T01:43:09.787

    @David integers, unless the results are non-integral, in which case fractions. – Maltysen – 2016-05-24T02:05:23.333

    1

    Actually, 21 bytes

    `;;3@/+;32/*;uk1½+♂≈`
    

    This program declares a function that performs the required operations on the top stack value.

    Try it online! (the extra . at the end evaluates the function and prints the result)

    Explanation:

    `;;3@/+;32/*;uk1½+♂≈`
     ;;                    make two copies of x
       3@/+                divide by 3, add that to x to get y
           ;32/*           make a copy of y and multiply by 2/3 to get z
                ;u         make a copy of z and add one
                  k        push stack as a list
                   1½+     add 0.5 to each element
                      ♂≈   apply int() to each element (make integers from floats by flooring; this is equivalent to rounding half-up because of adding 0.5)
    

    Mego

    Posted 2016-05-24T00:19:12.097

    Reputation: 32 998

    1

    Python 3, 45 bytes

    f=lambda i:map(round,[i,i*4/3,i*8/9,i*8/9+1])
    

    See this code running on ideone.com

    Byte Commander

    Posted 2016-05-24T00:19:12.097

    Reputation: 394

    1

    Lua, 52 Bytes

    This program takes a number by command-line argument and return the corresponding array. Programs in lua are technically functions, as the interpreter will always encapsulate them in a function. This is also this mechanic that is used when you "call" codes in other files (it basically uses loadfile/dofile).

    m=math.floor x=...z=m(x*8/9)return{x,m(x*4/3),z,z+1}
    

    Katenkyo

    Posted 2016-05-24T00:19:12.097

    Reputation: 2 857

    1

    05AB1E, 15 bytes

    Code:

    Ð3/+D·3/D>)1;+ï
    

    Uses CP-1252 encoding. Try it online!.

    Adnan

    Posted 2016-05-24T00:19:12.097

    Reputation: 41 965

    1

    Pyke, 11 bytes

    D}[}3/bD)[h
    

    Try it here!

                - implicit input()
    D           - a,b = ^
     }          - b*=2
      [}3/bD)   - macro:
       }        -   tos*=2
        3/      -   tos/=3
          b     -   tos = round(tos)
           D    -   old_tos = tos = tos
                - macro
             [  - macro
              h - d +=1
    

    Blue

    Posted 2016-05-24T00:19:12.097

    Reputation: 26 661

    1

    Mathcad, [tbd] bytes

    enter image description here


    Mathcad codegolf byte equivalance is yet to be determined. Taking a keyboard count as a rough equivalent, the solution is approx 40 bytes.

    Stuart Bruff

    Posted 2016-05-24T00:19:12.097

    Reputation: 501

    1

    C++0x - 95 102 185 189 109 129 chars

    int * n(int p){static int a[3];a[0]=p;a[1]=round(p+(p/3));a[2]=round((a[1]/3)*2);a[3]=a[2]+1;return a;}
    
    • This requires the cmath header to work.

    Degolfed

    #include <cmath>
    int * ninePattern(int p) {
            static int a[3]; // pattern array
            a[0] = p; // sets first iteration
            a[1] = round(p + (p / 3)); // sets second iteration
            a[2] = round((a[1] / 3) * 2); // sets third iteration
            a[3] = a[2] + 1; // sets fourth iteration
            return a; // returns array
    }
    

    InitializeSahib

    Posted 2016-05-24T00:19:12.097

    Reputation: 491

    2Not being a C++ expert but you could shorten it by reusing already calculated values which you have in the array. Also you might be able to remove some white space between ) and { don't know how strict C++ is. – Frozn – 2016-05-24T23:44:14.603

    Are those last two correct in the current version? Because I just saw you calculate p+(p/3)*(2/3) which is p+(2*p/9) instead of (p+(p/3))*(2/3) – Frozn – 2016-05-25T00:00:05.823

    Turns out it was an error on my part. I put - 1 instead of +1 for the last iteration :P – InitializeSahib – 2016-05-31T00:51:15.770

    1

    Javascript, 50 bytes

    I convert my java solution to JavaScript and skimmed it down little bit.

    var r=Math.round,g=a=>[a,r(a+a/3),a=r(a*8/9),++a]
    

    user902383

    Posted 2016-05-24T00:19:12.097

    Reputation: 1 360

    0

    Axiom, 59 bytes

    g(x)==round(x)::INT;f(x)==[x,a:=g(x+x/3.),b:=g(a*2./3),b+1]
    

    test

    (3) -> [[i,f(i)] for i in [9,8,6,23,159]]
       (3)
       [[9,[9,12,8,9]], [8,[8,11,7,8]], [6,[6,8,5,6]], [23,[23,31,21,22]],
        [159,[159,212,141,142]]]
                                                          Type: List List Any
    

    RosLuP

    Posted 2016-05-24T00:19:12.097

    Reputation: 3 036

    0

    PHP, 60 Bytes

    print_r([$a=$argn,$b=round($a+$a/3),$c=round($b*2/3),$c+1]);
    

    Try it online!

    Jörg Hülsermann

    Posted 2016-05-24T00:19:12.097

    Reputation: 13 026

    You can knock off a byte by doing $a*4/3. – jstnthms – 2017-09-08T22:40:44.997

    0

    PHP, 67 bytes

    function f($x){return [$x,$y=round($x*4/3),$z=round($y*2/3),$z+1];}
    

    jstnthms

    Posted 2016-05-24T00:19:12.097

    Reputation: 181

    0

    Erlang, 80 bytes

    -module(f).
    -export([f/1]).
    f(X)->Y=X+(X/3),Z=trunc(Y*(2/3)),[X,trunc(Y),Z,Z+1].
    

    To run, save as f.erl, compile and call the function. It will return a list of ints:

    fxk8y@fxk8y:/home/fxk8y/Dokumente/erlang/pcg# erl
    Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-    threads:10] [kernel-poll:false]
    
    Eshell V7.0  (abort with ^G)
    1> c(f).
    {ok,f}
    2> f:f(9).
    "\t\f\b\t"
    3>
    

    Note that Erlang automatically converts ints to ASCII chars if you are in the ASCII value range because Erlang doesn't have a char type. Calling the function with 100 gives you the better readable [100,133,88,89].

    Ungolfed:

    -module(f).
    -export([f/1]).
    
    f(X) ->
      Y = X+(X/3),
      Z = trunc(Y*(2/3)),
      [X, trunc(Y), Z, Z+1].
    

    fxk8y

    Posted 2016-05-24T00:19:12.097

    Reputation: 19

    0

    Erlang, 46 bytes

    Answer inspired by @fxk8y (I couldn't post a comment to his answer)

    F=fun(X)->Z=round(X*4/9),[X,Z*3,Z*2,Z*2+1]end.
    

    Also you can see the results with:

    2> io:fwrite("~w~n", [F(9)]).                         
    [9,12,8,9]
    ok
    

    Dominik Pawlak

    Posted 2016-05-24T00:19:12.097

    Reputation: 101

    0

    Pyth, 20 bytes

    m.RdZ[Jc*4Q3Kc*2J3hK
    

    Explanation:

                (Implicit print)
    m           For each d in array, d =
    .RdZ        Round d to zero decimal places
    [           The array of
      J         The result of setting J to
        c       The float division of
          *4Q   Input * 4
          3     and 3
                ,
      K         The result of setting K to
        c       The float division of
          *2J   J * 2
          3     and 3
                , and
      hK        K + 1.
                (Implicit end array)
    

    Test here

    RK.

    Posted 2016-05-24T00:19:12.097

    Reputation: 497

    0

    Jolf, 17 bytes

    Ώ‘Hγ+H/H3Βώ/γ3hΒ’
    

    Defines a function Ώ. It takes input implicitly, so it also doubles as a full program. Try it here!

    Conor O'Brien

    Posted 2016-05-24T00:19:12.097

    Reputation: 36 228

    Jolf is becoming ESMin slowly confirmed??? :P – Downgoat – 2016-06-20T04:12:11.997

    @Upgoat ey it's Greek. And midnight again. :P – Conor O'Brien – 2016-06-20T04:13:08.923

    ockquote>

    > oh. Very sorry if I waked you up >>>>

    – Downgoat – 2016-06-20T04:13:49.613

    @Upgoat not asleep yet ;) – Conor O'Brien – 2016-06-20T04:14:22.943

    :| idk if it's good thing I did lent wake you up or bad thing you're still awake – Downgoat – 2016-06-20T04:18:29.767

    0

    Mathematica, 51 bytes

    FoldList[#2@#&,{#,Round[4#/3]&,Round[2#/3]&,#+1&}]&
    

    Anonymous function that conforms to the current (at time of posting) version of post, which implies rounding at every step.

    FoldList is a typical operation in programming. It is invoked as FoldList[f, list] and applies the two-argument function f repeatedly to the result (or the first element of the list in the first iteration), taking the next element of the list as its second argument.

    Ungolfed: #2 @ # & is an anonymous functions that applies its second argument to the first. Therefore, the list argument of FoldList consists of the successive functions to be applied to the input.

    FoldList[#2 @ # &,
      {#, (* note the absence of '&' here, 
             this '#' stands for the argument
             of the complete function and is 
             covered by the & at the end      *)
       Round[4 # / 3] &, (* anonymous function that rounds 4/3 of its input *)
       Round[2 # / 3] &, (* ditto, 2/3 *)
       # + 1 &           (* add one function *)
      }] &               (* and the '&' makes the entire 
                            thing an anonymous function,
                            whose argument is the '#' up
                            at the top.                  *)
    

    Because input is integer and the divisions are by 3, there will never be a result like 4.5, therefore there's no need to worry about rules of rounding when the last digit is a 5: it will always be clearly closer to one integer, or another.

    LLlAMnYP

    Posted 2016-05-24T00:19:12.097

    Reputation: 361

    0

    Dyalog APL, 33 bytes

    (⌽,{1+⊃⍵})∘{⍵,⍨3÷⍨2×⊃⍵}(3÷⍨4∘×),⊢
    

    Adám

    Posted 2016-05-24T00:19:12.097

    Reputation: 37 779

    0

    Desmos, 37 bytes

    a=9
    b=a+\frac{a}{3}
    c=\frac{2}{3}b
    d=c+1
    

    Try it online
    Yay for unconventional languages!

    weatherman115

    Posted 2016-05-24T00:19:12.097

    Reputation: 605

    0

    CJam, 21 bytes

    qi__3d/+mo_2d3/*i_)]`
    

    Feedback is welcome

    Explanation

    • qi__ - Read the input as an integer and duplicate it twice
    • 3D/+mo - Divide one instance of the input by 3, then add it to the second instance to make y
    • _2d3/*i - Duplicate y, then multiply it by .6
    • _)]` - Dupe, increment, wrap in array, print as array (not in code because of the ` operator :( )

    Edit: Forgot to make the first three a double, so the program was broken. Fixed.

    The_Basset_Hound

    Posted 2016-05-24T00:19:12.097

    Reputation: 1 566