text:
Babylon.js - loop through a scene and apply a simple fragment shader to all of the objects
You have a library - a fully loaded 2014 Babylon.js.
You have a fragment shader - let's call it sample.fragment.fx.
You have a scene - loaded ahead of time, possibly from a .babylon JSON file.
Your goal is to assign the fragment shader to every textured object in the scene using a snippet of JavaScript or TypeScript code.
Scoring:
The main multiplier is calculated in the form of one divided by the total number of bytes in the snippet not counting whitespace characters used for formatting.
Additional multipliers (apply one for each condition met) -
*0.5 (bad) - The solution does not reference the "sample" fragment shader by name.
*0.8 (bad) - The solution is presented in TypeScript.
*1.1 (good) - The solution implements a proper for loop (either the for or forEach keyword is used).
*1.2 (good) - The solution intelligently applies the shader only to objects that meet a certain arbitrary criterion, for example: it has texture, or it has a certain prefix in its name.
*1.3 (good) - After all multipliers are applied, the score is greater than 0.008.
This should remain open indefinitely. The highest score wins.

In Javascript
// The suffix of all meshes wich should have the shader applied
var suffix = "shader";

//If true, the shader will be applied on this mesh
var predicate = function(mesh) {
    return (
       mesh.material
       && mesh.name.indexOf(suffix , mesh.name.length - suffix.length) !== -1
    );
};

// Creation of the shader material
var shaderMaterial = new BABYLON.ShaderMaterial("sampleShader", scene, "sample", {
            attributes: ["position"],
            uniforms: ["worldViewProjection"]
            });

// Apply the shader on all meshes
scene.meshes.forEach(function(m) {
    if (predicate(m)) {
        m.material = shaderMaterial;
    }
});

Welcome to PPCG.SE! Please add your score to your answer. :)

Thanks :) How can I do that ?

Well, count the non-whitespace characters. There are some online tools for that. I tend to just copy it into a text editor with regex-replace feature and replace \s by nothing to remove all whitespace, then look at how many bytes are left in the file. That's the base score, then you'll have to apply the scoring mechanism described in the challenge. Also you can of course save quite a few bytes by using single-letter variable names instead of suffix, predicate and shaderMaterial.

Thank you, and you're right about the variables. I didn't know the scoring was about the file size. I will update my solution accordingly.

var t = new BABYLON.ShaderMaterial("sh", scene, "./sample", {
    attributes: ["uv"], uniforms: ["view"]
});

scene.meshes.forEach(function(m) { m.material = m.material && t; });

score : 1/164 * 1.1 (forEach) * 1.2 (material predicate) = 0.00804 * 1.3 = 0.0104

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Palindromic prime
I'm solving task, where:
Input:
A number as an integer.
Output:
The closest greater palindromic prime as an integer.
I would appreciate hints how to make my solution shorter. Or directions if change of approach would be beneficial.
golf=lambda l,r=range:next(x for x in r(10**6)if(x==int(`x`[::-1]))&all(x%d for d in r(2,x))and x>l)

palindromic:
x==int(`x`[::-1])

prime:
all(x%d for d in r(2,x))

Before people close vote this, because it's not a challenge: things like this are on-topic now. The only thing I'm wondering is if this wasn't better suited as two separate questions "How can I make checking for palindromic numbers shorter?" and "How can I make checking for primes shorter?" (@Martin, don't do that though, until you get more feedback confirming this.)

@m.buettner, ok thanks.

Now, for some really big improvements. Your original program was 97 characters:
n=lambda l,r=range:next(x for x in r(10**6)if(x==int(`x`[::-1]))&all(x%d for d in r(2,x))and x>l)

With the improvements below, you could get to 90 characters:
n=lambda l,r=range:min(x for x in r(l+1,10**6)if(`x`==`x`[::-1])&all(x%d for d in r(2,x)))

With a trick to eliminate the parentheses around the palindrome checking statement, you can get to 87:
n=lambda l,r=range:min(x for x in r(l+1,10**4)if`x`==`x`[::-1]*all(x%d for d in r(2,x)))

However, I have a solution in 80 characters. To get it, focus on changing the big picture, not the individual components. Rethink your most basic choices in getting to this point. Why a lambda? Why a min of a filtered range? There may be a better way.

Using int() in the palindrome comparison is a lot of characters - can you see a shorter way to turn
x

and
`x`[::-1]

into the same type?
Also, that and x>l bit at the end is a lot of characters. Is there a way we could shorten it? Eliminate the need for it by changing something else?
Is next the right function for the job? Remember, this is code golf, runtime is irrelevant.
The prime checking function looks spot on, though.
Also, and this is merely aesthetic, I don't like aliasing functions, the way you are doing with range, when it doesn't save any characters, as in this case.

int for x==x[::-1], next for index [0] ...still thinking about and x>l

@MartinRajnoha HINT: take a deeper look into the range function.

Thx, guys I found that :) Current status -10chars. Great!

@MartinRajnoha As a quick reference point, I was able (in my short time golfing down your code) to remove 12 characters.

@BeetDemGuise now you are teasing me :) OK, how did u manage that?

@MartinRajnoha I have a solution with 17 less characters. See edited answer for hints.

@MartinRajnoha ``` is your friend.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/