1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[#1] Skript Challenge - Number Format

Discussion in 'Skript Challenge' started by BaeFell, Jan 30, 2017.

?

Do you like Skript Challenges like this?

Poll closed Feb 9, 2017.
  1. Yes

    41 vote(s)
    78.8%
  2. Kinda, they need work

    7 vote(s)
    13.5%
  3. No

    4 vote(s)
    7.7%
Thread Status:
Not open for further replies.
  1. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Code (Skript):
    1.  
    2. command /skriptchallenge [<text>]:
    3.     trigger:
    4.         if arg-1 is set:
    5.             set {_number::*} to arg-1 split at ""
    6.             loop size of {_number::*} times:
    7.                 add last element of {_number::*} to {_number2::*}
    8.                 set {_last} to size of {_number::*}
    9.                 delete {_number::%{_last}%}
    10.  
    11.  
    12.             set {_time} to 1
    13.             set {_n} to -1
    14.             set {_integer} to ""
    15.             loop {_number2::*}:
    16.                 add 1 to {_n}
    17.                 set {_integer} to "%loop-value%%{_integer}%"
    18.                 if ({_n} / 3) = {_time}:
    19.                     add 1 to {_time}
    20.                     if {_n} + 1 isn't size of {_number2::*}:
    21.                         set {_integer} to ",%{_integer}%"
    22.  
    23.             send "%{_integer}%"
    24.             stop
    25.  
    upload_2017-1-30_9-18-0.png
     
    #21 ShaneBee, Jan 30, 2017
    Last edited by a moderator: Jan 31, 2017
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    i count 5 1's on the end of that number, why's it returning 6 :O
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    5 1's? - - what u mean
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Why does "1234567811111"

    return

    2,345,678,111,111

    it should return

    1,234,567,811,111
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I know :emoji_sob:
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I'm not that much good at math specially when i try to make it in english.. because i'm not english so, i might use your code in some of my skripts (if you don't mind) and i will try to understand it more :emoji_slight_smile: Good work
     
    Tlatoani likes this.
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Code (Text):
    1.  
    2. regex replace "(?<=\d)(?=(\d{3})+(?!\d))" with "," in {_integer}
    3.  
    1 less character :emoji_wink:
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    That's just using regex. Not really using the ability of Skript in any way. I don't really think that the challenge was about that, but it works.
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    This one was about the shortest amount of code. I will however be making some focused on code design instead of character count :emoji_slight_smile:. Those ones I expect will show a completely different type of answer.
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    We don't read rules. Duh.
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    upload_2017-1-30_18-11-46.png
    Edited. now work
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Got in here with high hopes, hoping I've learned something and that I'd be able to join this challenge... saw numbers, saw math, headache hit, too dumb for this. GG, must admit, every code I saw (especially Snow-Pyon's(cuz shortest)) was pretty damn good. Anyone wants to teach me how to math?
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    First you start doing math. Realise it's stupid, and stop.

    That's how.
     
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    You don't really need that much math, just the modulus operator. All you need to do is do a reverse iteration through every char in the string, and when the char you're on is evenly divisible by 3 (I.E. char mod 3 = 0), add a comma.

    An example in Java would be:
    Code (Text):
    1.  
    2.  
    3.     public static String addCommas(String s){
    4.         String ret = "";
    5.         for(int i = s.length() - 1, j = 1; i > -1; i--, j++){//reverse iteration
    6.             ret = s.charAt(i) + ret;
    7.             if (j % 3 == 0){ //if evenly divisble by 3
    8.                 ret = "," + ret;
    9.             }
    10.         }
    11.         return ret;
    12.     }
    13.  
    I would hardly call it difficult, Should be able to do this within your first year of taking a programming course.

    Doing this in skript would be annoying because it doesn't have for loops, but it can be done:

    Code (Text):
    1.  
    2. //assume {s} is the string
    3.     {_ret} = ""
    4.     {_i} = {s}'s length
    5.     {_j} = 1
    6.     while {_i} > 0:
    7.         ret = text of {s} from i to i + {_ret}
    8.         if j mod 3 = 0:
    9.             ret = "'" + {_ret}
    10.         {_i} = i - 1
    11.         {_j} = j + 1
    12.     {s} = {_ret}
    13.     #Keep going
    14.  
    I haven't actually tested the above skript code, but if I didn't make any mistakes and the documentation is correct, it should work.
     
    #34 ShaneBee, Feb 3, 2017
    Last edited by a moderator: Feb 3, 2017
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Math.
     
  16. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    If you want to call basic arithmetic a lot of math, then sure, I guess...
     
  17. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    He's not calling it a lot of math. He was only responding to you stating that you don't need a lot of math, just the modulus operator, while the modulus operator is math.
     
  18. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    That's why I said "You don't really need that much math, just the modulus operator." One operation is not a lot of math, like I said.
     
  19. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Here's my code, with no addons :
    Code (Skript):
    1. set {_r} to "%{_number}%"
    2. set {_t} to ""
    3. loop round up length of {_r} / 3 times:
    4.     set {_l} to the last 3 characters of {_r}
    5.     set {_r} to the first length of {_r} - 3 characters of {_r}
    6.     if loop-number = 1:
    7.         set {_t} to "%{_l}%%{_t}%"
    8.     else:
    9.         set {_t} to "%{_l}%,%{_t}%"
    Formatted number will be in {_t}
     
  20. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Entries close on Monday, at whatever time I get up. I'll try and find the shortest answer but you lot argued about maths so much, I have no idea.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...