|
Post by Josh on Apr 26, 2017 16:10:53 GMT
Output the missing integerYou must generate a string that contains every integer from 0-9 that is missing one of the integers. Your program should then output the missing integer. Your program must not output anything else i.e. multiple newlines or spaces. The string must be created in your code, you are not allowed to take any input. Hard-coded solutions are not allowed.
Examples:
012346789 -> 5 128394507 -> 6 If you do not know where to start, we suggest using the string.match function or the string.find function because it's one character shorter.
Please format your solution as the language name followed by the number of characters that your solution contains before writing out the solution in a code block.
Good luck!
|
|
LittleBigKid
New Member
Veteran
Posts: 11
ROBLOX Username: LittleBigKid2000
|
Post by LittleBigKid on Apr 26, 2017 19:20:03 GMT
Lua, 22 characters (2 spaces, 1 newline)
s = "12346789" print("5")
You never said anything about the string being randomly generated.
|
|
|
Post by Josh on Apr 26, 2017 19:23:49 GMT
Lua, 22 characters (2 spaces, 1 newline) s = "12346789" print("5")
You never said anything about the string being randomly generated. Sorry, I forgot to mention in the post that hard-coded solutions are not allowed. The post has been updated.
|
|
|
Post by 128Gigabytes on Apr 26, 2017 19:33:49 GMT
print(45-load(("return 012356789"):gsub("%d","%1".."+"):sub(0,-2))()) Lua, 69 characters
|
|
LittleBigKid
New Member
Veteran
Posts: 11
ROBLOX Username: LittleBigKid2000
|
Post by LittleBigKid on Apr 26, 2017 19:36:10 GMT
local r = math.random(9) local s = "" for i = 1,9 do if i ~= r then s = s .. tostring(i) end end print(r)
|
|
|
Post by Josh on Apr 26, 2017 19:48:03 GMT
local r = math.random(9) local s = "" for i = 1,9 do if i ~= r then s = s .. tostring(i) end end print(r)
Thanks for attempting to solve the puzzle LittleBigKid! Unfortunately, your solution just outputs the random number given and does the opposite of what is asked for.
|
|
|
Post by goulstem on Apr 26, 2017 21:47:46 GMT
Lua, 285 characters.
local int,found,missing = "012456789",{},{};
for i = 0,9 do found[tostring(i)] = false; end for i in tostring(int):gmatch("%d") do if not found[i] then found[i] = true; end end for i,v in next,found do if not v then missing[#missing+1] = i; end end
print(table.concat(missing,", "));
|
|
|
Post by Bit on Apr 26, 2017 21:48:45 GMT
|
|
|
Post by 128Gigabytes on Apr 26, 2017 22:14:29 GMT
x=0 for z in("012346789"):gmatch("%d")do x=x+z end print(45-x) Lua, 62 characters.
|
|
|
Post by Bit on Apr 26, 2017 22:17:14 GMT
|
|
|
Post by goulstem on Apr 26, 2017 22:30:40 GMT
Heh, didn't think of that Micheal. Neat.
|
|
chimmihc
New Member
Veteran
Posts: 8
ROBLOX Username: chimmihc
|
Post by chimmihc on Apr 27, 2017 12:39:22 GMT
Brainf***, 240 characters.
+++++++++[>+++++<-]>>+>++>+++++>++++++++>>++++++>++++>+++>+++++++++<<<<<<<<[-<->]>[-<<->>]>[-<<<->>>]>[-<<<<->>>>]>[-<<<<<->>>>>]>[-<<<<<<->>>>>>]>[-<<<<<<<->>>>>>>]>[-<<<<<<<<->>>>>>>>]>[-<<<<<<<<<->>>>>>>>>]<<<<<<<<<<++++++++[>++++++<-]>.
Here is the non-minimized version with comments explaining it.
+++++++++
[ load 45
>+++++
<-
]
7 is missing here
>
>+ load 1
>++ load 2
>+++++ load 5
>++++++++ load 8
> load 0
>++++++ load 6
>++++ load 4
>+++ load 3
>+++++++++ load 9
<<<<<<<<
[ subtract first digit
-
<
-
>
]
>
[ subtract second digit
-
<<
-
>>
]
>
[ subtract third digit
-
<<<
-
>>>
]
>
[ subtract fourth digit
-
<<<<
-
>>>>
]
>
[ subtract fifth digit
-
<<<<<
-
>>>>>
]
>
[ subtract sixth digit
-
<<<<<<
-
>>>>>>
]
>
[ subtract seventh digit
-
<<<<<<<
-
>>>>>>>
]
>
[ subtract eighth digit
-
<<<<<<<<
-
>>>>>>>>
]
>
[ subtract ninth digit
-
<<<<<<<<<
-
>>>>>>>>>
]
<<<<<<<<<<
++++++++
[ add 48
>++++++
<-
]
>. print the result
|
|
LittleBigKid
New Member
Veteran
Posts: 11
ROBLOX Username: LittleBigKid2000
|
Post by LittleBigKid on Apr 27, 2017 21:52:40 GMT
Thanks for attempting to solve the puzzle LittleBigKid! Unfortunately, your solution just outputs the random number given and does the opposite of what is asked for. Definitely deliberate, and I definitely understand the puzzle
|
|
|
Post by cntkillme on Apr 27, 2017 22:20:32 GMT
128 you can nitpick yours a bit more to make it 4 characters shorter but that'd be a lame way for me to win. Trying to think of a new short approach
|
|
|
Post by 128Gigabytes on Apr 28, 2017 0:27:57 GMT
128 you can nitpick yours a bit more to make it 4 characters shorter but that'd be a lame way for me to win. Trying to think of a new short approach Hows this Lua, 58 characters
x=0("012346789"):gsub(".",function(z)x=x+z end)print(45-x)
|
|